| | |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.admin.ads.util.PreferredConnection.*; |
| | | import static org.opends.admin.ads.ServerDescriptor.getReplicationServer; |
| | | import static org.opends.admin.ads.ServerDescriptor.getServerRepresentation; |
| | | import static org.opends.admin.ads.ServerDescriptor.getSuffixDisplay; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | |
| | | * Returns an InitialLdapContext using the provided parameters. We try to |
| | | * guarantee that the connection is able to read the configuration. |
| | | * |
| | | * @param host |
| | | * the host name. |
| | | * @param port |
| | | * the port to connect. |
| | | * @param hostPort |
| | | * the host name and port to connect. |
| | | * @param useSSL |
| | | * whether to use SSL or not. |
| | | * @param useStartTLS |
| | |
| | | * @throws NamingException |
| | | * if there was an error establishing the connection. |
| | | */ |
| | | private InitialLdapContext createAdministrativeContext(String host, |
| | | int port, boolean useSSL, boolean useStartTLS, String bindDn, String pwd, |
| | | private InitialLdapContext createAdministrativeContext(HostPort hostPort, |
| | | boolean useSSL, boolean useStartTLS, String bindDn, String pwd, |
| | | int connectTimeout, ApplicationTrustManager trustManager) |
| | | throws NamingException |
| | | { |
| | | InitialLdapContext ctx; |
| | | String ldapUrl = getLDAPUrl(host, port, useSSL); |
| | | String ldapUrl = getLDAPUrl(hostPort, useSSL); |
| | | if (useSSL) |
| | | { |
| | | ctx = createLdapsContext(ldapUrl, bindDn, pwd, connectTimeout, null, trustManager, null); |
| | |
| | | ReturnCode.CLIENT_SIDE_CONNECT_ERROR, message); |
| | | } |
| | | } |
| | | String hostPort = |
| | | ServerDescriptor.getServerRepresentation(hostName, portNumber); |
| | | LocalizableMessage message = getMessageForException(e, hostPort); |
| | | HostPort hostPort = new HostPort(hostName, portNumber); |
| | | LocalizableMessage message = getMessageForException(e, hostPort.toString()); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR, message); |
| | | } |
| | | } |
| | |
| | | |
| | | private ReplicationCliReturnCode resetChangeNumber() |
| | | { |
| | | final String changeNumber; |
| | | final SourceDestinationServerUserData uData = new SourceDestinationServerUserData(); |
| | | |
| | | if (!argParser.isInteractive()) |
| | |
| | | } |
| | | catch (NamingException e) |
| | | { |
| | | String hostPort = getServerRepresentation(uData.getHostName(), uData.getPort()); |
| | | logger.error(LocalizableMessage.raw("Error when creating connection for:" + hostPort)); |
| | | logger.error(LocalizableMessage.raw("Error when creating connection for:" + uData.getHostPort())); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | return createAdministrativeContext(uData.getHostName(), uData.getPort(), |
| | | useSSL, useStartTLS, bindDn, |
| | | return createAdministrativeContext(uData.getHostPort(), useSSL, useStartTLS, bindDn, |
| | | uData.getAdminPwd(), getConnectTimeout(), getTrustManager(sourceServerCI)); |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | | String hostPort = getServerRepresentation(uData.getHostName(), uData.getPort()); |
| | | errPrintln(); |
| | | errPrintln(getMessageForException(ne, hostPort)); |
| | | errPrintln(getMessageForException(ne, uData.getHostPort().toString())); |
| | | logger.error(LocalizableMessage.raw("Complete error stack:"), ne); |
| | | return null; |
| | | } |
| | |
| | | |
| | | private LocalizableMessage getPurgeErrorMsg(String lastLogMsg, String state, InitialLdapContext ctx) |
| | | { |
| | | String server = getHostPort(ctx); |
| | | HostPort server = getHostPort(ctx); |
| | | if (lastLogMsg != null) |
| | | { |
| | | return ERR_UNEXPECTED_DURING_TASK_WITH_LOG.get(lastLogMsg, state, server); |
| | |
| | | if (ctx != null) |
| | | { |
| | | uData.setOnline(true); |
| | | uData.setHostName(sourceServerCI.getHostName()); |
| | | uData.setPort(sourceServerCI.getPortNumber()); |
| | | uData.setHostPort(new HostPort(sourceServerCI.getHostName(), sourceServerCI.getPortNumber())); |
| | | uData.setAdminUid(sourceServerCI.getAdministratorUID()); |
| | | uData.setAdminPwd(sourceServerCI.getBindPassword()); |
| | | } |
| | |
| | | |
| | | if (!cancelled) |
| | | { |
| | | uData.getServer1().setHostName(host1); |
| | | uData.getServer1().setPort(port1); |
| | | uData.getServer1().setHostPort(new HostPort(host1, port1)); |
| | | uData.getServer1().setBindDn(bindDn1); |
| | | uData.getServer1().setPwd(pwd1); |
| | | } |
| | |
| | | |
| | | if (!cancelled) |
| | | { |
| | | uData.getServer2().setHostName(host2); |
| | | uData.getServer2().setPort(port2); |
| | | uData.getServer2().setHostPort(new HostPort(host2, port2)); |
| | | uData.getServer2().setBindDn(bindDn2); |
| | | uData.getServer2().setPwd(pwd2); |
| | | } |
| | |
| | | |
| | | if (!cancelled) |
| | | { |
| | | uData.setHostName(host); |
| | | uData.setPort(port); |
| | | uData.setHostPort(new HostPort(host, port)); |
| | | uData.setAdminUid(adminUid); |
| | | uData.setBindDn(bindDn); |
| | | uData.setAdminPwd(adminPwd); |
| | |
| | | |
| | | private LocalizableMessage getPrompt(InitializeAllReplicationUserData uData, InitialLdapContext ctx) |
| | | { |
| | | String hostPortSource = getHostPort(ctx); |
| | | HostPort hostPortSource = getHostPort(ctx); |
| | | if (initializeADS(uData.getBaseDNs())) |
| | | { |
| | | return INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_ADS.get(ADSContext.getAdministrationSuffixDN(), hostPortSource); |
| | |
| | | InitialLdapContext ctx = createInitialLdapContextInteracting(sourceServerCI); |
| | | if (ctx != null) |
| | | { |
| | | uData.setHostName(sourceServerCI.getHostName()); |
| | | uData.setPort(sourceServerCI.getPortNumber()); |
| | | uData.setHostPort(new HostPort(sourceServerCI.getHostName(), sourceServerCI.getPortNumber())); |
| | | uData.setAdminUid(sourceServerCI.getAdministratorUID()); |
| | | uData.setAdminPwd(sourceServerCI.getBindPassword()); |
| | | if (uData instanceof StatusReplicationUserData) |
| | |
| | | private LocalizableMessage getInitializeReplicationPrompt(SourceDestinationServerUserData uData, |
| | | InitialLdapContext ctxSource, InitialLdapContext ctxDestination) |
| | | { |
| | | String hostPortSource = getHostPort(ctxSource); |
| | | String hostPortDestination = getHostPort(ctxDestination); |
| | | HostPort hostPortSource = getHostPort(ctxSource); |
| | | HostPort hostPortDestination = getHostPort(ctxDestination); |
| | | if (initializeADS(uData.getBaseDNs())) |
| | | { |
| | | final String adminSuffixDN = ADSContext.getAdministrationSuffixDN(); |
| | |
| | | private void setConnectionDetails( |
| | | EnableReplicationServerData server, ServerArgs args, String adminDN, String adminPwd) |
| | | { |
| | | server.setHostName(getValueOrDefault(args.hostNameArg)); |
| | | server.setPort(getValueOrDefault(args.portArg)); |
| | | server.setHostPort(new HostPort( |
| | | getValueOrDefault(args.hostNameArg), getValueOrDefault(args.portArg))); |
| | | |
| | | String pwd = args.getBindPassword(); |
| | | if (pwd == null) |
| | |
| | | // Best-effort: try to use admin, if it does not work, use bind DN. |
| | | try |
| | | { |
| | | InitialLdapContext ctx = createAdministrativeContext(server.getHostName(), server.getPort(), |
| | | InitialLdapContext ctx = createAdministrativeContext(server.getHostPort(), |
| | | useSSL, useStartTLS, adminDN, adminPwd, getConnectTimeout(), getTrustManager(sourceServerCI)); |
| | | server.setBindDn(adminDN); |
| | | server.setPwd(adminPwd); |
| | |
| | | uData.setBindDn(bindDn); |
| | | uData.setAdminPwd(argParser.getBindPasswordAdmin()); |
| | | |
| | | uData.setHostName(argParser.getHostNameToDisableOrDefault()); |
| | | uData.setPort(argParser.getPortToDisableOrDefault()); |
| | | uData.setHostPort(new HostPort( |
| | | argParser.getHostNameToDisableOrDefault(), argParser.getPortToDisableOrDefault())); |
| | | |
| | | uData.setDisableAll(argParser.disableAllArg.isPresent()); |
| | | uData.setDisableReplicationServer(argParser.disableReplicationServerArg.isPresent()); |
| | |
| | | { |
| | | initialize(uData); |
| | | |
| | | uData.setHostName(argParser.getHostNameToInitializeAllOrDefault()); |
| | | uData.setPort(argParser.getPortToInitializeAllOrDefault()); |
| | | uData.setHostPort(new HostPort( |
| | | argParser.getHostNameToInitializeAllOrDefault(), argParser.getPortToInitializeAllOrDefault())); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | initialize(uData); |
| | | |
| | | uData.setHostName(argParser.getHostNameToStatusOrDefault()); |
| | | uData.setPort(argParser.getPortToStatusOrDefault()); |
| | | uData.setHostPort(new HostPort(argParser.getHostNameToStatusOrDefault(), argParser.getPortToStatusOrDefault())); |
| | | uData.setScriptFriendly(argParser.isScriptFriendly()); |
| | | } |
| | | |
| | |
| | | boolean triedWithUserProvidedAdmin = false; |
| | | final ConnectionWrapper connWrapper1 = connWrapper.get(); |
| | | final InitialLdapContext ctx1 = connWrapper1.getLdapContext(); |
| | | String host = getHostName(ctx1); |
| | | int port = getPort(ctx1); |
| | | HostPort hostPort = getHostPort(ctx1); |
| | | boolean isSSL = isSSL(ctx1); |
| | | boolean isStartTLS = isStartTLS(ctx1); |
| | | if (getTrustManager(ci) == null) |
| | |
| | | close(ctx1); |
| | | try |
| | | { |
| | | final InitialLdapContext ctx2 = createAdministrativeContext(host, port, isSSL, |
| | | isStartTLS, getAdministratorDN(adminUid), |
| | | adminPwd, getConnectTimeout(), getTrustManager(ci)); |
| | | final InitialLdapContext ctx2 = createAdministrativeContext(hostPort, isSSL, isStartTLS, |
| | | getAdministratorDN(adminUid), adminPwd, getConnectTimeout(), getTrustManager(ci)); |
| | | final ConnectionWrapper connWrapper2 = |
| | | new ConnectionWrapper(ctx2, getConnectTimeout(), getTrustManager(ci)); |
| | | connWrapper.set(connWrapper2); |
| | |
| | | catch (Throwable t) |
| | | { |
| | | errPrintln(); |
| | | errPrintln( |
| | | ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get( |
| | | getServerRepresentation(host, port), t.getMessage())); |
| | | errPrintln(ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(hostPort, t.getMessage())); |
| | | logger.warn(LocalizableMessage.raw("Complete error stack:", t)); |
| | | errPrintln(); |
| | | } |
| | |
| | | } |
| | | catch (NamingException e) |
| | | { |
| | | String hostPort = getServerRepresentation(server.getHostName(), server.getPort()); |
| | | logger.error(LocalizableMessage.raw("Error when creating connection for:" + hostPort)); |
| | | logger.error(LocalizableMessage.raw("Error when creating connection for:" + server.getHostPort())); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | try |
| | | { |
| | | return createAdministrativeContext( |
| | | server.getHostName(), server.getPort(), useSSL, useStartTLS, server.getBindDn(), server.getPwd(), |
| | | server.getHostPort(), useSSL, useStartTLS, server.getBindDn(), server.getPwd(), |
| | | getConnectTimeout(), getTrustManager(sourceServerCI)); |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | | String hostPort = getServerRepresentation(server.getHostName(), server.getPort()); |
| | | errorMessages.add(getMessageForException(ne, hostPort)); |
| | | errorMessages.add(getMessageForException(ne, server.getHostPort().toString())); |
| | | logger.error(LocalizableMessage.raw("Complete error stack:"), ne); |
| | | return null; |
| | | } |
| | |
| | | try |
| | | { |
| | | return createAdministrativeContext( |
| | | server.getHost(), server.getPort(), useSSL, useStartTLS, |
| | | server, useSSL, useStartTLS, |
| | | getAdministratorDN(uData.getAdminUid()), uData.getAdminPwd(), |
| | | getConnectTimeout(), getTrustManager(sourceServerCI)); |
| | | } |
| | |
| | | catch (NamingException ne) |
| | | { |
| | | throw new ReplicationCliException( |
| | | getMessageForException(ne, getHostPort(ctx)), |
| | | getMessageForException(ne, getHostPort(ctx).toString()), |
| | | ERROR_READING_CONFIGURATION, ne); |
| | | } |
| | | } |
| | |
| | | Set<ServerDescriptor> serversWithNoReplica) |
| | | { |
| | | Set<ReplicaDescriptor> orderedReplicas = new LinkedHashSet<>(); |
| | | Set<String> hostPorts = new TreeSet<>(); |
| | | Set<HostPort> hostPorts = new TreeSet<>(); |
| | | Set<ServerDescriptor> notAddedReplicationServers = new TreeSet<>(new ReplicationServerComparator()); |
| | | for (Set<ReplicaDescriptor> replicas : orderedReplicaLists) |
| | | { |
| | |
| | | { |
| | | hostPorts.add(getHostPort2(replica.getServer(), cnx)); |
| | | } |
| | | for (String hostPort : hostPorts) |
| | | for (HostPort hostPort : hostPorts) |
| | | { |
| | | for (ReplicaDescriptor replica : replicas) |
| | | { |
| | |
| | | // Suffix DN |
| | | tableBuilder.appendCell(LocalizableMessage.raw(replica.getSuffix().getDN())); |
| | | // Server port |
| | | tableBuilder.appendCell( |
| | | LocalizableMessage.raw(getHostPort2(replica.getServer(), cnx))); |
| | | tableBuilder.appendCell(LocalizableMessage.raw("%s", getHostPort2(replica.getServer(), cnx))); |
| | | // Number of entries |
| | | int nEntries = replica.getEntries(); |
| | | if (nEntries >= 0) |
| | |
| | | // Suffix DN |
| | | tableBuilder.appendCell(EMPTY_MSG); |
| | | // Server port |
| | | tableBuilder.appendCell(LocalizableMessage.raw(getHostPort2(server, cnx))); |
| | | tableBuilder.appendCell(LocalizableMessage.raw("%s", getHostPort2(server, cnx))); |
| | | // Number of entries |
| | | if (scriptFriendly) |
| | | { |
| | |
| | | { |
| | | tableBuilder.startRow(); |
| | | // Server port |
| | | tableBuilder.appendCell(LocalizableMessage.raw(getHostPort2(server, cnx))); |
| | | tableBuilder.appendCell(LocalizableMessage.raw("%s", getHostPort2(server, cnx))); |
| | | // Replication port |
| | | int replicationPort = server.getReplicationServerPort(); |
| | | if (replicationPort >= 0) |
| | |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | | String hostPort = getHostPort2(s, cache.getPreferredConnections()); |
| | | LocalizableMessage msg = getMessageForException(ne, hostPort); |
| | | HostPort hostPort = getHostPort2(s, cache.getPreferredConnections()); |
| | | LocalizableMessage msg = getMessageForException(ne, hostPort.toString()); |
| | | throw new ReplicationCliException(msg, ERROR_CONNECTING, ne); |
| | | } |
| | | catch (Exception ode) |
| | | { |
| | | String hostPort = getHostPort2(s, cache.getPreferredConnections()); |
| | | HostPort hostPort = getHostPort2(s, cache.getPreferredConnections()); |
| | | LocalizableMessage msg = getMessageForEnableException(hostPort, baseDN); |
| | | throw new ReplicationCliException(msg, |
| | | ERROR_ENABLING_REPLICATION_ON_BASEDN, ode); |
| | | throw new ReplicationCliException(msg, ERROR_ENABLING_REPLICATION_ON_BASEDN, ode); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | | String hostPort = getHostPort(ctxSource); |
| | | LocalizableMessage msg = getMessageForException(ne, hostPort); |
| | | LocalizableMessage msg = getMessageForException(ne, getHostPort(ctxSource).toString()); |
| | | throw new ReplicationCliException(msg, ERROR_READING_CONFIGURATION, ne); |
| | | } |
| | | |
| | |
| | | |
| | | private LocalizableMessage getPrePostErrorMsg(String lastLogMsg, String state, InitialLdapContext ctx) |
| | | { |
| | | String server = getHostPort(ctx); |
| | | HostPort server = getHostPort(ctx); |
| | | if (lastLogMsg != null) |
| | | { |
| | | return ERR_UNEXPECTED_DURING_TASK_WITH_LOG.get(lastLogMsg, state, server); |
| | |
| | | { |
| | | boolean isOver = false; |
| | | String dn = null; |
| | | String serverDisplay = getHostPort(ctx); |
| | | HostPort serverDisplay = getHostPort(ctx); |
| | | Map<String, String> attrsMap = new TreeMap<>(); |
| | | attrsMap.put("ds-task-initialize-domain-dn", baseDN); |
| | | attrsMap.put("ds-task-initialize-replica-server-id", "all"); |
| | |
| | | } |
| | | } |
| | | |
| | | private LocalizableMessage getInitializeAllErrorMsg(String serverDisplay, String lastLogMsg, String state) |
| | | private LocalizableMessage getInitializeAllErrorMsg(HostPort serverDisplay, String lastLogMsg, String state) |
| | | { |
| | | if (lastLogMsg != null) |
| | | { |
| | |
| | | pwd, getTrustManager(sourceServerCI), getConnectTimeout(), cnx, filter); |
| | | ConnectionWrapper ctx = null; |
| | | String lastBaseDN = null; |
| | | String hostPort = null; |
| | | HostPort hostPort = null; |
| | | |
| | | try |
| | | { |
| | |
| | | catch (NamingException ne) |
| | | { |
| | | hostPort = getHostPort2(server, cnx); |
| | | LocalizableMessage msg = getMessageForException(ne, hostPort); |
| | | LocalizableMessage msg = getMessageForException(ne, hostPort.toString()); |
| | | throw new ReplicationCliException(msg, ERROR_CONNECTING, ne); |
| | | } |
| | | catch (Exception ode) |
| | |
| | | */ |
| | | private void deleteReplicationDomain(ConnectionWrapper ctx, String baseDN) throws ReplicationCliException |
| | | { |
| | | String hostPort = getHostPort(ctx.getLdapContext()); |
| | | HostPort hostPort = getHostPort(ctx.getLdapContext()); |
| | | try |
| | | { |
| | | RootCfgClient root = ctx.getRootConfiguration(); |
| | |
| | | private void disableReplicationServer(ConnectionWrapper connWrapper) |
| | | throws ReplicationCliException |
| | | { |
| | | String hostPort = getHostPort(connWrapper.getLdapContext()); |
| | | HostPort hostPort = getHostPort(connWrapper.getLdapContext()); |
| | | try |
| | | { |
| | | RootCfgClient root = connWrapper.getRootConfiguration(); |
| | |
| | | * the replication domain or updating the list of replication servers of |
| | | * the replication domain). |
| | | */ |
| | | private LocalizableMessage getMessageForEnableException(String hostPort, String baseDN) |
| | | private LocalizableMessage getMessageForEnableException(HostPort hostPort, String baseDN) |
| | | { |
| | | return ERR_REPLICATION_CONFIGURING_BASEDN.get(baseDN, hostPort); |
| | | } |
| | |
| | | * the replication domain or updating the list of replication servers of |
| | | * the replication domain). |
| | | */ |
| | | private LocalizableMessage getMessageForDisableException(String hostPort, String baseDN) |
| | | private LocalizableMessage getMessageForDisableException(HostPort hostPort, String baseDN) |
| | | { |
| | | return ERR_REPLICATION_CONFIGURING_BASEDN.get(baseDN, hostPort); |
| | | } |
| | |
| | | * @param cnx the preferred connections list. |
| | | * @return the host port string representation of the provided server. |
| | | */ |
| | | private String getHostPort2(ServerDescriptor server, |
| | | Collection<PreferredConnection> cnx) |
| | | private HostPort getHostPort2(ServerDescriptor server, Collection<PreferredConnection> cnx) |
| | | { |
| | | String hostPort = null; |
| | | HostPort hostPort = null; |
| | | for (PreferredConnection connection : cnx) |
| | | { |
| | | String url = connection.getLDAPURL(); |
| | |
| | | ctxDestination = adsCtx1.getDirContext(); |
| | | } |
| | | |
| | | String hostPortSource = getHostPort(ctxSource); |
| | | String hostPortDestination = getHostPort(ctxDestination); |
| | | HostPort hostPortSource = getHostPort(ctxSource); |
| | | HostPort hostPortDestination = getHostPort(ctxDestination); |
| | | if (isInteractive()) |
| | | { |
| | | LocalizableMessage msg = INFO_REPLICATION_MERGING_REGISTRIES_CONFIRMATION.get(hostPortSource, |