From b07dd3c9cf16b40636b797aeb801aafa73d21fa0 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 02 Aug 2016 08:47:41 +0000
Subject: [PATCH] ReplicationCliMain.java: various code cleanups
---
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 59 ++++++++++++++---------------
opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java | 27 +++++++++----
opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java | 6 --
3 files changed, 48 insertions(+), 44 deletions(-)
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 56df7fd..5d11a41 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
@@ -850,11 +850,7 @@
private static boolean isAddReplica(TopologyCacheFilter cacheFilter, DN baseDn)
{
- if (cacheFilter.searchAllBaseDNs())
- {
- return true;
- }
- return cacheFilter.getBaseDNsToSearch().contains(baseDn);
+ return cacheFilter.searchAllBaseDNs() || cacheFilter.getBaseDNsToSearch().contains(baseDn);
}
private static void updateReplication(ServerDescriptor desc, ConnectionWrapper conn, TopologyCacheFilter cacheFilter)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java
index d73a285..c3d5fd2 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java
@@ -16,6 +16,7 @@
*/
package org.opends.admin.ads;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -35,8 +36,8 @@
/**
* Returns whether we must search for base DN information or not.
- * @return <CODE>true</CODE> if we must search base DN information and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if we must search base DN information and
+ * {@code false} otherwise.
*/
boolean searchBaseDNInformation()
{
@@ -54,11 +55,10 @@
this.searchBaseDNInformation = searchBaseDNInformation;
}
-
/**
* Returns whether we must search for monitoring information or not.
- * @return <CODE>true</CODE> if we must search monitoring information and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if we must search monitoring information and
+ * {@code false} otherwise.
*/
boolean searchMonitoringInformation()
{
@@ -80,7 +80,7 @@
* Adds one of the base DNs we must search for. If at least one baseDN
* is added using this method, only the added baseDNs are searched. If no
* base DN is added, all the base DNs will be retrieved.
- * @param dn the DN of the base DN to look for.
+ * @param dn the base DN to look for.
*/
public void addBaseDNToSearch(DN dn)
{
@@ -88,6 +88,17 @@
}
/**
+ * Adds all the base DNs we must search for. If at least one baseDN
+ * is added using this method, only the added baseDNs are searched.
+ * If no base DN is added, all the base DNs will be retrieved.
+ * @param dns the base DNs to look for.
+ */
+ public void addBaseDNsToSearch(Collection<DN> dns)
+ {
+ dns.addAll(dns);
+ }
+
+ /**
* Returns the list of base DNs that will be searched for. If the list is
* empty we will search for all the base DNs.
* @return the list of base DNs we will search for.
@@ -99,8 +110,8 @@
/**
* Tells whether this filter specifies to search for all the base DNs or not.
- * @return <CODE>true</CODE> if the filter specifies to search for all the
- * base DNs and <CODE>false</CODE> otherwise.
+ * @return {@code true} if the filter specifies to search for all the
+ * base DNs and {@code false} otherwise.
*/
boolean searchAllBaseDNs()
{
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 d787959..5a3947e 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
@@ -4608,7 +4608,7 @@
filter.setSearchMonitoringInformation(false);
filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
filter.addBaseDNToSearch(Constants.SCHEMA_DN);
- addBaseDNs(filter, uData.getBaseDNs());
+ filter.addBaseDNsToSearch(uData.getBaseDNs());
ServerDescriptor serverDesc1 = createStandalone(conn1, filter);
ServerDescriptor serverDesc2 = createStandalone(conn2, filter);
@@ -5179,7 +5179,7 @@
TopologyCache cache = new TopologyCache(adsCtx, getTrustManager(sourceServerCI), getConnectTimeout());
cache.setPreferredConnections(cnx);
cache.getFilter().setSearchMonitoringInformation(false);
- addBaseDNs(cache.getFilter(), uData.getBaseDNs());
+ cache.getFilter().addBaseDNsToSearch(uData.getBaseDNs());
cache.reloadTopology();
return cache;
}
@@ -5220,7 +5220,7 @@
if (!uData.disableAll())
{
filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
- addBaseDNs(filter, uData.getBaseDNs());
+ filter.addBaseDNsToSearch(uData.getBaseDNs());
}
ServerDescriptor server = createStandalone(conn, filter);
@@ -5239,7 +5239,7 @@
cache.getFilter().setSearchMonitoringInformation(false);
if (!uData.disableAll())
{
- addBaseDNs(cache.getFilter(), uData.getBaseDNs());
+ cache.getFilter().addBaseDNsToSearch(uData.getBaseDNs());
}
cache.reloadTopology();
}
@@ -5614,14 +5614,6 @@
return false;
}
- private void addBaseDNs(TopologyCacheFilter filter, List<DN> baseDNs)
- {
- for (DN dn : baseDNs)
- {
- filter.addBaseDNToSearch(dn);
- }
- }
-
/**
* Displays the replication status of the different base DNs in the servers registered in the ADS.
*
@@ -5637,21 +5629,7 @@
StatusReplicationUserData uData) throws ReplicationCliException
{
ADSContext adsCtx = new ADSContext(conn);
-
- TopologyCache cache;
- try
- {
- cache = new TopologyCache(adsCtx, getTrustManager(sourceServerCI), getConnectTimeout());
- cache.setPreferredConnections(getPreferredConnections(conn));
- addBaseDNs(cache.getFilter(), uData.getBaseDNs());
- cache.reloadTopology();
- }
- catch (TopologyCacheException tce)
- {
- throw new ReplicationCliException(
- ERR_REPLICATION_READING_ADS.get(tce.getMessage()),
- ERROR_READING_TOPOLOGY_CACHE, tce);
- }
+ TopologyCache cache = createTopologyCache(conn, uData, adsCtx);
if (mustPrintCommandBuilder())
{
printNewCommandBuilder(STATUS_REPLICATION_SUBCMD_NAME, uData);
@@ -5754,6 +5732,25 @@
}
}
+ private TopologyCache createTopologyCache(ConnectionWrapper conn, StatusReplicationUserData uData, ADSContext adsCtx)
+ throws ReplicationCliException
+ {
+ try
+ {
+ TopologyCache cache = new TopologyCache(adsCtx, getTrustManager(sourceServerCI), getConnectTimeout());
+ cache.setPreferredConnections(getPreferredConnections(conn));
+ cache.getFilter().addBaseDNsToSearch(uData.getBaseDNs());
+ cache.reloadTopology();
+ return cache;
+ }
+ catch (TopologyCacheException tce)
+ {
+ throw new ReplicationCliException(
+ ERR_REPLICATION_READING_ADS.get(tce.getMessage()),
+ ERROR_READING_TOPOLOGY_CACHE, tce);
+ }
+ }
+
private Set<ReplicaDescriptor> findNonReplicatedReplicasForSuffixDn(List<Set<ReplicaDescriptor>> replicaLists,
DN suffixDn)
{
@@ -8799,7 +8796,7 @@
{
TopologyCache cache = new TopologyCache(adsCtx, getTrustManager(sourceServerCI), getConnectTimeout());
cache.getFilter().setSearchMonitoringInformation(false);
- addBaseDNs(cache.getFilter(), uData.getBaseDNs());
+ cache.getFilter().addBaseDNsToSearch(uData.getBaseDNs());
cache.reloadTopology();
suffixes.addAll(cache.getSuffixes());
}
@@ -9103,13 +9100,13 @@
private ConnectionWrapper getConnection(TopologyCache cache, ServerDescriptor server) throws NamingException
{
ConnectionWrapper conn = cache.getAdsContext().getConnection();
- DN dn = conn.getBindDn();
- String pwd = conn.getBindPassword();
+
TopologyCacheFilter filter = new TopologyCacheFilter();
filter.setSearchMonitoringInformation(false);
filter.setSearchBaseDNInformation(false);
+
ServerLoader loader = new ServerLoader(server.getAdsProperties(),
- dn, pwd, getTrustManager(sourceServerCI), getConnectTimeout(),
+ conn.getBindDn(), conn.getBindPassword(), getTrustManager(sourceServerCI), getConnectTimeout(),
cache.getPreferredConnections(), filter);
return loader.createConnectionWrapper();
}
--
Gitblit v1.10.0