From d6b296f5b3549079495ff902803d629dbbcb85b5 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 19 Aug 2016 13:36:19 +0000
Subject: [PATCH] installer, dsreplication, uninstaller: use HostPort
---
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 302 ++++++++++--------------
opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java | 15 +
opendj-server-legacy/src/main/java/org/opends/admin/ads/ReplicaDescriptor.java | 8
opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java | 5
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java | 21
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java | 226 +++++++++---------
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java | 14
opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java | 19 -
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallUserData.java | 6
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java | 9
opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java | 81 ++----
11 files changed, 312 insertions(+), 394 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ReplicaDescriptor.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ReplicaDescriptor.java
index e9adff3..5e92c6e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ReplicaDescriptor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ReplicaDescriptor.java
@@ -19,6 +19,8 @@
import java.util.HashSet;
import java.util.Set;
+import org.opends.server.types.HostPort;
+
/**
* The object of this class represent a Replica, i.e. a suffix in a given server instance.
* <p>
@@ -30,7 +32,7 @@
/** Number of entries held by this replica. */
private int nbEntries = -1;
private ServerDescriptor server;
- private final Set<String> replicationServers = new HashSet<>();
+ private final Set<HostPort> replicationServers = new HashSet<>();
/** This corresponds to the server-id of this replica. */
private int replicationId = -1;
private int missingChanges = -1;
@@ -125,7 +127,7 @@
* @return a set containing the String representation of the replication
* servers that are defined in the replication domain for this replica.
*/
- public Set<String> getReplicationServers()
+ public Set<HostPort> getReplicationServers()
{
return new HashSet<>(replicationServers);
}
@@ -137,7 +139,7 @@
* representation) that are defined in the replication domain for this
* replica.
*/
- public void setReplicationServers(Set<String> replicationServers)
+ public void setReplicationServers(Set<HostPort> replicationServers)
{
this.replicationServers.clear();
this.replicationServers.addAll(replicationServers);
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 f214db2..7246116 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
@@ -200,7 +200,7 @@
* on the information we have ("hostname":"replication port") and
* {@code null} if this is not a replication server.
*/
- public String getReplicationServerHostPort()
+ public HostPort getReplicationServerHostPort()
{
return isReplicationServer() ? getReplicationServer(getHostName(), getReplicationServerPort()) : null;
}
@@ -270,7 +270,7 @@
*/
public HostPort getLdapHostPort()
{
- return getHostPort0(ServerProperty.LDAP_ENABLED, ServerProperty.LDAP_PORT, false);
+ return getHostPort(getLdapPort(-1));
}
/**
@@ -280,26 +280,7 @@
*/
public HostPort getLdapsHostPort()
{
- return getHostPort0(ServerProperty.LDAPS_ENABLED, ServerProperty.LDAPS_PORT, true);
- }
-
- private HostPort getHostPort0(ServerProperty enabledProp, ServerProperty portProp, boolean useSSL)
- {
- int port = getPort(enabledProp, portProp);
- if (port != -1)
- {
- return new HostPort(getHostName(), port);
- }
- return null;
- }
-
- private int getPort(ServerProperty enabledProp, ServerProperty portProp)
- {
- if (!serverProperties.isEmpty())
- {
- return getPort(enabledProp, portProp, -1);
- }
- return -1;
+ return getHostPort(getLdapsPort(-1));
}
/**
@@ -309,7 +290,12 @@
*/
public HostPort getAdminConnectorHostPort()
{
- return getHostPort0(ServerProperty.ADMIN_ENABLED, ServerProperty.ADMIN_PORT, true);
+ return getHostPort(getAdminPort(-1));
+ }
+
+ private HostPort getHostPort(final int port)
+ {
+ return port != -1 ? new HostPort(getHostName(), port) : null;
}
/**
@@ -854,16 +840,17 @@
private static void updateReplication(ServerDescriptor desc, ConnectionWrapper conn, TopologyCacheFilter cacheFilter)
throws IOException
{
+ final Map<ServerProperty, Object> serverProps = desc.serverProperties;
+
SearchRequest request = newSearchRequest(
"cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config",
WHOLE_SUBTREE,
"(objectclass=ds-cfg-synchronization-provider)",
"ds-cfg-enabled");
SearchResultEntry sre = conn.getConnection().searchSingleEntry(request);
- Boolean replicationEnabled = asBoolean(sre, "ds-cfg-enabled");
- desc.serverProperties.put(ServerProperty.IS_REPLICATION_ENABLED, replicationEnabled);
+ serverProps.put(ServerProperty.IS_REPLICATION_ENABLED, asBoolean(sre, "ds-cfg-enabled"));
- Set<String> allReplicationServers = new LinkedHashSet<>();
+ Set<HostPort> allReplicationServers = new LinkedHashSet<>();
if (cacheFilter.searchBaseDNInformation())
{
@@ -882,7 +869,7 @@
SearchResultEntry sr = entryReader.readEntry();
int id = asInteger(sr, "ds-cfg-server-id");
- Set<String> replicationServers = asSetOfString(sr, "ds-cfg-replication-server");
+ Set<HostPort> replicationServers = toHostPorts(asSetOfString(sr, "ds-cfg-replication-server"));
Set<DN> dns = asSetOfDN(sr, "ds-cfg-base-dn");
for (DN dn : dns)
{
@@ -891,9 +878,8 @@
if (replica.getSuffix().getDN().equals(dn))
{
replica.setReplicationId(id);
- LinkedHashSet<String> repServers = toLowercase(replicationServers);
- replica.setReplicationServers(repServers);
- allReplicationServers.addAll(repServers);
+ replica.setReplicationServers(replicationServers);
+ allReplicationServers.addAll(replicationServers);
}
}
}
@@ -901,7 +887,7 @@
}
}
- desc.serverProperties.put(ServerProperty.IS_REPLICATION_SERVER, Boolean.FALSE);
+ serverProps.put(ServerProperty.IS_REPLICATION_SERVER, Boolean.FALSE);
request = newSearchRequest(
"cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config",
@@ -917,32 +903,25 @@
{
SearchResultEntry sr = entryReader.readEntry();
- desc.serverProperties.put(ServerProperty.IS_REPLICATION_SERVER, Boolean.TRUE);
- Integer port = asInteger(sr, "ds-cfg-replication-port");
- desc.serverProperties.put(ServerProperty.REPLICATION_SERVER_PORT, port);
- Integer serverId = asInteger(sr, "ds-cfg-replication-server-id");
- desc.serverProperties.put(ServerProperty.REPLICATION_SERVER_ID, serverId);
- LinkedHashSet<String> repServers = toLowercase(asSetOfString(sr, "ds-cfg-replication-server"));
- allReplicationServers.addAll(repServers);
- desc.serverProperties.put(ServerProperty.EXTERNAL_REPLICATION_SERVERS, allReplicationServers);
+ serverProps.put(ServerProperty.IS_REPLICATION_SERVER, Boolean.TRUE);
+ serverProps.put(ServerProperty.REPLICATION_SERVER_PORT, asInteger(sr, "ds-cfg-replication-port"));
+ serverProps.put(ServerProperty.REPLICATION_SERVER_ID, asInteger(sr, "ds-cfg-replication-server-id"));
+ allReplicationServers.addAll(toHostPorts(asSetOfString(sr, "ds-cfg-replication-server")));
+ serverProps.put(ServerProperty.EXTERNAL_REPLICATION_SERVERS, allReplicationServers);
}
}
- Boolean replicationSecure = isReplicationSecure(conn, replicationEnabled);
- desc.serverProperties.put(ServerProperty.IS_REPLICATION_SECURE, replicationSecure);
+ serverProps.put(ServerProperty.IS_REPLICATION_SECURE, isReplicationSecure(conn, asBoolean(sre, "ds-cfg-enabled")));
}
- /**
- * Keep the values of the replication servers in lower case to make use of Sets as String simpler.
- */
- private static LinkedHashSet<String> toLowercase(Set<String> values)
+ private static Set<HostPort> toHostPorts(Set<String> hostPorts)
{
- LinkedHashSet<String> repServers = new LinkedHashSet<>();
- for (String s: values)
+ final LinkedHashSet<HostPort> results = new LinkedHashSet<>();
+ for (String hostPort : hostPorts)
{
- repServers.add(s.toLowerCase());
+ results.add(HostPort.valueOf(hostPort));
}
- return repServers;
+ return results;
}
private static boolean isReplicationSecure(ConnectionWrapper conn, boolean replicationEnabled) throws IOException
@@ -1142,9 +1121,9 @@
* @return the replication server normalized String for a given host name
* and replication port.
*/
- public static String getReplicationServer(String hostName, int replicationPort)
+ public static HostPort getReplicationServer(String hostName, int replicationPort)
{
- return HostPort.toString(hostName, replicationPort);
+ return new HostPort(hostName, replicationPort);
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java
index de4dc02..61b3b78 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java
@@ -21,6 +21,7 @@
import java.util.TreeSet;
import org.forgerock.opendj.ldap.DN;
+import org.opends.server.types.HostPort;
/**
* The object of this class represent a topology of replicas across servers that
@@ -95,9 +96,9 @@
*
* @return the Set of Replication servers for the whole suffix topology.
*/
- public Set<String> getReplicationServers()
+ public Set<HostPort> getReplicationServers()
{
- Set<String> replicationServers = new HashSet<>();
+ Set<HostPort> replicationServers = new HashSet<>();
for (ReplicaDescriptor replica : getReplicas())
{
replicationServers.addAll(replica.getReplicationServers());
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java
index 085480d..cda6722 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java
@@ -171,8 +171,7 @@
{
for (SuffixDescriptor suffix : sufs)
{
- Set<String> rssInSuffix = suffix.getReplicationServers();
- for (String replicationServer : rssInSuffix)
+ for (HostPort replicationServer : suffix.getReplicationServers())
{
if (replica.getReplicationServers().contains(replicationServer))
{
@@ -256,10 +255,10 @@
{
Set<ReplicaDescriptor> candidateReplicas = new HashSet<>();
// It contains replication information: analyze it.
- String repServer = server.getReplicationServerHostPort();
+ HostPort repServer = server.getReplicationServerHostPort();
for (SuffixDescriptor suffix : getSuffixes())
{
- if (containsIgnoreCase(suffix.getReplicationServers(), repServer))
+ if (suffix.getReplicationServers().contains(repServer))
{
candidateReplicas.addAll(suffix.getReplicas());
}
@@ -267,18 +266,6 @@
return candidateReplicas;
}
- private boolean containsIgnoreCase(Set<String> col, String toFind)
- {
- for (String s : col)
- {
- if (s.equalsIgnoreCase(toFind))
- {
- return true;
- }
- }
- return false;
- }
-
/**
* Sets the list of LDAP URLs and connection type that are preferred to be
* used to connect to the servers. When we have a server to which we can
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java
index 41d5c18..6a2040d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -212,14 +212,12 @@
try
{
UninstallData d = new UninstallData(Installation.getLocal());
- userData.setReplicationServer(
- referencedHostName+":"+d.getReplicationServerPort());
+ userData.setReplicationServer(new HostPort(referencedHostName, d.getReplicationServerPort()));
}
catch (Throwable t)
{
logger.error(LocalizableMessage.raw("Could not create UninstallData: "+t, t));
- userData.setReplicationServer(
- referencedHostName+":8989");
+ userData.setReplicationServer(new HostPort(referencedHostName, 8989));
}
info = ControlPanelInfo.getInstance();
info.setTrustManager(userData.getTrustManager());
@@ -877,8 +875,7 @@
try
{
UninstallData d = new UninstallData(Installation.getLocal());
- userData.setReplicationServer(
- referencedHostName+":"+d.getReplicationServerPort());
+ userData.setReplicationServer(new HostPort(referencedHostName, d.getReplicationServerPort()));
userData.setReferencedHostName(referencedHostName);
}
catch (Throwable t)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallUserData.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallUserData.java
index 043aa07..d553cea 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallUserData.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallUserData.java
@@ -42,7 +42,7 @@
private HostPort localServerHostPort;
private boolean localServerSecure;
private Set<ServerDescriptor> remoteServers = new HashSet<>();
- private String replicationServer;
+ private HostPort replicationServer;
private String referencedHostName;
/**
@@ -280,7 +280,7 @@
* Returns the replication server as referenced in other servers.
* @return the replication server as referenced in other servers.
*/
- public String getReplicationServer() {
+ public HostPort getReplicationServer() {
return replicationServer;
}
@@ -289,7 +289,7 @@
* @param replicationServer the replication server as referenced in other
* servers.
*/
- public void setReplicationServer(String replicationServer) {
+ public void setReplicationServer(HostPort replicationServer) {
this.replicationServer = replicationServer;
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
index c6b545c..2db79cf 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
@@ -41,11 +41,13 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.ConfigurationFramework;
import org.forgerock.opendj.config.ManagedObjectNotFoundException;
+import org.forgerock.opendj.config.OperationsException;
+import org.forgerock.opendj.config.client.OperationRejectedException;
import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.ldap.LdapException;
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.opends.admin.ads.ADSContext;
import org.opends.admin.ads.ADSContextException;
import org.opends.admin.ads.ReplicaDescriptor;
@@ -1454,14 +1456,15 @@
loginDialog.setVisible(true);
if (!loginDialog.isCanceled())
{
- getUninstallUserData().setAdminUID(loginDialog.getAdministratorUid());
- getUninstallUserData().setAdminPwd(loginDialog.getAdministratorPwd());
+ final UninstallUserData uData = getUninstallUserData();
+ uData.setAdminUID(loginDialog.getAdministratorUid());
+ uData.setAdminPwd(loginDialog.getAdministratorPwd());
final ConnectionWrapper conn = loginDialog.getConnection();
- getUninstallUserData().setLocalServer(conn.getHostPort(), conn.isLdaps());
- getUninstallUserData().setReplicationServer(
- loginDialog.getHostName() + ":" +
- conf.getReplicationServerPort());
- getUninstallUserData().setReferencedHostName(loginDialog.getHostName());
+ uData.setLocalServer(conn.getHostPort(), conn.isLdaps());
+ uData.setReplicationServer(new HostPort(
+ loginDialog.getHostName(),
+ conf.getReplicationServerPort()));
+ uData.setReferencedHostName(loginDialog.getHostName());
BackgroundTask<TopologyCache> worker = new BackgroundTask<TopologyCache>()
{
@@ -1756,39 +1759,38 @@
* @throws ApplicationException if we are not working on force on error mode
* and there is an error.
*/
- private void removeReferences(ServerDescriptor server,
- Map<ADSContext.ServerProperty, Object> serverADSProperties)
- throws ApplicationException
+ private void removeReferences(ServerDescriptor server, Map<ADSContext.ServerProperty, Object> serverADSProperties)
+ throws ApplicationException
{
/* First check if the server must be updated based in the contents of the
* ServerDescriptor object. */
UninstallUserData uData = getUninstallUserData();
- String rsUrl = uData.getReplicationServer();
- if (!isReferenced(server.getServerProperties(), rsUrl)
- && !isReferenced(server.getReplicas(), rsUrl))
+ HostPort rsHp = uData.getReplicationServer();
+ HostPort serverHostPort = server.getHostPort(true);
+ if (!isReferenced(server.getServerProperties(), rsHp)
+ && !isReferenced(server.getReplicas(), rsHp))
{
- logger.info(LocalizableMessage.raw("No references in: " + server.getHostPort(true)));
+ logger.info(LocalizableMessage.raw("No references in: " + serverHostPort));
return;
}
- logger.info(LocalizableMessage.raw("Updating references in: " + server.getHostPort(true)));
- notifyListeners(getFormattedWithPoints(INFO_PROGRESS_REMOVING_REFERENCES.get(server.getHostPort(true))));
+ logger.info(LocalizableMessage.raw("Updating references in: " + serverHostPort));
+ notifyListeners(getFormattedWithPoints(INFO_PROGRESS_REMOVING_REFERENCES.get(serverHostPort)));
DN dn = ADSContext.getAdministratorDN(uData.getAdminUID());
String pwd = uData.getAdminPwd();
try (ConnectionWrapper connWrapper =
getRemoteConnection(server, dn, pwd, getConnectTimeout(), new LinkedHashSet<PreferredConnection>()))
{
- // Update replication servers and domains. If the domain
- // is an ADS, then remove it from there.
- removeReferences(connWrapper, server.getHostPort(true), serverADSProperties);
+ // Update replication servers and domains. If the domain is an ADS, then remove it from there.
+ removeReferences(connWrapper, serverHostPort, serverADSProperties);
notifyListeners(getFormattedDoneWithLineBreak());
}
catch (ApplicationException ae)
{
errorOnRemoteOccurred = true;
- logger.info(LocalizableMessage.raw("Error updating replication references in: " + server.getHostPort(true), ae));
+ logger.info(LocalizableMessage.raw("Error updating replication references in: " + serverHostPort, ae));
if (!uData.isForceOnError())
{
@@ -1805,40 +1807,26 @@
}
}
- private boolean isReferenced(Map<ServerProperty, Object> serverProperties, String toFind)
+ private boolean isReferenced(Map<ServerProperty, Object> serverProperties, HostPort toFind)
{
Object v = serverProperties.get(ServerDescriptor.ServerProperty.IS_REPLICATION_SERVER);
if (Boolean.TRUE.equals(v))
{
- Set<?> replicationServers = (Set<?>)
+ Set<HostPort> replicationServers = (Set)
serverProperties.get(ServerDescriptor.ServerProperty.EXTERNAL_REPLICATION_SERVERS);
- if (replicationServers != null)
- {
- for (Object rsUrl : replicationServers)
- {
- if (toFind.equalsIgnoreCase((String) rsUrl))
- {
- return true;
- }
- }
- }
+ return replicationServers != null && replicationServers.contains(toFind);
}
return false;
}
- private boolean isReferenced(Set<ReplicaDescriptor> replicas, String toFind)
+ private boolean isReferenced(Set<ReplicaDescriptor> replicas, HostPort toFind)
{
for (ReplicaDescriptor replica : replicas)
{
- if (replica.isReplicated())
+ if (replica.isReplicated()
+ && replica.getReplicationServers().contains(toFind))
{
- for (String rsUrl : replica.getReplicationServers())
- {
- if (toFind.equalsIgnoreCase(rsUrl))
- {
- return true;
- }
- }
+ return true;
}
}
return false;
@@ -1848,95 +1836,37 @@
* This method updates the replication in the remote server using the provided connection.
* It also tries to delete the server registration entry from the remote ADS
* servers if the serverADSProperties object passed is not null.
+ *
* @param connWrapper the connection to the remote server where we want to remove
* references to the server that we are trying to uninstall.
- * @param serverDisplay an String representation that is used to identify
- * the remote server in the log messages we present to the user.
+ * @param serverToUpdate the server where to remove references to the remote server
* @param serverADSProperties the Map with the ADS properties of the server
* that we are trying to uninstall.
* @throws ApplicationException if an error occurs while updating the remote
* OpenDS server configuration.
*/
- private void removeReferences(ConnectionWrapper connWrapper, HostPort serverDisplay,
- Map<ADSContext.ServerProperty, Object> serverADSProperties)
- throws ApplicationException
+ private void removeReferences(ConnectionWrapper connWrapper, HostPort serverToUpdate,
+ Map<ADSContext.ServerProperty, Object> serverADSProperties) throws ApplicationException
{
try
{
- RootCfgClient root = connWrapper.getRootConfiguration();
- ReplicationSynchronizationProviderCfgClient sync =
- (ReplicationSynchronizationProviderCfgClient)
- root.getSynchronizationProvider("Multimaster Synchronization");
- if (sync.hasReplicationServer())
- {
- ReplicationServerCfgClient replicationServer =
- sync.getReplicationServer();
- Set<String> replServers = replicationServer.getReplicationServer();
- if (replServers != null)
- {
- String replServer = findReplicationServer(replServers);
- if (replServer != null)
- {
- logger.info(LocalizableMessage.raw("Updating references in replication server on "+
- serverDisplay+"."));
- replServers.remove(replServer);
- if (!replServers.isEmpty())
- {
- replicationServer.setReplicationServer(replServers);
- replicationServer.commit();
- }
- else
- {
- sync.removeReplicationServer();
- sync.commit();
- }
- }
- }
- }
- String[] domainNames = sync.listReplicationDomains();
- if (domainNames != null)
- {
- for (String domainName : domainNames)
- {
- ReplicationDomainCfgClient domain =
- sync.getReplicationDomain(domainName);
- Set<String> replServers = domain.getReplicationServer();
- if (replServers != null)
- {
- String replServer = findReplicationServer(replServers);
- if (replServer != null)
- {
- logger.info(LocalizableMessage.raw("Updating references in domain " +
- domain.getBaseDN()+" on " + serverDisplay + "."));
- replServers.remove(replServer);
- if (!replServers.isEmpty())
- {
- domain.setReplicationServer(replServers);
- domain.commit();
- }
- else
- {
- sync.removeReplicationDomain(domainName);
- sync.commit();
- }
- }
- }
- }
- }
+ ReplicationSynchronizationProviderCfgClient sync = (ReplicationSynchronizationProviderCfgClient)
+ connWrapper.getRootConfiguration().getSynchronizationProvider("Multimaster Synchronization");
+ removeReferenceInReplicatonServer(sync, serverToUpdate);
+ removeReferenceInReplicationDomain(sync, serverToUpdate);
}
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
- logger.info(LocalizableMessage.raw("No synchronization found on "+ serverDisplay+".",
- monfe));
+ logger.info(LocalizableMessage.raw("No synchronization found on " + serverToUpdate + ".", monfe));
}
catch (Throwable t)
{
logger.warn(LocalizableMessage.raw(
"Error removing references in replication server on "+
- serverDisplay+": "+t, t));
+ serverToUpdate+": "+t, t));
LocalizableMessage errorMessage = INFO_ERROR_CONFIGURING_REMOTE_GENERIC.get(
- serverDisplay, t);
+ serverToUpdate, t);
throw new ApplicationException(
ReturnCode.CONFIGURATION_ERROR, errorMessage, t);
}
@@ -1958,7 +1888,7 @@
{
throw new ApplicationException(
ReturnCode.CONFIGURATION_ERROR,
- INFO_REMOTE_ADS_EXCEPTION.get(serverDisplay, ace),
+ INFO_REMOTE_ADS_EXCEPTION.get(serverToUpdate, ace),
ace);
}
else
@@ -1970,16 +1900,78 @@
}
}
- private String findReplicationServer(Set<String> replServers)
+ private void removeReferenceInReplicatonServer(ReplicationSynchronizationProviderCfgClient sync,
+ HostPort serverToUpdate) throws OperationsException, LdapException, OperationRejectedException
{
- for (String s : replServers)
+ if (sync.hasReplicationServer())
{
- if (getUninstallUserData().getReplicationServer().equalsIgnoreCase(s))
+ final ReplicationServerCfgClient replicationServer = sync.getReplicationServer();
+ final Set<String> replServers = replicationServer.getReplicationServer();
+ if (removeReplicationServer(replServers))
{
- return s;
+ logger.info(LocalizableMessage.raw("Updating references in replication server on " + serverToUpdate + "."));
+ if (!replServers.isEmpty())
+ {
+ replicationServer.setReplicationServer(replServers);
+ replicationServer.commit();
+ }
+ else
+ {
+ sync.removeReplicationServer();
+ sync.commit();
+ }
}
}
- return null;
+ }
+
+ private void removeReferenceInReplicationDomain(ReplicationSynchronizationProviderCfgClient sync,
+ HostPort serverToUpdate) throws OperationsException, LdapException, OperationRejectedException
+ {
+ final String[] domainNames = sync.listReplicationDomains();
+ if (domainNames == null)
+ {
+ return;
+ }
+
+ for (String domainName : domainNames)
+ {
+ final ReplicationDomainCfgClient domain = sync.getReplicationDomain(domainName);
+ final Set<String> replServers = domain.getReplicationServer();
+ if (removeReplicationServer(replServers))
+ {
+ logger.info(LocalizableMessage.raw(
+ "Updating references in domain " + domain.getBaseDN() + " on " + serverToUpdate + "."));
+ if (!replServers.isEmpty())
+ {
+ domain.setReplicationServer(replServers);
+ domain.commit();
+ }
+ else
+ {
+ sync.removeReplicationDomain(domainName);
+ sync.commit();
+ }
+ }
+ }
+ }
+
+ private boolean removeReplicationServer(Set<String> replServers)
+ {
+ if (replServers == null)
+ {
+ return false;
+ }
+ final String toFind = getUninstallUserData().getReplicationServer().toString();
+ for (Iterator<String> it = replServers.iterator(); it.hasNext();)
+ {
+ final String rs = it.next();
+ if (toFind.equalsIgnoreCase(rs))
+ {
+ it.remove();
+ return true;
+ }
+ }
+ return false;
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
index d45b86e..711b389 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -2009,13 +2009,13 @@
* as the set of ADS suffix replicas (all instances hosting the replication
* server also replicate ADS).
*/
- Map<DN, Set<String>> replicationServers = new HashMap<>();
- Set<String> adsServers = new HashSet<>();
+ Map<DN, Set<HostPort>> replicationServers = new HashMap<>();
+ Set<HostPort> adsServers = new HashSet<>();
if (getUserData().getReplicationOptions().getType() == DataReplicationOptions.Type.FIRST_IN_TOPOLOGY)
{
List<String> baseDns = getUserData().getNewSuffixOptions().getBaseDns();
- Set<String> h = new HashSet<>();
+ Set<HostPort> h = new HashSet<>();
h.add(getLocalReplicationServer());
adsServers.add(getLocalReplicationServer());
for (String dnStr : baseDns)
@@ -2028,7 +2028,7 @@
Set<SuffixDescriptor> suffixes = getUserData().getSuffixesToReplicateOptions().getSuffixes();
for (SuffixDescriptor suffix : suffixes)
{
- Set<String> h = new HashSet<>(suffix.getReplicationServers());
+ Set<HostPort> h = new HashSet<>(suffix.getReplicationServers());
adsServers.addAll(suffix.getReplicationServers());
h.add(getLocalReplicationServer());
adsServers.add(getLocalReplicationServer());
@@ -2038,7 +2038,7 @@
AuthenticationData repPort = getUserData().getRemoteWithNoReplicationPort().get(server);
if (repPort != null)
{
- String serverDisplay = server.getHostName() + ":" + repPort.getPort();
+ HostPort serverDisplay = new HostPort(server.getHostName(), repPort.getPort());
h.add(serverDisplay);
adsServers.add(serverDisplay);
}
@@ -2047,7 +2047,7 @@
}
}
replicationServers.put(ADSContext.getAdministrationSuffixDN(), adsServers);
- replicationServers.put(Constants.SCHEMA_DN, new HashSet<String>(adsServers));
+ replicationServers.put(Constants.SCHEMA_DN, new HashSet<HostPort>(adsServers));
long localTime = -1;
long localTimeMeasureTime = -1;
@@ -2120,10 +2120,10 @@
}
dns.add(ADSContext.getAdministrationSuffixDN());
dns.add(Constants.SCHEMA_DN);
- Map<DN, Set<String>> remoteReplicationServers = new HashMap<>();
+ Map<DN, Set<HostPort>> remoteReplicationServers = new HashMap<>();
for (DN dn : dns)
{
- Set<String> repServer = replicationServers.get(dn);
+ Set<HostPort> repServer = replicationServers.get(dn);
if (repServer == null)
{
// Do the comparison manually
@@ -4375,9 +4375,10 @@
return getPath(getInstallation().getCurrentConfigurationFile());
}
- private String getLocalReplicationServer()
+ private HostPort getLocalReplicationServer()
{
- return getUserData().getHostName() + ":" + getUserData().getReplicationOptions().getReplicationPort();
+ final UserData uData = getUserData();
+ return new HostPort(uData.getHostName(), uData.getReplicationOptions().getReplicationPort());
}
private void resetGenerationId(ConnectionWrapper conn, DN suffixDn, HostPort sourceServerDisplay)
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
index 4435a35..cb0f7a7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
@@ -22,6 +22,7 @@
import static org.opends.messages.QuickSetupMessages.*;
import static org.opends.quicksetup.Installation.*;
import static org.opends.server.types.ExistingFileBehavior.*;
+import static org.opends.server.types.HostPort.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -78,6 +79,7 @@
import org.opends.server.tools.ConfigureDS;
import org.opends.server.tools.ConfigureWindowsService;
import org.opends.server.tools.JavaPropertiesTool;
+import org.opends.server.types.HostPort;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.LDIFException;
@@ -371,7 +373,7 @@
* @return a ConfiguredReplication object describing what has been configured.
*/
public ConfiguredReplication configureReplication(
- ConnectionWrapper conn, Map<DN, Set<String>> replicationServers,
+ ConnectionWrapper conn, Map<DN, Set<HostPort>> replicationServers,
int replicationPort, boolean useSecureReplication, Set<Integer> usedReplicationServerIds,
Set<Integer> usedServerIds)
throws ApplicationException
@@ -476,9 +478,9 @@
servers = new HashSet<>();
}
Set<String> oldServers = new HashSet<>(servers);
- for (Set<String> rs : replicationServers.values())
+ for (Set<HostPort> rs : replicationServers.values())
{
- servers.addAll(rs);
+ servers.addAll(toLowerCaseStrings(rs));
}
replicationServer.setReplicationServer(servers);
@@ -535,15 +537,13 @@
{
oldServers = new TreeSet<>();
}
- servers = replicationServers.get(dn);
+ servers = toLowerCaseStrings(replicationServers.get(dn));
domain.setReplicationServer(servers);
usedServerIds.add(domain.getServerId());
domain.commit();
Set<String> addedServers = intersect(servers, oldServers);
- ConfiguredDomain domainConf = new ConfiguredDomain(domainName,
- isCreated, addedServers);
- domainsConf.add(domainConf);
+ domainsConf.add(new ConfiguredDomain(domainName, isCreated, addedServers));
}
return new ConfiguredReplication(synchProviderCreated,
synchProviderEnabled, replicationServerCreated,
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 dd506e0..ac5515a 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
@@ -37,6 +37,7 @@
import static org.opends.server.backends.task.TaskState.*;
import static org.opends.server.tools.dsreplication.ReplicationCliArgumentParser.*;
import static org.opends.server.tools.dsreplication.ReplicationCliReturnCode.*;
+import static org.opends.server.types.HostPort.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.BufferedWriter;
@@ -57,6 +58,7 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@@ -3520,18 +3522,17 @@
* replicated using the replication server and replication port information
* and {@code false} otherwise.
*/
- private boolean areFullyReplicated(ReplicaDescriptor rep1,
- ReplicaDescriptor rep2)
+ private boolean areFullyReplicated(ReplicaDescriptor rep1, ReplicaDescriptor rep2)
{
if (rep1.getSuffix().getDN().equals(rep2.getSuffix().getDN()) &&
rep1.isReplicated() && rep2.isReplicated() &&
rep1.getServer().isReplicationServer() &&
rep2.getServer().isReplicationServer())
{
- Set<String> servers1 = rep1.getReplicationServers();
- Set<String> servers2 = rep2.getReplicationServers();
- String server1 = rep1.getServer().getReplicationServerHostPort();
- String server2 = rep2.getServer().getReplicationServerHostPort();
+ Set<HostPort> servers1 = rep1.getReplicationServers();
+ Set<HostPort> servers2 = rep2.getReplicationServers();
+ HostPort server1 = rep1.getServer().getReplicationServerHostPort();
+ HostPort server2 = rep2.getServer().getReplicationServerHostPort();
return servers1.contains(server2) && servers2.contains(server1);
}
return false;
@@ -3543,16 +3544,16 @@
* have at least one common replication server referenced.
* @param rep1 the first replica.
* @param rep2 the second replica.
- * @return {@code true} if we can assure that the two replicas are
- * replicated and {@code false} otherwise.
+ * @return {@code true} if we can assure that the two replicas are replicated,
+ * {@code false} otherwise.
*/
private boolean areReplicated(ReplicaDescriptor rep1, ReplicaDescriptor rep2)
{
if (rep1.getSuffix().getDN().equals(rep2.getSuffix().getDN()) &&
rep1.isReplicated() && rep2.isReplicated())
{
- Set<String> servers1 = rep1.getReplicationServers();
- Set<String> servers2 = rep2.getReplicationServers();
+ Set<HostPort> servers1 = rep1.getReplicationServers();
+ Set<HostPort> servers2 = rep2.getReplicationServers();
servers1.retainAll(servers2);
return !servers1.isEmpty();
}
@@ -4792,15 +4793,15 @@
ERROR_READING_TOPOLOGY_CACHE, tce);
}
- final Set<String> twoReplServers = new LinkedHashSet<>();
+ final Set<HostPort> twoReplServers = new LinkedHashSet<>();
addToSets(serverDesc1, uData.getServer1(), conn1, twoReplServers, usedReplicationServerIds);
addToSets(serverDesc2, uData.getServer2(), conn2, twoReplServers, usedReplicationServerIds);
- final Map<DN, Set<String>> hmRepServers = new HashMap<>();
+ final Map<DN, Set<HostPort>> hmRepServers = new HashMap<>();
final Map<DN, Set<Integer>> hmUsedReplicationDomainIds = new HashMap<>();
for (DN baseDN : uData.getBaseDNs())
{
- Set<String> repServersForBaseDN = new LinkedHashSet<>();
+ Set<HostPort> repServersForBaseDN = new LinkedHashSet<>();
repServersForBaseDN.addAll(getReplicationServers(baseDN, cache1, serverDesc1));
repServersForBaseDN.addAll(getReplicationServers(baseDN, cache2, serverDesc2));
repServersForBaseDN.addAll(twoReplServers);
@@ -4826,8 +4827,8 @@
hmUsedReplicationDomainIds.put(baseDN, ids);
}
- final Set<String> allRepServers = new LinkedHashSet<>();
- for (Set<String> v : hmRepServers.values())
+ final Set<HostPort> allRepServers = new LinkedHashSet<>();
+ for (Set<HostPort> v : hmRepServers.values())
{
allRepServers.addAll(v);
}
@@ -4842,7 +4843,7 @@
for (DN baseDN : uData.getBaseDNs())
{
- Set<String> repServers = hmRepServers.get(baseDN);
+ Set<HostPort> repServers = hmRepServers.get(baseDN);
Set<Integer> usedIds = hmUsedReplicationDomainIds.get(baseDN);
Set<String> alreadyConfiguredServers = new HashSet<>();
@@ -5031,7 +5032,7 @@
}
private void addToSets(ServerDescriptor serverDesc, EnableReplicationServerData serverData, ConnectionWrapper conn,
- final Set<String> twoReplServers, final Set<Integer> usedReplicationServerIds)
+ final Set<HostPort> twoReplServers, final Set<Integer> usedReplicationServerIds)
{
if (serverDesc.isReplicationServer())
{
@@ -5046,7 +5047,7 @@
private void configureToReplicateBaseDN(EnableReplicationServerData server, ConnectionWrapper conn,
ServerDescriptor serverDesc, TopologyCache cache, DN baseDN, Set<Integer> usedIds,
- Set<String> alreadyConfiguredServers, Set<String> repServers, final Set<String> allRepServers,
+ Set<String> alreadyConfiguredServers, Set<HostPort> repServers, final Set<HostPort> allRepServers,
Set<String> alreadyConfiguredReplicationServers) throws ReplicationCliException
{
if (server.configureReplicationDomain()
@@ -5073,7 +5074,7 @@
private void configureServer(ConnectionWrapper conn, ServerDescriptor serverDesc,
EnableReplicationServerData enableServer, IntegerArgument replicationPortArg,
- Set<Integer> usedReplicationServerIds, Set<String> allRepServers,
+ Set<Integer> usedReplicationServerIds, Set<HostPort> allRepServers,
Set<String> alreadyConfiguredReplicationServers, Arg2<Number, Number> replicationServerAlreadyConfiguredMsg)
throws ReplicationCliException
{
@@ -5223,7 +5224,7 @@
&& (uData.disableReplicationServer() || uData.disableAll());
if (cache != null && disableReplicationServer)
{
- String replicationServer = server.getReplicationServerHostPort();
+ HostPort replicationServer = server.getReplicationServerHostPort();
// Figure out if this is the last replication server for a given
// topology (containing a different replica) or there will be only
// another replication server left (single point of failure).
@@ -5238,9 +5239,9 @@
continue;
}
- Set<String> repServers = suffix.getReplicationServers();
+ Set<HostPort> repServers = suffix.getReplicationServers();
if (repServers.size() <= 2
- && containsIgnoreCase(repServers, replicationServer))
+ && repServers.contains(replicationServer))
{
if (repServers.size() == 2)
{
@@ -5423,8 +5424,7 @@
}
}
- String replicationServerHostPort =
- server.isReplicationServer() ? server.getReplicationServerHostPort() : null;
+ HostPort replicationServerHostPort = server.getReplicationServerHostPort();
for (DN baseDN : suffixesToDisable)
{
@@ -5460,7 +5460,7 @@
// Find references in all servers.
for (SuffixDescriptor suffix : cache.getSuffixes())
{
- if (containsIgnoreCase(suffix.getReplicationServers(), replicationServerHostPort))
+ if (suffix.getReplicationServers().contains(replicationServerHostPort))
{
baseDNsToUpdate.add(suffix.getDN());
for (ReplicaDescriptor replica : suffix.getReplicas())
@@ -5474,7 +5474,7 @@
String pwd = conn.getBindPassword();
for (ServerDescriptor s : serversToUpdate)
{
- removeReferencesInServer(s, replicationServerHostPort, bindDn, pwd,
+ removeReferencesInServer(s, replicationServerHostPort.toString(), bindDn, pwd,
baseDNsToUpdate, disableReplicationServer,
getPreferredConnections(conn));
}
@@ -5973,12 +5973,12 @@
{
boolean isDomain = false;
boolean isRepServer = false;
- String replicationServer = server.getReplicationServerHostPort();
+ HostPort replicationServer = server.getReplicationServerHostPort();
for (ReplicaDescriptor replica : replicas)
{
if (!isRepServer)
{
- isRepServer = containsIgnoreCase(replica.getReplicationServers(), replicationServer);
+ isRepServer = isRepServer || replica.getReplicationServers().contains(replicationServer);
}
if (replica.getServer() == server)
{
@@ -6064,21 +6064,21 @@
* to replicate the baseDN defined in the server described by the
* ServerDescriptor.
*/
- private Set<String> getReplicationServers(DN baseDN, TopologyCache cache, ServerDescriptor server)
+ private Set<HostPort> getReplicationServers(DN baseDN, TopologyCache cache, ServerDescriptor server)
{
- Set<String> servers = getAllReplicationServers(baseDN, server);
+ Set<HostPort> servers = getAllReplicationServers(baseDN, server);
if (cache != null)
{
for (SuffixDescriptor suffix : cache.getSuffixes())
{
if (suffix.getDN().equals(baseDN))
{
- Set<String> s = suffix.getReplicationServers();
+ Set<HostPort> s = suffix.getReplicationServers();
// Test that at least we share one of the replication servers.
// If we do: we are dealing with the same replication topology
// (we must consider the case of disjoint replication topologies
// replicating the same base DN).
- Set<String> copy = new HashSet<>(s);
+ Set<HostPort> copy = new HashSet<>(s);
copy.retainAll(servers);
if (!copy.isEmpty())
{
@@ -6086,7 +6086,7 @@
break;
}
else if (server.isReplicationServer()
- && containsIgnoreCase(s, server.getReplicationServerHostPort()))
+ && s.contains(server.getReplicationServerHostPort()))
{
// this server is acting as replication server with no domain.
servers.addAll(s);
@@ -6098,18 +6098,6 @@
return servers;
}
- private boolean containsIgnoreCase(Set<String> col, String toFind)
- {
- for (String s : col)
- {
- if (s.equalsIgnoreCase(toFind))
- {
- return true;
- }
- }
- return false;
- }
-
private String findIgnoreCase(Set<String> col, String toFind)
{
for (String s : col)
@@ -6133,30 +6121,26 @@
*/
private SuffixDescriptor getSuffix(DN baseDN, TopologyCache cache, ServerDescriptor server)
{
- String replicationServer = null;
- if (server.isReplicationServer())
- {
- replicationServer = server.getReplicationServerHostPort();
- }
+ final HostPort replicationServer = server.getReplicationServerHostPort();
SuffixDescriptor returnValue = null;
- Set<String> servers = getAllReplicationServers(baseDN, server);
+ Set<HostPort> servers = getAllReplicationServers(baseDN, server);
for (SuffixDescriptor suffix : cache.getSuffixes())
{
if (suffix.getDN().equals(baseDN))
{
- Set<String> s = suffix.getReplicationServers();
+ Set<HostPort> s = suffix.getReplicationServers();
// Test that at least we share one of the replication servers.
// If we do: we are dealing with the same replication topology
// (we must consider the case of disjoint replication topologies
// replicating the same base DN).
- HashSet<String> copy = new HashSet<>(s);
+ HashSet<HostPort> copy = new HashSet<>(s);
copy.retainAll(servers);
if (!copy.isEmpty())
{
return suffix;
}
- else if (replicationServer != null && containsIgnoreCase(s, replicationServer))
+ else if (replicationServer != null && s.contains(replicationServer))
{
returnValue = suffix;
}
@@ -6165,10 +6149,10 @@
return returnValue;
}
- private Set<String> getAllReplicationServers(DN baseDN, ServerDescriptor server)
+ private Set<HostPort> getAllReplicationServers(DN baseDN, ServerDescriptor server)
{
ReplicaDescriptor replica = findReplicaForSuffixDN(server.getReplicas(), baseDN);
- Set<String> servers = new LinkedHashSet<>();
+ Set<HostPort> servers = new LinkedHashSet<>();
if (replica != null)
{
servers.addAll(replica.getReplicationServers());
@@ -6192,9 +6176,10 @@
*/
private void configureAsReplicationServer(ConnectionWrapper conn,
int replicationPort, boolean useSecureReplication,
- Set<String> replicationServers,
+ Set<HostPort> replicationServers,
Set<Integer> usedReplicationServerIds) throws Exception
{
+ Set<String> replicationServersLC = toLowerCaseStrings(replicationServers);
print(formatter.getFormattedWithPoints(
INFO_REPLICATION_ENABLE_CONFIGURING_REPLICATION_SERVER.get(conn.getHostPort())));
@@ -6229,10 +6214,8 @@
sync.commit();
/* Configure the replication server. */
- ReplicationServerCfgClient replicationServer;
-
+ ReplicationServerCfgClient rsCfgClient;
boolean mustCommit = false;
-
if (!sync.hasReplicationServer())
{
CryptoManagerCfgClient crypto = root.getCryptoManager();
@@ -6243,35 +6226,23 @@
}
int id = InstallerHelper.getReplicationId(usedReplicationServerIds);
usedReplicationServerIds.add(id);
- replicationServer = sync.createReplicationServer(
+ rsCfgClient = sync.createReplicationServer(
ReplicationServerCfgDefn.getInstance(),
new ArrayList<PropertyException>());
- replicationServer.setReplicationServerId(id);
- replicationServer.setReplicationPort(replicationPort);
- replicationServer.setReplicationServer(replicationServers);
+ rsCfgClient.setReplicationServerId(id);
+ rsCfgClient.setReplicationPort(replicationPort);
+ rsCfgClient.setReplicationServer(replicationServersLC);
mustCommit = true;
}
else
{
- replicationServer = sync.getReplicationServer();
- usedReplicationServerIds.add(
- replicationServer.getReplicationServerId());
- Set<String> servers = replicationServer.getReplicationServer();
- if (servers == null)
- {
- replicationServer.setReplicationServer(replicationServers);
- mustCommit = true;
- }
- else if (!areReplicationServersEqual(servers, replicationServers))
- {
- replicationServer.setReplicationServer(
- mergeReplicationServers(replicationServers, servers));
- mustCommit = true;
- }
+ rsCfgClient = sync.getReplicationServer();
+ usedReplicationServerIds.add(rsCfgClient.getReplicationServerId());
+ mustCommit = addAllReplicationServers(rsCfgClient, replicationServersLC);
}
if (mustCommit)
{
- replicationServer.commit();
+ rsCfgClient.commit();
}
print(formatter.getFormattedDone());
@@ -6289,37 +6260,41 @@
* @throws OpenDsException
* if there is an error updating the configuration.
*/
- private void updateReplicationServer(ConnectionWrapper conn,
- Set<String> replicationServers) throws Exception
+ private void updateReplicationServer(ConnectionWrapper conn, Set<HostPort> replicationServers) throws Exception
{
+ Set<String> replicationServersLC = toLowerCaseStrings(replicationServers);
print(formatter.getFormattedWithPoints(
INFO_REPLICATION_ENABLE_UPDATING_REPLICATION_SERVER.get(conn.getHostPort())));
- ReplicationSynchronizationProviderCfgClient sync = getMultimasterSynchronization(conn);
- boolean mustCommit = false;
- ReplicationServerCfgClient replicationServer = sync.getReplicationServer();
- Set<String> servers = replicationServer.getReplicationServer();
- if (servers == null)
+ ReplicationServerCfgClient rsCfgClient = getMultimasterSynchronization(conn).getReplicationServer();
+ if (addAllReplicationServers(rsCfgClient, replicationServersLC))
{
- replicationServer.setReplicationServer(replicationServers);
- mustCommit = true;
- }
- else if (!areReplicationServersEqual(servers, replicationServers))
- {
- replicationServers.addAll(servers);
- replicationServer.setReplicationServer(
- mergeReplicationServers(replicationServers, servers));
- mustCommit = true;
- }
- if (mustCommit)
- {
- replicationServer.commit();
+ rsCfgClient.commit();
}
print(formatter.getFormattedDone());
println();
}
+ private boolean addAllReplicationServers(ReplicationServerCfgClient rsCfgClient, Set<String> replicationServersLC)
+ {
+ final Set<String> servers = rsCfgClient.getReplicationServer();
+ if (servers == null)
+ {
+ rsCfgClient.setReplicationServer(replicationServersLC);
+ return true;
+ }
+
+ final Set<String> serversLC = toLowerCase(servers);
+ if (!serversLC.equals(replicationServersLC))
+ {
+ serversLC.addAll(replicationServersLC);
+ rsCfgClient.setReplicationServer(replicationServersLC);
+ return true;
+ }
+ return false;
+ }
+
/**
* Returns a Set containing all the replication server ids found in the
* servers of a given TopologyCache object.
@@ -6358,9 +6333,11 @@
*/
private void configureToReplicateBaseDN(ConnectionWrapper conn,
DN baseDN,
- Set<String> replicationServers,
+ Set<HostPort> replicationServers,
Set<Integer> usedReplicationDomainIds) throws Exception
{
+ Set<String> replicationServersLC = toLowerCaseStrings(replicationServers);
+
boolean userSpecifiedAdminBaseDN = false;
List<DN> baseDNs = toDNs(argParser.getBaseDNs());
if (baseDNs != null)
@@ -6398,7 +6375,7 @@
null);
domain.setServerId(domainId);
domain.setBaseDN(baseDN);
- domain.setReplicationServer(replicationServers);
+ domain.setReplicationServer(replicationServersLC);
mustCommit = true;
}
else
@@ -6409,10 +6386,15 @@
domain.setReplicationServer(null);
mustCommit = true;
}
- else if (!areReplicationServersEqual(servers, replicationServers))
+ else
{
- domain.setReplicationServer(mergeReplicationServers(replicationServers, servers));
- mustCommit = true;
+ Set<String> serversLC = toLowerCase(servers);
+ if (!serversLC.equals(replicationServersLC))
+ {
+ serversLC.addAll(replicationServersLC);
+ domain.setReplicationServer(replicationServersLC);
+ mustCommit = true;
+ }
}
}
@@ -6443,6 +6425,16 @@
return null;
}
+ private static Set<String> toLowerCase(Set<String> strings)
+ {
+ Set<String> results = new HashSet<>();
+ for (String s : strings)
+ {
+ results.add(s.toLowerCase(Locale.ROOT));
+ }
+ return results;
+ }
+
/**
* Configures the baseDN to replicate in all the Replicas found in a Topology
* Cache that are replicated with the Replica of the same base DN in the
@@ -6464,9 +6456,9 @@
* @throws ReplicationCliException if something goes wrong.
*/
private void configureToReplicateBaseDN(DN baseDN,
- Set<String> repServers, Set<Integer> usedIds,
+ Set<HostPort> repServers, Set<Integer> usedIds,
TopologyCache cache, ServerDescriptor server,
- Set<String> alreadyConfiguredServers, Set<String> allRepServers,
+ Set<String> alreadyConfiguredServers, Set<HostPort> allRepServers,
Set<String> alreadyConfiguredReplicationServers)
throws ReplicationCliException
{
@@ -6492,7 +6484,7 @@
if (s.isReplicationServer()
&& !alreadyConfiguredReplicationServers.contains(s.getId())
// Check if it is part of the replication topology
- && containsIgnoreCase(repServers, s.getReplicationServerHostPort()))
+ && repServers.contains(s.getReplicationServerHostPort()))
{
replicationServersToConfigure.add(s);
}
@@ -7369,50 +7361,6 @@
}
/**
- * Convenience method used to know if one Set of replication servers equals
- * another set of replication servers.
- * @param s1 the first set of replication servers.
- * @param s2 the second set of replication servers.
- * @return {@code true} if the two sets represent the same replication
- * servers and {@code false} otherwise.
- */
- private boolean areReplicationServersEqual(Set<String> s1, Set<String> s2)
- {
- Set<String> c1 = new HashSet<>();
- for (String s : s1)
- {
- c1.add(s.toLowerCase());
- }
- Set<String> c2 = new HashSet<>();
- for (String s : s2)
- {
- c2.add(s.toLowerCase());
- }
- return c1.equals(c2);
- }
-
- /**
- * Convenience method used to merge two Sets of replication servers.
- * @param s1 the first set of replication servers.
- * @param s2 the second set of replication servers.
- * @return a Set of replication servers containing all the replication servers
- * specified in the provided Sets.
- */
- private Set<String> mergeReplicationServers(Set<String> s1, Set<String> s2)
- {
- Set<String> c1 = new HashSet<>();
- for (String s : s1)
- {
- c1.add(s.toLowerCase());
- }
- for (String s : s2)
- {
- c1.add(s.toLowerCase());
- }
- return c1;
- }
-
- /**
* Returns the message that must be displayed to the user for a given
* exception. This is assumed to be a critical exception that stops all
* the processing.
@@ -8499,7 +8447,7 @@
{
int replicationPort = getReplicationPort(connOther);
boolean isReplicationServerConfigured = replicationPort != -1;
- String replicationServer = getReplicationServer(connOther.getHostPort().getHost(), replicationPort);
+ HostPort replicationServer = getReplicationServer(connOther.getHostPort().getHost(), replicationPort);
Collection<ReplicaDescriptor> replicas = getReplicas(connDomain);
for (ReplicaDescriptor replica : replicas)
@@ -8522,7 +8470,7 @@
{
availableSuffixes.add(suffixDn);
}
- else if (containsIgnoreCase(replica.getReplicationServers(), replicationServer))
+ else if (replica.getReplicationServers().contains(replicationServer))
{
alreadyReplicatedSuffixes.add(suffixDn);
}
@@ -8539,11 +8487,11 @@
{
int replicationPort1 = getReplicationPort(conn1);
boolean isReplicationServer1Configured = replicationPort1 != -1;
- String replicationServer1 = getReplicationServer(conn1.getHostPort().getHost(), replicationPort1);
+ HostPort replicationServer1 = getReplicationServer(conn1.getHostPort().getHost(), replicationPort1);
int replicationPort2 = getReplicationPort(conn2);
boolean isReplicationServer2Configured = replicationPort2 != -1;
- String replicationServer2 = getReplicationServer(conn2.getHostPort().getHost(), replicationPort2);
+ HostPort replicationServer2 = getReplicationServer(conn2.getHostPort().getHost(), replicationPort2);
TopologyCache cache1 = isReplicationServer1Configured ? createTopologyCache(conn1) : null;
TopologyCache cache2 = isReplicationServer2Configured ? createTopologyCache(conn2) : null;
@@ -8589,13 +8537,13 @@
}
private void addAllAvailableSuffixes(Collection<DN> availableSuffixes,
- Set<SuffixDescriptor> suffixes, String rsToFind)
+ Set<SuffixDescriptor> suffixes, HostPort rsToFind)
{
for (SuffixDescriptor suffix : suffixes)
{
- for (String rs : suffix.getReplicationServers())
+ for (HostPort rs : suffix.getReplicationServers())
{
- if (rs.equalsIgnoreCase(rsToFind))
+ if (rs.equals(rsToFind))
{
availableSuffixes.add(suffix.getDN());
}
@@ -8604,14 +8552,14 @@
}
private void updateAvailableAndReplicatedSuffixesForNoDomainOneSense(
- TopologyCache cache1, TopologyCache cache2, String replicationServer1, String replicationServer2,
+ TopologyCache cache1, TopologyCache cache2, HostPort replicationServer1, HostPort replicationServer2,
Set<DN> availableSuffixes, Set<DN> alreadyReplicatedSuffixes)
{
for (SuffixDescriptor suffix : cache1.getSuffixes())
{
- for (String rServer : suffix.getReplicationServers())
+ for (HostPort rServer : suffix.getReplicationServers())
{
- if (rServer.equalsIgnoreCase(replicationServer1))
+ if (rServer.equals(replicationServer1))
{
boolean isSecondReplicatedInSameTopology = false;
boolean isSecondReplicated = false;
@@ -8620,13 +8568,13 @@
{
if (suffix.getDN().equals(suffix2.getDN()))
{
- for (String rServer2 : suffix2.getReplicationServers())
+ for (HostPort rServer2 : suffix2.getReplicationServers())
{
- if (rServer2.equalsIgnoreCase(replicationServer2))
+ if (rServer2.equals(replicationServer2))
{
isSecondReplicated = true;
}
- if (rServer.equalsIgnoreCase(replicationServer2))
+ if (rServer.equals(replicationServer2))
{
isFirstReplicated = true;
}
@@ -8670,9 +8618,9 @@
createTopologyCache(adsCtx2, uData, suffixes);
int repPort1 = getReplicationPort(adsCtx1.getConnection());
- String repServer1 = getReplicationServer(server1.getHostName(), repPort1);
+ HostPort repServer1 = getReplicationServer(server1.getHostName(), repPort1);
int repPort2 = getReplicationPort(adsCtx2.getConnection());
- String repServer2 = getReplicationServer(server2.getHostName(), repPort2);
+ HostPort repServer2 = getReplicationServer(server2.getHostName(), repPort2);
for (DN baseDN : uData.getBaseDNs())
{
int nReplicationServers = 0;
@@ -8680,17 +8628,17 @@
{
if (suffix.getDN().equals(baseDN))
{
- Set<String> replicationServers = suffix.getReplicationServers();
+ Set<HostPort> replicationServers = suffix.getReplicationServers();
nReplicationServers += replicationServers.size();
- for (String repServer : replicationServers)
+ for (HostPort repServer : replicationServers)
{
if (server1.configureReplicationServer() &&
- repServer.equalsIgnoreCase(repServer1))
+ repServer.equals(repServer1))
{
nReplicationServers --;
}
if (server2.configureReplicationServer() &&
- repServer.equalsIgnoreCase(repServer2))
+ repServer.equals(repServer2))
{
nReplicationServers --;
}
@@ -8962,11 +8910,11 @@
}
int replicationID1 = serverToFind.getReplicationServerId();
- String replServerHostPort1 = serverToFind.getReplicationServerHostPort();
+ HostPort replServerHostPort1 = serverToFind.getReplicationServerHostPort();
for (ServerDescriptor server2 : servers)
{
if (server2.isReplicationServer() && server2.getReplicationServerId() == replicationID1
- && !server2.getReplicationServerHostPort().equalsIgnoreCase(replServerHostPort1))
+ && !server2.getReplicationServerHostPort().equals(replServerHostPort1))
{
commonRepServerIDErrors.add(ERR_REPLICATION_ENABLE_COMMON_REPLICATION_SERVER_ID_ARG.get(
serverToFind.getHostPort(true), server2.getHostPort(true), replicationID1));
@@ -9074,11 +9022,11 @@
final ReplicaDescriptor replica2 = findReplicaForSuffixDN(server2.getReplicas(), baseDN);
if (replica1 != null && replica2 != null)
{
- Set<String> replServers1 = replica1.getSuffix().getReplicationServers();
- Set<String> replServers2 = replica1.getSuffix().getReplicationServers();
- for (String replServer1 : replServers1)
+ Set<HostPort> replServers1 = replica1.getSuffix().getReplicationServers();
+ Set<HostPort> replServers2 = replica1.getSuffix().getReplicationServers();
+ for (HostPort replServer1 : replServers1)
{
- if (containsIgnoreCase(replServers2, replServer1))
+ if (replServers2.contains(replServer1))
{
// it is replicated in both
return true;
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 f5dbf92..128ac44 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,6 +16,8 @@
*/
package org.opends.server.types;
+import static org.opends.messages.ReplicationMessages.*;
+
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
@@ -23,13 +25,12 @@
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import static org.opends.messages.ReplicationMessages.*;
-
/**
* This class defines a data structure that combines an address and port number,
* as may be used to accept a connection from or initiate a connection to a
@@ -151,6 +152,16 @@
return localAddresses;
}
+ public static Set<String> toLowerCaseStrings(Set<HostPort> hps)
+ {
+ final Set<String> results = new HashSet<>();
+ for (HostPort hp : hps)
+ {
+ results.add(hp.toString().toLowerCase(Locale.ROOT));
+ }
+ return results;
+ }
+
/**
* Returns a a new HostPort for all addresses, also known as a wildcard
* address.
--
Gitblit v1.10.0