Skip to content

Commit

Permalink
Merge pull request #243 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
Fixes due to the upgraded Spring framework and log4j
  • Loading branch information
ashitsalesforce authored Jan 14, 2021
2 parents 051f5cb + 4380d5c commit afda769
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 81 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.force</groupId>
<artifactId>dataloader</artifactId>
<packaging>jar</packaging>
<version>51.0.0</version>
<version>51.0.1</version>
<name>Data Loader</name>
<url>https://github.com/forcedotcom/dataloader</url>
<organization>
Expand All @@ -14,9 +14,9 @@

<properties>
<short.version>51</short.version>
<force.wsc.version>${version}</force.wsc.version>
<force.partner.api.version>${version}</force.partner.api.version>
<build.year>2020</build.year>
<force.wsc.version>51.0.0</force.wsc.version>
<force.partner.api.version>${force.wsc.version}</force.partner.api.version>
<build.year>2021</build.year>
<java.compile.version>11</java.compile.version>
<minJvmVersion>1.11.0</minJvmVersion>
<codesign>DONTSIGN</codesign>
Expand Down
28 changes: 17 additions & 11 deletions release/win/samples/conf/database-conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,46 @@
<beans>
<bean id="dbDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
destroy-method="close"
scope="prototype">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@my.server.com:1521:dataBaseName"/>
<property name="username" value="user"/>
<property name="password" value="password"/>
</bean>
<bean id="queryAccountAll"
class="com.salesforce.dataloader.dao.database.DatabaseConfig"
singleton="true">
scope="singleton">
<property name="sqlConfig" ref="queryAccountAllSql"/>
<property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="queryAccount"
class="com.salesforce.dataloader.dao.database.DatabaseConfig"
singleton="true">
scope="singleton">
<property name="sqlConfig" ref="queryAccountSql"/>
<property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="insertAccount"
class="com.salesforce.dataloader.dao.database.DatabaseConfig"
singleton="true">
scope="singleton">
<property name="sqlConfig" ref="insertAccountSql"/>
<property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="updateAccount"
class="com.salesforce.dataloader.dao.database.DatabaseConfig"
singleton="true">
scope="singleton">
<property name="sqlConfig" ref="updateAccountSql"/>
<property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="deleteAccountAll"
class="com.salesforce.dataloader.dao.database.DatabaseConfig"
singleton="true">
scope="singleton">
<property name="sqlConfig" ref="deleteAccountAllSql"/>
<property name="dataSource" ref="dbDataSource"/>
</bean>
<bean id="queryAccountAllSql"
class="com.salesforce.dataloader.dao.database.SqlConfig" singleton="true">
class="com.salesforce.dataloader.dao.database.SqlConfig"
scope="singleton">
<property name="sqlString">
<value>
SELECT ACCOUNT_NAME, BUSINESS_PHONE, SFDC_ACCOUNT_ID, ACCOUNT_EXT_ID, ANNUAL_REVENUE, LAST_UPDATED, ACCOUNT_NUMBER
Expand All @@ -59,7 +61,8 @@
</property>
</bean>
<bean id="queryAccountSql"
class="com.salesforce.dataloader.dao.database.SqlConfig" singleton="true">
class="com.salesforce.dataloader.dao.database.SqlConfig"
scope="singleton">
<property name="sqlString">
<value>
SELECT ACCOUNT_NAME, BUSINESS_PHONE, ACCOUNT_EXT_ID, ANNUAL_REVENUE, LAST_UPDATED, ACCOUNT_NUMBER
Expand All @@ -85,7 +88,8 @@
</bean>
<!--- this is for updating Customers in Oracle based on SFDC Accounts -->
<bean id="updateAccountSql"
class="com.salesforce.dataloader.dao.database.SqlConfig" singleton="true">
class="com.salesforce.dataloader.dao.database.SqlConfig"
scope="singleton">
<property name="sqlString">
<value>
update TableOwner.Accounts accounts
Expand All @@ -110,7 +114,8 @@
</property>
</bean>
<bean id="insertAccountSql"
class="com.salesforce.dataloader.dao.database.SqlConfig" singleton="true">
class="com.salesforce.dataloader.dao.database.SqlConfig"
scope="singleton">
<property name="sqlString">
<value>
INSERT INTO TableOwner.Accounts (
Expand All @@ -130,7 +135,8 @@
</property>
</bean>
<bean id="deleteAccountAllSql"
class="com.salesforce.dataloader.dao.database.SqlConfig" singleton="true">
class="com.salesforce.dataloader.dao.database.SqlConfig"
scope="singleton">
<property name="sqlString">
<value>
DELETE FROM TableOwner.Accounts
Expand Down
56 changes: 23 additions & 33 deletions release/win/samples/conf/log-conf.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="A1" class="org.apache.log4j.FileAppender">
<param name="File" value="${java.io.tmpdir}/sdl.log" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %-5p [%t] %C{2} %M (%F:%L) - %m%n"/>
</layout>
</appender>
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %-5p [%t] %C{2} %M (%F:%L) - %m%n"/>
</layout>
</appender>

<category name="org.apache.log4j.xml">
<priority value="warn" />
<appender-ref ref="A1" />
<appender-ref ref="STDOUT" />
</category>

<logger name="org.apache" >
<level value ="warn" />
<configuration>
<appenders>
<File name="A1" fileName="${sys:java.io.tmpdir}/sdl.log" append="false">
<PatternLayout pattern="%d %-5p [%t] %C{2} %M (%F:%L) - %m%n"/>
</File>
<CONSOLE name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %C{2} %M (%F:%L) - %m%n"/>
</CONSOLE>
</appenders>
<loggers>
<logger name="org.apache.log4j.xml" level="warn">
<appender-ref ref="A1"/>
<AppenderRef ref="STDOUT" />
</logger>

<root>
<priority value ="@LOG_LEVEL@" />
<appender-ref ref="A1" />
<appender-ref ref="STDOUT" />
</root>
</log4j:configuration>

<logger name="org.apache" level="warn">
<appender-ref ref="A1"/>
<AppenderRef ref="STDOUT" />
</logger>
<root level="@LOG_LEVEL@">
<AppenderRef ref="A1"/>
<AppenderRef ref="STDOUT" />
</root>
</loggers>
</configuration>
8 changes: 4 additions & 4 deletions release/win/samples/conf/process-conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<beans>
<bean id="accountMasterProcess"
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
scope="prototype">
<description>AccountMaster job gets the Customer record updates from ERP (Oracle financials) and uploads them to salesforce using 'upsert'.</description>
<property name="name" value="accountMasterProcess"/>
<property name="configOverrideMap">
Expand All @@ -29,7 +29,7 @@
</bean>
<bean id="opportunityUpsertProcess"
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
scope="prototype">
<description>Opportunity Upsert job gets the Customer record updates from a CSV file and uploads them to salesforce using 'upsert'.</description>
<property name="name" value="opportunityUpsertProcess"/>
<property name="configOverrideMap">
Expand All @@ -54,7 +54,7 @@
</bean>
<bean id="databaseAccountExtractProcess"
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
scope="prototype">
<description>DatabaseAccountExtract job gets account info from salesforce and updates or inserts info into database."</description>
<property name="name" value="databaseAccountExtract"/>
<property name="configOverrideMap">
Expand All @@ -80,7 +80,7 @@
</bean>
<bean id="csvAccountExtractProcess"
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
scope="prototype">
<description>csvAccountExtract job gets account info from salesforce and saves info into a CSV file."</description>
<property name="name" value="csvAccountExtract"/>
<property name="configOverrideMap">
Expand Down
41 changes: 31 additions & 10 deletions src/main/java/com/salesforce/dataloader/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Controller {
private static final String LOG_CONF_OVERRIDE = "log-conf.xml";

private static boolean isLogInitialized = false; // make sure log is initialized only once
private static boolean areStaticVarsInitialized = false; // make sure log is initialized only once

/**
* the system property name used to determine the config directory
Expand Down Expand Up @@ -146,8 +147,11 @@ private String getConfigDirFromArgMap(String[] args) {
argNameValuePair.get(CONFIG_DIR_PROP) : null;
}

public static void initStaticVariable() throws ControllerInitializationException {
Properties versionProps = new Properties();
private static synchronized void initStaticVariable() throws ControllerInitializationException {
if (areStaticVarsInitialized) {
return;
}
Properties versionProps = new Properties();
try {
versionProps.load(Controller.class.getClassLoader().getResourceAsStream("com/salesforce/dataloader/version.properties"));
} catch (IOException e) {
Expand All @@ -158,11 +162,16 @@ public static void initStaticVariable() throws ControllerInitializationException
// FIXME clean this up, make static
// dataloader version has 3 parts, salesforce app api version should match first two parts
APP_VERSION = versionProps.getProperty("dataloader.version");
String[] dataloaderVersion = APP_VERSION.split("\\.");
API_VERSION = dataloaderVersion[0] + "." + dataloaderVersion[1];
String apiVersionStr = versionProps.getProperty("dataloader.apiversion");
if ( apiVersionStr == null || apiVersionStr.isEmpty()) {
apiVersionStr = APP_VERSION;
}
String[] apiVersion = apiVersionStr.split("\\.");
API_VERSION = apiVersion[0] + "." + apiVersion[1];


OS_TYPE = AppUtil.getOSType();
areStaticVarsInitialized = true;
}

public void setConfigDefaults() {
Expand Down Expand Up @@ -458,23 +467,35 @@ private static String getProductName() {
return APP_NAME + " " + APP_VERSION;
}

public static synchronized void initLog() throws FactoryConfigurationError {

public static synchronized void initLog() throws FactoryConfigurationError, ControllerInitializationException {
// init the log if not initialized already
if (Controller.isLogInitialized) {
return;
}

File logConfXml = Paths.get(System.getProperty("user.dir"), "configs", LOG_CONF_OVERRIDE).toFile();
if (logConfXml.exists()) {
System.setProperty("log4j.configurationFile", logConfXml.getAbsolutePath());
try {
initStaticVariable();
} catch (ControllerInitializationException ex) {
System.out.println("Controller.initLog(): Unable to initialize Controller static vars: " + ex.getMessage());
throw ex;
}

String log4jConfigFile = System.getenv(
"LOG4J_CONFIGURATION_FILE");
if (log4jConfigFile == null || log4jConfigFile.isEmpty()) { // use the override
File logConfXml = Paths.get(System.getProperty("user.dir"), "configs", LOG_CONF_OVERRIDE).toFile();
log4jConfigFile = logConfXml.getAbsolutePath();
if (logConfXml.exists()) {
System.setProperty("log4j2.configurationFile", log4jConfigFile);
}
}

logger = LogManager.getLogger(Controller.class);
LoggerContext context = (LoggerContext) LogManager.getContext();
String logConfigLocation = context.getConfiguration().getConfigurationSource().getLocation();
if (logConfigLocation == null) {
logger.error("Unable to initialize logging using log4j2 config file at "
+ logConfXml.getAbsolutePath()
+ log4jConfigFile
+ ". All error messages will be logged on STDOUT.");
} else {
logger.info("Using log4j2 configuration file at location: " + logConfigLocation);
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/com/salesforce/dataloader/process/ProcessRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class ProcessRunner implements InitializingBean, Job, Runnable {
public static final String PROCESS_NAME = "process.name";

//logger
private static final Logger logger = LogManager.getLogger(ProcessRunner.class);
private static final Logger logger;

// Name of the current engine runner. Improves readability of the log output
String name;
Expand All @@ -98,6 +98,15 @@ public class ProcessRunner implements InitializingBean, Job, Runnable {

private Controller controller;

static {
try {
Controller.initLog();
} catch (ControllerInitializationException e) {
System.out.println("ProcessRunner: Controller not initialized" + e );
throw new RuntimeException(e.getMessage());
}
logger = LogManager.getLogger(ProcessRunner.class);
}
/**
* Enforce use of factory method - getInstance() by hiding the constructor
*/
Expand Down Expand Up @@ -178,16 +187,6 @@ public synchronized void run(ILoaderProgress monitor) {
}
}

private static void ensureLogging() throws FactoryConfigurationError {
try {
Controller.initStaticVariable();
} catch (ControllerInitializationException e) {
logger.error("ensureLogging(): Control not initialized", e );
throw new RuntimeException(e.getMessage());
}
Controller.initLog();
}

private void setThreadName(final String name) {
if (name != null && name.length() > 0) {
try {
Expand Down Expand Up @@ -249,7 +248,6 @@ private static boolean validateCmdLineArgs (String[] args) {
}

private static void topLevelError(String message, Throwable err) {
ensureLogging();
logger.fatal(message, err);
System.exit(-1);
}
Expand Down Expand Up @@ -278,8 +276,6 @@ public static void main(String[] args) {
* @throws ProcessInitializationException
*/
private static ProcessRunner getInstance(String[] args) throws ProcessInitializationException {
ensureLogging();

if(!validateCmdLineArgs(args)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,30 @@
import org.apache.logging.log4j.LogManager;

import com.salesforce.dataloader.controller.Controller;
import com.salesforce.dataloader.exception.ControllerInitializationException;

/**
* Abstract class that should be extended to manage
* Processes for a specific application that needs
* sheduled processes.
*/
public class ProcessScheduler extends Timer {

/** Instance of this class so it can be called from the command line */
protected static ProcessScheduler processScheduler;

/** Log4J */
private static Logger logger = LogManager.getLogger(ProcessScheduler.class);

private static Logger logger;
static {
try {
Controller.initLog();
} catch (ControllerInitializationException e) {
System.out.println("ProcessScheduler: Controller not initialized" + e );
throw new RuntimeException(e.getMessage());
}
logger = LogManager.getLogger(ProcessScheduler.class);
}

public ProcessScheduler() {
Controller.initLog();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dataloader.name = ${project.name}
dataloader.version = ${project.version}
dataloader.vendor = ${organization.name}
dataloader.vendor = ${organization.name}
dataloader.apiversion = ${force.partner.api.version}

0 comments on commit afda769

Please sign in to comment.