| | |
| | | import org.opends.admin.ads.ADSContext.AdministratorProperty; |
| | | import org.opends.admin.ads.util.ApplicationTrustManager; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.admin.ads.util.PreferredConnection; |
| | | import org.opends.admin.ads.util.ServerLoader; |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | |
| | | subcommandLaunched = false; |
| | | } |
| | | |
| | | if (subcommandLaunched) |
| | | // Display the log file only if the operation is successful (when there |
| | | // is a critical error this is already displayed). |
| | | if (subcommandLaunched && (returnValue == SUCCESSFUL_NOP)) |
| | | { |
| | | File logFile = QuickSetupLog.getLogFile(); |
| | | if (logFile != null) |
| | |
| | | // LDAPConnectionConsoleInteraction object might have changed. |
| | | TopologyCache cache = new TopologyCache(adsContext, |
| | | getTrustManager()); |
| | | cache.setPreferredConnections(getPreferredConnections(ctx[0])); |
| | | cache.reloadTopology(); |
| | | |
| | | reloadTopology = false; |
| | |
| | | adminPwd, getTrustManager()); |
| | | adsContext = new ADSContext(ctx[0]); |
| | | cache = new TopologyCache(adsContext, getTrustManager()); |
| | | cache.setPreferredConnections( |
| | | getPreferredConnections(ctx[0])); |
| | | connected = true; |
| | | } |
| | | catch (Throwable t) |
| | |
| | | LinkedHashSet<Message> messages = new LinkedHashSet<Message>(); |
| | | try |
| | | { |
| | | LinkedHashSet<PreferredConnection> cnx = |
| | | new LinkedHashSet<PreferredConnection>(); |
| | | cnx.addAll(getPreferredConnections(ctx1)); |
| | | cnx.addAll(getPreferredConnections(ctx2)); |
| | | if (adsCtx1.hasAdminData()) |
| | | { |
| | | TopologyCache cache = new TopologyCache(adsCtx1, getTrustManager()); |
| | | cache.setPreferredConnections(cnx); |
| | | cache.reloadTopology(); |
| | | messages.addAll(getErrorMessages(cache)); |
| | | } |
| | |
| | | if (adsCtx2.hasAdminData()) |
| | | { |
| | | TopologyCache cache = new TopologyCache(adsCtx2, getTrustManager()); |
| | | cache.setPreferredConnections(cnx); |
| | | cache.reloadTopology(); |
| | | messages.addAll(getErrorMessages(cache)); |
| | | } |
| | |
| | | TopologyCache cache2 = null; |
| | | try |
| | | { |
| | | LinkedHashSet<PreferredConnection> cnx = |
| | | new LinkedHashSet<PreferredConnection>(); |
| | | cnx.addAll(getPreferredConnections(ctx1)); |
| | | cnx.addAll(getPreferredConnections(ctx2)); |
| | | if (adsCtx1.hasAdminData()) |
| | | { |
| | | cache1 = new TopologyCache(adsCtx1, getTrustManager()); |
| | | cache1.setPreferredConnections(cnx); |
| | | cache1.reloadTopology(); |
| | | usedReplicationServerIds.addAll(getReplicationServerIds(cache1)); |
| | | } |
| | |
| | | if (adsCtx2.hasAdminData()) |
| | | { |
| | | cache2 = new TopologyCache(adsCtx2, getTrustManager()); |
| | | cache2.setPreferredConnections(cnx); |
| | | cache2.reloadTopology(); |
| | | usedReplicationServerIds.addAll(getReplicationServerIds(cache2)); |
| | | } |
| | |
| | | if (adsCtx.hasAdminData() && tryToUpdateRemote) |
| | | { |
| | | cache = new TopologyCache(adsCtx, getTrustManager()); |
| | | cache.setPreferredConnections(getPreferredConnections(ctx)); |
| | | cache.reloadTopology(); |
| | | } |
| | | } |
| | |
| | | for (ServerDescriptor s : serversToUpdate) |
| | | { |
| | | removeReferencesInServer(s, replicationServerHostPort, bindDn, pwd, |
| | | suffixesToDisable, disableAllBaseDns); |
| | | suffixesToDisable, disableAllBaseDns, getPreferredConnections(ctx)); |
| | | } |
| | | |
| | | if (disableAllBaseDns) |
| | |
| | | try |
| | | { |
| | | cache = new TopologyCache(adsCtx, getTrustManager()); |
| | | cache.setPreferredConnections(getPreferredConnections(ctx)); |
| | | cache.reloadTopology(); |
| | | } |
| | | catch (TopologyCacheException tce) |
| | |
| | | for (Set<ReplicaDescriptor> replicas : orderedReplicaLists) |
| | | { |
| | | printlnProgress(); |
| | | displayStatus(replicas, uData.isScriptFriendly()); |
| | | displayStatus(replicas, uData.isScriptFriendly(), |
| | | getPreferredConnections(ctx)); |
| | | } |
| | | if (oneReplicated && !uData.isScriptFriendly()) |
| | | { |
| | |
| | | * that all the replicas have the same baseDN and that if they are replicated |
| | | * all the replicas are replicated with each other. |
| | | * @param replicas the list of replicas that we are trying to display. |
| | | * @param cnx the preferred connections used to connect to the server. |
| | | * @param scriptFriendly wheter to display it on script-friendly mode or not. |
| | | */ |
| | | private void displayStatus(Set<ReplicaDescriptor> replicas, |
| | | boolean scriptFriendly) |
| | | boolean scriptFriendly, LinkedHashSet<PreferredConnection> cnx) |
| | | { |
| | | |
| | | boolean isReplicated = false; |
| | |
| | | { |
| | | isReplicated = true; |
| | | } |
| | | hostPorts.add(replica.getServer().getHostPort(true)); |
| | | hostPorts.add(getHostPort(replica.getServer(), cnx)); |
| | | } |
| | | for (String hostPort : hostPorts) |
| | | { |
| | | for (ReplicaDescriptor replica : replicas) |
| | | { |
| | | if (replica.getServer().getHostPort(true).equals(hostPort)) |
| | | if (getHostPort(replica.getServer(), cnx).equals(hostPort)) |
| | | { |
| | | orderedReplicas.add(replica); |
| | | } |
| | |
| | | switch (j) |
| | | { |
| | | case SERVERPORT: |
| | | v = Message.raw(replica.getServer().getHostPort(true)); |
| | | v = Message.raw(getHostPort(replica.getServer(), cnx)); |
| | | break; |
| | | case NUMBER_ENTRIES: |
| | | int nEntries = replica.getEntries(); |
| | |
| | | cache.getAdsContext().getDirContext()); |
| | | |
| | | ServerLoader loader = new ServerLoader(s.getAdsProperties(), |
| | | dn, pwd, getTrustManager()); |
| | | dn, pwd, getTrustManager(), cache.getPreferredConnections()); |
| | | InitialLdapContext ctx = null; |
| | | try |
| | | { |
| | |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | | String hostPort = server.getHostPort(true); |
| | | String hostPort = getHostPort(server, |
| | | cache.getPreferredConnections()); |
| | | Message msg = getMessageForException(ne, hostPort); |
| | | throw new ReplicationCliException(msg, ERROR_CONNECTING, ne); |
| | | } |
| | | catch (OpenDsException ode) |
| | | { |
| | | String hostPort = server.getHostPort(true); |
| | | String hostPort = getHostPort(server, |
| | | cache.getPreferredConnections()); |
| | | Message msg = getMessageForEnableException(ode, hostPort, baseDN); |
| | | throw new ReplicationCliException(msg, |
| | | ERROR_ENABLING_REPLICATION_ON_BASEDN, ode); |
| | |
| | | * to the provided replication server. |
| | | * @param removeFromReplicationServers if references must be removed from |
| | | * the replication servers. |
| | | * @param preferredURLs the preferred LDAP URLs to be used to connect to the |
| | | * server. |
| | | * @throws ReplicationCliException if there is an error updating the |
| | | * configuration. |
| | | */ |
| | | private void removeReferencesInServer(ServerDescriptor server, |
| | | String replicationServer, String bindDn, String pwd, |
| | | Collection<String> baseDNs, boolean updateReplicationServers) |
| | | Collection<String> baseDNs, boolean updateReplicationServers, |
| | | LinkedHashSet<PreferredConnection> cnx) |
| | | throws ReplicationCliException |
| | | { |
| | | ServerLoader loader = new ServerLoader(server.getAdsProperties(), bindDn, |
| | | pwd, getTrustManager()); |
| | | pwd, getTrustManager(), cnx); |
| | | InitialLdapContext ctx = null; |
| | | String lastBaseDN = null; |
| | | String hostPort = null; |
| | |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | | hostPort = server.getHostPort(true); |
| | | hostPort = getHostPort(server, cnx); |
| | | Message msg = getMessageForException(ne, hostPort); |
| | | throw new ReplicationCliException(msg, ERROR_CONNECTING, ne); |
| | | } |
| | |
| | | } |
| | | return returnValue; |
| | | } |
| | | |
| | | /** |
| | | * Commodity method that generates a list of preferred connection (of just |
| | | * one) with the information on a given InitialLdapContext. |
| | | * @param ctx the connection we retrieve the inforamtion from. |
| | | * @return a list containing the preferred connection object. |
| | | */ |
| | | private LinkedHashSet<PreferredConnection> getPreferredConnections( |
| | | InitialLdapContext ctx) |
| | | { |
| | | PreferredConnection cnx = PreferredConnection.getPreferredConnection(ctx); |
| | | LinkedHashSet<PreferredConnection> returnValue = |
| | | new LinkedHashSet<PreferredConnection>(); |
| | | returnValue.add(cnx); |
| | | return returnValue; |
| | | } |
| | | |
| | | /** |
| | | * Returns the host port representation of the server to be used in progress, |
| | | * status and error messages. It takes into account the fact the host and |
| | | * port provided by the user. |
| | | * @param server the ServerDescriptor. |
| | | * @param cnx the preferred connections list. |
| | | * @return the host port string representation of the provided server. |
| | | */ |
| | | protected String getHostPort(ServerDescriptor server, |
| | | Collection<PreferredConnection> cnx) |
| | | { |
| | | String hostPort = null; |
| | | |
| | | for (PreferredConnection connection : cnx) |
| | | { |
| | | String url = connection.getLDAPURL(); |
| | | if (url.equals(server.getLDAPURL())) |
| | | { |
| | | hostPort = server.getHostPort(false); |
| | | } |
| | | else if (url.equals(server.getLDAPsURL())) |
| | | { |
| | | hostPort = server.getHostPort(true); |
| | | } |
| | | } |
| | | if (hostPort == null) |
| | | { |
| | | hostPort = server.getHostPort(true); |
| | | } |
| | | return hostPort; |
| | | } |
| | | } |