From 78829b320c27a50a4b28e92f3a8d35096d4b2c56 Mon Sep 17 00:00:00 2001 From: Ashit Patel Date: Tue, 12 Jan 2021 10:48:03 -0800 Subject: [PATCH 1/2] Fixes due to the upgraded Spring framework and log4j Fixes include: - New syntax for log-conf.xml, process-conf.xml, and database-conf.xml in samples folder necessiated by Spring framework and log4j upgrades. - Fixes in ProcessRunner and ProcessScheduler necessiated by log4j framework upgrade - Controller.initlog() needs to be invoked before instantiating a logger through LogManager.getLogger() call. - Fixes in Controller.java and version.properties to decouple data loader versioning from the API version used for partner API. --- pom.xml | 8 +-- release/win/samples/conf/database-conf.xml | 28 ++++++---- release/win/samples/conf/log-conf.xml | 56 ++++++++----------- release/win/samples/conf/process-conf.xml | 8 +-- .../dataloader/controller/Controller.java | 41 ++++++++++---- .../dataloader/process/ProcessRunner.java | 24 ++++---- .../dataloader/process/ProcessScheduler.java | 16 ++++-- .../salesforce/dataloader/version.properties | 3 +- 8 files changed, 103 insertions(+), 81 deletions(-) diff --git a/pom.xml b/pom.xml index b21ad717..0bb9c818 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.force dataloader jar - 51.0.0 + 51.0.1 Data Loader https://github.com/forcedotcom/dataloader @@ -14,9 +14,9 @@ 51 - ${version} - ${version} - 2020 + ${short.version}.0.0 + ${force.wsc.version} + 2021 11 1.11.0 DONTSIGN diff --git a/release/win/samples/conf/database-conf.xml b/release/win/samples/conf/database-conf.xml index 7d0f4211..500b31d9 100644 --- a/release/win/samples/conf/database-conf.xml +++ b/release/win/samples/conf/database-conf.xml @@ -2,7 +2,8 @@ + destroy-method="close" + scope="prototype"> @@ -10,36 +11,37 @@ + scope="singleton"> + scope="singleton"> + scope="singleton"> + scope="singleton"> + scope="singleton"> + class="com.salesforce.dataloader.dao.database.SqlConfig" + scope="singleton"> SELECT ACCOUNT_NAME, BUSINESS_PHONE, SFDC_ACCOUNT_ID, ACCOUNT_EXT_ID, ANNUAL_REVENUE, LAST_UPDATED, ACCOUNT_NUMBER @@ -59,7 +61,8 @@ + class="com.salesforce.dataloader.dao.database.SqlConfig" + scope="singleton"> SELECT ACCOUNT_NAME, BUSINESS_PHONE, ACCOUNT_EXT_ID, ANNUAL_REVENUE, LAST_UPDATED, ACCOUNT_NUMBER @@ -85,7 +88,8 @@ + class="com.salesforce.dataloader.dao.database.SqlConfig" + scope="singleton"> update TableOwner.Accounts accounts @@ -110,7 +114,8 @@ + class="com.salesforce.dataloader.dao.database.SqlConfig" + scope="singleton"> INSERT INTO TableOwner.Accounts ( @@ -130,7 +135,8 @@ + class="com.salesforce.dataloader.dao.database.SqlConfig" + scope="singleton"> DELETE FROM TableOwner.Accounts diff --git a/release/win/samples/conf/log-conf.xml b/release/win/samples/conf/log-conf.xml index 1ce23047..05697e05 100644 --- a/release/win/samples/conf/log-conf.xml +++ b/release/win/samples/conf/log-conf.xml @@ -1,35 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + diff --git a/release/win/samples/conf/process-conf.xml b/release/win/samples/conf/process-conf.xml index c84b4b2a..c69fe672 100644 --- a/release/win/samples/conf/process-conf.xml +++ b/release/win/samples/conf/process-conf.xml @@ -2,7 +2,7 @@ + scope="prototype"> AccountMaster job gets the Customer record updates from ERP (Oracle financials) and uploads them to salesforce using 'upsert'. @@ -29,7 +29,7 @@ + scope="prototype"> Opportunity Upsert job gets the Customer record updates from a CSV file and uploads them to salesforce using 'upsert'. @@ -54,7 +54,7 @@ + scope="prototype"> DatabaseAccountExtract job gets account info from salesforce and updates or inserts info into database." @@ -80,7 +80,7 @@ + scope="prototype"> csvAccountExtract job gets account info from salesforce and saves info into a CSV file." diff --git a/src/main/java/com/salesforce/dataloader/controller/Controller.java b/src/main/java/com/salesforce/dataloader/controller/Controller.java index d12d9b3c..ad5b3a7f 100644 --- a/src/main/java/com/salesforce/dataloader/controller/Controller.java +++ b/src/main/java/com/salesforce/dataloader/controller/Controller.java @@ -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 @@ -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) { @@ -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() { @@ -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); diff --git a/src/main/java/com/salesforce/dataloader/process/ProcessRunner.java b/src/main/java/com/salesforce/dataloader/process/ProcessRunner.java index a8494c85..fb1d448e 100644 --- a/src/main/java/com/salesforce/dataloader/process/ProcessRunner.java +++ b/src/main/java/com/salesforce/dataloader/process/ProcessRunner.java @@ -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; @@ -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 */ @@ -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 { @@ -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); } @@ -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; } diff --git a/src/main/java/com/salesforce/dataloader/process/ProcessScheduler.java b/src/main/java/com/salesforce/dataloader/process/ProcessScheduler.java index f7c05b6e..724830bb 100644 --- a/src/main/java/com/salesforce/dataloader/process/ProcessScheduler.java +++ b/src/main/java/com/salesforce/dataloader/process/ProcessScheduler.java @@ -56,6 +56,7 @@ 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 @@ -63,15 +64,22 @@ * 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(); } /** diff --git a/src/main/resources/com/salesforce/dataloader/version.properties b/src/main/resources/com/salesforce/dataloader/version.properties index 4970a840..91ca6708 100644 --- a/src/main/resources/com/salesforce/dataloader/version.properties +++ b/src/main/resources/com/salesforce/dataloader/version.properties @@ -1,3 +1,4 @@ dataloader.name = ${project.name} dataloader.version = ${project.version} -dataloader.vendor = ${organization.name} \ No newline at end of file +dataloader.vendor = ${organization.name} +dataloader.apiversion = ${force.partner.api.version} From 4380d5cce42cb3f1aa33d7ece630cfcdd9bb2eb6 Mon Sep 17 00:00:00 2001 From: Ashit Patel Date: Tue, 12 Jan 2021 15:48:12 -0800 Subject: [PATCH 2/2] Explicitly set WSC version and consequently partner API version. Decouple versioning of data loader installation artifects from that of WSC and Partner API. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0bb9c818..b14ec605 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 51 - ${short.version}.0.0 + 51.0.0 ${force.wsc.version} 2021 11