| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.quicksetup.installer; |
| | | |
| | |
| | | import static org.opends.quicksetup.installer.DataReplicationOptions.Type.*; |
| | | import static org.opends.quicksetup.installer.InstallProgressStep.*; |
| | | import static org.opends.quicksetup.util.Utils.*; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | |
| | | 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; |
| | | import org.opends.quicksetup.ButtonName; |
| | |
| | | */ |
| | | private void unconfigureRemote() |
| | | { |
| | | InitialLdapContext ctx = null; |
| | | ConnectionWrapper connectionWrapper = null; |
| | | if (registeredNewServerOnRemote || createdAdministrator || createdRemoteAds) |
| | | { |
| | | // Try to connect |
| | |
| | | } |
| | | try |
| | | { |
| | | ctx = createInitialLdapContext(auth); |
| | | connectionWrapper = createConnection(auth); |
| | | |
| | | ADSContext adsContext = new ADSContext(ctx); |
| | | ADSContext adsContext = new ADSContext(connectionWrapper); |
| | | if (createdRemoteAds) |
| | | { |
| | | adsContext.removeAdminData(true); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(connectionWrapper); |
| | | } |
| | | } |
| | | InstallerHelper helper = new InstallerHelper(); |
| | |
| | | notifyListeners(getFormattedWithPoints(INFO_PROGRESS_UNCONFIGURING_REPLICATION_REMOTE.get(getHostPort(server)))); |
| | | try |
| | | { |
| | | ctx = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | helper.unconfigureReplication(ctx, hmConfiguredRemoteReplication.get(server), ConnectionUtils.getHostPort(ctx)); |
| | | connectionWrapper = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | helper.unconfigureReplication(connectionWrapper, hmConfiguredRemoteReplication.get(server), |
| | | ConnectionUtils.getHostPort(connectionWrapper.getLdapContext())); |
| | | } |
| | | catch (ApplicationException ae) |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(connectionWrapper); |
| | | } |
| | | notifyListeners(getFormattedDoneWithLineBreak()); |
| | | } |
| | |
| | | private void createReplicatedBackends(final Map<String, Set<String>> hmBackendSuffix, |
| | | final Map<String, BackendTypeUIAdapter> backendTypes) throws ApplicationException |
| | | { |
| | | InitialLdapContext ctx = null; |
| | | ConnectionWrapper connection = null; |
| | | try |
| | | { |
| | | ctx = createLocalContext(); |
| | | connection = createLocalConnection(); |
| | | final InstallerHelper helper = new InstallerHelper(); |
| | | for (String backendName : hmBackendSuffix.keySet()) |
| | | { |
| | | helper.createBackend(ctx, backendName, hmBackendSuffix.get(backendName), ConnectionUtils.getHostPort(ctx), |
| | | backendTypes.get(backendName).getLegacyConfigurationFrameworkBackend()); |
| | | helper.createBackend(connection, backendName, hmBackendSuffix.get(backendName), |
| | | ConnectionUtils.getHostPort(connection.getLdapContext()), |
| | | backendTypes.get(backendName).getBackend()); |
| | | } |
| | | } |
| | | catch (NamingException ne) |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(connection); |
| | | } |
| | | } |
| | | |
| | |
| | | replicationServers.put(ADSContext.getAdministrationSuffixDN(), adsServers); |
| | | replicationServers.put(Constants.SCHEMA_DN, new HashSet<String>(adsServers)); |
| | | |
| | | InitialLdapContext ctx = null; |
| | | ConnectionWrapper connWrapper = null; |
| | | long localTime = -1; |
| | | long localTimeMeasureTime = -1; |
| | | String localServerDisplay = null; |
| | | try |
| | | { |
| | | ctx = createLocalContext(); |
| | | helper.configureReplication(ctx, replicationServers, |
| | | connWrapper = createLocalConnection(); |
| | | helper.configureReplication(connWrapper, replicationServers, |
| | | getUserData().getReplicationOptions().getReplicationPort(), |
| | | getUserData().getReplicationOptions().useSecureReplication(), |
| | | getLocalHostPort(), |
| | | knownReplicationServerIds, knownServerIds); |
| | | localTimeMeasureTime = System.currentTimeMillis(); |
| | | localTime = Utils.getServerClock(ctx); |
| | | localServerDisplay = ConnectionUtils.getHostPort(ctx); |
| | | localTime = Utils.getServerClock(connWrapper.getLdapContext()); |
| | | localServerDisplay = ConnectionUtils.getHostPort(connWrapper.getLdapContext()); |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(connWrapper); |
| | | } |
| | | notifyListeners(getFormattedDoneWithLineBreak()); |
| | | checkAbort(); |
| | |
| | | } |
| | | } |
| | | |
| | | ctx = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | connWrapper = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | InitialLdapContext ctx = connWrapper.getLdapContext(); |
| | | ConfiguredReplication repl = |
| | | helper.configureReplication(ctx, remoteReplicationServers, replicationPort, enableSecureReplication, |
| | | helper.configureReplication(connWrapper, remoteReplicationServers, replicationPort, enableSecureReplication, |
| | | ConnectionUtils.getHostPort(ctx), knownReplicationServerIds, knownServerIds); |
| | | long remoteTimeMeasureTime = System.currentTimeMillis(); |
| | | long remoteTime = Utils.getServerClock(ctx); |
| | |
| | | |
| | | hmConfiguredRemoteReplication.put(server, repl); |
| | | |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(connWrapper); |
| | | notifyListeners(getFormattedDoneWithLineBreak()); |
| | | checkAbort(); |
| | | } |
| | |
| | | */ |
| | | protected void initializeSuffixes() throws ApplicationException |
| | | { |
| | | InitialLdapContext ctx = null; |
| | | ConnectionWrapper conn = null; |
| | | try |
| | | { |
| | | ctx = createLocalContext(); |
| | | conn = createLocalConnection(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | LocalizableMessage failedMsg = getThrowableMsg(INFO_ERROR_CONNECTING_TO_LOCAL.get(), t); |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(conn); |
| | | throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, failedMsg, t); |
| | | } |
| | | |
| | |
| | | /* Initialize local ADS and schema contents using any replica. */ |
| | | { |
| | | ServerDescriptor server = suffixes.iterator().next().getReplicas().iterator().next().getServer(); |
| | | InitialLdapContext rCtx = null; |
| | | ConnectionWrapper remoteConn = null; |
| | | try |
| | | { |
| | | rCtx = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | | filter.setSearchMonitoringInformation(false); |
| | | filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN()); |
| | | filter.addBaseDNToSearch(Constants.SCHEMA_DN); |
| | | ServerDescriptor s = createStandalone(rCtx, filter); |
| | | ServerDescriptor s = createStandalone(remoteConn.getLdapContext(), filter); |
| | | for (ReplicaDescriptor replica : s.getReplicas()) |
| | | { |
| | | String dn = replica.getSuffix().getDN(); |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(rCtx); |
| | | StaticUtils.close(remoteConn); |
| | | } |
| | | } |
| | | |
| | |
| | | if (replicationId == -1) |
| | | { |
| | | // This occurs if the remote server had not replication configured. |
| | | InitialLdapContext rCtx = null; |
| | | ConnectionWrapper remoteConn = null; |
| | | try |
| | | { |
| | | rCtx = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections()); |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | | filter.setSearchMonitoringInformation(false); |
| | | filter.addBaseDNToSearch(dn); |
| | | ServerDescriptor s = createStandalone(rCtx, filter); |
| | | ServerDescriptor s = createStandalone(remoteConn.getLdapContext(), filter); |
| | | for (ReplicaDescriptor r : s.getReplicas()) |
| | | { |
| | | if (areDnsEqual(r.getSuffix().getDN(), dn)) |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(rCtx); |
| | | StaticUtils.close(remoteConn); |
| | | } |
| | | } |
| | | if (replicationId == -1) |
| | |
| | | logger.info(LocalizableMessage.raw("Calling initializeSuffix with base DN: " + dn)); |
| | | logger.info(LocalizableMessage.raw("Try number: " + (6 - nTries))); |
| | | logger.info(LocalizableMessage.raw("replicationId of source replica: " + replicationId)); |
| | | initializeSuffix(ctx, replicationId, dn, !isADS && !isSchema, hostPort); |
| | | initializeSuffix(conn.getLdapContext(), replicationId, dn, !isADS && !isSchema, hostPort); |
| | | initDone = true; |
| | | } |
| | | catch (PeerNotFoundException pnfe) |
| | |
| | | } |
| | | catch (ApplicationException ae) |
| | | { |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(conn); |
| | | throw ae; |
| | | } |
| | | if ((isADS || isSchema) && isVerbose()) |
| | |
| | | DataReplicationOptions repl = getUserData().getReplicationOptions(); |
| | | boolean isRemoteServer = repl.getType() == DataReplicationOptions.Type.IN_EXISTING_TOPOLOGY; |
| | | AuthenticationData auth = isRemoteServer ? repl.getAuthenticationData() : null; |
| | | InitialLdapContext remoteCtx = null; // Bound to remote ADS host (if any). |
| | | InitialLdapContext localCtx = null; // Bound to local server. |
| | | ConnectionWrapper remoteConn = null; // Bound to remote ADS host (if any). |
| | | ConnectionWrapper localConn = null; // Bound to local server. |
| | | ADSContext adsContext = null; // Bound to ADS host (via one of above). |
| | | |
| | | /* |
| | |
| | | { |
| | | if (isRemoteServer) |
| | | { |
| | | remoteCtx = createInitialLdapContext(auth); |
| | | adsContext = new ADSContext(remoteCtx); // adsContext owns remoteCtx |
| | | remoteConn = createConnection(auth); |
| | | adsContext = new ADSContext(remoteConn); // adsContext owns remoteCtx |
| | | |
| | | /* |
| | | * Check the remote server for ADS. If it does not exist, create the |
| | |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | | filter.setSearchMonitoringInformation(false); |
| | | filter.setSearchBaseDNInformation(false); |
| | | ServerDescriptor server = createStandalone(remoteCtx, filter); |
| | | ServerDescriptor server = createStandalone(remoteConn.getLdapContext(), filter); |
| | | server.updateAdsPropertiesWithServerProperties(); |
| | | adsContext.registerServer(server.getAdsProperties()); |
| | | createdRemoteAds = true; |
| | |
| | | { |
| | | notifyListeners(getFormattedWithPoints(INFO_PROGRESS_CREATING_ADS.get())); |
| | | } |
| | | localCtx = createLocalContext(); |
| | | localConn = createLocalConnection(); |
| | | // if (isRemoteServer) |
| | | // { |
| | | // /* Create an empty ADS suffix on the local server. */ |
| | |
| | | if (!isRemoteServer) |
| | | { |
| | | /* Configure local server to have an ADS */ |
| | | adsContext = new ADSContext(localCtx); // adsContext owns localCtx |
| | | adsContext = new ADSContext(localConn); // adsContext owns localCtx |
| | | adsContext.createAdminData(null); |
| | | } |
| | | /* Register new server in ADS. */ |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | | filter.setSearchMonitoringInformation(false); |
| | | filter.setSearchBaseDNInformation(false); |
| | | ServerDescriptor server = createStandalone(localCtx, filter); |
| | | ServerDescriptor server = createStandalone(localConn.getLdapContext(), filter); |
| | | server.updateAdsPropertiesWithServerProperties(); |
| | | if (0 == adsContext.registerOrUpdateServer(server.getAdsProperties())) |
| | | { |
| | |
| | | } |
| | | if (isRemoteServer) |
| | | { |
| | | seedAdsTrustStore(localCtx, adsContext.getTrustedCertificates()); |
| | | seedAdsTrustStore(localConn.getLdapContext(), adsContext.getTrustedCertificates()); |
| | | } |
| | | if (isVerbose()) |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(remoteCtx, localCtx); |
| | | StaticUtils.close(remoteConn, localConn); |
| | | } |
| | | } |
| | | |
| | | private InitialLdapContext createInitialLdapContext(AuthenticationData auth) throws NamingException |
| | | private ConnectionWrapper createConnection(AuthenticationData auth) throws NamingException |
| | | { |
| | | String ldapUrl = getLdapUrl(auth); |
| | | String dn = auth.getDn(); |
| | | String pwd = auth.getPwd(); |
| | | |
| | | InitialLdapContext context = null; |
| | | |
| | | if (auth.useSecureConnection()) |
| | | { |
| | | ApplicationTrustManager trustManager = getTrustManager(); |
| | | trustManager.setHost(auth.getHostName()); |
| | | return createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, trustManager, null); |
| | | context = createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, trustManager, null); |
| | | } |
| | | return createLdapContext(ldapUrl, dn, pwd, getConnectTimeout(), null); |
| | | else |
| | | { |
| | | context = createLdapContext(ldapUrl, dn, pwd, getConnectTimeout(), null); |
| | | } |
| | | return new ConnectionWrapper(context, getConnectTimeout(), getTrustManager()); |
| | | } |
| | | |
| | | /** |
| | |
| | | host = getHostNameForLdapUrl(host); |
| | | String ldapUrl = "ldaps://" + host + ":" + port; |
| | | InitialLdapContext ctx = null; |
| | | ConnectionWrapper conn = null; |
| | | |
| | | ApplicationTrustManager trustManager = getTrustManager(); |
| | | trustManager.setHost(host); |
| | |
| | | throw t; |
| | | } |
| | | } |
| | | |
| | | ADSContext adsContext = new ADSContext(ctx); |
| | | conn = new ConnectionWrapper(ctx, getConnectTimeout(), trustManager); |
| | | ADSContext adsContext = new ADSContext(conn); |
| | | if (adsContext.hasAdminData()) |
| | | { |
| | | /* Check if there are already global administrators */ |
| | |
| | | finally |
| | | { |
| | | StaticUtils.close(ctx); |
| | | StaticUtils.close(conn); |
| | | } |
| | | } |
| | | |
| | |
| | | return servers; |
| | | } |
| | | |
| | | private InitialLdapContext createLocalContext() throws NamingException |
| | | private ConnectionWrapper createLocalConnection() throws NamingException |
| | | { |
| | | String ldapUrl = |
| | | "ldaps://" + getHostNameForLdapUrl(getUserData().getHostName()) + ":" + getUserData().getAdminConnectorPort(); |
| | | String dn = getUserData().getDirectoryManagerDn(); |
| | | String pwd = getUserData().getDirectoryManagerPwd(); |
| | | return createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, null, null); |
| | | InitialLdapContext context = createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, null, null); |
| | | return new ConnectionWrapper(context, getConnectTimeout(), null); |
| | | } |
| | | |
| | | /** |
| | | * Gets an InitialLdapContext based on the information that appears on the |
| | | * Gets a connection based on the information that appears on the |
| | | * provided ServerDescriptor. |
| | | * |
| | | * @param server |
| | |
| | | * @throws ApplicationException |
| | | * if something goes wrong. |
| | | */ |
| | | private InitialLdapContext getRemoteConnection(ServerDescriptor server, ApplicationTrustManager trustManager, |
| | | private ConnectionWrapper getRemoteConnection(ServerDescriptor server, ApplicationTrustManager trustManager, |
| | | Set<PreferredConnection> cnx) throws ApplicationException |
| | | { |
| | | Map<ADSContext.ServerProperty, Object> adsProperties; |