| | |
| | | import org.opends.server.types.OpenDsException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.backends.task.TaskState; |
| | | import org.opends.server.backends.task.FailedDependencyAction; |
| | | import org.opends.messages.Message; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | |
| | | import java.util.Set; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.LinkedList; |
| | | import java.util.EnumSet; |
| | | import java.util.Collections; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | |
| | | // Argument for describing the task's start time |
| | | StringArgument startArg; |
| | | |
| | | // Argument for specifying completion notifications |
| | | StringArgument completionNotificationArg; |
| | | |
| | | // Argument for specifying error notifications |
| | | StringArgument errorNotificationArg; |
| | | |
| | | // Argument for specifying dependency |
| | | StringArgument dependencyArg; |
| | | |
| | | // Argument for specifying a failed dependency action |
| | | StringArgument failedDependencyActionArg; |
| | | |
| | | // Client for interacting with the task backend |
| | | TaskClient taskClient; |
| | | |
| | | /** |
| | | * Called when this utility should perform its actions locally in this |
| | | * JVM. |
| | |
| | | null, null, |
| | | INFO_DESCRIPTION_START_DATETIME.get()); |
| | | argParser.addArgument(startArg, taskGroup); |
| | | |
| | | completionNotificationArg = new StringArgument( |
| | | OPTION_LONG_COMPLETION_NOTIFICATION_EMAIL, |
| | | OPTION_SHORT_COMPLETION_NOTIFICATION_EMAIL, |
| | | OPTION_LONG_COMPLETION_NOTIFICATION_EMAIL, |
| | | false, true, true, OPTION_VALUE_EMAIL_ADDRESS, |
| | | null, null, INFO_DESCRIPTION_TASK_COMPLETION_NOTIFICATION.get()); |
| | | argParser.addArgument(completionNotificationArg, taskGroup); |
| | | |
| | | errorNotificationArg = new StringArgument( |
| | | OPTION_LONG_ERROR_NOTIFICATION_EMAIL, |
| | | OPTION_SHORT_ERROR_NOTIFICATION_EMAIL, |
| | | OPTION_LONG_ERROR_NOTIFICATION_EMAIL, |
| | | false, true, true, OPTION_VALUE_EMAIL_ADDRESS, |
| | | null, null, INFO_DESCRIPTION_TASK_ERROR_NOTIFICATION.get()); |
| | | argParser.addArgument(errorNotificationArg, taskGroup); |
| | | |
| | | dependencyArg = new StringArgument( |
| | | OPTION_LONG_DEPENDENCY, |
| | | OPTION_SHORT_DEPENDENCY, |
| | | OPTION_LONG_DEPENDENCY, |
| | | false, true, true, OPTION_VALUE_TASK_ID, |
| | | null, null, INFO_DESCRIPTION_TASK_DEPENDENCY_ID.get()); |
| | | argParser.addArgument(dependencyArg, taskGroup); |
| | | |
| | | Set fdaValSet = EnumSet.allOf(FailedDependencyAction.class); |
| | | failedDependencyActionArg = new StringArgument( |
| | | OPTION_LONG_FAILED_DEPENDENCY_ACTION, |
| | | OPTION_SHORT_FAILED_DEPENDENCY_ACTION, |
| | | OPTION_LONG_FAILED_DEPENDENCY_ACTION, |
| | | false, true, true, OPTION_VALUE_ACTION, |
| | | null, null, INFO_DESCRIPTION_TASK_FAILED_DEPENDENCY_ACTION.get( |
| | | StaticUtils.collectionToString(fdaValSet, ","), |
| | | FailedDependencyAction.defaultValue().name())); |
| | | argParser.addArgument(failedDependencyActionArg, taskGroup); |
| | | |
| | | } catch (ArgumentException e) { |
| | | // should never happen |
| | | } |
| | |
| | | throw new ArgumentException(ERR_START_DATETIME_FORMAT.get()); |
| | | } |
| | | } |
| | | |
| | | if (!processAsTask() && completionNotificationArg.isPresent()) { |
| | | throw new ArgumentException(ERR_TASKTOOL_OPTIONS_FOR_TASK_ONLY.get( |
| | | completionNotificationArg.getLongIdentifier())); |
| | | } |
| | | |
| | | if (!processAsTask() && errorNotificationArg.isPresent()) { |
| | | throw new ArgumentException(ERR_TASKTOOL_OPTIONS_FOR_TASK_ONLY.get( |
| | | errorNotificationArg.getLongIdentifier())); |
| | | } |
| | | |
| | | if (!processAsTask() && dependencyArg.isPresent()) { |
| | | throw new ArgumentException(ERR_TASKTOOL_OPTIONS_FOR_TASK_ONLY.get( |
| | | dependencyArg.getLongIdentifier())); |
| | | } |
| | | |
| | | if (!processAsTask() && failedDependencyActionArg.isPresent()) { |
| | | throw new ArgumentException(ERR_TASKTOOL_OPTIONS_FOR_TASK_ONLY.get( |
| | | failedDependencyActionArg.getLongIdentifier())); |
| | | } |
| | | |
| | | if (completionNotificationArg.isPresent()) { |
| | | LinkedList<String> addrs = completionNotificationArg.getValues(); |
| | | for (String addr : addrs) { |
| | | if (!StaticUtils.isEmailAddress(addr)) { |
| | | throw new ArgumentException(ERR_TASKTOOL_INVALID_EMAIL_ADDRESS.get( |
| | | addr, completionNotificationArg.getLongIdentifier())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (errorNotificationArg.isPresent()) { |
| | | LinkedList<String> addrs = errorNotificationArg.getValues(); |
| | | for (String addr : addrs) { |
| | | if (!StaticUtils.isEmailAddress(addr)) { |
| | | throw new ArgumentException(ERR_TASKTOOL_INVALID_EMAIL_ADDRESS.get( |
| | | addr, errorNotificationArg.getLongIdentifier())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (failedDependencyActionArg.isPresent()) { |
| | | |
| | | if (!dependencyArg.isPresent()) { |
| | | throw new ArgumentException(ERR_TASKTOOL_FDA_WITH_NO_DEPENDENCY.get()); |
| | | } |
| | | |
| | | String fda = failedDependencyActionArg.getValue(); |
| | | if (null == FailedDependencyAction.fromString(fda)) { |
| | | Set fdaValSet = EnumSet.allOf(FailedDependencyAction.class); |
| | | throw new ArgumentException(ERR_TASKTOOL_INVALID_FDA.get(fda, |
| | | StaticUtils.collectionToString(fdaValSet, ","))); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public List<String> getDependencyIds() { |
| | | if (dependencyArg.isPresent()) { |
| | | return dependencyArg.getValues(); |
| | | } else { |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public FailedDependencyAction getFailedDependencyAction() { |
| | | FailedDependencyAction fda = null; |
| | | if (failedDependencyActionArg.isPresent()) { |
| | | String fdaString = failedDependencyActionArg.getValue(); |
| | | fda = FailedDependencyAction.fromString(fdaString); |
| | | } |
| | | return fda; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public List<String> getNotifyUponCompletionEmailAddresses() { |
| | | if (completionNotificationArg.isPresent()) { |
| | | return completionNotificationArg.getValues(); |
| | | } else { |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public List<String> getNotifyUponErrorEmailAddresses() { |
| | | if (errorNotificationArg.isPresent()) { |
| | | return errorNotificationArg.getValues(); |
| | | } else { |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Either invokes initiates this tool's local action or schedule this |
| | | * tool using the tasks interface based on user input. |
| | | * |
| | |
| | | PrintStream out, PrintStream err) { |
| | | int ret; |
| | | |
| | | if (argParser.argumentsPresent()) |
| | | if (processAsTask()) |
| | | { |
| | | if (initializeServer) |
| | | { |
| | |
| | | return ret; |
| | | } |
| | | |
| | | private boolean processAsTask() { |
| | | return argParser.connectionArgumentsPresent(); |
| | | } |
| | | |
| | | } |