opends/src/messages/messages/tools.properties
@@ -2201,4 +2201,6 @@ SEVERE_ERR_TASK_CLIENT_INVALID_RESPONSE_TYPE_1318=ERROR: Expected an add response \ message but got a %s message instead INFO_TASK_CLIENT_TASK_SCHEDULED_1319=Scheduled task %s SEVERE_ERR_LDAP_CONN_INCOMPATIBLE_ARGS_1320=ERROR: argument %s is incompatible \ with use of this tool to interact with the directory as a client opends/src/server/org/opends/server/tools/BackUpDB.java
@@ -43,6 +43,7 @@ import org.opends.server.api.Backend; import org.opends.server.api.ErrorLogPublisher; import org.opends.server.config.ConfigException; import static org.opends.server.config.ConfigConstants.*; import org.opends.server.core.CoreConfigManager; import org.opends.server.core.DirectoryServer; import org.opends.server.core.LockFileManager; @@ -56,16 +57,21 @@ import org.opends.server.types.DN; import org.opends.server.types.InitializationException; import org.opends.server.types.NullOutputStream; import org.opends.server.types.RawAttribute; import org.opends.server.util.args.ArgumentException; import org.opends.server.util.args.ArgumentParser; import org.opends.server.util.args.BooleanArgument; import org.opends.server.util.args.StringArgument; import org.opends.server.util.args.LDAPConnectionArgumentParser; import static org.opends.messages.ToolMessages.*; import static org.opends.server.util.ServerConstants.*; import static org.opends.server.util.StaticUtils.*; import static org.opends.server.tools.ToolConstants.*; import org.opends.server.tools.tasks.TaskTool; import org.opends.server.admin.std.server.BackendCfg; import org.opends.server.tasks.BackupTask; import org.opends.server.protocols.asn1.ASN1OctetString; import org.opends.server.protocols.ldap.LDAPAttribute; /** @@ -76,7 +82,7 @@ * a process that is intended to run separate from Directory Server and not * internally within the server process (e.g., via the tasks interface). */ public class BackUpDB public class BackUpDB extends TaskTool { private static ErrorLogPublisher errorLogPublisher = null; /** @@ -127,6 +133,29 @@ public static int mainBackUpDB(String[] args, boolean initializeServer, OutputStream outStream, OutputStream errStream) { BackUpDB tool = new BackUpDB(); return tool.process(args, initializeServer, outStream, errStream); } // Define the command-line arguments that may be used with this program. private BooleanArgument backUpAll = null; private BooleanArgument compress = null; private BooleanArgument displayUsage = null; private BooleanArgument encrypt = null; private BooleanArgument hash = null; private BooleanArgument incremental = null; private BooleanArgument signHash = null; private StringArgument backendID = null; private StringArgument backupIDString = null; private StringArgument configClass = null; private StringArgument configFile = null; private StringArgument backupDirectory = null; private StringArgument incrementalBaseID = null; private int process(String[] args, boolean initializeServer, OutputStream outStream, OutputStream errStream) { PrintStream out; if (outStream == null) { @@ -147,35 +176,20 @@ err = new PrintStream(errStream); } // Define the command-line arguments that may be used with this program. BooleanArgument backUpAll = null; BooleanArgument compress = null; BooleanArgument displayUsage = null; BooleanArgument encrypt = null; BooleanArgument hash = null; BooleanArgument incremental = null; BooleanArgument signHash = null; StringArgument backendID = null; StringArgument backupIDString = null; StringArgument configClass = null; StringArgument configFile = null; StringArgument backupDirectory = null; StringArgument incrementalBaseID = null; // Create the command-line argument parser for use with this program. Message toolDescription = INFO_BACKUPDB_TOOL_DESCRIPTION.get(); ArgumentParser argParser = new ArgumentParser("org.opends.server.tools.BackUpDB", toolDescription, LDAPConnectionArgumentParser argParser = new LDAPConnectionArgumentParser("org.opends.server.tools.BackUpDB", toolDescription, false); // Initialize all the command-line argument types and register them with the // parser. try { configClass = new StringArgument("configclass", OPTION_SHORT_CONFIG_CLASS, new StringArgument( "configclass", OPTION_SHORT_CONFIG_CLASS, OPTION_LONG_CONFIG_CLASS, true, false, true, OPTION_VALUE_CONFIG_CLASS, ConfigFileHandler.class.getName(), null, @@ -185,7 +199,8 @@ configFile = new StringArgument("configfile", 'f', "configFile", true, false, new StringArgument( "configfile", 'f', "configFile", true, false, true, "{configFile}", null, null, INFO_DESCRIPTION_CONFIG_FILE.get()); configFile.setHidden(true); @@ -193,7 +208,8 @@ backendID = new StringArgument("backendid", 'n', "backendID", false, true, true, new StringArgument( "backendid", 'n', "backendID", false, true, true, "{backendID}", null, null, INFO_BACKUPDB_DESCRIPTION_BACKEND_ID.get()); argParser.addArgument(backendID); @@ -206,14 +222,16 @@ backupIDString = new StringArgument("backupid", 'I', "backupID", false, false, true, new StringArgument( "backupid", 'I', "backupID", false, false, true, "{backupID}", null, null, INFO_BACKUPDB_DESCRIPTION_BACKUP_ID.get()); argParser.addArgument(backupIDString); backupDirectory = new StringArgument("backupdirectory", 'd', "backupDirectory", true, new StringArgument( "backupdirectory", 'd', "backupDirectory", true, false, true, "{backupDir}", null, null, INFO_BACKUPDB_DESCRIPTION_BACKUP_DIR.get()); argParser.addArgument(backupDirectory); @@ -233,30 +251,35 @@ argParser.addArgument(incrementalBaseID); compress = new BooleanArgument("compress", OPTION_SHORT_COMPRESS, compress = new BooleanArgument( "compress", OPTION_SHORT_COMPRESS, OPTION_LONG_COMPRESS, INFO_BACKUPDB_DESCRIPTION_COMPRESS.get()); argParser.addArgument(compress); encrypt = new BooleanArgument("encrypt", 'y', "encrypt", encrypt = new BooleanArgument( "encrypt", 'y', "encrypt", INFO_BACKUPDB_DESCRIPTION_ENCRYPT.get()); argParser.addArgument(encrypt); hash = new BooleanArgument("hash", 'h', "hash", hash = new BooleanArgument( "hash", 'A', "hash", INFO_BACKUPDB_DESCRIPTION_HASH.get()); argParser.addArgument(hash); signHash = new BooleanArgument("signhash", 's', "signHash", new BooleanArgument( "signhash", 's', "signHash", INFO_BACKUPDB_DESCRIPTION_SIGN_HASH.get()); argParser.addArgument(signHash); displayUsage = new BooleanArgument("help", OPTION_SHORT_HELP, new BooleanArgument( "help", OPTION_SHORT_HELP, OPTION_LONG_HELP, INFO_DESCRIPTION_USAGE.get()); argParser.addArgument(displayUsage); @@ -316,24 +339,8 @@ return 1; } // If no backup ID was provided, then create one with the current timestamp. String backupID; if (backupIDString.isPresent()) { backupID = backupIDString.getValue(); } else { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT_TIME); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); backupID = dateFormat.format(new Date()); } // If the incremental base ID was specified, then make sure it is an // incremental backup. String incrementalBase; if (incrementalBaseID.isPresent()) { if (! incremental.isPresent()) @@ -345,14 +352,7 @@ err.println(wrapText(message, MAX_LINE_WIDTH)); return 1; } incrementalBase = incrementalBaseID.getValue(); } else { incrementalBase = null; } // If the signHash option was provided, then make sure that the hash option // was given. @@ -365,6 +365,128 @@ return 1; } return process(argParser, initializeServer, out, err); } /** * {@inheritDoc} */ public void addTaskAttributes(List<RawAttribute> attributes) { ArrayList<ASN1OctetString> values; if (backUpAll.getValue() != null && !backUpAll.getValue().equals( backUpAll.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(backUpAll.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_ALL, values)); } if (compress.getValue() != null && !compress.getValue().equals( compress.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(compress.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_COMPRESS, values)); } if (encrypt.getValue() != null && !encrypt.getValue().equals( encrypt.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(encrypt.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_ENCRYPT, values)); } if (hash.getValue() != null && !hash.getValue().equals( hash.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(hash.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_HASH, values)); } if (incremental.getValue() != null && !incremental.getValue().equals( incremental.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(incremental.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_INCREMENTAL, values)); } if (signHash.getValue() != null && !signHash.getValue().equals( signHash.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(signHash.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_SIGN_HASH, values)); } List<String> backendIDs = backendID.getValues(); if (backendIDs != null && backendIDs.size() > 0) { values = new ArrayList<ASN1OctetString>(backendIDs.size()); for (String s : backendIDs) { values.add(new ASN1OctetString(s)); } attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_BACKEND_ID, values)); } if (backupIDString.getValue() != null && !backupIDString.getValue().equals( backupIDString.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(backupIDString.getValue())); attributes.add( new LDAPAttribute(ATTR_BACKUP_ID, values)); } if (backupDirectory.getValue() != null && !backupDirectory.getValue().equals( backupDirectory.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(backupDirectory.getValue())); attributes.add( new LDAPAttribute(ATTR_BACKUP_DIRECTORY_PATH, values)); } if (incrementalBaseID.getValue() != null && !incrementalBaseID.getValue().equals( incrementalBaseID.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(incrementalBaseID.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_BACKUP_INCREMENTAL_BASE_ID, values)); } } /** * {@inheritDoc} */ public String getTaskObjectclass() { return "ds-task-backup"; } /** * {@inheritDoc} */ public Class getTaskClass() { return BackupTask.class; } /** * {@inheritDoc} */ protected int processLocal(boolean initializeServer, PrintStream out, PrintStream err) { // Make sure that the backup directory exists. If not, then create it. File backupDirFile = new File(backupDirectory.getValue()); @@ -384,6 +506,30 @@ } } // If no backup ID was provided, then create one with the current timestamp. String backupID; if (backupIDString.isPresent()) { backupID = backupIDString.getValue(); } else { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT_TIME); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); backupID = dateFormat.format(new Date()); } // If the incremental base ID was specified, then make sure it is an // incremental backup. String incrementalBase; if (incrementalBaseID.isPresent()) { incrementalBase = incrementalBaseID.getValue(); } else { incrementalBase = null; } // Perform the initial bootstrap of the Directory Server and process the // configuration. opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -365,7 +365,7 @@ argParser.addArgument(isEncrypted); quietMode = new BooleanArgument("quietmode", null, "quiet", quietMode = new BooleanArgument("quietmode", 'Q', "quiet", INFO_LDIFIMPORT_DESCRIPTION_QUIET.get()); argParser.addArgument(quietMode); @@ -441,6 +441,11 @@ return 1; } // Don't write non-error messages to console if quite if (quietMode.isPresent()) { out = new PrintStream(NullOutputStream.instance()); } return process(argParser, initializeServer, out, err); } opends/src/server/org/opends/server/tools/RestoreDB.java
@@ -41,6 +41,7 @@ import org.opends.server.api.Backend; import org.opends.server.api.ErrorLogPublisher; import org.opends.server.config.ConfigException; import static org.opends.server.config.ConfigConstants.*; import org.opends.server.core.CoreConfigManager; import org.opends.server.core.DirectoryServer; import org.opends.server.core.LockFileManager; @@ -55,17 +56,22 @@ import org.opends.server.types.InitializationException; import org.opends.server.types.NullOutputStream; import org.opends.server.types.RestoreConfig; import org.opends.server.types.RawAttribute; import org.opends.server.util.args.ArgumentException; import org.opends.server.util.args.ArgumentParser; import org.opends.server.util.args.BooleanArgument; import org.opends.server.util.args.StringArgument; import org.opends.server.util.args.LDAPConnectionArgumentParser; import static org.opends.server.loggers.ErrorLogger.*; import static org.opends.messages.ToolMessages.*; import static org.opends.server.util.ServerConstants.*; import static org.opends.server.util.StaticUtils.*; import static org.opends.server.tools.ToolConstants.*; import org.opends.server.tools.tasks.TaskTool; import org.opends.server.admin.std.server.BackendCfg; import org.opends.server.protocols.asn1.ASN1OctetString; import org.opends.server.protocols.ldap.LDAPAttribute; import org.opends.server.tasks.RestoreTask; /** @@ -74,8 +80,8 @@ * be a process that is intended to run separate from Directory Server and not * internally within the server process (e.g., via the tasks interface). */ public class RestoreDB { public class RestoreDB extends TaskTool { private static ErrorLogPublisher errorLogPublisher = null; /** * The main method for RestoreDB tool. @@ -127,6 +133,24 @@ OutputStream outStream, OutputStream errStream) { RestoreDB tool = new RestoreDB(); return tool.process(args, initializeServer, outStream, errStream); } // Define the command-line arguments that may be used with this program. private BooleanArgument displayUsage = null; private BooleanArgument listBackups = null; private BooleanArgument verifyOnly = null; private StringArgument backupIDString = null; private StringArgument configClass = null; private StringArgument configFile = null; private StringArgument backupDirectory = null; private int process(String[] args, boolean initializeServer, OutputStream outStream, OutputStream errStream) { PrintStream out; if (outStream == null) { @@ -147,20 +171,10 @@ err = new PrintStream(errStream); } // Define the command-line arguments that may be used with this program. BooleanArgument displayUsage = null; BooleanArgument listBackups = null; BooleanArgument verifyOnly = null; StringArgument backupIDString = null; StringArgument configClass = null; StringArgument configFile = null; StringArgument backupDirectory = null; // Create the command-line argument parser for use with this program. Message toolDescription = INFO_RESTOREDB_TOOL_DESCRIPTION.get(); ArgumentParser argParser = new ArgumentParser("org.opends.server.tools.RestoreDB", LDAPConnectionArgumentParser argParser = new LDAPConnectionArgumentParser("org.opends.server.tools.RestoreDB", toolDescription, false); @@ -251,6 +265,75 @@ } if (listBackups.isPresent() && argParser.isLdapOperation()) { Message message = ERR_LDAP_CONN_INCOMPATIBLE_ARGS.get( listBackups.getLongIdentifier()); err.println(wrapText(message, MAX_LINE_WIDTH)); return 1; } return process(argParser, initializeServer, out, err); } /** * {@inheritDoc} */ public void addTaskAttributes(List<RawAttribute> attributes) { ArrayList<ASN1OctetString> values; if (backupDirectory.getValue() != null && !backupDirectory.getValue().equals( backupDirectory.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(backupDirectory.getValue())); attributes.add( new LDAPAttribute(ATTR_BACKUP_DIRECTORY_PATH, values)); } if (backupIDString.getValue() != null && !backupIDString.getValue().equals( backupIDString.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(backupIDString.getValue())); attributes.add( new LDAPAttribute(ATTR_BACKUP_ID, values)); } if (verifyOnly.getValue() != null && !verifyOnly.getValue().equals( verifyOnly.getDefaultValue())) { values = new ArrayList<ASN1OctetString>(1); values.add(new ASN1OctetString(verifyOnly.getValue())); attributes.add( new LDAPAttribute(ATTR_TASK_RESTORE_VERIFY_ONLY, values)); } } /** * {@inheritDoc} */ public String getTaskObjectclass() { return "ds-task-restore"; } /** * {@inheritDoc} */ public Class getTaskClass() { return RestoreTask.class; } /** * {@inheritDoc} */ protected int processLocal(boolean initializeServer, PrintStream out, PrintStream err) { // Perform the initial bootstrap of the Directory Server and process the // configuration. DirectoryServer directoryServer = DirectoryServer.getInstance(); opends/src/server/org/opends/server/tools/tasks/TaskSchedulingClient.java
@@ -29,6 +29,7 @@ import org.opends.server.types.LDAPException; import org.opends.server.types.RawAttribute; import org.opends.server.types.ResultCode; import org.opends.server.protocols.asn1.ASN1OctetString; import org.opends.server.protocols.asn1.ASN1Exception; import org.opends.server.protocols.ldap.LDAPControl; @@ -82,8 +83,8 @@ * Schedule a task for execution by writing an entry to the task backend. * * @param information to be scheduled * @param out stream for writing error messages * @param err stream for writing error messages * @param out stream for writing error messages; may be null * @param err stream for writing error messages; may be null * @return int representing an LDAP return code */ public synchronized int schedule(TaskScheduleInformation information, @@ -136,26 +137,26 @@ if (responseMessage == null) { Message message = ERR_TASK_CLIENT_UNEXPECTED_CONNECTION_CLOSURE.get(); err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); return LDAPResultCode.CLIENT_SIDE_SERVER_DOWN; } } catch (IOException ioe) { Message message = ERR_TASK_CLIENT_IO_ERROR.get(String.valueOf(ioe)); err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); return LDAPResultCode.CLIENT_SIDE_SERVER_DOWN; } catch (ASN1Exception ae) { Message message = ERR_TASK_CLIENT_DECODE_ERROR.get(ae.getMessage()); err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); return LDAPResultCode.CLIENT_SIDE_DECODING_ERROR; } catch (LDAPException le) { Message message = ERR_TASK_CLIENT_DECODE_ERROR.get(le.getMessage()); err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); return LDAPResultCode.CLIENT_SIDE_DECODING_ERROR; } @@ -176,7 +177,7 @@ Message message = extendedResponse.getErrorMessage(); if (message != null) { err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); } return extendedResponse.getResultCode(); @@ -185,18 +186,20 @@ Message message = ERR_TASK_CLIENT_INVALID_RESPONSE_TYPE.get( responseMessage.getProtocolOpName()); err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); return LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR; } AddResponseProtocolOp addResponse = responseMessage.getAddResponseProtocolOp(); Message errorMessage = addResponse.getErrorMessage(); if (errorMessage != null) if (errorMessage != null && err != null) { err.println(wrapText(errorMessage, MAX_LINE_WIDTH)); } else if (addResponse.getResultCode() == ResultCode.SUCCESS.getIntValue() && out != null) { out.println(wrapText(INFO_TASK_CLIENT_TASK_SCHEDULED.get(taskID), MAX_LINE_WIDTH)); opends/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -53,8 +53,8 @@ * @param argParser used to parse user arguments * @param initializeServer indicates whether or not to initialize the * directory server in the case of a local action * @param out stream to write messages * @param err stream to write messages * @param out stream to write messages; may be null * @param err stream to write messages; may be null * @return int indicating the result of this action */ protected int process(LDAPConnectionArgumentParser argParser, @@ -69,11 +69,11 @@ ret = tc.schedule(this, out, err); } catch (LDAPConnectionException e) { Message message = ERR_LDAP_CONN_CANNOT_CONNECT.get(e.getMessage()); err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); ret = LDAPResultCode.CLIENT_SIDE_CONNECT_ERROR; } catch (ArgumentException e) { Message message = e.getMessageObject(); err.println(wrapText(message, MAX_LINE_WIDTH)); if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH)); ret = LDAPResultCode.CLIENT_SIDE_PARAM_ERROR; } } @@ -90,8 +90,8 @@ * * @param initializeServer indicates whether or not to initialize the * directory server in the case of a local action * @param out stream to write messages * @param err stream to write messages * @param out stream to write messages; may be null * @param err stream to write messages; may be null * @return int indicating the result of this action */ abstract protected int processLocal(boolean initializeServer, opends/src/server/org/opends/server/util/args/BooleanArgument.java
@@ -35,10 +35,10 @@ /** * This class defines an argument type that will be used to represent Boolean * values. These arguments will never take values and will never be required. * If the argument is provided, then it will be considered true, and if not then * it will be considered false. As such, the default value will always be * "false". * values. These arguments will never take values from the command line but * and will never be required. If the argument is provided, then it will be * considered true, and if not then it will be considered false. As such, * the default value will always be "false". */ public class BooleanArgument extends Argument @@ -64,7 +64,7 @@ throws ArgumentException { super(name, shortIdentifier, longIdentifier, false, false, false, null, null, null, description); String.valueOf(false), null, description); } @@ -90,5 +90,26 @@ return false; } /** * {@inheritDoc} */ final public void addValue(String valueString) { if (valueString != null) { clearValues(); super.addValue(valueString); super.setPresent(Boolean.valueOf(valueString)); } } /** * {@inheritDoc} */ final public void setPresent(boolean isPresent) { addValue(String.valueOf(isPresent)); } }