From 943a2d7d4cca6371830b33db941af3ec0431fb5c Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Sun, 26 Aug 2007 03:16:07 +0000
Subject: [PATCH] This commit includes all the code for the first version of the replication tools. As they require further testing the command line associated with them has not been committed.
---
opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java | 101 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 84 insertions(+), 17 deletions(-)
diff --git a/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java b/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
index 2034463..49d63ee 100644
--- a/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
+++ b/opendj-sdk/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -27,17 +27,14 @@
package org.opends.admin.ads;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
-import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -181,6 +178,69 @@
}
/**
+ * Tells whether this server is a replication server or not.
+ * @return <CODE>true</CODE> if the server is a replication server and
+ * <CODE>false</CODE> otherwise.
+ */
+ public boolean isReplicationServer()
+ {
+ return Boolean.TRUE.equals(
+ serverProperties.get(ServerProperty.IS_REPLICATION_SERVER));
+ }
+
+ /**
+ * Returns the String representation of this replication server based
+ * on the information we have ("hostname":"replication port") and
+ * <CODE>null</CODE> if this is not a replication server.
+ * @return the String representation of this replication server based
+ * on the information we have ("hostname":"replication port") and
+ * <CODE>null</CODE> if this is not a replication server.
+ */
+ public String getReplicationServerHostPort()
+ {
+ String hostPort = null;
+ if (isReplicationServer())
+ {
+ hostPort = getHostName().toLowerCase()+ ":" + getReplicationServerPort();
+ }
+ return hostPort;
+ }
+
+ /**
+ * Returns the replication server ID of this server and -1 if this is not a
+ * replications server.
+ * @return the replication server ID of this server and -1 if this is not a
+ * replications server.
+ */
+ public int getReplicationServerId()
+ {
+ int port = -1;
+ if (isReplicationServer())
+ {
+ port = (Integer)serverProperties.get(
+ ServerProperty.REPLICATION_SERVER_ID);
+ }
+ return port;
+ }
+
+ /**
+ * Returns the replication port of this server and -1 if this is not a
+ * replications server.
+ * @return the replication port of this server and -1 if this is not a
+ * replications server.
+ */
+ public int getReplicationServerPort()
+ {
+ int port = -1;
+ if (isReplicationServer())
+ {
+ port = (Integer)serverProperties.get(
+ ServerProperty.REPLICATION_SERVER_PORT);
+ }
+ return port;
+ }
+
+ /**
* Sets the ADS properties of the server.
* @param adsProperties a Map containing the ADS properties of the server.
*/
@@ -405,6 +465,7 @@
adsProperties.put(adsProps[i][1], String.valueOf(port));
}
}
+ adsProperties.put(ADSContext.ServerProperty.ID, getHostPort(true));
}
/**
@@ -442,17 +503,9 @@
updateReplicas(desc, ctx);
updateReplication(desc, ctx);
- String s = (String)ctx.getEnvironment().get(Context.PROVIDER_URL);
- try
- {
- URI ldapURL = new URI(s);
- desc.serverProperties.put(ServerProperty.HOST_NAME, ldapURL.getHost());
- }
- catch (URISyntaxException use)
- {
- // This is really strange. Seems like a bug somewhere.
- LOG.log(Level.WARNING, "Error parsing ldap URL "+s, use);
- }
+ desc.serverProperties.put(ServerProperty.HOST_NAME,
+ ConnectionUtils.getHostName(ctx));
+
return desc;
}
@@ -683,7 +736,14 @@
if (areDnsEqual(replica.getSuffix().getDN(), dn))
{
replica.setReplicationId(id);
- replica.setReplicationServers(replicationServers);
+ // Keep the values of the replication servers in lower case
+ // to make use of Sets as String simpler.
+ LinkedHashSet<String> repServers = new LinkedHashSet<String>();
+ for (String s: replicationServers)
+ {
+ repServers.add(s.toLowerCase());
+ }
+ replica.setReplicationServers(repServers);
}
}
}
@@ -724,8 +784,15 @@
desc.serverProperties.put(ServerProperty.REPLICATION_SERVER_ID,
Integer.parseInt(v));
Set<String> values = getValues(sr, "ds-cfg-replication-server");
+ // Keep the values of the replication servers in lower case
+ // to make use of Sets as String simpler.
+ LinkedHashSet<String> repServers = new LinkedHashSet<String>();
+ for (String s: values)
+ {
+ repServers.add(s.toLowerCase());
+ }
desc.serverProperties.put(ServerProperty.EXTERNAL_REPLICATION_SERVERS,
- values);
+ repServers);
}
}
catch (NameNotFoundException nse)
--
Gitblit v1.10.0