From 92ca37b3ae4ee03b8319a1f5586b9bffd8d73f81 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 07 Apr 2016 20:05:24 +0000
Subject: [PATCH] OPENDJ-2822 Enabling replication throws a NPE OPENDJ-2821 status tool throws an exception with -X option
---
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 101 +++++++-------
opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java | 20 ++
opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java | 291 ++++-------------------------------------
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java | 4
opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java | 4
5 files changed, 105 insertions(+), 315 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
index 71232a4..9313818 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
@@ -129,8 +129,8 @@
*/
INSTANCE_PUBLIC_KEY_CERTIFICATE("ds-cfg-public-key-certificate", ADSPropertySyntax.CERTIFICATE_BINARY);
- private String attrName;
- private ADSPropertySyntax attSyntax;
+ private final String attrName;
+ private final ADSPropertySyntax attSyntax;
/**
* Private constructor.
@@ -170,29 +170,6 @@
/** Default global admin UID. */
public static final String GLOBAL_ADMIN_UID = "admin";
- private static Map<String, ServerProperty> NAME_TO_SERVER_PROPERTY;
-
- /**
- * Get a ServerProperty associated to a name.
- *
- * @param name
- * The name of the property to retrieve.
- * @return The corresponding ServerProperty or null if name doesn't match with
- * an existing property.
- */
- public static ServerProperty getServerPropFromName(String name)
- {
- if (NAME_TO_SERVER_PROPERTY == null)
- {
- NAME_TO_SERVER_PROPERTY = new HashMap<>();
- for (ServerProperty s : ServerProperty.values())
- {
- NAME_TO_SERVER_PROPERTY.put(s.getAttributeName(), s);
- }
- }
- return NAME_TO_SERVER_PROPERTY.get(name);
- }
-
/** The list of server properties that are multivalued. */
private static final Set<ServerProperty> MULTIVALUED_SERVER_PROPERTIES = new HashSet<>();
static
@@ -201,10 +178,10 @@
}
/** The default server group which will contain all registered servers. */
- public static final String ALL_SERVERGROUP_NAME = "all-servers";
+ private static final String ALL_SERVERGROUP_NAME = "all-servers";
/** Enumeration containing the different server group properties that are stored in the ADS. */
- public enum ServerGroupProperty
+ private enum ServerGroupProperty
{
/** The UID of the server group. */
UID("cn"),
@@ -213,7 +190,7 @@
/** The members of the server group. */
MEMBERS("uniqueMember");
- private String attrName;
+ private final String attrName;
/**
* Private constructor.
@@ -258,8 +235,8 @@
/** The administrator privilege. */
PRIVILEGE("privilege", ADSPropertySyntax.STRING);
- private String attrName;
- private ADSPropertySyntax attrSyntax;
+ private final String attrName;
+ private final ADSPropertySyntax attrSyntax;
/**
* Private constructor.
@@ -296,29 +273,6 @@
}
}
- private static HashMap<String, AdministratorProperty> nameToAdminUserProperty;
-
- /**
- * Get a AdministratorProperty associated to a name.
- *
- * @param name
- * The name of the property to retrieve.
- * @return The corresponding AdministratorProperty or null if name doesn't
- * match with an existing property.
- */
- public static AdministratorProperty getAdminUserPropFromName(String name)
- {
- if (nameToAdminUserProperty == null)
- {
- nameToAdminUserProperty = new HashMap<>();
- for (AdministratorProperty u : AdministratorProperty.values())
- {
- nameToAdminUserProperty.put(u.getAttributeName(), u);
- }
- }
- return nameToAdminUserProperty.get(name);
- }
-
/** The context used to retrieve information. */
private final InitialLdapContext dirContext;
private final ConnectionWrapper connectionWrapper;
@@ -433,7 +387,8 @@
* @throws ADSContextException
* if the server could not be registered.
*/
- public void updateServer(Map<ServerProperty, Object> serverProperties, String newServerId) throws ADSContextException
+ private void updateServer(Map<ServerProperty, Object> serverProperties, String newServerId)
+ throws ADSContextException
{
LdapName dn = makeDNFromServerProperties(serverProperties);
@@ -602,7 +557,7 @@
* @throws ADSContextException
* if something went wrong.
*/
- public boolean isServerAlreadyRegistered(Map<ServerProperty, Object> serverProperties) throws ADSContextException
+ private boolean isServerAlreadyRegistered(Map<ServerProperty, Object> serverProperties) throws ADSContextException
{
return isExistingEntry(makeDNFromServerProperties(serverProperties));
}
@@ -617,7 +572,7 @@
* @throws ADSContextException
* if something went wrong.
*/
- public boolean isAdministratorAlreadyRegistered(String uid) throws ADSContextException
+ private boolean isAdministratorAlreadyRegistered(String uid) throws ADSContextException
{
return isExistingEntry(makeDNFromAdministratorProperties(uid));
}
@@ -662,7 +617,7 @@
* @throws ADSContextException
* if something goes wrong.
*/
- public Set<String> getServerGroupMemberList(String serverGroupId) throws ADSContextException
+ private Set<String> getServerGroupMemberList(String serverGroupId) throws ADSContextException
{
LdapName dn = nameFromDN("cn=" + Rdn.escapeValue(serverGroupId) + "," + getServerGroupContainerDN());
@@ -813,7 +768,7 @@
* @throws ADSContextException
* if something goes wrong.
*/
- public void createServerGroup(Map<ServerGroupProperty, Object> serverGroupProperties) throws ADSContextException
+ private void createServerGroup(Map<ServerGroupProperty, Object> serverGroupProperties) throws ADSContextException
{
LdapName dn = makeDNFromServerGroupProperties(serverGroupProperties);
BasicAttributes attrs = makeAttrsFromServerGroupProperties(serverGroupProperties);
@@ -847,7 +802,7 @@
* @throws ADSContextException
* if something goes wrong.
*/
- public void updateServerGroup(String groupID, Map<ServerGroupProperty, Object> serverGroupProperties)
+ private void updateServerGroup(String groupID, Map<ServerGroupProperty, Object> serverGroupProperties)
throws ADSContextException
{
LdapName dn = nameFromDN("cn=" + Rdn.escapeValue(groupID) + "," + getServerGroupContainerDN());
@@ -892,77 +847,25 @@
}
/**
- * Updates the properties of a Server Group in the ADS.
- *
- * @param serverGroupProperties
- * the new properties of the server group to be updated.
- * @param groupID
- * The group name.
- * @throws ADSContextException
- * if something goes wrong.
- */
- public void removeServerGroupProp(String groupID, Set<ServerGroupProperty> serverGroupProperties)
- throws ADSContextException
- {
- LdapName dn = nameFromDN("cn=" + Rdn.escapeValue(groupID) + "," + getServerGroupContainerDN());
- BasicAttributes attrs = makeAttrsFromServerGroupProperties(serverGroupProperties);
- try
- {
- dirContext.modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, attrs);
- }
- catch (NameAlreadyBoundException x)
- {
- throw new ADSContextException(ErrorType.ALREADY_REGISTERED);
- }
- catch (NamingException x)
- {
- throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
- }
- }
-
- /**
- * Deletes a Server Group in the ADS.
- *
- * @param serverGroupProperties
- * the properties of the server group to be deleted.
- * @throws ADSContextException
- * if something goes wrong.
- */
- public void deleteServerGroup(Map<ServerGroupProperty, Object> serverGroupProperties) throws ADSContextException
- {
- LdapName dn = makeDNFromServerGroupProperties(serverGroupProperties);
- try
- {
- dirContext.destroySubcontext(dn);
- }
- catch (NamingException x)
- {
- throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
- }
- }
-
- /**
* Returns a set containing the server groups that are defined in the ADS.
*
* @return a set containing the server groups that are defined in the ADS.
* @throws ADSContextException
* if something goes wrong.
*/
- public Set<Map<ServerGroupProperty, Object>> readServerGroupRegistry() throws ADSContextException
+ private Set<Map<ServerGroupProperty, Object>> readServerGroupRegistry() throws ADSContextException
{
Set<Map<ServerGroupProperty, Object>> result = new HashSet<>();
NamingEnumeration<SearchResult> ne = null;
try
{
SearchControls sc = new SearchControls();
-
sc.setSearchScope(SearchControls.ONELEVEL_SCOPE);
ne = dirContext.search(getServerGroupContainerDN(), "(objectclass=*)", sc);
while (ne.hasMore())
{
SearchResult sr = ne.next();
- Map<ServerGroupProperty, Object> properties = makePropertiesFromServerGroupAttrs(sr.getAttributes());
- result.add(properties);
+ result.add(makePropertiesFromServerGroupAttrs(sr.getAttributes()));
}
}
catch (NameNotFoundException x)
@@ -998,7 +901,6 @@
try
{
SearchControls sc = new SearchControls();
-
sc.setSearchScope(SearchControls.ONELEVEL_SCOPE);
String[] attList = { "cn", "userpassword", "ds-privilege-name", "description" };
sc.setReturningAttributes(attList);
@@ -1006,9 +908,7 @@
while (ne.hasMore())
{
SearchResult sr = ne.next();
- Map<AdministratorProperty, Object> properties =
- makePropertiesFromAdministratorAttrs(getRdn(sr.getName()), sr.getAttributes());
- result.add(properties);
+ result.add(makePropertiesFromAdministratorAttrs(getRdn(sr.getName()), sr.getAttributes()));
}
}
catch (NameNotFoundException x)
@@ -1240,85 +1140,6 @@
}
/**
- * Updates and administrator registered in the ADS.
- *
- * @param adminProperties
- * the new properties of the administrator.
- * @param newAdminUserId
- * The new admin user Identifier, or null.
- * @throws ADSContextException
- * if something goes wrong.
- */
- public void updateAdministrator(Map<AdministratorProperty, Object> adminProperties, String newAdminUserId)
- throws ADSContextException
- {
- LdapName dnCentralAdmin = makeDNFromAdministratorProperties(adminProperties);
-
- boolean updatePassword = adminProperties.containsKey(AdministratorProperty.PASSWORD);
-
- NamingEnumeration<?> currentPrivileges = null;
- try
- {
- // Entry renaming
- if (newAdminUserId != null)
- {
- Map<AdministratorProperty, Object> newAdminUserProps = new HashMap<>(adminProperties);
- newAdminUserProps.put(AdministratorProperty.UID, newAdminUserId);
- LdapName newDn = makeDNFromAdministratorProperties(newAdminUserProps);
- dirContext.rename(dnCentralAdmin, newDn);
- dnCentralAdmin = newDn;
- adminProperties.put(AdministratorProperty.UID, newAdminUserId);
- }
-
- // if modification includes 'privilege', we have to get first the
- // current privileges list.
- if (adminProperties.containsKey(AdministratorProperty.PRIVILEGE))
- {
- SearchControls sc = new SearchControls();
- sc.setSearchScope(SearchControls.OBJECT_SCOPE);
- String[] attList = { "ds-privilege-name" };
- sc.setReturningAttributes(attList);
- NamingEnumeration<SearchResult> ne = dirContext.search(dnCentralAdmin, "(objectclass=*)", sc);
- try
- {
- while (ne.hasMore())
- {
- currentPrivileges = ne.next().getAttributes().get("ds-privilege-name").getAll();
- }
- }
- finally
- {
- handleCloseNamingEnumeration(ne);
- }
- }
-
- // Replace properties, if needed.
- if (adminProperties.size() > 1)
- {
- BasicAttributes attrs =
- makeAttrsFromAdministratorProperties(adminProperties, updatePassword, currentPrivileges);
- dirContext.modifyAttributes(dnCentralAdmin, DirContext.REPLACE_ATTRIBUTE, attrs);
- }
- }
- catch (NameNotFoundException x)
- {
- throw new ADSContextException(ErrorType.NOT_YET_REGISTERED);
- }
- catch (NoPermissionException x)
- {
- throw new ADSContextException(ErrorType.ACCESS_PERMISSION);
- }
- catch (NamingException x)
- {
- throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x);
- }
- finally
- {
- handleCloseNamingEnumeration(currentPrivileges);
- }
- }
-
- /**
* Returns the DN of the suffix that contains the administration data.
*
* @return the DN of the suffix that contains the administration data.
@@ -1419,26 +1240,6 @@
/**
* This method returns the DN of the entry that corresponds to the given
- * server properties.
- *
- * @param serverProperties
- * the server properties.
- * @return the DN of the entry that corresponds to the given server
- * properties.
- * @throws ADSContextException
- * if something goes wrong.
- */
- public static String getServerIdFromServerProperties(Map<ServerProperty, Object> serverProperties)
- throws ADSContextException
- {
- LdapName ldapName = makeDNFromServerProperties(serverProperties);
- String rdn = ldapName.get(ldapName.size() - 1);
- int pos = rdn.indexOf("=");
- return rdn.substring(pos + 1);
- }
-
- /**
- * This method returns the DN of the entry that corresponds to the given
* administrator properties.
*
* @param adminProperties
@@ -1663,29 +1464,6 @@
}
/**
- * Returns the attributes for some server group properties.
- *
- * @param serverGroupProperties
- * the server group properties.
- * @return the attributes for the given server group properties.
- */
- private static BasicAttributes makeAttrsFromServerGroupProperties(Set<ServerGroupProperty> serverGroupProperties)
- {
- BasicAttributes result = new BasicAttributes();
-
- // Transform 'properties' into 'attributes'
- for (ServerGroupProperty prop : serverGroupProperties)
- {
- Attribute attr = makeAttrFromServerGroupProperty(prop, null);
- if (attr != null)
- {
- result.put(attr);
- }
- }
- return result;
- }
-
- /**
* Returns the attribute for a given server group property.
*
* @param property
@@ -1858,9 +1636,7 @@
throws ADSContextException
{
Map<AdministratorProperty, Object> result = new HashMap<>();
- LdapName nameObj;
- nameObj = nameFromDN(rdn);
- String dn = nameObj + "," + getAdministratorContainerDN();
+ String dn = nameFromDN(rdn) + "," + getAdministratorContainerDN();
result.put(AdministratorProperty.ADMINISTRATOR_DN, dn);
NamingEnumeration<? extends Attribute> ne = null;
try
@@ -1916,7 +1692,7 @@
*
* @return the parent entry of the server entries.
*/
- public static String getServerContainerDN()
+ private static String getServerContainerDN()
{
return "cn=Servers," + getAdministrationSuffixDN();
}
@@ -1936,7 +1712,7 @@
*
* @return the parent entry of the server group entries.
*/
- public static String getServerGroupContainerDN()
+ private static String getServerGroupContainerDN()
{
return "cn=Server Groups," + getAdministrationSuffixDN();
}
@@ -2116,24 +1892,22 @@
try
{
SearchControls sc = new SearchControls();
-
sc.setSearchScope(SearchControls.OBJECT_SCOPE);
sc.setReturningAttributes(new String[] { SchemaConstants.NO_ATTRIBUTES });
NamingEnumeration<SearchResult> sr = getDirContext().search(dn, "(objectclass=*)", sc);
- boolean result = false;
try
{
while (sr.hasMore())
{
sr.next();
- result = true;
+ return true;
}
}
finally
{
sr.close();
}
- return result;
+ return false;
}
catch (NameNotFoundException x)
{
@@ -2159,10 +1933,10 @@
*/
private void createContainerEntry(String dn) throws ADSContextException
{
- BasicAttributes attrs = new BasicAttributes();
Attribute oc = new BasicAttribute("objectclass");
oc.add("top");
oc.add("ds-cfg-branch");
+ BasicAttributes attrs = new BasicAttributes();
attrs.put(oc);
createEntry(dn, attrs);
}
@@ -2175,9 +1949,9 @@
*/
private void createAdministratorContainerEntry() throws ADSContextException
{
- BasicAttributes attrs = new BasicAttributes();
Attribute oc = new BasicAttribute("objectclass");
oc.add("groupofurls");
+ BasicAttributes attrs = new BasicAttributes();
attrs.put(oc);
attrs.put("memberURL", "ldap:///" + getAdministratorContainerDN() + "??one?(objectclass=*)");
attrs.put("description", "Group of identities which have full access.");
@@ -2192,10 +1966,10 @@
*/
private void createTopContainerEntry() throws ADSContextException
{
- BasicAttributes attrs = new BasicAttributes();
Attribute oc = new BasicAttribute("objectclass");
oc.add("top");
oc.add("ds-cfg-branch");
+ BasicAttributes attrs = new BasicAttributes();
attrs.put(oc);
createEntry(getAdministrationSuffixDN(), attrs);
}
@@ -2233,7 +2007,7 @@
* @throws ADSContextException
* if something goes wrong.
*/
- public void createAdministrationSuffix(String backendName) throws ADSContextException
+ private void createAdministrationSuffix(String backendName) throws ADSContextException
{
ADSContextHelper helper = new ADSContextHelper();
String ben = backendName;
@@ -2259,7 +2033,7 @@
*
* @return the LDIF file of the administration data.
*/
- public static String getAdminLDIFFile()
+ static String getAdminLDIFFile()
{
return "config" + File.separator + "admin-backend.ldif";
}
@@ -2271,7 +2045,7 @@
*
* @return the parent entry of the server key entries in ADS.
*/
- public static String getInstanceKeysContainerDN()
+ static String getInstanceKeysContainerDN()
{
return "cn=instance keys," + getAdministrationSuffixDN();
}
@@ -2281,7 +2055,7 @@
*
* @return the parent entry of the secret key entries in ADS.
*/
- public static String getSecretKeysContainerDN()
+ private static String getSecretKeysContainerDN()
{
return "cn=secret keys," + getAdministrationSuffixDN();
}
@@ -2321,11 +2095,8 @@
* key entry belongs.
* @param serverEntryDn
* The server's ADS entry DN.
- * @throws NamingException
- * In case some JNDI operation fails.
- * @throws CryptoManager.CryptoManagerException
- * In case there is a problem getting the instance public key
- * certificate ID.
+ * @throws ADSContextException
+ * In case there is a problem registering the instance public key certificate ID
*/
private void registerInstanceKeyCertificate(Map<ServerProperty, Object> serverProperties, LdapName serverEntryDn)
throws ADSContextException
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java
index 943718d..8d18a05 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java
@@ -603,7 +603,7 @@
startTLSEnabled = Boolean.TRUE.equals(array.get(array.size() -1));
}
adsProperties.put(ADSContext.ServerProperty.STARTTLS_ENABLED, Boolean.toString(startTLSEnabled));
- adsProperties.put(ADSContext.ServerProperty.ID, getHostPort(true));
+ adsProperties.put(ADSContext.ServerProperty.ID, getHostPort(true).toString());
adsProperties.put(ADSContext.ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE,
getInstancePublicKeyCertificate());
}
@@ -1401,7 +1401,7 @@
*/
public static String getReplicationServer(String hostName, int replicationPort)
{
- return new HostPort(hostName, replicationPort).toString();
+ return HostPort.toString(hostName, replicationPort);
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
index 14407f8..07ebac6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
@@ -134,7 +134,9 @@
{
try
{
- return new SSLContextBuilder().setTrustManager(trustManager).getSSLContext();
+ return new SSLContextBuilder()
+ .setTrustManager(trustManager != null ? trustManager : new BlindTrustManager())
+ .getSSLContext();
}
catch (GeneralSecurityException e)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index 3ff3743..0995a1d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -60,19 +60,35 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
-import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg0;
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1;
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
+import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.ConfigurationFramework;
import org.forgerock.opendj.config.ManagedObjectNotFoundException;
import org.forgerock.opendj.config.PropertyException;
import org.forgerock.opendj.config.server.ConfigException;
-import org.opends.admin.ads.*;
+import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.server.config.client.CryptoManagerCfgClient;
+import org.forgerock.opendj.server.config.client.ReplicationDomainCfgClient;
+import org.forgerock.opendj.server.config.client.ReplicationServerCfgClient;
+import org.forgerock.opendj.server.config.client.ReplicationSynchronizationProviderCfgClient;
+import org.forgerock.opendj.server.config.client.RootCfgClient;
+import org.forgerock.opendj.server.config.meta.ReplicationDomainCfgDefn;
+import org.forgerock.opendj.server.config.meta.ReplicationServerCfgDefn;
+import org.forgerock.opendj.server.config.meta.ReplicationSynchronizationProviderCfgDefn;
+import org.opends.admin.ads.ADSContext;
import org.opends.admin.ads.ADSContext.ADSPropertySyntax;
import org.opends.admin.ads.ADSContext.AdministratorProperty;
import org.opends.admin.ads.ADSContext.ServerProperty;
+import org.opends.admin.ads.ADSContextException;
+import org.opends.admin.ads.ReplicaDescriptor;
+import org.opends.admin.ads.ServerDescriptor;
+import org.opends.admin.ads.SuffixDescriptor;
+import org.opends.admin.ads.TopologyCache;
+import org.opends.admin.ads.TopologyCacheException;
+import org.opends.admin.ads.TopologyCacheFilter;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.admin.ads.util.OpendsCertificateException;
@@ -80,7 +96,11 @@
import org.opends.admin.ads.util.ServerLoader;
import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
-import org.opends.guitools.controlpanel.util.*;
+import org.opends.guitools.controlpanel.util.ConfigFromDirContext;
+import org.opends.guitools.controlpanel.util.ConfigFromFile;
+import org.opends.guitools.controlpanel.util.ControlPanelLog;
+import org.opends.guitools.controlpanel.util.ProcessReader;
+import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.quicksetup.ApplicationException;
import org.opends.quicksetup.Constants;
import org.opends.quicksetup.Installation;
@@ -91,17 +111,13 @@
import org.opends.quicksetup.installer.PeerNotFoundException;
import org.opends.quicksetup.installer.offline.OfflineInstaller;
import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
-import org.forgerock.opendj.server.config.client.*;
-import org.forgerock.opendj.server.config.meta.ReplicationDomainCfgDefn;
-import org.forgerock.opendj.server.config.meta.ReplicationServerCfgDefn;
-import org.forgerock.opendj.server.config.meta.ReplicationSynchronizationProviderCfgDefn;
import org.opends.server.core.DirectoryServer;
import org.opends.server.tasks.PurgeConflictsHistoricalTask;
import org.opends.server.tools.dsreplication.EnableReplicationUserData.EnableReplicationServerData;
+import org.opends.server.tools.dsreplication.ReplicationCliArgumentParser.ServerArgs;
import org.opends.server.tools.tasks.TaskEntry;
import org.opends.server.tools.tasks.TaskScheduleInteraction;
import org.opends.server.tools.tasks.TaskScheduleUserData;
-import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.HostPort;
import org.opends.server.types.InitializationException;
import org.opends.server.types.NullOutputStream;
@@ -134,15 +150,15 @@
import com.forgerock.opendj.cli.ValidationCallback;
import static com.forgerock.opendj.cli.ArgumentConstants.*;
+import static com.forgerock.opendj.cli.CommonArguments.*;
import static com.forgerock.opendj.cli.Utils.*;
import static com.forgerock.opendj.util.OperatingSystem.*;
-import static com.forgerock.opendj.cli.CommonArguments.*;
import static java.util.Collections.*;
+
import static org.forgerock.util.Utils.*;
+import static org.opends.admin.ads.ServerDescriptor.*;
import static org.opends.admin.ads.util.ConnectionUtils.*;
import static org.opends.admin.ads.util.PreferredConnection.*;
-import static org.opends.admin.ads.ServerDescriptor.getReplicationServer;
-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.*;
@@ -3219,7 +3235,6 @@
adminPwd = sourceServerCI.getBindPassword();
ctxSource = createConnectionInteracting(sourceServerCI);
-
if (ctxSource == null)
{
cancelled = true;
@@ -3293,7 +3308,6 @@
if (!error)
{
ctxDestination = createConnectionInteracting(destinationServerCI, true);
-
if (ctxDestination == null)
{
cancelled = true;
@@ -3315,26 +3329,24 @@
cancelled = true;
}
}
+
if (!cancelled)
{
uData.setHostNameDestination(hostDestination);
uData.setPortDestination(portDestination);
- }
- if (!cancelled)
- {
List<String> suffixes = argParser.getBaseDNs();
cancelled = serversOperations.continueAfterUserInput(
suffixes, ctxSource.getLdapContext(), ctxDestination.getLdapContext(), true);
uData.setBaseDNs(suffixes);
- }
- if (!cancelled)
- {
- println();
- cancelled = serversOperations.confirmOperation(
- uData, ctxSource.getLdapContext(), ctxDestination.getLdapContext(), true);
- println();
+ if (!cancelled)
+ {
+ println();
+ cancelled = serversOperations.confirmOperation(
+ uData, ctxSource.getLdapContext(), ctxDestination.getLdapContext(), true);
+ println();
+ }
}
close(ctxSource, ctxDestination);
@@ -4003,9 +4015,9 @@
println();
print(formatter.getFormattedWithPoints(INFO_REPLICATION_CONNECTING.get()));
- LinkedList<LocalizableMessage> errorMessages = new LinkedList<>();
- ctx1 = createAdministrativeConnection(uData, true, errorMessages);
- ctx2 = createAdministrativeConnection(uData, false, errorMessages);
+ List<LocalizableMessage> errorMessages = new LinkedList<>();
+ ctx1 = createAdministrativeConnection(uData.getServer1(), errorMessages);
+ ctx2 = createAdministrativeConnection(uData.getServer2(), errorMessages);
if (!errorMessages.isEmpty())
{
@@ -4080,7 +4092,7 @@
}
private void checksForNonInteractiveMode(EnableReplicationUserData uData,
- ConnectionWrapper connWrapper1, ConnectionWrapper connWrapper2, LinkedList<LocalizableMessage> errorMessages)
+ ConnectionWrapper connWrapper1, ConnectionWrapper connWrapper2, List<LocalizableMessage> errorMessages)
{
EnableReplicationServerData server1 = uData.getServer1();
EnableReplicationServerData server2 = uData.getServer2();
@@ -4104,7 +4116,7 @@
}
private int checkReplicationPort(
- ConnectionWrapper connWrapper, EnableReplicationServerData server, LinkedList<LocalizableMessage> errorMessages)
+ ConnectionWrapper connWrapper, EnableReplicationServerData server, List<LocalizableMessage> errorMessages)
{
int replPort = getReplicationPort(connWrapper);
boolean hasReplicationPort = replPort > 0;
@@ -4126,7 +4138,7 @@
}
private void checkAdminAndReplicationPortsAreDifferent(
- int replPort, EnableReplicationServerData server, LinkedList<LocalizableMessage> errorMessages)
+ int replPort, EnableReplicationServerData server, List<LocalizableMessage> errorMessages)
{
if (replPort > 0 && replPort == server.getPort())
{
@@ -4150,7 +4162,7 @@
println();
}
- private void errPrintLn(LinkedList<LocalizableMessage> errorMessages)
+ private void errPrintLn(List<LocalizableMessage> errorMessages)
{
for (LocalizableMessage msg : errorMessages)
{
@@ -4159,13 +4171,12 @@
}
}
- private ConnectionWrapper createAdministrativeConnection(EnableReplicationUserData uData, boolean isFirstSetOfValues,
- LinkedList<LocalizableMessage> errorMessages)
+ private ConnectionWrapper createAdministrativeConnection(EnableReplicationServerData server,
+ List<LocalizableMessage> errorMessages)
{
- EnableReplicationServerData server = isFirstSetOfValues ? uData.getServer1() : uData.getServer2();
try
{
- return new ConnectionWrapper(createAdministrativeContext(uData, isFirstSetOfValues, errorMessages),
+ return new ConnectionWrapper(createAdministrativeContext(server, errorMessages),
getConnectTimeout(), getTrustManager(sourceServerCI));
}
catch (NamingException e)
@@ -4175,10 +4186,9 @@
}
}
- private InitialLdapContext createAdministrativeContext(EnableReplicationUserData uData, boolean isFirstSetOfValues,
- LinkedList<LocalizableMessage> errorMessages)
+ private InitialLdapContext createAdministrativeContext(EnableReplicationServerData server,
+ List<LocalizableMessage> errorMessages)
{
- EnableReplicationServerData server = isFirstSetOfValues ? uData.getServer1() : uData.getServer2();
try
{
return createAdministrativeContext(
@@ -5091,9 +5101,8 @@
* parameters to update the configuration.
* @throws ReplicationCliException if there is an error.
*/
- private void updateConfiguration(ConnectionWrapper ctx1,
- ConnectionWrapper ctx2, EnableReplicationUserData uData)
- throws ReplicationCliException
+ private void updateConfiguration(ConnectionWrapper ctx1, ConnectionWrapper ctx2, EnableReplicationUserData uData)
+ throws ReplicationCliException
{
final Set<String> twoReplServers = new LinkedHashSet<>();
final Set<String> allRepServers = new LinkedHashSet<>();
@@ -5885,10 +5894,7 @@
}
}
- /**
- * Try to figure out if we must explicitly disable replication on
- * cn=admin data and cn=schema.
- */
+ // Try to figure out if we must explicitly disable replication on cn=admin data and cn=schema.
boolean forceDisableSchema = false;
boolean forceDisableADS = false;
boolean schemaReplicated = false;
@@ -8152,38 +8158,32 @@
}
}
- /** {@inheritDoc} */
@Override
public boolean isAdvancedMode() {
return false;
}
- /** {@inheritDoc} */
@Override
public boolean isInteractive() {
return !forceNonInteractive && argParser.isInteractive();
}
- /** {@inheritDoc} */
@Override
public boolean isMenuDrivenMode() {
return true;
}
- /** {@inheritDoc} */
@Override
public boolean isQuiet()
{
return argParser.isQuiet();
}
- /** {@inheritDoc} */
@Override
public boolean isScriptFriendly() {
return argParser.isScriptFriendly();
}
- /** {@inheritDoc} */
@Override
public boolean isVerbose() {
return true;
@@ -9855,7 +9855,6 @@
/** Class used to compare replication servers. */
class ReplicationServerComparator implements Comparator<ServerDescriptor>
{
- /** {@inheritDoc} */
@Override
public int compare(ServerDescriptor s1, ServerDescriptor s2)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java b/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java
index ec07ac7..279996d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java
@@ -16,7 +16,11 @@
*/
package org.opends.server.types;
-import java.net.*;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Objects;
@@ -371,6 +375,20 @@
@Override
public String toString()
{
+ return toString(host, port);
+ }
+
+ /**
+ * Returns a string representation of the provided host and port. No validation is performed.
+ *
+ * @param host
+ * the host name
+ * @param port
+ * the port number
+ * @return A string representation of the provided host and port.
+ */
+ public static String toString(String host, int port)
+ {
if (host != null && host.contains(":"))
{
return "[" + host + "]:" + port;
--
Gitblit v1.10.0