| | |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.admin.ads.util.PreferredConnection; |
| | | import org.opends.admin.ads.util.ServerLoader; |
| | | import org.opends.guitools.controlpanel.util.ControlPanelLog; |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.opends.quicksetup.ApplicationException; |
| | | import org.opends.quicksetup.Constants; |
| | | import org.opends.quicksetup.QuickSetupLog; |
| | | import org.opends.quicksetup.ReturnCode; |
| | | import org.opends.quicksetup.event.ProgressUpdateEvent; |
| | | import org.opends.quicksetup.event.ProgressUpdateListener; |
| | |
| | | err = new PrintStream(errStream); |
| | | } |
| | | |
| | | try { |
| | | QuickSetupLog.initLogFileHandler( |
| | | File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX), |
| | | ReplicationCliMain.class.getPackage().getName()); |
| | | QuickSetupLog.disableConsoleLogging(); |
| | | try |
| | | { |
| | | ControlPanelLog.initLogFileHandler( |
| | | File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX)); |
| | | } catch (Throwable t) { |
| | | System.err.println("Unable to initialize log"); |
| | | t.printStackTrace(); |
| | | } |
| | | |
| | | ReplicationCliMain replicationCli = new ReplicationCliMain(out, err, |
| | | inStream); |
| | | return replicationCli.execute(args, initializeServer); |
| | |
| | | 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.isInteractive()) |
| | | { |
| | | String subCommand = null; |
| | | switch (promptForSubcommand()) |
| | | { |
| | | case ENABLE: |
| | |
| | | break; |
| | | |
| | | default: |
| | | // User cancelled |
| | | // User canceled |
| | | returnValue = USER_CANCELLED; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Display the log file only if the operation is successful (when there |
| | | // is a critical error this is already displayed). |
| | | if (subcommandLaunched && (returnValue == SUCCESSFUL_NOP)) |
| | | if (subcommandLaunched && (returnValue == SUCCESSFUL) && |
| | | displayLogFileAtEnd(subCommand)) |
| | | { |
| | | File logFile = QuickSetupLog.getLogFile(); |
| | | File logFile = ControlPanelLog.getLogFile(); |
| | | if (logFile != null) |
| | | { |
| | | println(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | return returnValue.getReturnCode(); |
| | | } |
| | | |
| | |
| | | */ |
| | | private ReplicationCliReturnCode enableReplication() |
| | | { |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | ReplicationCliReturnCode returnValue; |
| | | EnableReplicationUserData uData = new EnableReplicationUserData(); |
| | | if (argParser.isInteractive()) |
| | | { |
| | |
| | | */ |
| | | private ReplicationCliReturnCode disableReplication() |
| | | { |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | ReplicationCliReturnCode returnValue; |
| | | DisableReplicationUserData uData = new DisableReplicationUserData(); |
| | | if (argParser.isInteractive()) |
| | | { |
| | |
| | | */ |
| | | private ReplicationCliReturnCode initializeAllReplication() |
| | | { |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | ReplicationCliReturnCode returnValue; |
| | | InitializeAllReplicationUserData uData = |
| | | new InitializeAllReplicationUserData(); |
| | | if (argParser.isInteractive()) |
| | |
| | | */ |
| | | private ReplicationCliReturnCode preExternalInitialization() |
| | | { |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | ReplicationCliReturnCode returnValue; |
| | | PreExternalInitializationUserData uData = |
| | | new PreExternalInitializationUserData(); |
| | | if (argParser.isInteractive()) |
| | |
| | | */ |
| | | private ReplicationCliReturnCode postExternalInitialization() |
| | | { |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | ReplicationCliReturnCode returnValue; |
| | | PostExternalInitializationUserData uData = |
| | | new PostExternalInitializationUserData(); |
| | | if (argParser.isInteractive()) |
| | |
| | | */ |
| | | private ReplicationCliReturnCode statusReplication() |
| | | { |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | ReplicationCliReturnCode returnValue; |
| | | StatusReplicationUserData uData = new StatusReplicationUserData(); |
| | | if (argParser.isInteractive()) |
| | | { |
| | |
| | | */ |
| | | private ReplicationCliReturnCode initializeReplication() |
| | | { |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | ReplicationCliReturnCode returnValue; |
| | | InitializeReplicationUserData uData = new InitializeReplicationUserData(); |
| | | if (argParser.isInteractive()) |
| | | { |
| | |
| | | ADSContext adsContext = new ADSContext(ctx); |
| | | if (adsContext.hasAdminData()) |
| | | { |
| | | Set administrators = adsContext.readAdministratorRegistry(); |
| | | Set<?> administrators = adsContext.readAdministratorRegistry(); |
| | | isAdminDefined = administrators.size() > 0; |
| | | } |
| | | } |
| | |
| | | printProgress(msg); |
| | | printlnProgress(); |
| | | initializeSuffix(baseDN, ctxSource, ctxDestination, true); |
| | | returnValue = SUCCESSFUL; |
| | | } |
| | | catch (ReplicationCliException rce) |
| | | { |
| | |
| | | printProgress(msg); |
| | | println(); |
| | | initializeAllSuffix(baseDN, ctx, true); |
| | | returnValue = SUCCESSFUL; |
| | | } |
| | | catch (ReplicationCliException rce) |
| | | { |
| | |
| | | t); |
| | | } |
| | | } |
| | | returnValue = SUCCESSFUL; |
| | | for (String baseDN : baseDNs) |
| | | { |
| | | try |
| | |
| | | t); |
| | | } |
| | | } |
| | | returnValue = SUCCESSFUL; |
| | | for (String baseDN : baseDNs) |
| | | { |
| | | try |
| | |
| | | } |
| | | try |
| | | { |
| | | NamingEnumeration res = ctx.search(dn, filter, searchControls); |
| | | SearchResult sr = (SearchResult)res.next(); |
| | | NamingEnumeration<SearchResult> res = |
| | | ctx.search(dn, filter, searchControls); |
| | | SearchResult sr = res.next(); |
| | | String logMsg = getFirstValue(sr, "ds-task-log-message"); |
| | | if (logMsg != null) |
| | | { |
| | |
| | | } |
| | | try |
| | | { |
| | | NamingEnumeration res = ctx.search(dn, filter, searchControls); |
| | | SearchResult sr = (SearchResult)res.next(); |
| | | NamingEnumeration<SearchResult> res = |
| | | ctx.search(dn, filter, searchControls); |
| | | SearchResult sr = res.next(); |
| | | |
| | | // Get the number of entries that have been handled and |
| | | // a percentage... |
| | |
| | | { |
| | | MessageBuilder mb = new MessageBuilder(); |
| | | mb.append(rce.getMessageObject()); |
| | | File logFile = QuickSetupLog.getLogFile(); |
| | | File logFile = ControlPanelLog.getLogFile(); |
| | | if ((logFile != null) && |
| | | (rce.getErrorCode() != ReplicationCliReturnCode.USER_CANCELLED)) |
| | | { |
| | |
| | | } |
| | | return isReplicatedInBoth; |
| | | } |
| | | |
| | | private boolean displayLogFileAtEnd(String subCommand) |
| | | { |
| | | String[] subCommands = |
| | | { |
| | | ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME, |
| | | ReplicationCliArgumentParser.DISABLE_REPLICATION_SUBCMD_NAME, |
| | | ReplicationCliArgumentParser.INITIALIZE_ALL_REPLICATION_SUBCMD_NAME, |
| | | ReplicationCliArgumentParser.INITIALIZE_REPLICATION_SUBCMD_NAME}; |
| | | for (String sub : subCommands) |
| | | { |
| | | if (sub.equals(subCommand)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | |