options.addOption(sourceIdOption);
options.addOption(dbOption);
options.addOption(cmdLinePropsOption);
options.addOption(log4jPropsOption);
CommandLine cmd = null;
try
{
cmd = cliParser.parse(options, args);
}
catch (ParseException pe)
{
LOG.error("Bootstrap Physical Config: failed to parse command-line options.", pe);
throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
}
if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR))
{
String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
PropertyConfigurator.configure(log4jPropFile);
LOG.info("Using custom logging settings from file " + log4jPropFile);
}
else
{
PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(defaultAppender);
LOG.info("Using default logging settings");
}
if (cmd.hasOption(HELP_OPT_CHAR))
{
printCliHelp(options);
System.exit(0);
}
if ( !cmd.hasOption(SOURCE_ID_OPT_CHAR))
throw new RuntimeException("Source ID is not provided");
if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR) )
throw new RuntimeException("Bootstrap config is not provided");
String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile);
_sBootstrapConfigProps = new Properties();
FileInputStream f = new FileInputStream(propFile);
try
{
_sBootstrapConfigProps.load(f);
} finally {
f.close();
}
if (cmd.hasOption(CMD_LINE_PROPS_OPT_CHAR))
{
String cmdLinePropString = cmd.getOptionValue(CMD_LINE_PROPS_OPT_CHAR);
updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
}
return Integer.parseInt(cmd.getOptionValue(SOURCE_ID_OPT_CHAR));
}