From 18de8b9ed9f6ba9780d3292d2828f67de08b7483 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 24 Jul 2009 09:46:24 +0000
Subject: [PATCH] Refactor the code of dsreplication and extract some of its commodity methods and move them to the classes they apply to.
---
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java | 31 --
opends/src/ads/org/opends/admin/ads/TopologyCache.java | 56 ++++
opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java | 88 +++++++
opends/src/ads/org/opends/admin/ads/ADSContext.java | 24 +
opends/src/server/org/opends/server/util/args/ArgumentParser.java | 33 ++
opends/src/quicksetup/org/opends/quicksetup/util/Utils.java | 34 ++
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java | 49 ++++
opends/src/ads/org/opends/admin/ads/ServerDescriptor.java | 59 ++++
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 337 ++++-----------------------
9 files changed, 394 insertions(+), 317 deletions(-)
diff --git a/opends/src/ads/org/opends/admin/ads/ADSContext.java b/opends/src/ads/org/opends/admin/ads/ADSContext.java
index a0c3214..fdab5be 100644
--- a/opends/src/ads/org/opends/admin/ads/ADSContext.java
+++ b/opends/src/ads/org/opends/admin/ads/ADSContext.java
@@ -688,16 +688,15 @@
/**
* Returns whether a given administrator is already registered or not.
- * @param adminProperties the administrator properties.
+ * @param uid the administrator UID.
* @return <CODE>true</CODE> if the administrator was registered and
* <CODE>false</CODE> otherwise.
* @throws ADSContextException if something went wrong.
*/
- public boolean isAdministratorAlreadyRegistered(
- Map<AdministratorProperty, Object> adminProperties)
+ public boolean isAdministratorAlreadyRegistered(String uid)
throws ADSContextException
{
- LdapName dn = makeDNFromAdministratorProperties(adminProperties);
+ LdapName dn = makeDNFromAdministratorProperties(uid);
return isExistingEntry(dn);
}
@@ -1505,7 +1504,20 @@
throws ADSContextException
{
String adminUid = getAdministratorUID(adminProperties);
+ return makeDNFromAdministratorProperties(adminUid);
+ }
+ /**
+ * This method returns the DN of the entry that corresponds to the given
+ * administrator properties.
+ * @param adminUid the administrator uid.
+ * @return the DN of the entry that corresponds to the given administrator
+ * properties.
+ * @throws ADSContextException if something goes wrong.
+ */
+ private static LdapName makeDNFromAdministratorProperties(String adminUid)
+ throws ADSContextException
+ {
String dnCentralAdmin = getAdministratorDN(adminUid);
return nameFromDN(dnCentralAdmin);
@@ -2463,9 +2475,9 @@
SortedSet<String> notDefinedAdmins = new TreeSet<String>();
for (Map<AdministratorProperty, Object> admin2 : admins2)
{
- if (!isAdministratorAlreadyRegistered(admin2))
+ String uid = (String)admin2.get(AdministratorProperty.UID);
+ if (!isAdministratorAlreadyRegistered(uid))
{
- String uid = (String)admin2.get(AdministratorProperty.UID);
notDefinedAdmins.add(uid);
}
}
diff --git a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
index 0c34f65..f5af8fe 100644
--- a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
+++ b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -46,6 +46,7 @@
import javax.naming.ldap.Rdn;
import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.quicksetup.Constants;
import org.opends.quicksetup.util.Utils;
/**
@@ -1435,4 +1436,62 @@
}
return areDnsEqual;
}
+
+ /**
+ * Returns the replication server normalized String for a given host name
+ * and replication port.
+ * @param hostName the host name.
+ * @param replicationPort the replication port.
+ * @return the replication server normalized String for a given host name
+ * and replication port.
+ */
+ public static String getReplicationServer(String hostName,
+ int replicationPort)
+ {
+ return hostName.toLowerCase() + ":" + replicationPort;
+ }
+
+ /**
+ * Returns the normalized server representation for a given host name and
+ * port.
+ * @param hostName the host name.
+ * @param port the port.
+ * @return the normalized server representation for a given host name and
+ * port.
+ */
+ public static String getServerRepresentation(String hostName, int port)
+ {
+ return hostName.toLowerCase() + ":" + port;
+ }
+
+ /**
+ * Returns a representation of a base DN for a set of servers.
+ * @param baseDN the base DN.
+ * @param servers the servers.
+ * @return a representation of a base DN for a set of servers.
+ */
+ public static String getSuffixDisplay(String baseDN,
+ Set<ServerDescriptor> servers)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append(baseDN);
+ for (ServerDescriptor server : servers)
+ {
+ sb.append(Constants.LINE_SEPARATOR+" ");
+ sb.append(server.getHostPort(true));
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Tells whether the provided server descriptor represents the same server
+ * as this object.
+ * @param server the server to make the comparison.
+ * @return whether the provided server descriptor represents the same server
+ * as this object or not.
+ */
+ public boolean isSameServer(ServerDescriptor server)
+ {
+ return getId().equals(server.getId());
+ }
}
diff --git a/opends/src/ads/org/opends/admin/ads/TopologyCache.java b/opends/src/ads/org/opends/admin/ads/TopologyCache.java
index 1f2045d..7c5949b 100644
--- a/opends/src/ads/org/opends/admin/ads/TopologyCache.java
+++ b/opends/src/ads/org/opends/admin/ads/TopologyCache.java
@@ -27,6 +27,11 @@
package org.opends.admin.ads;
+import static org.opends.messages.QuickSetupMessages.
+ INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER;
+import static org.opends.messages.QuickSetupMessages.
+ INFO_NOT_GLOBAL_ADMINISTRATOR_PROVIDED;
+
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -51,6 +56,7 @@
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.admin.ads.util.PreferredConnection;
import org.opends.admin.ads.util.ServerLoader;
+import org.opends.messages.Message;
import org.opends.quicksetup.util.Utils;
/**
@@ -370,6 +376,56 @@
return adsContext;
}
+
+
+ /**
+ * Returns a set of error messages encountered in the TopologyCache.
+ * @return a set of error messages encountered in the TopologyCache.
+ */
+ public LinkedHashSet<Message> getErrorMessages()
+ {
+ Set<TopologyCacheException> exceptions =
+ new HashSet<TopologyCacheException>();
+ Set<ServerDescriptor> servers = getServers();
+ LinkedHashSet<Message> exceptionMsgs = new LinkedHashSet<Message>();
+ for (ServerDescriptor server : servers)
+ {
+ TopologyCacheException e = server.getLastException();
+ if (e != null)
+ {
+ exceptions.add(e);
+ }
+ }
+ /* Check the exceptions and see if we throw them or not. */
+ for (TopologyCacheException e : exceptions)
+ {
+ switch (e.getType())
+ {
+ case NOT_GLOBAL_ADMINISTRATOR:
+ exceptionMsgs.add(INFO_NOT_GLOBAL_ADMINISTRATOR_PROVIDED.get());
+
+ break;
+ case GENERIC_CREATING_CONNECTION:
+ if ((e.getCause() != null) &&
+ Utils.isCertificateException(e.getCause()))
+ {
+ exceptionMsgs.add(
+ INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
+ e.getHostPort(), e.getCause().getMessage()));
+ }
+ else
+ {
+ exceptionMsgs.add(Utils.getMessage(e));
+ }
+ break;
+ default:
+ exceptionMsgs.add(Utils.getMessage(e));
+ }
+ }
+ return exceptionMsgs;
+ }
+
+
/**
* Updates the monitoring information of the provided replicas using the
* information located in cn=monitor of a given replication server.
diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index 4399381..e77eb9e 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -42,6 +42,7 @@
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
+import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
@@ -1687,6 +1688,39 @@
}
/**
+ * Basic method to know if the host is local or not. This is only used to
+ * know if we can perform a port check or not.
+ * @param host the host to analyze.
+ * @return <CODE>true</CODE> if it is the local host and <CODE>false</CODE>
+ * otherwise.
+ */
+ public static boolean isLocalHost(String host)
+ {
+ boolean isLocalHost = false;
+ if (!"localhost".equalsIgnoreCase(host))
+ {
+ try
+ {
+ InetAddress localAddress = InetAddress.getLocalHost();
+ InetAddress[] addresses = InetAddress.getAllByName(host);
+ for (int i=0; i<addresses.length && !isLocalHost; i++)
+ {
+ isLocalHost = localAddress.equals(addresses[i]);
+ }
+ }
+ catch (Throwable t)
+ {
+ LOG.log(Level.WARNING, "Failing checking host names: "+t, t);
+ }
+ }
+ else
+ {
+ isLocalHost = true;
+ }
+ return isLocalHost;
+ }
+
+ /**
* Returns the HTML representation of a plain text string which is obtained
* by converting some special characters (like '<') into its equivalent
* escaped HTML representation.
diff --git a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
index 175ff7c..9765e3b 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
@@ -254,37 +254,6 @@
* Get the password which has to be used for the command without prompting
* the user. If no password was specified, return null.
*
- * @param clearArg
- * The password StringArgument argument.
- * @param fileArg
- * The password FileBased argument.
- * @return The password stored into the specified file on by the
- * command line argument, or null it if not specified.
- */
- public String getBindPassword(StringArgument clearArg,
- FileBasedArgument fileArg)
- {
- String pwd;
- if (clearArg.isPresent())
- {
- pwd = clearArg.getValue();
- }
- else
- if (fileArg.isPresent())
- {
- pwd = fileArg.getValue();
- }
- else
- {
- pwd = null;
- }
- return pwd;
- }
-
- /**
- * Get the password which has to be used for the command without prompting
- * the user. If no password was specified, return null.
- *
* @return The password stored into the specified file on by the
* command line argument, or null it if not specified.
*/
diff --git a/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index a8fafa3..88230d8 100644
--- a/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -27,6 +27,9 @@
package org.opends.server.tools.dsreplication;
+import static org.opends.admin.ads.ServerDescriptor.getReplicationServer;
+import static org.opends.admin.ads.ServerDescriptor.getServerRepresentation;
+import static org.opends.admin.ads.ServerDescriptor.getSuffixDisplay;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
import static org.opends.messages.ToolMessages.*;
@@ -42,7 +45,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
-import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
@@ -844,7 +846,7 @@
* Use a copy of the argument properties since the map might be cleared
* in initializeGlobalArguments.
*/
- initializeGlobalArguments(host1, port1, adminUid,
+ ci.initializeGlobalArguments(host1, port1, adminUid,
bindDn1, pwd,
pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
InitialLdapContext ctx1 = null;
@@ -885,7 +887,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -969,10 +971,10 @@
{
replicationPort1 = askPort(
INFO_REPLICATION_ENABLE_REPLICATIONPORT1_PROMPT.get(),
- argParser.getDefaultReplicationPort1());
+ argParser.getDefaultReplicationPort1(), LOG);
println();
}
- if (!argParser.skipReplicationPortCheck() && isLocalHost(host1))
+ if (!argParser.skipReplicationPortCheck() && Utils.isLocalHost(host1))
{
if (!SetupUtils.canUseAsPort(replicationPort1))
{
@@ -1098,7 +1100,7 @@
* Use a copy of the argument properties since the map might be cleared
* in initializeGlobalArguments.
*/
- initializeGlobalArguments(host2, port2, adminUid,
+ ci.initializeGlobalArguments(host2, port2, adminUid,
bindDn2, pwd,
pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
}
@@ -1158,7 +1160,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -1242,10 +1244,11 @@
{
replicationPort2 = askPort(
INFO_REPLICATION_ENABLE_REPLICATIONPORT2_PROMPT.get(),
- argParser.getDefaultReplicationPort2());
+ argParser.getDefaultReplicationPort2(), LOG);
println();
}
- if (!argParser.skipReplicationPortCheck() && isLocalHost(host2))
+ if (!argParser.skipReplicationPortCheck() &&
+ Utils.isLocalHost(host2))
{
if (!SetupUtils.canUseAsPort(replicationPort2))
{
@@ -1485,7 +1488,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -1748,7 +1751,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -1884,7 +1887,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -1995,7 +1998,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -2087,7 +2090,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -2171,7 +2174,8 @@
* Use a copy of the argument properties since the map might be cleared
* in initializeGlobalArguments.
*/
- initializeGlobalArguments(hostSource, portSource, adminUid, null, adminPwd,
+ ci.initializeGlobalArguments(hostSource, portSource, adminUid, null,
+ adminPwd,
pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
/*
* Try to connect to the source server.
@@ -2203,7 +2207,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -2236,7 +2240,7 @@
* Use a copy of the argument properties since the map might be cleared
* in initializeGlobalArguments.
*/
- initializeGlobalArguments(hostDestination, portDestination,
+ ci.initializeGlobalArguments(hostDestination, portDestination,
adminUid, null, adminPwd,
pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
/*
@@ -2268,7 +2272,7 @@
println();
println(ce.getMessageObject());
println();
- resetConnectionArguments();
+ ci.resetConnectionArguments();
}
catch (ArgumentException ae)
{
@@ -2789,7 +2793,7 @@
if (getTrustManager() == null)
{
// This is required when the user did connect to the server using SSL or
- // Start TLS. In this case LDAPConnectionInteraction.run does not
+ // Start TLS. In this case LDAPConnectionConsoleInteraction.run does not
// initialize the keystore and the trust manager is null.
forceTrustManagerInitialization();
}
@@ -3312,7 +3316,7 @@
{
if (!argParser.skipReplicationPortCheck() &&
uData.configureReplicationServer1() &&
- isLocalHost(host1) &&
+ Utils.isLocalHost(host1) &&
!SetupUtils.canUseAsPort(replPort1))
{
errorMessages.add(getCannotBindToPortError(replPort1));
@@ -3322,7 +3326,7 @@
{
if (!argParser.skipReplicationPortCheck() &&
uData.configureReplicationServer2() &&
- isLocalHost(host2) &&
+ Utils.isLocalHost(host2) &&
!SetupUtils.canUseAsPort(replPort2))
{
errorMessages.add(getCannotBindToPortError(replPort2));
@@ -4917,7 +4921,7 @@
cache.getFilter().addBaseDNToSearch(dn);
}
cache.reloadTopology();
- messages.addAll(getErrorMessages(cache));
+ messages.addAll(cache.getErrorMessages());
}
if (adsCtx2.hasAdminData())
@@ -4930,7 +4934,7 @@
cache.getFilter().addBaseDNToSearch(dn);
}
cache.reloadTopology();
- messages.addAll(getErrorMessages(cache));
+ messages.addAll(cache.getErrorMessages());
}
}
catch (TopologyCacheException tce)
@@ -5613,7 +5617,7 @@
LinkedHashSet<Message> messages = new LinkedHashSet<Message>();
if (cache != null)
{
- messages.addAll(getErrorMessages(cache));
+ messages.addAll(cache.getErrorMessages());
}
if (!messages.isEmpty())
{
@@ -5768,7 +5772,7 @@
new TreeSet<ServerDescriptor>(new ServerComparator());
for (ReplicaDescriptor replica : suffix.getReplicas())
{
- if (!areSameServer(replica.getServer(), server))
+ if (!replica.getServer().isSameServer(server))
{
servers.add(replica.getServer());
}
@@ -6138,7 +6142,7 @@
LinkedHashSet<Message> messages = new LinkedHashSet<Message>();
if (cache != null)
{
- messages.addAll(getErrorMessages(cache));
+ messages.addAll(cache.getErrorMessages());
}
if (!messages.isEmpty())
{
@@ -6807,17 +6811,6 @@
break;
}
}
- if (servers.isEmpty())
- {
- boolean found = false;
- for (ReplicaDescriptor replica : server.getReplicas())
- {
- if (Utils.areDnsEqual(replica.getSuffix().getDN(), baseDN))
- {
- found = true;
- }
- }
- }
if (cache != null)
{
Set<SuffixDescriptor> suffixes = cache.getSuffixes();
@@ -6837,6 +6830,29 @@
servers.addAll(s);
break;
}
+ else
+ {
+ // Check if this server is acting as replication server with
+ // no domain.
+ if (server.isReplicationServer())
+ {
+ boolean found = false;
+ String repServer = server.getReplicationServerHostPort();
+ for (String rS : s)
+ {
+ if (rS.equalsIgnoreCase(repServer))
+ {
+ servers.addAll(s);
+ found = true;
+ break;
+ }
+ }
+ if (found)
+ {
+ break;
+ }
+ }
+ }
}
}
}
@@ -7964,54 +7980,6 @@
}
/**
- * Returns a set of error messages encountered in the provided TopologyCache.
- * @param cache the topology cache.
- * @return a set of error messages encountered in the provided TopologyCache.
- */
- private LinkedHashSet<Message> getErrorMessages(TopologyCache cache)
- {
- Set<TopologyCacheException> exceptions =
- new HashSet<TopologyCacheException>();
- Set<ServerDescriptor> servers = cache.getServers();
- LinkedHashSet<Message> exceptionMsgs = new LinkedHashSet<Message>();
- for (ServerDescriptor server : servers)
- {
- TopologyCacheException e = server.getLastException();
- if (e != null)
- {
- exceptions.add(e);
- }
- }
- /* Check the exceptions and see if we throw them or not. */
- for (TopologyCacheException e : exceptions)
- {
- switch (e.getType())
- {
- case NOT_GLOBAL_ADMINISTRATOR:
- exceptionMsgs.add(INFO_NOT_GLOBAL_ADMINISTRATOR_PROVIDED.get());
-
- break;
- case GENERIC_CREATING_CONNECTION:
- if ((e.getCause() != null) &&
- Utils.isCertificateException(e.getCause()))
- {
- exceptionMsgs.add(
- INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
- e.getHostPort(), e.getCause().getMessage()));
- }
- else
- {
- exceptionMsgs.add(Utils.getMessage(e));
- }
- break;
- default:
- exceptionMsgs.add(Utils.getMessage(e));
- }
- }
- return exceptionMsgs;
- }
-
- /**
* Removes the references to a replication server in the base DNs of a
* given server.
* @param server the server that we want to update.
@@ -8302,29 +8270,6 @@
}
/**
- * Returns a message object for the given NamingException.
- * @param ne the NamingException.
- * @param hostPort the hostPort representation of the server we were
- * contacting when the NamingException occurred.
- * @return a message object for the given NamingException.
- */
- private Message getMessageForException(NamingException ne, String hostPort)
- {
- Message msg;
- if (Utils.isCertificateException(ne))
- {
- msg = INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
- hostPort, ne.toString(true));
- }
- else
- {
- msg = INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC.get(
- hostPort, ne.toString(true));
- }
- return msg;
- }
-
- /**
* Returns a message for a given OpenDsException (we assume that was an
* exception generated updating the configuration of the server) that
* occurred when we were configuring the replication server.
@@ -8490,39 +8435,6 @@
return mb.toMessage();
}
- /**
- * Basic method to know if the host is local or not. This is only used to
- * know if we can perform a port check or not.
- * @param host the host to analyze.
- * @return <CODE>true</CODE> if it is the local host and <CODE>false</CODE>
- * otherwise.
- */
- private boolean isLocalHost(String host)
- {
- boolean isLocalHost = false;
- if (!"localhost".equalsIgnoreCase(host))
- {
- try
- {
- InetAddress localAddress = InetAddress.getLocalHost();
- InetAddress[] addresses = InetAddress.getAllByName(host);
- for (int i=0; i<addresses.length && !isLocalHost; i++)
- {
- isLocalHost = localAddress.equals(addresses[i]);
- }
- }
- catch (Throwable t)
- {
- LOG.log(Level.WARNING, "Failing checking host names: "+t, t);
- }
- }
- else
- {
- isLocalHost = true;
- }
- return isLocalHost;
- }
-
private boolean mustInitializeSchema(ServerDescriptor server1,
ServerDescriptor server2, EnableReplicationUserData uData)
{
@@ -8641,31 +8553,6 @@
}
/**
- * Commodity method used to repeatidly ask the user to provide a port value.
- * @param prompt the prompt message.
- * @param defaultValue the default value of the port to be proposed to the
- * user.
- * @return the port value provided by the user.
- */
- private int askPort(Message prompt, int defaultValue)
- {
- int port = -1;
- while (port == -1)
- {
- try
- {
- port = readPort(prompt, defaultValue);
- }
- catch (CLIException ce)
- {
- port = -1;
- LOG.log(Level.WARNING, "Error reading input: "+ce, ce);
- }
- }
- return port;
- }
-
- /**
* Prompts the user to give the Global Administrator UID.
* @param defaultValue the default value that will be proposed in the prompt
* message.
@@ -8709,90 +8596,6 @@
}
/**
- * Resets the connection parameters for the LDAPConsoleInteraction object.
- * The reset does not apply to the certificate parameters. This is called
- * in order the LDAPConnectionConsoleInteraction object to ask for all this
- * connection parameters next time we call
- * LDAPConnectionConsoleInteraction.run().
- */
- private void resetConnectionArguments()
- {
- argParser.getSecureArgsList().hostNameArg.clearValues();
- argParser.getSecureArgsList().hostNameArg.setPresent(false);
- argParser.getSecureArgsList().portArg.clearValues();
- argParser.getSecureArgsList().portArg.setPresent(false);
- // This is done to be able to call IntegerArgument.getIntValue()
- argParser.getSecureArgsList().portArg.addValue(
- argParser.getSecureArgsList().portArg.getDefaultValue());
- argParser.getSecureArgsList().bindDnArg.clearValues();
- argParser.getSecureArgsList().bindDnArg.setPresent(false);
- argParser.getSecureArgsList().bindPasswordArg.clearValues();
- argParser.getSecureArgsList().bindPasswordArg.setPresent(false);
- argParser.getSecureArgsList().bindPasswordFileArg.clearValues();
- argParser.getSecureArgsList().bindPasswordFileArg.getNameToValueMap().
- clear();
- argParser.getSecureArgsList().bindPasswordFileArg.setPresent(false);
- argParser.getSecureArgsList().adminUidArg.clearValues();
- argParser.getSecureArgsList().adminUidArg.setPresent(false);
- }
-
- /**
- * Initializes the global arguments in the parser with the provided values.
- */
- private void initializeGlobalArguments(String hostName, int port,
- String adminUid, String bindDn,
- String bindPwd, LinkedHashMap<String, String> pwdFile)
- {
- resetConnectionArguments();
- if (hostName != null)
- {
- argParser.getSecureArgsList().hostNameArg.addValue(hostName);
- argParser.getSecureArgsList().hostNameArg.setPresent(true);
- }
- // resetConnectionArguments does not clear the values for the port
- argParser.getSecureArgsList().portArg.clearValues();
- if (port != -1)
- {
- argParser.getSecureArgsList().portArg.addValue(String.valueOf(port));
- argParser.getSecureArgsList().portArg.setPresent(true);
- }
- else
- {
- // This is done to be able to call IntegerArgument.getIntValue()
- argParser.getSecureArgsList().portArg.addValue(
- argParser.getSecureArgsList().portArg.getDefaultValue());
- }
- argParser.getSecureArgsList().useSSLArg.setPresent(useSSL);
- argParser.getSecureArgsList().useStartTLSArg.setPresent(useStartTLS);
- if (adminUid != null)
- {
- argParser.getSecureArgsList().adminUidArg.addValue(adminUid);
- argParser.getSecureArgsList().adminUidArg.setPresent(true);
- }
- if (bindDn != null)
- {
- argParser.getSecureArgsList().bindDnArg.addValue(bindDn);
- argParser.getSecureArgsList().bindDnArg.setPresent(true);
- }
- if (pwdFile != null)
- {
- argParser.getSecureArgsList().bindPasswordFileArg.getNameToValueMap().
- putAll(pwdFile);
- for (String value : pwdFile.keySet())
- {
- argParser.getSecureArgsList().bindPasswordFileArg.addValue(value);
- }
- argParser.getSecureArgsList().bindPasswordFileArg.setPresent(true);
- }
- else if (bindPwd != null)
- {
- argParser.getSecureArgsList().bindPasswordArg.addValue(bindPwd);
- argParser.getSecureArgsList().bindPasswordArg.setPresent(true);
- }
- }
-
-
- /**
* Forces the initialization of the trust manager in the
* LDAPConnectionInteraction object.
*/
@@ -10179,34 +9982,6 @@
}
}
- private String getReplicationServer(String hostName, int replicationPort)
- {
- return hostName.toLowerCase() + ":" + replicationPort;
- }
-
- private String getServerRepresentation(String hostName, int port)
- {
- return hostName.toLowerCase() + ":" + port;
- }
-
- private String getSuffixDisplay(String baseDN, Set<ServerDescriptor> servers)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(baseDN);
- for (ServerDescriptor server : servers)
- {
- sb.append(Constants.LINE_SEPARATOR+" ");
- sb.append(server.getHostPort(true));
- }
- return sb.toString();
- }
-
- private boolean areSameServer(ServerDescriptor server1,
- ServerDescriptor server2)
- {
- return server1.getId().equals(server2.getId());
- }
-
/**
* Merge the contents of the two registries but only does it partially.
* Only one of the two ADSContext will be updated (in terms of data in
@@ -10331,12 +10106,14 @@
ConnectionUtils.getHostPort(ctxDestination),
ConnectionUtils.getHostPort(ctxSource),
ConnectionUtils.getHostPort(ctxDestination));
+ println(msg);
+ println();
}
printProgress(INFO_REPLICATION_MERGING_REGISTRIES_PROGRESS.get());
pointAdder.start();
- Collection<Message> cache1Errors = getErrorMessages(cache1);
+ Collection<Message> cache1Errors = cache1.getErrorMessages();
if (!cache1Errors.isEmpty())
{
throw new ReplicationCliException(
@@ -10347,7 +10124,7 @@
ERROR_READING_ADS, null);
}
- Collection<Message> cache2Errors = getErrorMessages(cache2);
+ Collection<Message> cache2Errors = cache2.getErrorMessages();
if (!cache2Errors.isEmpty())
{
throw new ReplicationCliException(
diff --git a/opends/src/server/org/opends/server/util/args/ArgumentParser.java b/opends/src/server/org/opends/server/util/args/ArgumentParser.java
index b5168a6..1c1e412 100644
--- a/opends/src/server/org/opends/server/util/args/ArgumentParser.java
+++ b/opends/src/server/org/opends/server/util/args/ArgumentParser.java
@@ -1828,5 +1828,38 @@
{
return versionPresent;
}
+
+
+
+ /**
+ * Get the password which has to be used for the command without prompting
+ * the user. If no password was specified, return null.
+ *
+ * @param clearArg
+ * The password StringArgument argument.
+ * @param fileArg
+ * The password FileBased argument.
+ * @return The password stored into the specified file on by the
+ * command line argument, or null it if not specified.
+ */
+ public static String getBindPassword(StringArgument clearArg,
+ FileBasedArgument fileArg)
+ {
+ String pwd;
+ if (clearArg.isPresent())
+ {
+ pwd = clearArg.getValue();
+ }
+ else
+ if (fileArg.isPresent())
+ {
+ pwd = fileArg.getValue();
+ }
+ else
+ {
+ pwd = null;
+ }
+ return pwd;
+ }
}
diff --git a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
index 720ed8f..1d149d9 100644
--- a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
+++ b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -648,6 +648,55 @@
}
/**
+ * Returns a message object for the given NamingException.
+ * @param ne the NamingException.
+ * @param hostPort the hostPort representation of the server we were
+ * contacting when the NamingException occurred.
+ * @return a message object for the given NamingException.
+ */
+ protected Message getMessageForException(NamingException ne, String hostPort)
+ {
+ Message msg;
+ if (Utils.isCertificateException(ne))
+ {
+ msg = INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
+ hostPort, ne.toString(true));
+ }
+ else
+ {
+ msg = INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC.get(
+ hostPort, ne.toString(true));
+ }
+ return msg;
+ }
+
+ /**
+ * Commodity method used to repeatidly ask the user to provide a port value.
+ * @param prompt the prompt message.
+ * @param defaultValue the default value of the port to be proposed to the
+ * user.
+ * @param logger the logger where the errors will be written.
+ * @return the port value provided by the user.
+ */
+ protected int askPort(Message prompt, int defaultValue, Logger logger)
+ {
+ int port = -1;
+ while (port == -1)
+ {
+ try
+ {
+ port = readPort(prompt, defaultValue);
+ }
+ catch (CLIException ce)
+ {
+ port = -1;
+ logger.log(Level.WARNING, "Error reading input: "+ce, ce);
+ }
+ }
+ return port;
+ }
+
+ /**
* Interactively prompts for user input and continues until valid
* input is provided.
*
diff --git a/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java b/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
index 5433283..26ace2c 100644
--- a/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
+++ b/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
@@ -58,6 +58,7 @@
import java.security.KeyStoreException;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
+import java.util.LinkedHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -1934,6 +1935,93 @@
}
}
+ /**
+ * Initializes the global arguments in the parser with the provided values.
+ * This is useful when we want to call LDAPConnectionConsoleInteraction.run()
+ * with some default values.
+ * @param hostName the host name.
+ * @param port the port to connect to the server.
+ * @param adminUid the administrator UID.
+ * @param bindDn the bind DN to bind to the server.
+ * @param bindPwd the password to bind.
+ * @param pwdFile the Map containing the file and the password to bind.
+ */
+ public void initializeGlobalArguments(String hostName, int port,
+ String adminUid, String bindDn,
+ String bindPwd, LinkedHashMap<String, String> pwdFile)
+ {
+ resetConnectionArguments();
+ if (hostName != null)
+ {
+ secureArgsList.hostNameArg.addValue(hostName);
+ secureArgsList.hostNameArg.setPresent(true);
+ }
+ // resetConnectionArguments does not clear the values for the port
+ secureArgsList.portArg.clearValues();
+ if (port != -1)
+ {
+ secureArgsList.portArg.addValue(String.valueOf(port));
+ secureArgsList.portArg.setPresent(true);
+ }
+ else
+ {
+ // This is done to be able to call IntegerArgument.getIntValue()
+ secureArgsList.portArg.addValue(secureArgsList.portArg.getDefaultValue());
+ }
+ secureArgsList.useSSLArg.setPresent(useSSL);
+ secureArgsList.useStartTLSArg.setPresent(useStartTLS);
+ if (adminUid != null)
+ {
+ secureArgsList.adminUidArg.addValue(adminUid);
+ secureArgsList.adminUidArg.setPresent(true);
+ }
+ if (bindDn != null)
+ {
+ secureArgsList.bindDnArg.addValue(bindDn);
+ secureArgsList.bindDnArg.setPresent(true);
+ }
+ if (pwdFile != null)
+ {
+ secureArgsList.bindPasswordFileArg.getNameToValueMap().putAll(pwdFile);
+ for (String value : pwdFile.keySet())
+ {
+ secureArgsList.bindPasswordFileArg.addValue(value);
+ }
+ secureArgsList.bindPasswordFileArg.setPresent(true);
+ }
+ else if (bindPwd != null)
+ {
+ secureArgsList.bindPasswordArg.addValue(bindPwd);
+ secureArgsList.bindPasswordArg.setPresent(true);
+ }
+ }
+
+ /**
+ * Resets the connection parameters for the LDAPConsoleInteraction object.
+ * The reset does not apply to the certificate parameters. This is called
+ * in order the LDAPConnectionConsoleInteraction object to ask for all this
+ * connection parameters next time we call
+ * LDAPConnectionConsoleInteraction.run().
+ */
+ public void resetConnectionArguments()
+ {
+ secureArgsList.hostNameArg.clearValues();
+ secureArgsList.hostNameArg.setPresent(false);
+ secureArgsList.portArg.clearValues();
+ secureArgsList.portArg.setPresent(false);
+ // This is done to be able to call IntegerArgument.getIntValue()
+ secureArgsList.portArg.addValue(secureArgsList.portArg.getDefaultValue());
+ secureArgsList.bindDnArg.clearValues();
+ secureArgsList.bindDnArg.setPresent(false);
+ secureArgsList.bindPasswordArg.clearValues();
+ secureArgsList.bindPasswordArg.setPresent(false);
+ secureArgsList.bindPasswordFileArg.clearValues();
+ secureArgsList.bindPasswordFileArg.getNameToValueMap().clear();
+ secureArgsList.bindPasswordFileArg.setPresent(false);
+ secureArgsList.adminUidArg.clearValues();
+ secureArgsList.adminUidArg.setPresent(false);
+ }
+
private void initializeTrustManager() throws ArgumentException
{
// Get truststore info
--
Gitblit v1.10.0