* The configuration file is test_etl_config.xml which is expected to be under APP_HOME/config *
test_etl_config.xml
* The ETL scenario is APP_HOME/data/scenario/Examples/engine/db2file.xml. It is configured to extract data from 3 tables in the java db * database and use it to create json files. It can create files in any supported format without any scenario * modification. *
* Data are streamed from the source database to the destination which means the memory consumption is minimal. *
* There are no input files. Output files are: APP_HOME/data/EMPLOYEE.json, APP_HOME/data/CONFIG_PROPERTY.json and * APP_HOME/data/CONFIG_VALUE.json *
* The logger is manually set to the INFO mode which increases verbosity of the etl engine. * */ public class LoadScenarioAndConfigurationFromFile { /** * Configures ETL engine and executes ETL scenario. * * @param args the command line arguments */ public static void main(String[] args) { LoadScenarioAndConfigurationFromFile engine = new LoadScenarioAndConfigurationFromFile(); try { // instantiates ETL configuration EtlConfig etlConfig = new EtlConfig(); // set log level to INFO which increases verbosity of the etl engine Logger.setLevel(EtlLogger.class, Logger.INFO); // creates embedded ETL process EtlProcess etlProcess = new EtlProcess(EtlProcess.EtlMode.EMBEDDED); // print out framework version System.out.println(SystemConfig.instance().getTitle( EtlConfig.DEFAULT_TITLE) + " " + SystemConfig.instance().getSystemProperty( SystemConfig.VERSION)); // load configuration which contains source and destination // connections and ETL scenario name. Load and execute ETL scenario. // If no full path // provided the configuration file test_etl_config.xml is expected // to be under app_home/config EtlResponse response = engine.loadConfigAndExecute(etlConfig, "test_etl_config.xml", etlProcess); // print out formatted output from the ETL response System.out.println(engine.getMessage(response, "Exampes/Engine/db2file.xml")); } catch (Exception ex) { System.out.println(Utils.getStackTraceAsString(ex)); } System.exit(0); } /** * Creates the formatted message from the ETL response * * @param response the ETl response * @param scenarioName the ETL scenario name * * @return formatted message from the ETL response */ private String getMessage(EtlResponse response, String scenarioName) { String msg = ""; String start = response != null ? response.getStartTime().toString() : new Date().toString(); String end = response != null && response.getEndTime() != null ? response .getEndTime().toString() : new Date().toString(); String diff = response != null ? String .valueOf(Utils.getDateDiff(response.getEndTime(), response.getStartTime(), Calendar.SECOND)) : "0"; if (response.getRetCode() == EtlConfig.RETURN_OK) { msg = Utils .format("\n" + EtlResource.FINISH_SUCCESS_MSG.getValue() + "\n" + "Scenario name: %1" + "\n" + "Started at %2, finished at %3, total execution time %4 seconds.", scenarioName, start, end, diff); if (!Utils.isNothing(response.getWarnings())) { msg = msg + "\n" + EtlResource.WARING_NOTHING_WAS_EXECUTED.getValue(); } } else if (response.getRetCode() == EtlConfig.RETURN_NO_DRIVERS) { msg = "\n" + EtlResource.NO_DRIVERS_MSG.getValue(); } else { msg = Utils .format("\n" + EtlResource.FINISH_ERROR_MSG.getValue() + "\n" + "Scenario name: %1" + "\n" + "Started at %2, finished at %3, total execution time %4 seconds.", scenarioName, start, end, diff) + "\n" + Utils.getStackTraceAsString(response.getException()); } return msg; } /** * Loads ETL configuration file using given name. Creates connections for the ETL process * by parsing configuration file. Executes ETL scenario specified in the ETL configuration file. * @param config the ETl config * @param configFileName the ETL config file name * @param etlProcess the ETL process * @return ETl response * @throws Exception in case of any error */ private EtlResponse loadConfigAndExecute(EtlConfig config, String configFileName, EtlProcess etlProcess) throws Exception { // loads specified configuration file // from the default folder: APP_HOME/config. Creates connections and // loads scenario in process. if (!config.initConfigXml(configFileName)) { System.out.println("Cannot read " + config.getXmlConfigFileName() + ". Check log for details."); System.exit(0); } // executes ETL scenario specified in the configuration file return etlProcess.execute(config); } }