*
* @return The error code.
*/
public int execute(String[] args, boolean initializeServer)
{
ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP;
// Create the command-line argument parser for use with this
// program.
try
{
createArgumenParser();
}
catch (ArgumentException ae)
{
Message message =
ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
println(message);
LOG.log(Level.SEVERE, "Complete error stack:", ae);
returnValue = CANNOT_INITIALIZE_ARGS;
}
if (returnValue == SUCCESSFUL_NOP)
{
try
{
argParser.getSecureArgsList().initArgumentsWithConfiguration();
}
catch (ConfigException ce)
{
// Ignore.
}
// Parse the command-line arguments provided to this program.
try
{
argParser.parseArguments(args);
}
catch (ArgumentException ae)
{
Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
println(message);
println();
println(Message.raw(argParser.getUsage()));
LOG.log(Level.SEVERE, "Complete error stack:", ae);
returnValue = ERROR_USER_DATA;
}
}
if (!argParser.usageOrVersionDisplayed())
{
if (returnValue == SUCCESSFUL_NOP)
{
/* Check that the provided parameters are compatible.
*/
MessageBuilder buf = new MessageBuilder();
argParser.validateOptions(buf);
if (buf.length() > 0)
{
println(buf.toMessage());
println(Message.raw(argParser.getUsage()));
returnValue = ERROR_USER_DATA;
}
}
if (initializeServer && returnValue == SUCCESSFUL_NOP)
{
DirectoryServer.bootstrapClient();
// Bootstrap definition classes.
try
{
if (!ClassLoaderProvider.getInstance().isEnabled())
{
ClassLoaderProvider.getInstance().enable();
}
// Switch off class name validation in client.
ClassPropertyDefinition.setAllowClassValidation(false);
// Switch off attribute type name validation in client.
AttributeTypePropertyDefinition.setCheckSchema(false);
}
catch (InitializationException ie)
{
println(ie.getMessageObject());
returnValue = ERROR_INITIALIZING_ADMINISTRATION_FRAMEWORK;
}
}
if (returnValue == SUCCESSFUL_NOP)
{
if (argParser.getSecureArgsList().
bindPasswordFileArg.isPresent())
{
try
{
userProvidedAdminPwdFile = new FileBasedArgument(
"adminPasswordFile",
OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
userProvidedAdminPwdFile.getNameToValueMap().putAll(
argParser.getSecureArgsList().
bindPasswordFileArg.getNameToValueMap());
}
catch (Throwable t)
{
throw new IllegalStateException("Unexpected error: "+t, t);
}
}
ci = new LDAPConnectionConsoleInteraction(this,
argParser.getSecureArgsList());
ci.setDisplayLdapIfSecureParameters(false);
}
if (returnValue == SUCCESSFUL_NOP)
{
boolean subcommandLaunched = true;
String subCommand = null;
if (argParser.isEnableReplicationSubcommand())
{
returnValue = enableReplication();
subCommand =
ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME;
}
else if (argParser.isDisableReplicationSubcommand())
{
returnValue = disableReplication();
subCommand =
ReplicationCliArgumentParser.DISABLE_REPLICATION_SUBCMD_NAME;
}
else if (argParser.isInitializeReplicationSubcommand())
{
returnValue = initializeReplication();
subCommand =
ReplicationCliArgumentParser.INITIALIZE_REPLICATION_SUBCMD_NAME;
}
else if (argParser.isInitializeAllReplicationSubcommand())
{
returnValue = initializeAllReplication();
subCommand =
ReplicationCliArgumentParser.INITIALIZE_ALL_REPLICATION_SUBCMD_NAME;
}
else if (argParser.isPreExternalInitializationSubcommand())
{
returnValue = preExternalInitialization();
subCommand =
ReplicationCliArgumentParser.PRE_EXTERNAL_INITIALIZATION_SUBCMD_NAME;
}
else if (argParser.isPostExternalInitializationSubcommand())
{
returnValue = postExternalInitialization();
subCommand =
ReplicationCliArgumentParser.POST_EXTERNAL_INITIALIZATION_SUBCMD_NAME;
}
else if (argParser.isStatusReplicationSubcommand())
{
returnValue = statusReplication();
subCommand =
ReplicationCliArgumentParser.STATUS_REPLICATION_SUBCMD_NAME;
}
else if (argParser.isPurgeHistoricalSubcommand())
{
returnValue = purgeHistorical();
subCommand =
ReplicationCliArgumentParser.PURGE_HISTORICAL_SUBCMD_NAME;
}
else
{
if (argParser.isInteractive())
{
switch (promptForSubcommand())
{
case ENABLE:
subCommand =
ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME;
break;
case DISABLE:
subCommand =
ReplicationCliArgumentParser.DISABLE_REPLICATION_SUBCMD_NAME;
break;
case INITIALIZE:
subCommand =
ReplicationCliArgumentParser.INITIALIZE_REPLICATION_SUBCMD_NAME;
break;
case INITIALIZE_ALL:
subCommand =
ReplicationCliArgumentParser.
INITIALIZE_ALL_REPLICATION_SUBCMD_NAME;
break;
case PRE_EXTERNAL_INITIALIZATION:
subCommand = ReplicationCliArgumentParser.
PRE_EXTERNAL_INITIALIZATION_SUBCMD_NAME;
break;
case POST_EXTERNAL_INITIALIZATION:
subCommand = ReplicationCliArgumentParser.
POST_EXTERNAL_INITIALIZATION_SUBCMD_NAME;
break;
case STATUS:
subCommand =
ReplicationCliArgumentParser.STATUS_REPLICATION_SUBCMD_NAME;
break;
case PURGE_HISTORICAL:
subCommand =
ReplicationCliArgumentParser.PURGE_HISTORICAL_SUBCMD_NAME;
break;
default:
// User canceled
returnValue = USER_CANCELLED;
}
if (subCommand != null)
{
String[] newArgs = new String[args.length + 1];
newArgs[0] = subCommand;
for (int i=0; i<args.length ; i++)
{
newArgs[i+1] = args[i];
}
// The server (if requested) has already been initialized.
return execute(newArgs, false);
}
}
else
{
println(ERR_REPLICATION_VALID_SUBCOMMAND_NOT_FOUND.get(
"--"+ToolConstants.OPTION_LONG_NO_PROMPT));
println(Message.raw(argParser.getUsage()));
returnValue = ERROR_USER_DATA;
subcommandLaunched = false;
}
}
// Display the log file only if the operation is successful (when there
// is a critical error this is already displayed).
if (subcommandLaunched && (returnValue == SUCCESSFUL) &&
displayLogFileAtEnd(subCommand))
{
File logFile = ControlPanelLog.getLogFile();
if (logFile != null)
{
println();
println(INFO_GENERAL_SEE_FOR_DETAILS.get(logFile.getPath()));
println();
}
}
}
}
return returnValue.getReturnCode();
}