From fa9c515bf663d5189abd094e68051f380205f24d Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 18 Apr 2016 08:52:40 +0000
Subject: [PATCH] Replaced uses of ConnectionUtils.getHostPort() by ConnectionWrapper.getHostPort()
---
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 165 +++++++++-----------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java | 16 +-
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java | 106 +++---------
opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java | 19 +
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java | 53 +++++-
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java | 67 +++----
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java | 29 ++-
7 files changed, 218 insertions(+), 237 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 9313818..71238f0 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
@@ -53,10 +53,10 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.admin.ads.ADSContextException.ErrorType;
-import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.quicksetup.Constants;
import org.opends.server.schema.SchemaConstants;
+import org.opends.server.types.HostPort;
/** Class used to update and read the contents of the Administration Data. */
public class ADSContext
@@ -310,6 +310,16 @@
}
/**
+ * Returns the host name and port number of this connection.
+ *
+ * @return the hostPort of this connection
+ */
+ public HostPort getHostPort()
+ {
+ return connectionWrapper.getHostPort();
+ }
+
+ /**
* Method called to register a server in the ADS.
*
* @param serverProperties
@@ -2189,8 +2199,7 @@
}
catch (ADSContextException adce)
{
- LocalizableMessage msg = ERR_ADS_MERGE.get(ConnectionUtils.getHostPort(getDirContext()),
- ConnectionUtils.getHostPort(adsCtx.getDirContext()), adce.getMessageObject());
+ LocalizableMessage msg = ERR_ADS_MERGE.get(getHostPort(), adsCtx.getHostPort(), adce.getMessageObject());
throw new ADSContextException(ErrorType.ERROR_MERGING, msg, adce);
}
}
@@ -2220,8 +2229,8 @@
if (!notDefinedAdmins.isEmpty())
{
LocalizableMessage msg = ERR_ADS_ADMINISTRATOR_MERGE.get(
- ConnectionUtils.getHostPort(adsCtx.getDirContext()), ConnectionUtils.getHostPort(getDirContext()),
- joinAsString(Constants.LINE_SEPARATOR, notDefinedAdmins), ConnectionUtils.getHostPort(getDirContext()));
+ adsCtx.getHostPort(), getHostPort(),
+ joinAsString(Constants.LINE_SEPARATOR, notDefinedAdmins), getHostPort());
throw new ADSContextException(ErrorType.ERROR_MERGING, msg, null);
}
}
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 3e46e06..4dfef44 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
@@ -62,6 +62,7 @@
private final LDAPConnectionFactory connectionFactory;
private final Connection connection;
private final InitialLdapContext ldapContext;
+ private final HostPort hostPort;
private final int connectTimeout;
private final TrustManager trustManager;
private final KeyManager keyManager;
@@ -151,13 +152,14 @@
public ConnectionWrapper(HostPort hostPort, PreferredConnection.Type connectionType, String bindDn, String bindPwd,
int connectTimeout, TrustManager trustManager, KeyManager keyManager) throws NamingException
{
+ this.hostPort = hostPort;
this.connectTimeout = connectTimeout;
this.trustManager = trustManager;
this.keyManager = keyManager;
final Options options = toOptions(connectionType, bindDn, bindPwd, connectTimeout, trustManager, keyManager);
- ldapContext = createAdministrativeContext(hostPort, options);
- connectionFactory = buildConnectionFactory(options, hostPort);
+ ldapContext = createAdministrativeContext(options);
+ connectionFactory = new LDAPConnectionFactory(hostPort.getHost(), hostPort.getPort(), options);
connection = buildConnection();
}
@@ -191,9 +193,9 @@
}
}
- private InitialLdapContext createAdministrativeContext(HostPort hostPort, Options options) throws NamingException
+ private InitialLdapContext createAdministrativeContext(Options options) throws NamingException
{
- final InitialLdapContext ctx = createAdministrativeContext0(hostPort, options);
+ final InitialLdapContext ctx = createAdministrativeContext0(options);
if (!connectedAsAdministrativeUser(ctx))
{
throw new NoPermissionException(ERR_NOT_ADMINISTRATIVE_USER.get().toString());
@@ -201,7 +203,7 @@
return ctx;
}
- private InitialLdapContext createAdministrativeContext0(HostPort hostPort, Options options) throws NamingException
+ private InitialLdapContext createAdministrativeContext0(Options options) throws NamingException
{
SSLContext sslContext = options.get(SSL_CONTEXT);
boolean useSSL = sslContext != null;
@@ -209,7 +211,7 @@
SimpleBindRequest bindRequest = (SimpleBindRequest) options.get(AUTHN_BIND_REQUEST);
String bindDn = bindRequest.getName();
String bindPwd = new String(bindRequest.getPassword());
- final String ldapUrl = getLDAPUrl(hostPort, useSSL);
+ final String ldapUrl = getLDAPUrl(getHostPort(), useSSL);
if (useSSL)
{
return createLdapsContext(ldapUrl, bindDn, bindPwd, connectTimeout, null, trustManager, keyManager);
@@ -224,11 +226,6 @@
}
}
- private LDAPConnectionFactory buildConnectionFactory(Options options, HostPort hostPort)
- {
- return new LDAPConnectionFactory(hostPort.getHost(), hostPort.getPort(), options);
- }
-
private Connection buildConnection() throws NamingException
{
try
@@ -262,6 +259,16 @@
}
/**
+ * Returns the host name and port number of this connection.
+ *
+ * @return the hostPort of this connection
+ */
+ public HostPort getHostPort()
+ {
+ return hostPort;
+ }
+
+ /**
* Returns the root configuration client by using the inrnal Connection.
*
* @return the root configuration client
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java
index 0755923..9f265b1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java
@@ -16,10 +16,10 @@
*/
package org.opends.guitools.controlpanel.ui;
-import static org.opends.admin.ads.util.ConnectionUtils.getHostPort;
+import static com.forgerock.opendj.cli.Utils.OBFUSCATED_VALUE;
+
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
-import static com.forgerock.opendj.cli.Utils.OBFUSCATED_VALUE;
import java.awt.Component;
import java.awt.GridBagConstraints;
@@ -31,7 +31,6 @@
import java.util.Set;
import java.util.TreeSet;
-import javax.naming.ldap.InitialLdapContext;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
@@ -44,7 +43,10 @@
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.ldap.DN;
import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
@@ -53,14 +55,12 @@
import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
import org.opends.guitools.controlpanel.task.Task;
import org.opends.guitools.controlpanel.util.Utilities;
-import org.forgerock.i18n.LocalizableMessage;
import org.opends.quicksetup.ui.UIFactory;
import org.opends.quicksetup.util.Utils;
import org.opends.server.tools.ImportLDIF;
import org.opends.server.tools.dsreplication.ReplicationCliArgumentParser;
import org.opends.server.tools.dsreplication.ReplicationCliException;
import org.opends.server.tools.dsreplication.ReplicationCliMain;
-import org.forgerock.opendj.ldap.DN;
/**
* The panel where the user can import the contents of an LDIF file to the
@@ -818,12 +818,12 @@
INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_INITIALIZE_ALL.get()+ "<br><b>"+cmd+"</b><br><br>",
ColorAndFontConstants.progressFont));
- InitialLdapContext ctx = getInfo().getConnection().getLdapContext();
+ ConnectionWrapper conn = getInfo().getConnection();
for (DN baseDN : replicatedBaseDNs)
{
- LocalizableMessage msg = INFO_PROGRESS_INITIALIZING_SUFFIX.get(baseDN, getHostPort(ctx));
+ LocalizableMessage msg = INFO_PROGRESS_INITIALIZING_SUFFIX.get(baseDN, conn.getHostPort());
getProgressDialog().appendProgressHtml(Utilities.applyFont(msg + "<br>", ColorAndFontConstants.progressFont));
- repl.initializeAllSuffix(baseDN.toString(), ctx, true);
+ repl.initializeAllSuffix(baseDN.toString(), conn.getLdapContext(), true);
}
}
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 058486f..e712929 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
@@ -23,7 +23,15 @@
import java.net.InetAddress;
import java.net.URI;
import java.security.cert.X509Certificate;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import javax.naming.Context;
import javax.naming.NamingException;
@@ -33,6 +41,12 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.ConfigurationFramework;
+import org.forgerock.opendj.config.ManagedObjectNotFoundException;
+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;
@@ -40,23 +54,36 @@
import org.opends.admin.ads.TopologyCache;
import org.opends.admin.ads.TopologyCacheException;
import org.opends.admin.ads.util.ApplicationTrustManager;
-import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.admin.ads.util.PreferredConnection;
import org.opends.guitools.uninstaller.ui.ConfirmUninstallPanel;
import org.opends.guitools.uninstaller.ui.LoginDialog;
-import org.opends.quicksetup.*;
-import org.opends.quicksetup.ui.*;
+import org.opends.quicksetup.ApplicationException;
+import org.opends.quicksetup.ButtonName;
+import org.opends.quicksetup.CliApplication;
+import org.opends.quicksetup.Installation;
+import org.opends.quicksetup.Launcher;
+import org.opends.quicksetup.ProgressStep;
+import org.opends.quicksetup.ReturnCode;
+import org.opends.quicksetup.Step;
+import org.opends.quicksetup.UserData;
+import org.opends.quicksetup.UserDataCertificateException;
+import org.opends.quicksetup.UserDataException;
+import org.opends.quicksetup.WizardStep;
+import org.opends.quicksetup.ui.CertificateDialog;
+import org.opends.quicksetup.ui.FieldName;
+import org.opends.quicksetup.ui.FinishedPanel;
+import org.opends.quicksetup.ui.GuiApplication;
+import org.opends.quicksetup.ui.ProgressDialog;
+import org.opends.quicksetup.ui.ProgressPanel;
+import org.opends.quicksetup.ui.QuickSetup;
+import org.opends.quicksetup.ui.QuickSetupDialog;
+import org.opends.quicksetup.ui.QuickSetupStepPanel;
+import org.opends.quicksetup.ui.Utilities;
import org.opends.quicksetup.util.BackgroundTask;
import org.opends.quicksetup.util.ServerController;
import org.opends.quicksetup.util.UIKeyStore;
import org.opends.quicksetup.util.Utils;
-import org.forgerock.opendj.config.ConfigurationFramework;
-import org.forgerock.opendj.config.ManagedObjectNotFoundException;
-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.server.core.DirectoryServer;
import org.opends.server.types.HostPort;
import org.opends.server.util.DynamicConstants;
@@ -67,6 +94,7 @@
import static com.forgerock.opendj.cli.ArgumentConstants.*;
import static com.forgerock.opendj.cli.Utils.*;
import static com.forgerock.opendj.util.OperatingSystem.*;
+
import static org.forgerock.util.Utils.*;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
@@ -2064,9 +2092,8 @@
{
if (adsContext.hasAdminData() && serverADSProperties != null)
{
- logger.info(LocalizableMessage.raw("Unregistering server on ADS of server "+
- ConnectionUtils.getHostPort(connWrapper.getLdapContext())+". Properties: "+
- serverADSProperties));
+ logger.info(LocalizableMessage.raw("Unregistering server on ADS of server " + connWrapper.getHostPort()
+ + ". Properties: " + serverADSProperties));
adsContext.unregisterServer(serverADSProperties);
}
}
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 28f205b..de9381c 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
@@ -16,9 +16,9 @@
*/
package org.opends.quicksetup.installer;
-import static com.forgerock.opendj.util.OperatingSystem.isWindows;
import static com.forgerock.opendj.cli.ArgumentConstants.*;
import static com.forgerock.opendj.cli.Utils.*;
+import static com.forgerock.opendj.util.OperatingSystem.isWindows;
import static org.forgerock.util.Utils.*;
import static org.opends.admin.ads.ServerDescriptor.*;
@@ -82,7 +82,6 @@
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.ConnectionUtils;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.admin.ads.util.PreferredConnection;
import org.opends.quicksetup.ApplicationException;
@@ -1792,7 +1791,6 @@
*/
private void unconfigureRemote()
{
- ConnectionWrapper connectionWrapper = null;
if (registeredNewServerOnRemote || createdAdministrator || createdRemoteAds)
{
// Try to connect
@@ -1802,10 +1800,8 @@
{
notifyListeners(getFormattedWithPoints(INFO_PROGRESS_UNCONFIGURING_ADS_ON_REMOTE.get(auth.getHostPort())));
}
- try
+ try (ConnectionWrapper connectionWrapper = createConnection(auth))
{
- connectionWrapper = createConnection(auth);
-
ADSContext adsContext = new ADSContext(connectionWrapper);
if (createdRemoteAds)
{
@@ -1844,29 +1840,20 @@
{
notifyListeners(getFormattedError(t, true));
}
- finally
- {
- StaticUtils.close(connectionWrapper);
- }
}
InstallerHelper helper = new InstallerHelper();
for (ServerDescriptor server : hmConfiguredRemoteReplication.keySet())
{
notifyListeners(getFormattedWithPoints(INFO_PROGRESS_UNCONFIGURING_REPLICATION_REMOTE.get(getHostPort(server))));
- try
+ try (ConnectionWrapper connectionWrapper =
+ getRemoteConnection(server, getTrustManager(), getPreferredConnections()))
{
- connectionWrapper = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
- helper.unconfigureReplication(connectionWrapper, hmConfiguredRemoteReplication.get(server),
- ConnectionUtils.getHostPort(connectionWrapper.getLdapContext()));
+ helper.unconfigureReplication(connectionWrapper, hmConfiguredRemoteReplication.get(server));
}
catch (ApplicationException ae)
{
notifyListeners(getFormattedError(ae, true));
}
- finally
- {
- StaticUtils.close(connectionWrapper);
- }
notifyListeners(getFormattedDoneWithLineBreak());
}
}
@@ -1961,15 +1948,12 @@
private void createReplicatedBackends(final Map<String, Set<String>> hmBackendSuffix,
final Map<String, BackendTypeUIAdapter> backendTypes) throws ApplicationException
{
- ConnectionWrapper connection = null;
- try
+ try (ConnectionWrapper connection = createLocalConnection())
{
- connection = createLocalConnection();
final InstallerHelper helper = new InstallerHelper();
for (String backendName : hmBackendSuffix.keySet())
{
helper.createBackend(connection, backendName, hmBackendSuffix.get(backendName),
- ConnectionUtils.getHostPort(connection.getLdapContext()),
backendTypes.get(backendName).getBackend());
}
}
@@ -1978,10 +1962,6 @@
LocalizableMessage failedMsg = getThrowableMsg(INFO_ERROR_CONNECTING_TO_LOCAL.get(), ne);
throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, failedMsg, ne);
}
- finally
- {
- StaticUtils.close(connection);
- }
}
/**
@@ -2081,31 +2061,25 @@
replicationServers.put(ADSContext.getAdministrationSuffixDN(), adsServers);
replicationServers.put(Constants.SCHEMA_DN, new HashSet<String>(adsServers));
- ConnectionWrapper connWrapper = null;
long localTime = -1;
long localTimeMeasureTime = -1;
HostPort localServerDisplay = null;
- try
+ try (ConnectionWrapper conn = createLocalConnection())
{
- connWrapper = createLocalConnection();
- helper.configureReplication(connWrapper, replicationServers,
+ helper.configureReplication(conn, replicationServers,
getUserData().getReplicationOptions().getReplicationPort(),
getUserData().getReplicationOptions().useSecureReplication(),
- getUserData().getHostPort(),
- knownReplicationServerIds, knownServerIds);
+ knownReplicationServerIds,
+ knownServerIds);
localTimeMeasureTime = System.currentTimeMillis();
- localTime = Utils.getServerClock(connWrapper.getLdapContext());
- localServerDisplay = ConnectionUtils.getHostPort(connWrapper.getLdapContext());
+ localTime = Utils.getServerClock(conn.getLdapContext());
+ localServerDisplay = conn.getHostPort();
}
catch (NamingException ne)
{
LocalizableMessage failedMsg = getThrowableMsg(INFO_ERROR_CONNECTING_TO_LOCAL.get(), ne);
throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, failedMsg, ne);
}
- finally
- {
- StaticUtils.close(connWrapper);
- }
notifyListeners(getFormattedDoneWithLineBreak());
checkAbort();
@@ -2185,25 +2159,25 @@
}
}
- connWrapper = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
- InitialLdapContext ctx = connWrapper.getLdapContext();
- ConfiguredReplication repl =
- helper.configureReplication(connWrapper, remoteReplicationServers, replicationPort, enableSecureReplication,
- ConnectionUtils.getHostPort(ctx), knownReplicationServerIds, knownServerIds);
- long remoteTimeMeasureTime = System.currentTimeMillis();
- long remoteTime = Utils.getServerClock(ctx);
- if (localTime != -1
- && remoteTime != -1
- && Math.abs(localTime - remoteTime - localTimeMeasureTime + remoteTimeMeasureTime) >
- THRESHOLD_CLOCK_DIFFERENCE_WARNING * 60 * 1000)
+ try (ConnectionWrapper conn = getRemoteConnection(server, getTrustManager(), getPreferredConnections()))
{
- notifyListeners(getFormattedWarning(INFO_WARNING_SERVERS_CLOCK_DIFFERENCE.get(localServerDisplay,
- ConnectionUtils.getHostPort(ctx), THRESHOLD_CLOCK_DIFFERENCE_WARNING)));
+ ConfiguredReplication repl = helper.configureReplication(
+ conn, remoteReplicationServers, replicationPort, enableSecureReplication,
+ knownReplicationServerIds, knownServerIds);
+ long remoteTimeMeasureTime = System.currentTimeMillis();
+ long remoteTime = Utils.getServerClock(conn.getLdapContext());
+ if (localTime != -1
+ && remoteTime != -1
+ && Math.abs(localTime - remoteTime - localTimeMeasureTime + remoteTimeMeasureTime) >
+ THRESHOLD_CLOCK_DIFFERENCE_WARNING * 60 * 1000)
+ {
+ notifyListeners(getFormattedWarning(INFO_WARNING_SERVERS_CLOCK_DIFFERENCE.get(
+ localServerDisplay, conn.getHostPort(), THRESHOLD_CLOCK_DIFFERENCE_WARNING)));
+ }
+
+ hmConfiguredRemoteReplication.put(server, repl);
}
- hmConfiguredRemoteReplication.put(server, repl);
-
- StaticUtils.close(connWrapper);
notifyListeners(getFormattedDoneWithLineBreak());
checkAbort();
}
@@ -2339,20 +2313,14 @@
*/
private void writeHostName()
{
- BufferedWriter writer = null;
- try
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(getHostNameFile(), false)))
{
- writer = new BufferedWriter(new FileWriter(getHostNameFile(), false));
writer.append(getUserData().getHostName());
}
catch (IOException ioe)
{
logger.warn(LocalizableMessage.raw("Error writing host name file: " + ioe, ioe));
}
- finally
- {
- StaticUtils.close(writer);
- }
}
/**
@@ -2509,10 +2477,8 @@
/* Initialize local ADS and schema contents using any replica. */
{
ServerDescriptor server = suffixes.iterator().next().getReplicas().iterator().next().getServer();
- ConnectionWrapper remoteConn = null;
- try
+ try (ConnectionWrapper remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections()))
{
- remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
TopologyCacheFilter filter = new TopologyCacheFilter();
filter.setSearchMonitoringInformation(false);
filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
@@ -2544,10 +2510,6 @@
}
throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, msg, ne);
}
- finally
- {
- StaticUtils.close(remoteConn);
- }
}
for (SuffixDescriptor suffix : suffixes)
@@ -2585,10 +2547,8 @@
if (replicationId == -1)
{
// This occurs if the remote server had not replication configured.
- ConnectionWrapper remoteConn = null;
- try
+ try (ConnectionWrapper remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections()))
{
- remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
TopologyCacheFilter filter = new TopologyCacheFilter();
filter.setSearchMonitoringInformation(false);
filter.addBaseDNToSearch(dn);
@@ -2614,10 +2574,6 @@
}
throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, msg, ne);
}
- finally
- {
- StaticUtils.close(remoteConn);
- }
}
if (replicationId == -1)
{
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 d1731f3..7318f2c 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
@@ -47,7 +47,22 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.ManagedObjectDefinition;
+import org.forgerock.opendj.config.ManagedObjectNotFoundException;
+import org.forgerock.opendj.config.PropertyException;
import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.server.config.client.BackendCfgClient;
+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.BackendCfgDefn;
+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.forgerock.opendj.server.config.server.BackendCfg;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.messages.BackendMessages;
@@ -60,28 +75,12 @@
import org.opends.quicksetup.UserData;
import org.opends.quicksetup.util.OutputReader;
import org.opends.quicksetup.util.Utils;
-import org.forgerock.opendj.config.ManagedObjectDefinition;
-import org.forgerock.opendj.config.ManagedObjectNotFoundException;
-import org.forgerock.opendj.config.PropertyException;
-import org.forgerock.opendj.server.config.client.BackendCfgClient;
-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.BackendCfgDefn;
-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.forgerock.opendj.server.config.server.BackendCfg;
import org.opends.server.backends.task.TaskState;
import org.opends.server.core.DirectoryServer;
import org.opends.server.tools.ConfigureDS;
import org.opends.server.tools.ConfigureWindowsService;
import org.opends.server.tools.JavaPropertiesTool;
-import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
-import org.opends.server.types.HostPort;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.LDIFException;
@@ -348,26 +347,24 @@
/**
* Creates a database backend on the server.
*
- * @param connWrapper
+ * @param conn
* the connection to the server.
* @param backendName
* the name of the backend to be created.
* @param baseDNs
* the list of base DNs to be defined on the server.
- * @param serverDisplay
- * the server display.
* @param backendType
* the backend type.
* @throws ApplicationException
* if something goes wrong.
*/
- public void createBackend(ConnectionWrapper connWrapper, String backendName, Set<String> baseDNs,
- HostPort serverDisplay, ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType)
+ public void createBackend(ConnectionWrapper conn, String backendName, Set<String> baseDNs,
+ ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType)
throws ApplicationException
{
try
{
- RootCfgClient root = connWrapper.getRootConfiguration();
+ RootCfgClient root = conn.getRootConfiguration();
BackendCfgClient backend = root.createBackend(backendType, backendName, null);
backend.setEnabled(true);
backend.setBaseDN(toByteStrings(baseDNs));
@@ -378,7 +375,7 @@
catch (Throwable t)
{
throw new ApplicationException(
- ReturnCode.CONFIGURATION_ERROR, INFO_ERROR_CONFIGURING_REMOTE_GENERIC.get(serverDisplay, t), t);
+ ReturnCode.CONFIGURATION_ERROR, INFO_ERROR_CONFIGURING_REMOTE_GENERIC.get(conn.getHostPort(), t), t);
}
}
@@ -421,7 +418,7 @@
/**
* Configures the replication on a given server.
- * @param connWrapper the connection to the server where we want to configure
+ * @param conn the connection to the server where we want to configure
* the replication.
* @param replicationServers a Map where the key value is the base dn and
* the value is the list of replication servers for that base dn (or domain).
@@ -429,7 +426,6 @@
* configured (it might not exist and the user specified it in the setup).
* @param useSecureReplication whether to encrypt connections with the
* replication port or not.
- * @param serverDisplay the server display.
* @param usedReplicationServerIds the list of replication server ids that
* are already used.
* @param usedServerIds the list of server ids (domain ids) that
@@ -438,9 +434,9 @@
* @return a ConfiguredReplication object describing what has been configured.
*/
public ConfiguredReplication configureReplication(
- ConnectionWrapper connWrapper, Map<String,Set<String>> replicationServers,
- int replicationPort, boolean useSecureReplication, HostPort serverDisplay,
- Set<Integer> usedReplicationServerIds, Set<Integer> usedServerIds)
+ ConnectionWrapper conn, Map<String,Set<String>> replicationServers,
+ int replicationPort, boolean useSecureReplication, Set<Integer> usedReplicationServerIds,
+ Set<Integer> usedServerIds)
throws ApplicationException
{
boolean synchProviderCreated;
@@ -449,7 +445,7 @@
boolean secureReplicationEnabled;
try
{
- RootCfgClient root = connWrapper.getRootConfiguration();
+ RootCfgClient root = conn.getRootConfiguration();
/*
* Configure Synchronization plugin.
@@ -622,7 +618,7 @@
{
throw new ApplicationException(
ReturnCode.CONFIGURATION_ERROR,
- INFO_ERROR_CONFIGURING_REMOTE_GENERIC.get(serverDisplay, t),
+ INFO_ERROR_CONFIGURING_REMOTE_GENERIC.get(conn.getHostPort(), t),
t);
}
}
@@ -637,22 +633,19 @@
/**
* Configures the replication on a given server.
*
- * @param connWrapper
+ * @param conn
* the connection to the server where we want to configure the
* replication.
* @param replConf
* the object describing what was configured.
- * @param serverDisplay
- * the server display.
* @throws ApplicationException
* if something goes wrong.
*/
- public void unconfigureReplication(ConnectionWrapper connWrapper, ConfiguredReplication replConf,
- HostPort serverDisplay) throws ApplicationException
+ public void unconfigureReplication(ConnectionWrapper conn, ConfiguredReplication replConf) throws ApplicationException
{
try
{
- RootCfgClient root = connWrapper.getRootConfiguration();
+ RootCfgClient root = conn.getRootConfiguration();
final String syncProvider = "Multimaster Synchronization";
// Unconfigure Synchronization plugin.
if (replConf.isSynchProviderCreated())
@@ -739,7 +732,7 @@
catch (Throwable t)
{
throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, INFO_ERROR_CONFIGURING_REMOTE_GENERIC.get(
- serverDisplay, t), t);
+ conn.getHostPort(), t), t);
}
}
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 db6c9cd..f3b1c52 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
@@ -2222,7 +2222,7 @@
if (replicationServer1Configured && !configureReplicationServer1)
{
final LocalizableMessage msg =
- INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(getHostPort(ctx1.getLdapContext()), repPort1);
+ INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(ctx1.getHostPort(), repPort1);
if (!askConfirmation(msg, false))
{
cancelled = true;
@@ -2490,7 +2490,7 @@
if (replicationServer2Configured && !configureReplicationServer2)
{
final LocalizableMessage prompt =
- INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(getHostPort(ctx2.getLdapContext()), repPort2);
+ INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(ctx2.getHostPort(), repPort2);
if (!askConfirmation(prompt, false))
{
cancelled = true;
@@ -2833,8 +2833,7 @@
if (disableReplicationServer && repPort < 0)
{
disableReplicationServer = false;
- final LocalizableMessage msg = INFO_REPLICATION_PROMPT_NO_REPLICATION_SERVER_TO_DISABLE.get(
- getHostPort(ctx.getLdapContext()));
+ final LocalizableMessage msg = INFO_REPLICATION_PROMPT_NO_REPLICATION_SERVER_TO_DISABLE.get(ctx.getHostPort());
try
{
cancelled = askConfirmation(msg, false, logger);
@@ -2866,7 +2865,7 @@
{
uData.setDisableReplicationServer(askConfirmation(
INFO_REPLICATION_DISABLE_ALL_SUFFIXES_DISABLE_REPLICATION_SERVER.get(
- getHostPort(ctx.getLdapContext()), repPort), true,
+ ctx.getHostPort(), repPort), true,
logger));
}
catch (ClientException ce)
@@ -2951,7 +2950,7 @@
// Ask for confirmation to initialize.
println();
- if (!askConfirmation(getPrompt(uData, conn.getLdapContext()), true))
+ if (!askConfirmation(getPrompt(uData, conn), true))
{
return false;
}
@@ -2960,9 +2959,9 @@
}
}
- private LocalizableMessage getPrompt(InitializeAllReplicationUserData uData, InitialLdapContext ctx)
+ private LocalizableMessage getPrompt(InitializeAllReplicationUserData uData, ConnectionWrapper conn)
{
- HostPort hostPortSource = getHostPort(ctx);
+ HostPort hostPortSource = conn.getHostPort();
if (initializeADS(uData.getBaseDNs()))
{
return INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_ADS.get(ADSContext.getAdministrationSuffixDN(), hostPortSource);
@@ -3518,7 +3517,7 @@
boolean triedWithUserProvidedAdmin = false;
final ConnectionWrapper connWrapper1 = connWrapper.get();
final InitialLdapContext ctx1 = connWrapper1.getLdapContext();
- HostPort hostPort = getHostPort(ctx1);
+ HostPort hostPort = connWrapper1.getHostPort();
boolean isSSL = isSSL(ctx1);
boolean isStartTLS = isStartTLS(ctx1);
Type connectionType;
@@ -3992,7 +3991,7 @@
try
{
updateConfiguration(ctx1, ctx2, uData);
- printSuccessfullyEnabled(ctx1.getLdapContext(), ctx2.getLdapContext());
+ printSuccessfullyEnabled(ctx1, ctx2);
return SUCCESSFUL;
}
catch (ReplicationCliException rce)
@@ -4015,7 +4014,7 @@
int repPort = getReplicationPort(connWrapper);
if (!server.configureReplicationServer() && repPort > 0)
{
- println(INFO_REPLICATION_SERVER_CONFIGURED_WARNING.get(getHostPort(connWrapper.getLdapContext()), repPort));
+ println(INFO_REPLICATION_SERVER_CONFIGURED_WARNING.get(connWrapper.getHostPort(), repPort));
println();
}
}
@@ -4075,15 +4074,15 @@
}
}
- private void printSuccessfullyEnabled(InitialLdapContext ctx1, InitialLdapContext ctx2)
+ private void printSuccessfullyEnabled(ConnectionWrapper conn1, ConnectionWrapper conn2)
{
- long time1 = getServerClock(ctx1);
- long time2 = getServerClock(ctx2);
+ long time1 = getServerClock(conn1.getLdapContext());
+ long time2 = getServerClock(conn2.getLdapContext());
if (time1 != -1
&& time2 != -1
&& Math.abs(time1 - time2) > Installer.THRESHOLD_CLOCK_DIFFERENCE_WARNING * 60 * 1000)
{
- println(INFO_WARNING_SERVERS_CLOCK_DIFFERENCE.get(getHostPort(ctx1), getHostPort(ctx2),
+ println(INFO_WARNING_SERVERS_CLOCK_DIFFERENCE.get(conn1.getHostPort(), conn2.getHostPort(),
Installer.THRESHOLD_CLOCK_DIFFERENCE_WARNING));
}
println();
@@ -4163,7 +4162,7 @@
{
uData.setDisableReplicationServer(false);
println(
- INFO_REPLICATION_WARNING_NO_REPLICATION_SERVER_TO_DISABLE.get(getHostPort(connWrapper.getLdapContext())));
+ INFO_REPLICATION_WARNING_NO_REPLICATION_SERVER_TO_DISABLE.get(connWrapper.getHostPort()));
println();
}
}
@@ -4179,7 +4178,7 @@
// Inform the user that the replication server will not be disabled.
// Inform also of the user of the disableReplicationServerArg
println(INFO_REPLICATION_DISABLE_ALL_SUFFIXES_KEEP_REPLICATION_SERVER.get(
- getHostPort(connWrapper.getLdapContext()),
+ connWrapper.getHostPort(),
argParser.disableReplicationServerArg.getLongIdentifier(),
argParser.disableAllArg.getLongIdentifier()));
}
@@ -5028,8 +5027,8 @@
filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
filter.addBaseDNToSearch(Constants.SCHEMA_DN);
addBaseDNs(filter, uData.getBaseDNs());
- ServerDescriptor serverDesc1 = createStandalone(ctx1.getLdapContext(), filter);
- ServerDescriptor serverDesc2 = createStandalone(ctx2.getLdapContext(), filter);
+ ServerDescriptor serverDesc1 = createStandalone(ctx1, filter);
+ ServerDescriptor serverDesc2 = createStandalone(ctx2, filter);
ADSContext adsCtx1 = new ADSContext(ctx1);
ADSContext adsCtx2 = new ADSContext(ctx2);
@@ -5312,8 +5311,8 @@
{
logger.error(LocalizableMessage.raw("Error seeding truststores: "+t, t));
throw new ReplicationCliException(
- ERR_REPLICATION_ENABLE_SEEDING_TRUSTSTORE.get(getHostPort(ctxDestination.getLdapContext()),
- getHostPort(adsCtxSource.getDirContext()), toString(t)),
+ ERR_REPLICATION_ENABLE_SEEDING_TRUSTSTORE.get(ctxDestination.getHostPort(),
+ adsCtxSource.getHostPort(), toString(t)),
ERROR_SEEDING_TRUSTORE, t);
}
}
@@ -5430,7 +5429,7 @@
if (adsMergeDone)
{
PointAdder pointAdder = new PointAdder(this);
- print(INFO_ENABLE_REPLICATION_INITIALIZING_ADS_ALL.get(getHostPort(ctxSource.getLdapContext())));
+ print(INFO_ENABLE_REPLICATION_INITIALIZING_ADS_ALL.get(ctxSource.getHostPort()));
pointAdder.start();
try
{
@@ -5447,8 +5446,7 @@
else if (ctxSource != null && ctxDestination != null)
{
print(formatter.getFormattedWithPoints(
- INFO_ENABLE_REPLICATION_INITIALIZING_ADS.get(
- getHostPort(ctxDestination.getLdapContext()), getHostPort(ctxSource.getLdapContext()))));
+ INFO_ENABLE_REPLICATION_INITIALIZING_ADS.get(ctxDestination.getHostPort(), ctxSource.getHostPort())));
initializeSuffix(
ADSContext.getAdministrationSuffixDN(), ctxSource.getLdapContext(), ctxDestination.getLdapContext(), false);
@@ -5473,7 +5471,7 @@
{
PointAdder pointAdder = new PointAdder(this);
println(INFO_ENABLE_REPLICATION_INITIALIZING_SCHEMA.get(
- getHostPort(ctxDestination.getLdapContext()), getHostPort(ctxSource.getLdapContext())));
+ ctxDestination.getHostPort(), ctxSource.getHostPort()));
pointAdder.start();
try
{
@@ -5488,7 +5486,7 @@
else
{
print(formatter.getFormattedWithPoints(INFO_ENABLE_REPLICATION_INITIALIZING_SCHEMA.get(
- getHostPort(ctxDestination.getLdapContext()), getHostPort(ctxSource.getLdapContext()))));
+ ctxDestination.getHostPort(), ctxSource.getHostPort())));
initializeSuffix(Constants.SCHEMA_DN, ctxSource.getLdapContext(), ctxDestination.getLdapContext(), false);
}
print(formatter.getFormattedDone());
@@ -5524,7 +5522,7 @@
}
catch (Exception ode)
{
- LocalizableMessage msg = getMessageForEnableException(getHostPort(ctx.getLdapContext()), baseDN);
+ LocalizableMessage msg = getMessageForEnableException(ctx.getHostPort(), baseDN);
throw new ReplicationCliException(msg, ERROR_ENABLING_REPLICATION_ON_BASEDN, ode);
}
}
@@ -5552,7 +5550,7 @@
}
catch (Exception ode)
{
- throw errorConfiguringReplicationServer(ctx.getLdapContext(), ode);
+ throw errorConfiguringReplicationServer(ctx, ode);
}
}
else if (serverDesc.isReplicationServer())
@@ -5563,7 +5561,7 @@
}
catch (Exception ode)
{
- throw errorConfiguringReplicationServer(ctx.getLdapContext(), ode);
+ throw errorConfiguringReplicationServer(ctx, ode);
}
if (replicationPortArg.isPresent() && enableServer.getReplicationPort() != serverDesc.getReplicationServerPort())
{
@@ -5576,10 +5574,10 @@
alreadyConfiguredReplicationServers.add(serverDesc.getId());
}
- private ReplicationCliException errorConfiguringReplicationServer(InitialLdapContext ctx, Exception ode)
+ private ReplicationCliException errorConfiguringReplicationServer(ConnectionWrapper conn, Exception ode)
{
return new ReplicationCliException(
- ERR_REPLICATION_CONFIGURING_REPLICATIONSERVER.get(getHostPort(ctx)),
+ ERR_REPLICATION_CONFIGURING_REPLICATIONSERVER.get(conn.getHostPort()),
ERROR_CONFIGURING_REPLICATIONSERVER, ode);
}
@@ -5598,18 +5596,17 @@
return null;
}
- private ServerDescriptor createStandalone(InitialLdapContext ctx, TopologyCacheFilter filter)
+ private ServerDescriptor createStandalone(ConnectionWrapper conn, TopologyCacheFilter filter)
throws ReplicationCliException
{
try
{
- return ServerDescriptor.createStandalone(ctx, filter);
+ return ServerDescriptor.createStandalone(conn.getLdapContext(), filter);
}
catch (NamingException ne)
{
throw new ReplicationCliException(
- getMessageForException(ne, getHostPort(ctx).toString()),
- ERROR_READING_CONFIGURATION, ne);
+ getMessageForException(ne, conn.getHostPort().toString()), ERROR_READING_CONFIGURATION, ne);
}
}
@@ -5631,7 +5628,7 @@
filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
addBaseDNs(filter, uData.getBaseDNs());
}
- ServerDescriptor server = createStandalone(ctx.getLdapContext(), filter);
+ ServerDescriptor server = createStandalone(ctx, filter);
ADSContext adsCtx = new ADSContext(ctx);
@@ -5912,9 +5909,8 @@
}
catch (OpenDsException ode)
{
- LocalizableMessage msg = getMessageForDisableException(getHostPort(ctx.getLdapContext()), baseDN);
- throw new ReplicationCliException(msg,
- ERROR_DISABLING_REPLICATION_ON_BASEDN, ode);
+ LocalizableMessage msg = getMessageForDisableException(ctx.getHostPort(), baseDN);
+ throw new ReplicationCliException(msg, ERROR_DISABLING_REPLICATION_ON_BASEDN, ode);
}
}
@@ -6705,10 +6701,9 @@
}
/**
- * Configures the server to which the provided InitialLdapContext is connected
- * as a replication server. The replication server listens in the provided
- * port.
- * @param ctx the context connected to the server that we want to configure.
+ * Configures the server as a replication server by using the provided connection.
+ * The replication server listens to the provided port.
+ * @param conn the connection to the server that we want to configure.
* @param replicationPort the replication port of the replication server.
* @param useSecureReplication whether to have encrypted communication with
* the replication port or not.
@@ -6719,15 +6714,15 @@
* that will be used by the newly configured replication server.
* @throws OpenDsException if there is an error updating the configuration.
*/
- private void configureAsReplicationServer(ConnectionWrapper ctx,
+ private void configureAsReplicationServer(ConnectionWrapper conn,
int replicationPort, boolean useSecureReplication,
Set<String> replicationServers,
Set<Integer> usedReplicationServerIds) throws Exception
{
print(formatter.getFormattedWithPoints(
- INFO_REPLICATION_ENABLE_CONFIGURING_REPLICATION_SERVER.get(getHostPort(ctx.getLdapContext()))));
+ INFO_REPLICATION_ENABLE_CONFIGURING_REPLICATION_SERVER.get(conn.getHostPort())));
- RootCfgClient root = ctx.getRootConfiguration();
+ RootCfgClient root = conn.getRootConfiguration();
/* Configure Synchronization plugin. */
ReplicationSynchronizationProviderCfgClient sync = null;
@@ -6739,7 +6734,7 @@
catch (ManagedObjectNotFoundException monfe)
{
logger.info(LocalizableMessage.raw(
- "Synchronization server does not exist in " + getHostPort(ctx.getLdapContext())));
+ "Synchronization server does not exist in " + conn.getHostPort()));
}
if (sync == null)
{
@@ -6821,7 +6816,7 @@
Set<String> replicationServers) throws Exception
{
print(formatter.getFormattedWithPoints(
- INFO_REPLICATION_ENABLE_UPDATING_REPLICATION_SERVER.get(getHostPort(ctx.getLdapContext()))));
+ INFO_REPLICATION_ENABLE_UPDATING_REPLICATION_SERVER.get(ctx.getHostPort())));
RootCfgClient root = ctx.getRootConfiguration();
@@ -6899,12 +6894,12 @@
&& areDnsEqual(baseDN, ADSContext.getAdministrationSuffixDN()))
{
print(formatter.getFormattedWithPoints(
- INFO_REPLICATION_ENABLE_CONFIGURING_ADS.get(getHostPort(ctx.getLdapContext()))));
+ INFO_REPLICATION_ENABLE_CONFIGURING_ADS.get(ctx.getHostPort())));
}
else
{
print(formatter.getFormattedWithPoints(
- INFO_REPLICATION_ENABLE_CONFIGURING_BASEDN.get(baseDN, getHostPort(ctx.getLdapContext()))));
+ INFO_REPLICATION_ENABLE_CONFIGURING_BASEDN.get(baseDN, ctx.getHostPort())));
}
RootCfgClient root = ctx.getRootConfiguration();
@@ -7162,8 +7157,8 @@
* @param displayProgress whether we want to display progress or not.
* @throws ReplicationCliException if an unexpected error occurs.
*/
- public void initializeAllSuffix(String baseDN, InitialLdapContext ctx,
- boolean displayProgress) throws ReplicationCliException
+ public void initializeAllSuffix(String baseDN, InitialLdapContext ctx, boolean displayProgress)
+ throws ReplicationCliException
{
if (argParser == null)
{
@@ -7651,7 +7646,7 @@
try
{
ctx = loader.createConnectionWrapper();
- hostPort = getHostPort(ctx.getLdapContext());
+ hostPort = ctx.getHostPort();
RootCfgClient root = ctx.getRootConfiguration();
ReplicationSynchronizationProviderCfgClient sync = null;
try
@@ -7749,8 +7744,7 @@
}
else
{
- LocalizableMessage msg = ERR_REPLICATION_ERROR_READING_CONFIGURATION.get(hostPort,
- ode.getMessage());
+ LocalizableMessage msg = ERR_REPLICATION_ERROR_READING_CONFIGURATION.get(hostPort, ode.getMessage());
throw new ReplicationCliException(msg, ERROR_CONNECTING, ode);
}
}
@@ -7763,18 +7757,17 @@
/**
* Deletes a replication domain in a server for a given base DN (disable
* replication of the base DN).
- * @param ctx the connection to the server.
- * @param baseDN the base DN of the replication domain that we want to
- * delete.
+ * @param conn the connection to the server.
+ * @param baseDN the base DN of the replication domain that we want to delete.
* @throws ReplicationCliException if there is an error updating the
* configuration of the server.
*/
- private void deleteReplicationDomain(ConnectionWrapper ctx, String baseDN) throws ReplicationCliException
+ private void deleteReplicationDomain(ConnectionWrapper conn, String baseDN) throws ReplicationCliException
{
- HostPort hostPort = getHostPort(ctx.getLdapContext());
+ HostPort hostPort = conn.getHostPort();
try
{
- RootCfgClient root = ctx.getRootConfiguration();
+ RootCfgClient root = conn.getRootConfiguration();
ReplicationSynchronizationProviderCfgClient sync = null;
try
{
@@ -7784,8 +7777,7 @@
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
- logger.info(LocalizableMessage.raw("No synchronization found on "+ hostPort +".",
- monfe));
+ logger.info(LocalizableMessage.raw("No synchronization found on " + hostPort + ".", monfe));
}
if (sync != null)
{
@@ -7827,7 +7819,7 @@
private void disableReplicationServer(ConnectionWrapper connWrapper)
throws ReplicationCliException
{
- HostPort hostPort = getHostPort(connWrapper.getLdapContext());
+ HostPort hostPort = connWrapper.getHostPort();
try
{
RootCfgClient root = connWrapper.getRootConfiguration();
@@ -7845,15 +7837,13 @@
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
- logger.info(LocalizableMessage.raw("No synchronization found on "+ hostPort +".",
- monfe));
+ logger.info(LocalizableMessage.raw("No synchronization found on " + hostPort + ".", monfe));
}
if (replicationServer != null)
{
String s = String.valueOf(replicationServer.getReplicationPort());
print(formatter.getFormattedWithPoints(
- INFO_REPLICATION_DISABLING_REPLICATION_SERVER.get(s,
- hostPort)));
+ INFO_REPLICATION_DISABLING_REPLICATION_SERVER.get(s, hostPort)));
sync.removeReplicationServer();
sync.commit();
@@ -9332,7 +9322,7 @@
}
catch (Throwable t)
{
- String msg = "Error loading topology cache from " + getHostPort(adsCtx.getDirContext()) + ": " + t;
+ String msg = "Error loading topology cache from " + adsCtx.getHostPort() + ": " + t;
logger.warn(LocalizableMessage.raw(msg, t));
}
}
@@ -9369,21 +9359,21 @@
int nRepServers1 = countReplicationServers(cache1);
int nRepServers2 = countReplicationServers(cache2);
- InitialLdapContext ctxSource;
- InitialLdapContext ctxDestination;
+ ADSContext ctxSource;
+ ADSContext ctxDestination;
if (nRepServers1 >= nRepServers2)
{
- ctxSource = adsCtx1.getDirContext();
- ctxDestination = adsCtx2.getDirContext();
+ ctxSource = adsCtx1;
+ ctxDestination = adsCtx2;
}
else
{
- ctxSource = adsCtx2.getDirContext();
- ctxDestination = adsCtx1.getDirContext();
+ ctxSource = adsCtx2;
+ ctxDestination = adsCtx1;
}
- HostPort hostPortSource = getHostPort(ctxSource);
- HostPort hostPortDestination = getHostPort(ctxDestination);
+ HostPort hostPortSource = ctxSource.getHostPort();
+ HostPort hostPortDestination = ctxDestination.getHostPort();
if (isInteractive())
{
LocalizableMessage msg = INFO_REPLICATION_MERGING_REGISTRIES_CONFIRMATION.get(hostPortSource,
@@ -9475,11 +9465,11 @@
}
catch (ADSContextException adce)
{
- logger.error(LocalizableMessage.raw("Error merging registry of "+
- getHostPort(adsCtxSource.getDirContext())+
- " with registry of "+
- getHostPort(adsCtxDestination.getDirContext())+" "+
- adce, adce));
+ logger.error(LocalizableMessage.raw("Error merging registry of "
+ + adsCtxSource.getHostPort()
+ + " with registry of "
+ + adsCtxDestination.getHostPort()
+ + " " + adce, adce));
if (adce.getError() == ADSContextException.ErrorType.ERROR_MERGING)
{
throw new ReplicationCliException(adce.getMessageObject(),
@@ -9500,8 +9490,7 @@
if (server.isReplicationServer())
{
logger.info(LocalizableMessage.raw("Seeding to replication server on "+
- server.getHostPort(true)+" with certificates of "+
- getHostPort(adsCtxSource.getDirContext())));
+ server.getHostPort(true)+" with certificates of "+ adsCtxSource.getHostPort()));
try (ConnectionWrapper conn = getDirContextForServer(cacheDestination, server))
{
ServerDescriptor.seedAdsTrustStore(conn.getLdapContext(), adsCtxSource.getTrustedCertificates());
@@ -9512,8 +9501,8 @@
catch (Throwable t)
{
logger.error(LocalizableMessage.raw("Error seeding truststore: "+t, t));
- LocalizableMessage msg = ERR_REPLICATION_ENABLE_SEEDING_TRUSTSTORE.get(getHostPort(adsCtx2.getDirContext()),
- getHostPort(adsCtx1.getDirContext()), toString(t));
+ LocalizableMessage msg = ERR_REPLICATION_ENABLE_SEEDING_TRUSTSTORE.get(adsCtx2.getHostPort(),
+ adsCtx1.getHostPort(), toString(t));
throw new ReplicationCliException(msg, ERROR_SEEDING_TRUSTORE, t);
}
pointAdder.stop();
@@ -9550,7 +9539,7 @@
{
LocalizableMessage msg = getMessageFromCollection(cacheErrors, Constants.LINE_SEPARATOR);
throw new ReplicationCliException(
- ERR_REPLICATION_CANNOT_MERGE_WITH_ERRORS.get(getHostPort(adsCtx.getDirContext()), msg),
+ ERR_REPLICATION_CANNOT_MERGE_WITH_ERRORS.get(adsCtx.getHostPort(), msg),
ERROR_READING_ADS, null);
}
}
@@ -9622,7 +9611,7 @@
catch (TopologyCacheException te)
{
logger.error(LocalizableMessage.raw(
- "Error reading topology cache of " + getHostPort(adsCtx.getDirContext()) + " " + te, te));
+ "Error reading topology cache of " + adsCtx.getHostPort() + " " + te, te));
throw new ReplicationCliException(ERR_REPLICATION_READING_ADS.get(te.getMessageObject()), ERROR_UPDATING_ADS, te);
}
}
--
Gitblit v1.10.0