| | |
| | | * @param interactive if user has to input information |
| | | * @return whether we should stop |
| | | */ |
| | | boolean continueAfterUserInput(Collection<String> baseDNs, ConnectionWrapper source, ConnectionWrapper dest, |
| | | boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source, ConnectionWrapper dest, |
| | | boolean interactive); |
| | | |
| | | /** |
| | |
| | | private ReplicationCliReturnCode purgeHistoricalLocally( |
| | | PurgeHistoricalUserData uData) |
| | | { |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | checkSuffixesForLocalPurgeHistorical(baseDNs, false); |
| | | if (!baseDNs.isEmpty()) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private List<DN> toDNs(List<String> baseDNs) |
| | | { |
| | | final List<DN> results = new ArrayList<>(baseDNs.size()); |
| | | for (String dn : baseDNs) |
| | | { |
| | | results.add(DN.valueOf(dn)); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | private void printPurgeProgressMessage(PurgeHistoricalUserData uData) |
| | | { |
| | | String separator = formatter.getLineBreak().toString() + formatter.getTab(); |
| | |
| | | args.add("--"+argParser.noPromptArg.getLongIdentifier()); |
| | | args.add("--"+argParser.maximumDurationArg.getLongIdentifier()); |
| | | args.add(String.valueOf(uData.getMaximumDuration())); |
| | | for (String baseDN : uData.getBaseDNs()) |
| | | for (DN baseDN : uData.getBaseDNs()) |
| | | { |
| | | args.add("--"+argParser.baseDNsArg.getLongIdentifier()); |
| | | args.add(baseDN); |
| | | args.add(baseDN.toString()); |
| | | } |
| | | ProcessBuilder pb = new ProcessBuilder(args); |
| | | // Use the java args in the script. |
| | |
| | | |
| | | try |
| | | { |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | checkSuffixesForPurgeHistorical(baseDNs, conn, false); |
| | | if (baseDNs.isEmpty()) |
| | | { |
| | |
| | | resetChangeNumberOperations = new OperationBetweenSourceAndDestinationServers() |
| | | { |
| | | @Override |
| | | public boolean continueAfterUserInput(Collection<String> baseDNs, ConnectionWrapper source, |
| | | public boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source, |
| | | ConnectionWrapper dest, boolean interactive) |
| | | { |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | |
| | | DN targetBaseDN = DN.rootDN(); |
| | | try |
| | | { |
| | | for (String adn : getCommonSuffixes(connSource, connDest, SuffixRelationType.REPLICATED)) |
| | | for (DN dn : getCommonSuffixes(connSource, connDest, SuffixRelationType.REPLICATED)) |
| | | { |
| | | DN dn = DN.valueOf(adn); |
| | | if (DN.valueOf(targetDN).isSubordinateOrEqualTo(dn) && dn.isSubordinateOrEqualTo(targetBaseDN)) |
| | | { |
| | | targetBaseDN = dn; |
| | |
| | | * @param interactive whether to ask the user to provide interactively |
| | | * base DNs if none of the provided base DNs can be purged. |
| | | */ |
| | | private void checkSuffixesForPurgeHistorical(Collection<String> suffixes, ConnectionWrapper conn, boolean interactive) |
| | | private void checkSuffixesForPurgeHistorical(Collection<DN> suffixes, ConnectionWrapper conn, boolean interactive) |
| | | { |
| | | checkSuffixesForPurgeHistorical(suffixes, getReplicas(conn), interactive); |
| | | } |
| | |
| | | * @param interactive whether to ask the user to provide interactively |
| | | * base DNs if none of the provided base DNs can be purged. |
| | | */ |
| | | private void checkSuffixesForLocalPurgeHistorical(Collection<String> suffixes, |
| | | boolean interactive) |
| | | private void checkSuffixesForLocalPurgeHistorical(Collection<DN> suffixes, boolean interactive) |
| | | { |
| | | checkSuffixesForPurgeHistorical(suffixes, getLocalReplicas(), interactive); |
| | | } |
| | |
| | | return replicas; |
| | | } |
| | | |
| | | private void checkSuffixesForPurgeHistorical(Collection<String> suffixes, Collection<ReplicaDescriptor> replicas, |
| | | private void checkSuffixesForPurgeHistorical(Collection<DN> suffixes, Collection<ReplicaDescriptor> replicas, |
| | | boolean interactive) |
| | | { |
| | | TreeSet<String> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<String> notReplicatedSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> notReplicatedSuffixes = new TreeSet<>(); |
| | | |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | String dn = rep.getSuffix().getDN(); |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | availableSuffixes.add(dn); |
| | |
| | | checkSuffixesForPurgeHistorical(suffixes, availableSuffixes, notReplicatedSuffixes, interactive); |
| | | } |
| | | |
| | | private void checkSuffixesForPurgeHistorical(Collection<String> suffixes, |
| | | Collection<String> availableSuffixes, |
| | | Collection<String> notReplicatedSuffixes, |
| | | private void checkSuffixesForPurgeHistorical(Collection<DN> suffixes, |
| | | Collection<DN> availableSuffixes, |
| | | Collection<DN> notReplicatedSuffixes, |
| | | boolean interactive) |
| | | { |
| | | if (availableSuffixes.isEmpty()) |
| | |
| | | else |
| | | { |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<String> notFound = new TreeSet<>(); |
| | | TreeSet<String> alreadyNotReplicated = new TreeSet<>(); |
| | | for (String dn : suffixes) |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyNotReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!containsDN(availableSuffixes, dn)) |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (containsDN(notReplicatedSuffixes, dn)) |
| | | if (notReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyNotReplicated.add(dn); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void askConfirmations(Collection<String> suffixes, |
| | | Collection<String> availableSuffixes, Arg0 noSuffixAvailableMsg, |
| | | private void askConfirmations(Collection<DN> suffixes, |
| | | Collection<DN> availableSuffixes, Arg0 noSuffixAvailableMsg, |
| | | Arg0 noSuffixSelectedMsg, Arg1<Object> confirmationMsgPromt) |
| | | { |
| | | if (containsOnlySchemaOrAdminSuffix(availableSuffixes)) |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean containsOnlySchemaOrAdminSuffix(Collection<String> suffixes) |
| | | private boolean containsOnlySchemaOrAdminSuffix(Collection<DN> suffixes) |
| | | { |
| | | for (String suffix : suffixes) |
| | | for (DN suffix : suffixes) |
| | | { |
| | | if (!isSchemaOrInternalAdminSuffix(suffix)) |
| | | { |
| | |
| | | return true; |
| | | } |
| | | |
| | | private boolean isSchemaOrInternalAdminSuffix(String suffix) |
| | | private boolean isSchemaOrInternalAdminSuffix(DN suffix) |
| | | { |
| | | return areDnsEqual(suffix, ADSContext.getAdministrationSuffixDN()) |
| | | || areDnsEqual(suffix, Constants.SCHEMA_DN) |
| | | || areDnsEqual(suffix, Constants.REPLICATION_CHANGES_DN); |
| | | return suffix.equals(ADSContext.getAdministrationSuffixDN()) |
| | | || suffix.equals(Constants.SCHEMA_DN) |
| | | || suffix.equals(Constants.REPLICATION_CHANGES_DN); |
| | | } |
| | | |
| | | /** |
| | |
| | | initializeReplicationOperations = new OperationBetweenSourceAndDestinationServers() |
| | | { |
| | | @Override |
| | | public boolean continueAfterUserInput(Collection<String> baseDNs, ConnectionWrapper source, |
| | | public boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source, |
| | | ConnectionWrapper dest, boolean interactive) |
| | | { |
| | | checkSuffixesForInitializeReplication(baseDNs, source, dest, interactive); |
| | |
| | | } |
| | | uData.setMaximumDuration(maximumDuration); |
| | | |
| | | List<String> suffixes = argParser.getBaseDNs(); |
| | | List<DN> suffixes = toDNs(argParser.getBaseDNs()); |
| | | if (uData.isOnline()) |
| | | { |
| | | checkSuffixesForPurgeHistorical(suffixes, conn, true); |
| | |
| | | |
| | | if (!cancelled) |
| | | { |
| | | List<String> suffixes = argParser.getBaseDNs(); |
| | | List<DN> suffixes = toDNs(argParser.getBaseDNs()); |
| | | checkSuffixesForEnableReplication(suffixes, conn1, conn2, true, uData); |
| | | cancelled = suffixes.isEmpty(); |
| | | |
| | |
| | | uData.setDisableReplicationServer(disableReplicationServer); |
| | | if (!cancelled && !disableAll) |
| | | { |
| | | List<String> suffixes = argParser.getBaseDNs(); |
| | | List<DN> suffixes = toDNs(argParser.getBaseDNs()); |
| | | checkSuffixesForDisableReplication(suffixes, conn, true, !disableReplicationServer); |
| | | cancelled = suffixes.isEmpty() && !disableReplicationServer; |
| | | |
| | |
| | | // Ask for confirmation to disable if not already done. |
| | | boolean disableADS = false; |
| | | boolean disableSchema = false; |
| | | for (String dn : uData.getBaseDNs()) |
| | | for (DN dn : uData.getBaseDNs()) |
| | | { |
| | | if (areDnsEqual(ADSContext.getAdministrationSuffixDN(), dn)) |
| | | if (ADSContext.getAdministrationSuffixDN().equals(dn)) |
| | | { |
| | | disableADS = true; |
| | | } |
| | | else if (areDnsEqual(Constants.SCHEMA_DN, dn)) |
| | | else if (Constants.SCHEMA_DN.equals(dn)) |
| | | { |
| | | disableSchema = true; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | List<String> suffixes = argParser.getBaseDNs(); |
| | | List<DN> suffixes = toDNs(argParser.getBaseDNs()); |
| | | checkSuffixesForInitializeReplication(suffixes, conn, true); |
| | | if (suffixes.isEmpty()) |
| | | { |
| | |
| | | { |
| | | return false; |
| | | } |
| | | List<String> suffixes = argParser.getBaseDNs(); |
| | | List<DN> suffixes = toDNs(argParser.getBaseDNs()); |
| | | checkSuffixesForInitializeReplication(suffixes, conn, true); |
| | | uData.setBaseDNs(suffixes); |
| | | return !suffixes.isEmpty(); |
| | |
| | | |
| | | if (!cancelled) |
| | | { |
| | | uData.setBaseDNs(argParser.getBaseDNs()); |
| | | uData.setBaseDNs(toDNs(argParser.getBaseDNs())); |
| | | } |
| | | return !cancelled; |
| | | } |
| | |
| | | uData.setHostNameDestination(hostDestination); |
| | | uData.setPortDestination(portDestination); |
| | | |
| | | List<String> suffixes = argParser.getBaseDNs(); |
| | | List<DN> suffixes = toDNs(argParser.getBaseDNs()); |
| | | cancelled = serversOperations.continueAfterUserInput(suffixes, connSource, connDestination, true); |
| | | uData.setBaseDNs(suffixes); |
| | | |
| | |
| | | HostPort hostPortDestination = connDestination.getHostPort(); |
| | | if (initializeADS(uData.getBaseDNs())) |
| | | { |
| | | final String adminSuffixDN = ADSContext.getAdministrationSuffixDN(); |
| | | final DN adminSuffixDN = ADSContext.getAdministrationSuffixDN(); |
| | | return INFO_REPLICATION_CONFIRM_INITIALIZE_ADS.get(adminSuffixDN, hostPortDestination, hostPortSource); |
| | | } |
| | | return INFO_REPLICATION_CONFIRM_INITIALIZE_GENERIC.get(hostPortDestination, hostPortSource); |
| | | } |
| | | |
| | | private boolean initializeADS(List<String> baseDNs) |
| | | private boolean initializeADS(List<DN> baseDNs) |
| | | { |
| | | for (String dn : baseDNs) |
| | | { |
| | | if (areDnsEqual(ADSContext.getAdministrationSuffixDN(), dn)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | return baseDNs.contains(ADSContext.getAdministrationSuffixDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private void initializeWithArgParser(DisableReplicationUserData uData) |
| | | { |
| | | uData.setBaseDNs(new LinkedList<String>(argParser.getBaseDNs())); |
| | | uData.setBaseDNs(toDNs(argParser.getBaseDNs())); |
| | | String adminUid = argParser.getAdministratorUID(); |
| | | String bindDn = argParser.getBindDNToDisable(); |
| | | if (bindDn == null && adminUid == null) |
| | |
| | | |
| | | private void initialize(ReplicationUserData uData) |
| | | { |
| | | uData.setBaseDNs(new LinkedList<String>(argParser.getBaseDNs())); |
| | | uData.setBaseDNs(toDNs(argParser.getBaseDNs())); |
| | | uData.setAdminUid(argParser.getAdministratorUIDOrDefault()); |
| | | uData.setAdminPwd(argParser.getBindPasswordAdmin()); |
| | | } |
| | |
| | | * @return a Collection containing a list of suffixes that are replicated |
| | | * (or those that can be replicated) in two servers. |
| | | */ |
| | | private List<String> getCommonSuffixes(ConnectionWrapper conn1, ConnectionWrapper conn2, SuffixRelationType type) |
| | | private List<DN> getCommonSuffixes(ConnectionWrapper conn1, ConnectionWrapper conn2, SuffixRelationType type) |
| | | { |
| | | LinkedList<String> suffixes = new LinkedList<>(); |
| | | List<DN> suffixes = new LinkedList<>(); |
| | | try |
| | | { |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | |
| | | { |
| | | for (ReplicaDescriptor rep2 : server2.getReplicas()) |
| | | { |
| | | String rep1SuffixDN = rep1.getSuffix().getDN(); |
| | | String rep2SuffixDN = rep2.getSuffix().getDN(); |
| | | boolean areDnsEqual = areDnsEqual(rep1SuffixDN, rep2SuffixDN); |
| | | DN rep1SuffixDN = rep1.getSuffix().getDN(); |
| | | DN rep2SuffixDN = rep2.getSuffix().getDN(); |
| | | boolean areDnsEqual = rep1SuffixDN.equals(rep2SuffixDN); |
| | | switch (type) |
| | | { |
| | | case NOT_REPLICATED: |
| | |
| | | private boolean areFullyReplicated(ReplicaDescriptor rep1, |
| | | ReplicaDescriptor rep2) |
| | | { |
| | | if (areDnsEqual(rep1.getSuffix().getDN(), rep2.getSuffix().getDN()) && |
| | | if (rep1.getSuffix().getDN().equals(rep2.getSuffix().getDN()) && |
| | | rep1.isReplicated() && rep2.isReplicated() && |
| | | rep1.getServer().isReplicationServer() && |
| | | rep2.getServer().isReplicationServer()) |
| | |
| | | */ |
| | | private boolean areReplicated(ReplicaDescriptor rep1, ReplicaDescriptor rep2) |
| | | { |
| | | if (areDnsEqual(rep1.getSuffix().getDN(), rep2.getSuffix().getDN()) && |
| | | if (rep1.getSuffix().getDN().equals(rep2.getSuffix().getDN()) && |
| | | rep1.isReplicated() && rep2.isReplicated()) |
| | | { |
| | | Set<String> servers1 = rep1.getReplicationServers(); |
| | |
| | | } |
| | | } |
| | | |
| | | List<String> suffixes = uData.getBaseDNs(); |
| | | List<DN> suffixes = uData.getBaseDNs(); |
| | | checkSuffixesForEnableReplication(suffixes, conn1, conn2, false, uData); |
| | | if (suffixes.isEmpty()) |
| | | { |
| | |
| | | print(formatter.getFormattedDone()); |
| | | println(); |
| | | |
| | | List<String> suffixes = uData.getBaseDNs(); |
| | | List<DN> suffixes = uData.getBaseDNs(); |
| | | checkSuffixesForDisableReplication(suffixes, conn, false, !uData.disableReplicationServer()); |
| | | if (suffixes.isEmpty() && !uData.disableReplicationServer() && !uData.disableAll()) |
| | | { |
| | |
| | | return ERROR_CONNECTING; |
| | | } |
| | | |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | checkSuffixesForInitializeReplication(baseDNs, connSource, connDestination, false); |
| | | if (baseDNs.isEmpty()) |
| | | { |
| | |
| | | } |
| | | |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | for (String baseDN : baseDNs) |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | try |
| | | { |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | checkSuffixesForInitializeReplication(baseDNs, conn, false); |
| | | if (baseDNs.isEmpty()) |
| | | { |
| | |
| | | } |
| | | |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP; |
| | | for (String baseDN : baseDNs) |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | try |
| | | { |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | checkSuffixesForInitializeReplication(baseDNs, conn, false); |
| | | if (baseDNs.isEmpty()) |
| | | { |
| | |
| | | } |
| | | |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL; |
| | | for (String baseDN : baseDNs) |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | try |
| | | { |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | checkSuffixesForInitializeReplication(baseDNs, conn, false); |
| | | if (baseDNs.isEmpty()) |
| | | { |
| | |
| | | } |
| | | |
| | | ReplicationCliReturnCode returnValue = SUCCESSFUL; |
| | | for (String baseDN : baseDNs) |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | try |
| | | { |
| | |
| | | * but it is assumed that it contains information about whether the |
| | | * replication domains must be configured or not. |
| | | */ |
| | | private void checkSuffixesForEnableReplication(Collection<String> suffixes, |
| | | private void checkSuffixesForEnableReplication(Collection<DN> suffixes, |
| | | ConnectionWrapper conn1, ConnectionWrapper conn2, |
| | | boolean interactive, EnableReplicationUserData uData) |
| | | { |
| | | EnableReplicationServerData server1 = uData.getServer1(); |
| | | EnableReplicationServerData server2 = uData.getServer2(); |
| | | final TreeSet<String> availableSuffixes = new TreeSet<>(); |
| | | final TreeSet<String> alreadyReplicatedSuffixes = new TreeSet<>(); |
| | | final TreeSet<DN> availableSuffixes = new TreeSet<>(); |
| | | final TreeSet<DN> alreadyReplicatedSuffixes = new TreeSet<>(); |
| | | if (server1.configureReplicationDomain() && |
| | | server2.configureReplicationDomain()) |
| | | { |
| | |
| | | errPrintln(ERR_NO_SUFFIXES_AVAILABLE_TO_ENABLE_REPLICATION.get()); |
| | | } |
| | | |
| | | List<String> userProvidedSuffixes = argParser.getBaseDNs(); |
| | | TreeSet<String> userProvidedReplicatedSuffixes = new TreeSet<>(); |
| | | List<DN> userProvidedSuffixes = toDNs(argParser.getBaseDNs()); |
| | | TreeSet<DN> userProvidedReplicatedSuffixes = new TreeSet<>(); |
| | | |
| | | for (String s1 : userProvidedSuffixes) |
| | | for (DN s1 : userProvidedSuffixes) |
| | | { |
| | | for (String s2 : alreadyReplicatedSuffixes) |
| | | for (DN s2 : alreadyReplicatedSuffixes) |
| | | { |
| | | if (areDnsEqual(s1, s2)) |
| | | if (s1.equals(s2)) |
| | | { |
| | | userProvidedReplicatedSuffixes.add(s1); |
| | | } |
| | |
| | | else |
| | | { |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<String> notFound = new TreeSet<>(); |
| | | TreeSet<String> alreadyReplicated = new TreeSet<>(); |
| | | for (String dn : suffixes) |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!containsDN(availableSuffixes, dn)) |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (containsDN(alreadyReplicatedSuffixes, dn)) |
| | | if (alreadyReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyReplicated.add(dn); |
| | | } |
| | |
| | | * base DNs if none of the provided base DNs can be disabled. |
| | | * @param displayErrors whether to display errors or not. |
| | | */ |
| | | private void checkSuffixesForDisableReplication(Collection<String> suffixes, |
| | | private void checkSuffixesForDisableReplication(Collection<DN> suffixes, |
| | | ConnectionWrapper conn, boolean interactive, boolean displayErrors) |
| | | { |
| | | // whether the user must provide base DNs or not |
| | | // (if it is <CODE>false</CODE> the user will be proposed the suffixes only once) |
| | | final boolean areSuffixRequired = displayErrors; |
| | | |
| | | TreeSet<String> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<String> notReplicatedSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> notReplicatedSuffixes = new TreeSet<>(); |
| | | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | String dn = rep.getSuffix().getDN(); |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | availableSuffixes.add(dn); |
| | |
| | | errPrintln(); |
| | | errPrintln(ERR_NO_SUFFIXES_AVAILABLE_TO_DISABLE_REPLICATION.get()); |
| | | } |
| | | List<String> userProvidedSuffixes = argParser.getBaseDNs(); |
| | | TreeSet<String> userProvidedNotReplicatedSuffixes = new TreeSet<>(); |
| | | for (String s1 : userProvidedSuffixes) |
| | | List<DN> userProvidedSuffixes = toDNs(argParser.getBaseDNs()); |
| | | TreeSet<DN> userProvidedNotReplicatedSuffixes = new TreeSet<>(); |
| | | for (DN s1 : userProvidedSuffixes) |
| | | { |
| | | for (String s2 : notReplicatedSuffixes) |
| | | for (DN s2 : notReplicatedSuffixes) |
| | | { |
| | | if (areDnsEqual(s1, s2)) |
| | | if (s1.equals(s2)) |
| | | { |
| | | userProvidedNotReplicatedSuffixes.add(s1); |
| | | } |
| | |
| | | else |
| | | { |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<String> notFound = new TreeSet<>(); |
| | | TreeSet<String> alreadyNotReplicated = new TreeSet<>(); |
| | | for (String dn : suffixes) |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyNotReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!containsDN(availableSuffixes, dn)) |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (containsDN(notReplicatedSuffixes, dn)) |
| | | if (notReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyNotReplicated.add(dn); |
| | | } |
| | |
| | | } |
| | | |
| | | private boolean askConfirmations(Arg1<Object> confirmationMsg, |
| | | Collection<String> availableSuffixes, Collection<String> suffixes) |
| | | Collection<DN> availableSuffixes, Collection<DN> suffixes) |
| | | { |
| | | for (String dn : availableSuffixes) |
| | | for (DN dn : availableSuffixes) |
| | | { |
| | | if (!isSchemaOrInternalAdminSuffix(dn)) |
| | | { |
| | |
| | | * base DNs if none of the provided base DNs can be initialized. |
| | | */ |
| | | private void checkSuffixesForInitializeReplication( |
| | | Collection<String> suffixes, ConnectionWrapper conn, boolean interactive) |
| | | Collection<DN> suffixes, ConnectionWrapper conn, boolean interactive) |
| | | { |
| | | TreeSet<String> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<String> notReplicatedSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> notReplicatedSuffixes = new TreeSet<>(); |
| | | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | String dn = rep.getSuffix().getDN(); |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | availableSuffixes.add(dn); |
| | |
| | | errPrintln( |
| | | ERR_NO_SUFFIXES_AVAILABLE_TO_INITIALIZE_LOCAL_REPLICATION.get()); |
| | | } |
| | | List<String> userProvidedSuffixes = argParser.getBaseDNs(); |
| | | TreeSet<String> userProvidedNotReplicatedSuffixes = new TreeSet<>(); |
| | | for (String s1 : userProvidedSuffixes) |
| | | List<DN> userProvidedSuffixes = toDNs(argParser.getBaseDNs()); |
| | | TreeSet<DN> userProvidedNotReplicatedSuffixes = new TreeSet<>(); |
| | | for (DN s1 : userProvidedSuffixes) |
| | | { |
| | | for (String s2 : notReplicatedSuffixes) |
| | | for (DN s2 : notReplicatedSuffixes) |
| | | { |
| | | if (areDnsEqual(s1, s2)) |
| | | if (s1.equals(s2)) |
| | | { |
| | | userProvidedNotReplicatedSuffixes.add(s1); |
| | | } |
| | |
| | | else |
| | | { |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<String> notFound = new TreeSet<>(); |
| | | TreeSet<String> alreadyNotReplicated = new TreeSet<>(); |
| | | for (String dn : suffixes) |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyNotReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!containsDN(availableSuffixes, dn)) |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (containsDN(notReplicatedSuffixes, dn)) |
| | | if (notReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyNotReplicated.add(dn); |
| | | } |
| | |
| | | errPrintln(ERR_NO_SUFFIXES_SELECTED_TO_POST_EXTERNAL_INITIALIZATION.get()); |
| | | } |
| | | |
| | | for (String dn : availableSuffixes) |
| | | for (DN dn : availableSuffixes) |
| | | { |
| | | if (!isSchemaOrInternalAdminSuffix(dn)) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private String toSingleLine(Collection<String> notFound) |
| | | private String toSingleLine(Collection<?> notFound) |
| | | { |
| | | return joinAsString(Constants.LINE_SEPARATOR, notFound); |
| | | } |
| | |
| | | * @param interactive whether to ask the user to provide interactively |
| | | * base DNs if none of the provided base DNs can be initialized. |
| | | */ |
| | | private void checkSuffixesForInitializeReplication(Collection<String> suffixes, ConnectionWrapper connSource, |
| | | private void checkSuffixesForInitializeReplication(Collection<DN> suffixes, ConnectionWrapper connSource, |
| | | ConnectionWrapper connDestination, boolean interactive) |
| | | { |
| | | TreeSet<String> availableSuffixes = new TreeSet<>( |
| | | TreeSet<DN> availableSuffixes = new TreeSet<>( |
| | | getCommonSuffixes(connSource, connDestination, SuffixRelationType.REPLICATED)); |
| | | if (availableSuffixes.isEmpty()) |
| | | { |
| | |
| | | else |
| | | { |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | LinkedList<String> notFound = new LinkedList<>(); |
| | | for (String dn : suffixes) |
| | | LinkedList<DN> notFound = new LinkedList<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!containsDN(availableSuffixes, dn)) |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | notFound.add(dn); |
| | | } |
| | |
| | | { |
| | | final Set<String> twoReplServers = new LinkedHashSet<>(); |
| | | final Set<String> allRepServers = new LinkedHashSet<>(); |
| | | final Map<String, Set<String>> hmRepServers = new HashMap<>(); |
| | | final Map<DN, Set<String>> hmRepServers = new HashMap<>(); |
| | | final Set<Integer> usedReplicationServerIds = new HashSet<>(); |
| | | final Map<String, Set<Integer>> hmUsedReplicationDomainIds = new HashMap<>(); |
| | | final Map<DN, Set<Integer>> hmUsedReplicationDomainIds = new HashMap<>(); |
| | | |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | | filter.setSearchMonitoringInformation(false); |
| | | filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN()); |
| | | filter.addBaseDNToSearch(Constants.SCHEMA_DN); |
| | | filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN().toString()); |
| | | filter.addBaseDNToSearch(Constants.SCHEMA_DN.toString()); |
| | | addBaseDNs(filter, uData.getBaseDNs()); |
| | | ServerDescriptor serverDesc1 = createStandalone(conn1, filter); |
| | | ServerDescriptor serverDesc2 = createStandalone(conn2, filter); |
| | |
| | | } |
| | | } |
| | | // Check whether there is more than one replication server in the topology. |
| | | Set<String> baseDNsWithOneReplicationServer = new TreeSet<>(); |
| | | Set<String> baseDNsWithNoReplicationServer = new TreeSet<>(); |
| | | Set<DN> baseDNsWithOneReplicationServer = new TreeSet<>(); |
| | | Set<DN> baseDNsWithNoReplicationServer = new TreeSet<>(); |
| | | updateBaseDnsWithNotEnoughReplicationServer(adsCtx1, adsCtx2, uData, |
| | | baseDNsWithNoReplicationServer, baseDNsWithOneReplicationServer); |
| | | |
| | |
| | | print(formatter.getFormattedDone()); |
| | | println(); |
| | | } |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | if (!adsAlreadyReplicated |
| | | && !containsDN(baseDNs, ADSContext.getAdministrationSuffixDN())) |
| | | && !baseDNs.contains(ADSContext.getAdministrationSuffixDN())) |
| | | { |
| | | baseDNs.add(ADSContext.getAdministrationSuffixDN()); |
| | | uData.setBaseDNs(baseDNs); |
| | |
| | | addToSets(serverDesc1, uData.getServer1(), conn1, twoReplServers, usedReplicationServerIds); |
| | | addToSets(serverDesc2, uData.getServer2(), conn2, twoReplServers, usedReplicationServerIds); |
| | | |
| | | for (String baseDN : uData.getBaseDNs()) |
| | | for (DN baseDN : uData.getBaseDNs()) |
| | | { |
| | | Set<String> repServersForBaseDN = new LinkedHashSet<>(); |
| | | repServersForBaseDN.addAll(getReplicationServers(baseDN, cache1, serverDesc1)); |
| | |
| | | usedReplicationServerIds, allRepServers, alreadyConfiguredReplicationServers, |
| | | WARN_SECOND_REPLICATION_SERVER_ALREADY_CONFIGURED); |
| | | |
| | | for (String baseDN : uData.getBaseDNs()) |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | Set<String> repServers = hmRepServers.get(baseDN); |
| | | Set<Integer> usedIds = hmUsedReplicationDomainIds.get(baseDN); |
| | |
| | | } |
| | | |
| | | private void configureToReplicateBaseDN(EnableReplicationServerData server, ConnectionWrapper conn, |
| | | ServerDescriptor serverDesc, TopologyCache cache, String baseDN, Set<Integer> usedIds, |
| | | ServerDescriptor serverDesc, TopologyCache cache, DN baseDN, Set<Integer> usedIds, |
| | | Set<String> alreadyConfiguredServers, Set<String> repServers, final Set<String> allRepServers, |
| | | Set<String> alreadyConfiguredReplicationServers) throws ReplicationCliException |
| | | { |
| | | if (server.configureReplicationDomain() |
| | | || areDnsEqual(baseDN, ADSContext.getAdministrationSuffixDN())) |
| | | || baseDN.equals(ADSContext.getAdministrationSuffixDN())) |
| | | { |
| | | try |
| | | { |
| | |
| | | filter.setSearchMonitoringInformation(false); |
| | | if (!uData.disableAll()) |
| | | { |
| | | filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN()); |
| | | filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN().toString()); |
| | | addBaseDNs(filter, uData.getBaseDNs()); |
| | | } |
| | | ServerDescriptor server = createStandalone(conn, filter); |
| | |
| | | // Inform the user |
| | | if (!beforeLastRepServer.isEmpty()) |
| | | { |
| | | Set<String> baseDNs = new LinkedHashSet<>(); |
| | | Set<DN> baseDNs = new LinkedHashSet<>(); |
| | | for (SuffixDescriptor suffix : beforeLastRepServer) |
| | | { |
| | | if (!isSchemaOrInternalAdminSuffix(suffix.getDN())) |
| | |
| | | Set<String> suffixArg = new LinkedHashSet<>(); |
| | | for (SuffixDescriptor suffix : lastRepServer) |
| | | { |
| | | boolean baseDNSpecified = false; |
| | | for (String baseDN : uData.getBaseDNs()) |
| | | { |
| | | if (!isSchemaOrInternalAdminSuffix(baseDN) && areDnsEqual(baseDN, suffix.getDN())) |
| | | { |
| | | baseDNSpecified = true; |
| | | break; |
| | | } |
| | | } |
| | | if (!baseDNSpecified) |
| | | if (!isBaseDNSpecified(uData.getBaseDNs(), suffix.getDN())) |
| | | { |
| | | Set<ServerDescriptor> servers = new TreeSet<>(new ServerComparator()); |
| | | for (ReplicaDescriptor replica : suffix.getReplicas()) |
| | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | String dn = rep.getSuffix().getDN(); |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | if (areDnsEqual(ADSContext.getAdministrationSuffixDN(), dn)) |
| | | if (ADSContext.getAdministrationSuffixDN().equals(dn)) |
| | | { |
| | | adsReplicated = true; |
| | | } |
| | | else if (areDnsEqual(Constants.SCHEMA_DN, dn)) |
| | | else if (Constants.SCHEMA_DN.equals(dn)) |
| | | { |
| | | schemaReplicated = true; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | Set<String> suffixesToDisable = new HashSet<>(); |
| | | Set<DN> suffixesToDisable = new HashSet<>(); |
| | | if (uData.disableAll()) |
| | | { |
| | | for (ReplicaDescriptor replica : server.getReplicas()) |
| | |
| | | forceDisableSchema = schemaReplicated; |
| | | forceDisableADS = adsReplicated; |
| | | } |
| | | for (String dn : uData.getBaseDNs()) |
| | | for (DN dn : uData.getBaseDNs()) |
| | | { |
| | | if (areDnsEqual(ADSContext.getAdministrationSuffixDN(), dn)) |
| | | if (ADSContext.getAdministrationSuffixDN().equals(dn)) |
| | | { |
| | | // The user already asked this to be explicitly disabled |
| | | forceDisableADS = false; |
| | | } |
| | | else if (areDnsEqual(Constants.SCHEMA_DN, dn)) |
| | | else if (Constants.SCHEMA_DN.equals(dn)) |
| | | { |
| | | // The user already asked this to be explicitly disabled |
| | | forceDisableSchema = false; |
| | |
| | | String replicationServerHostPort = |
| | | server.isReplicationServer() ? server.getReplicationServerHostPort() : null; |
| | | |
| | | for (String baseDN : suffixesToDisable) |
| | | for (DN baseDN : suffixesToDisable) |
| | | { |
| | | try |
| | | { |
| | |
| | | if (replicationServerHostPort != null && cache != null) |
| | | { |
| | | Set<ServerDescriptor> serversToUpdate = new LinkedHashSet<>(); |
| | | Set<String> baseDNsToUpdate = new HashSet<>(suffixesToDisable); |
| | | for (String baseDN : baseDNsToUpdate) |
| | | Set<DN> baseDNsToUpdate = new HashSet<>(suffixesToDisable); |
| | | for (DN baseDN : baseDNsToUpdate) |
| | | { |
| | | SuffixDescriptor suffix = getSuffix(baseDN, cache, server); |
| | | if (suffix != null) |
| | |
| | | } |
| | | } |
| | | |
| | | private void addBaseDNs(TopologyCacheFilter filter, List<String> baseDNs) |
| | | private boolean isBaseDNSpecified(List<DN> baseDns, DN dnToFind) |
| | | { |
| | | for (String dn : baseDNs) |
| | | for (DN baseDN : baseDns) |
| | | { |
| | | filter.addBaseDNToSearch(dn); |
| | | if (!isSchemaOrInternalAdminSuffix(baseDN) && baseDN.equals(dnToFind)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private void addBaseDNs(TopologyCacheFilter filter, List<DN> baseDNs) |
| | | { |
| | | for (DN dn : baseDNs) |
| | | { |
| | | filter.addBaseDNToSearch(dn.toString()); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | List<String> userBaseDNs = uData.getBaseDNs(); |
| | | List<DN> userBaseDNs = uData.getBaseDNs(); |
| | | List<Set<ReplicaDescriptor>> replicaLists = new LinkedList<>(); |
| | | |
| | | boolean oneReplicated = false; |
| | |
| | | boolean displayAll = userBaseDNs.isEmpty(); |
| | | for (SuffixDescriptor suffix : cache.getSuffixes()) |
| | | { |
| | | String dn = suffix.getDN(); |
| | | DN dn = suffix.getDN(); |
| | | |
| | | // If no base DNs where specified display all the base DNs but the schema |
| | | // and cn=admin data. |
| | | boolean found = containsDN(userBaseDNs, dn) || (displayAll && !isSchemaOrInternalAdminSuffix(dn)); |
| | | boolean found = userBaseDNs.contains(dn) || (displayAll && !isSchemaOrInternalAdminSuffix(dn)); |
| | | if (found) |
| | | { |
| | | if (isAnyReplicated(suffix)) |
| | |
| | | for (Set<ReplicaDescriptor> replicas : replicaLists) |
| | | { |
| | | ReplicaDescriptor replica = replicas.iterator().next(); |
| | | if (!replica.isReplicated() && |
| | | areDnsEqual(dn, replica.getSuffix().getDN())) |
| | | if (!replica.isReplicated() && dn.equals(replica.getSuffix().getDN())) |
| | | { |
| | | replicas.addAll(suffix.getReplicas()); |
| | | found = true; |
| | |
| | | List<Set<ReplicaDescriptor>> orderedReplicaLists = new LinkedList<>(); |
| | | for (Set<ReplicaDescriptor> replicas : replicaLists) |
| | | { |
| | | String dn1 = replicas.iterator().next().getSuffix().getDN(); |
| | | DN dn1 = replicas.iterator().next().getSuffix().getDN(); |
| | | boolean inserted = false; |
| | | for (int i=0; i<orderedReplicaLists.size() && !inserted; i++) |
| | | { |
| | | String dn2 = orderedReplicaLists.get(i).iterator().next().getSuffix().getDN(); |
| | | DN dn2 = orderedReplicaLists.get(i).iterator().next().getSuffix().getDN(); |
| | | if (dn1.compareTo(dn2) < 0) |
| | | { |
| | | orderedReplicaLists.add(i, replicas); |
| | |
| | | { |
| | | tableBuilder.startRow(); |
| | | // Suffix DN |
| | | tableBuilder.appendCell(LocalizableMessage.raw(replica.getSuffix().getDN())); |
| | | tableBuilder.appendCell(LocalizableMessage.raw(replica.getSuffix().getDN().toString())); |
| | | // Server port |
| | | tableBuilder.appendCell(LocalizableMessage.raw("%s", getHostPort2(replica.getServer(), cnx))); |
| | | // Number of entries |
| | |
| | | * to replicate the baseDN defined in the server described by the |
| | | * ServerDescriptor. |
| | | */ |
| | | private Set<String> getReplicationServers(String baseDN, |
| | | TopologyCache cache, ServerDescriptor server) |
| | | private Set<String> getReplicationServers(DN baseDN, TopologyCache cache, ServerDescriptor server) |
| | | { |
| | | Set<String> servers = getAllReplicationServers(baseDN, server); |
| | | if (cache != null) |
| | | { |
| | | for (SuffixDescriptor suffix : cache.getSuffixes()) |
| | | { |
| | | if (areDnsEqual(suffix.getDN(), baseDN)) |
| | | if (suffix.getDN().equals(baseDN)) |
| | | { |
| | | Set<String> s = suffix.getReplicationServers(); |
| | | // Test that at least we share one of the replication servers. |
| | |
| | | * @param server the ServerDescriptor. |
| | | * @return the suffix in the TopologyCache for a given baseDN. |
| | | */ |
| | | private SuffixDescriptor getSuffix(String baseDN, TopologyCache cache, |
| | | ServerDescriptor server) |
| | | private SuffixDescriptor getSuffix(DN baseDN, TopologyCache cache, ServerDescriptor server) |
| | | { |
| | | String replicationServer = null; |
| | | if (server.isReplicationServer()) |
| | |
| | | Set<String> servers = getAllReplicationServers(baseDN, server); |
| | | for (SuffixDescriptor suffix : cache.getSuffixes()) |
| | | { |
| | | if (areDnsEqual(suffix.getDN(), baseDN)) |
| | | if (suffix.getDN().equals(baseDN)) |
| | | { |
| | | Set<String> s = suffix.getReplicationServers(); |
| | | // Test that at least we share one of the replication servers. |
| | |
| | | return returnValue; |
| | | } |
| | | |
| | | private Set<String> getAllReplicationServers(String baseDN, ServerDescriptor server) |
| | | private Set<String> getAllReplicationServers(DN baseDN, ServerDescriptor server) |
| | | { |
| | | Set<String> servers = new LinkedHashSet<>(); |
| | | for (ReplicaDescriptor replica : server.getReplicas()) |
| | | { |
| | | if (areDnsEqual(replica.getSuffix().getDN(), baseDN)) |
| | | if (replica.getSuffix().getDN().equals(baseDN)) |
| | | { |
| | | servers.addAll(replica.getReplicationServers()); |
| | | break; |
| | |
| | | * @return a Set containing the replication domain IDs for a given baseDN in |
| | | * the ServerDescriptor. |
| | | */ |
| | | private Set<Integer> getReplicationDomainIds(String baseDN, |
| | | ServerDescriptor server) |
| | | private Set<Integer> getReplicationDomainIds(DN baseDN, ServerDescriptor server) |
| | | { |
| | | Set<Integer> ids = new HashSet<>(); |
| | | for (ReplicaDescriptor replica : server.getReplicas()) |
| | | { |
| | | if (replica.isReplicated() |
| | | && areDnsEqual(replica.getSuffix().getDN(), baseDN)) |
| | | && replica.getSuffix().getDN().equals(baseDN)) |
| | | { |
| | | ids.add(replica.getReplicationId()); |
| | | break; |
| | |
| | | * if there is an error updating the configuration. |
| | | */ |
| | | private void configureToReplicateBaseDN(ConnectionWrapper conn, |
| | | String baseDN, |
| | | DN baseDN, |
| | | Set<String> replicationServers, |
| | | Set<Integer> usedReplicationDomainIds) throws Exception |
| | | { |
| | | boolean userSpecifiedAdminBaseDN = false; |
| | | List<String> l = argParser.getBaseDNs(); |
| | | if (l != null) |
| | | List<DN> baseDNs = toDNs(argParser.getBaseDNs()); |
| | | if (baseDNs != null) |
| | | { |
| | | userSpecifiedAdminBaseDN = containsDN(l, ADSContext.getAdministrationSuffixDN()); |
| | | userSpecifiedAdminBaseDN = baseDNs.contains(ADSContext.getAdministrationSuffixDN()); |
| | | } |
| | | if (!userSpecifiedAdminBaseDN |
| | | && areDnsEqual(baseDN, ADSContext.getAdministrationSuffixDN())) |
| | | && baseDN.equals(ADSContext.getAdministrationSuffixDN())) |
| | | { |
| | | print(formatter.getFormattedWithPoints( |
| | | INFO_REPLICATION_ENABLE_CONFIGURING_ADS.get(conn.getHostPort()))); |
| | |
| | | ReplicationDomainCfgClient domain = null; |
| | | for (ReplicationDomainCfgClient domain2 : domains) |
| | | { |
| | | if (areDnsEqual(baseDN, domain2.getBaseDN().toString())) |
| | | if (baseDN.equals(domain2.getBaseDN())) |
| | | { |
| | | domain = domain2; |
| | | break; |
| | |
| | | ReplicationDomainCfgDefn.getInstance(), domainName, |
| | | new ArrayList<PropertyException>()); |
| | | domain.setServerId(domainId); |
| | | domain.setBaseDN(DN.valueOf(baseDN)); |
| | | domain.setBaseDN(baseDN); |
| | | domain.setReplicationServer(replicationServers); |
| | | mustCommit = true; |
| | | } |
| | |
| | | * replication server. |
| | | * @throws ReplicationCliException if something goes wrong. |
| | | */ |
| | | private void configureToReplicateBaseDN(String baseDN, |
| | | private void configureToReplicateBaseDN(DN baseDN, |
| | | Set<String> repServers, Set<Integer> usedIds, |
| | | TopologyCache cache, ServerDescriptor server, |
| | | Set<String> alreadyConfiguredServers, Set<String> allRepServers, |
| | |
| | | return adminProperties; |
| | | } |
| | | |
| | | private void initializeSuffix(String baseDN, ConnectionWrapper connSource, ConnectionWrapper connDestination, |
| | | boolean displayProgress) |
| | | throws ReplicationCliException |
| | | private void initializeSuffix(DN baseDN, ConnectionWrapper connSource, ConnectionWrapper connDestination, |
| | | boolean displayProgress) throws ReplicationCliException |
| | | { |
| | | int replicationId = -1; |
| | | try |
| | | { |
| | | TopologyCacheFilter filter = new TopologyCacheFilter(); |
| | | filter.setSearchMonitoringInformation(false); |
| | | filter.addBaseDNToSearch(baseDN); |
| | | filter.addBaseDNToSearch(baseDN.toString()); |
| | | ServerDescriptor source = ServerDescriptor.createStandalone(connSource, filter); |
| | | for (ReplicaDescriptor replica : source.getReplicas()) |
| | | { |
| | | if (areDnsEqual(replica.getSuffix().getDN(), baseDN)) |
| | | if (replica.getSuffix().getDN().equals(baseDN)) |
| | | { |
| | | replicationId = replica.getReplicationId(); |
| | | break; |
| | |
| | | * @param displayProgress whether we want to display progress or not. |
| | | * @throws ReplicationCliException if an unexpected error occurs. |
| | | */ |
| | | public void initializeAllSuffix(String baseDN, ConnectionWrapper conn, boolean displayProgress) |
| | | public void initializeAllSuffix(DN baseDN, ConnectionWrapper conn, boolean displayProgress) |
| | | throws ReplicationCliException |
| | | { |
| | | if (argParser == null) |
| | |
| | | * @throws ReplicationCliException if there is an error performing the |
| | | * operation. |
| | | */ |
| | | private void preExternalInitialization(String baseDN, ConnectionWrapper conn) throws ReplicationCliException |
| | | private void preExternalInitialization(DN baseDN, ConnectionWrapper conn) throws ReplicationCliException |
| | | { |
| | | postPreExternalInitialization(baseDN, conn, true); |
| | | } |
| | |
| | | * @throws ReplicationCliException if there is an error performing the |
| | | * operation. |
| | | */ |
| | | private void postExternalInitialization(String baseDN, ConnectionWrapper conn) throws ReplicationCliException |
| | | private void postExternalInitialization(DN baseDN, ConnectionWrapper conn) throws ReplicationCliException |
| | | { |
| | | postPreExternalInitialization(baseDN, conn, false); |
| | | } |
| | |
| | | * @param isPre whether this is the pre operation or the post operation. |
| | | * @throws ReplicationCliException if there is an error performing the operation |
| | | */ |
| | | private void postPreExternalInitialization(String baseDN, |
| | | private void postPreExternalInitialization(DN baseDN, |
| | | ConnectionWrapper conn, boolean isPre) throws ReplicationCliException |
| | | { |
| | | boolean isOver = false; |
| | |
| | | { |
| | | attrMap.put("ds-task-reset-generation-id-new-value", "-1"); |
| | | } |
| | | attrMap.put("ds-task-reset-generation-id-domain-base-dn", baseDN); |
| | | attrMap.put("ds-task-reset-generation-id-domain-base-dn", baseDN.toString()); |
| | | |
| | | try { |
| | | dn = createServerTask(conn, |
| | |
| | | * @throws PeerNotFoundException if the replication mechanism cannot find |
| | | * a peer. |
| | | */ |
| | | private void initializeAllSuffixTry(String baseDN, ConnectionWrapper conn, boolean displayProgress) |
| | | private void initializeAllSuffixTry(DN baseDN, ConnectionWrapper conn, boolean displayProgress) |
| | | throws ClientException, PeerNotFoundException |
| | | { |
| | | boolean isOver = false; |
| | | String dn = null; |
| | | HostPort hostPort = conn.getHostPort(); |
| | | Map<String, String> attrsMap = new TreeMap<>(); |
| | | attrsMap.put("ds-task-initialize-domain-dn", baseDN); |
| | | attrsMap.put("ds-task-initialize-domain-dn", baseDN.toString()); |
| | | attrsMap.put("ds-task-initialize-replica-server-id", "all"); |
| | | try |
| | | { |
| | |
| | | */ |
| | | private void removeReferencesInServer(ServerDescriptor server, |
| | | String replicationServer, DN bindDn, String pwd, |
| | | Collection<String> baseDNs, boolean updateReplicationServers, |
| | | Collection<DN> baseDNs, boolean updateReplicationServers, |
| | | Set<PreferredConnection> cnx) |
| | | throws ReplicationCliException |
| | | { |
| | |
| | | filter.setSearchBaseDNInformation(false); |
| | | ServerLoader loader = new ServerLoader(server.getAdsProperties(), bindDn, |
| | | pwd, getTrustManager(sourceServerCI), getConnectTimeout(), cnx, filter); |
| | | String lastBaseDN = null; |
| | | DN lastBaseDN = null; |
| | | HostPort hostPort = null; |
| | | |
| | | try (ConnectionWrapper conn = loader.createConnectionWrapper()) |
| | |
| | | { |
| | | for (String domainName : domainNames) |
| | | { |
| | | ReplicationDomainCfgClient domain = |
| | | sync.getReplicationDomain(domainName); |
| | | for (String baseDN : baseDNs) |
| | | ReplicationDomainCfgClient domain = sync.getReplicationDomain(domainName); |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | lastBaseDN = baseDN; |
| | | if (areDnsEqual(domain.getBaseDN().toString(), baseDN)) |
| | | if (domain.getBaseDN().equals(baseDN)) |
| | | { |
| | | print(formatter.getFormattedWithPoints( |
| | | INFO_REPLICATION_REMOVING_REFERENCES_ON_REMOTE.get(baseDN, hostPort))); |
| | |
| | | * @throws ReplicationCliException if there is an error updating the |
| | | * configuration of the server. |
| | | */ |
| | | private void deleteReplicationDomain(ConnectionWrapper conn, String baseDN) throws ReplicationCliException |
| | | private void deleteReplicationDomain(ConnectionWrapper conn, DN baseDN) throws ReplicationCliException |
| | | { |
| | | HostPort hostPort = conn.getHostPort(); |
| | | try |
| | |
| | | { |
| | | ReplicationDomainCfgClient domain = |
| | | sync.getReplicationDomain(domainName); |
| | | if (areDnsEqual(domain.getBaseDN().toString(), baseDN)) |
| | | if (domain.getBaseDN().equals(baseDN)) |
| | | { |
| | | print(formatter.getFormattedWithPoints( |
| | | INFO_REPLICATION_DISABLING_BASEDN.get(baseDN, hostPort))); |
| | |
| | | * the replication domain or updating the list of replication servers of |
| | | * the replication domain). |
| | | */ |
| | | private LocalizableMessage getMessageForEnableException(HostPort hostPort, String baseDN) |
| | | private LocalizableMessage getMessageForEnableException(HostPort hostPort, DN 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(HostPort hostPort, String baseDN) |
| | | private LocalizableMessage getMessageForDisableException(HostPort hostPort, DN baseDN) |
| | | { |
| | | return ERR_REPLICATION_CONFIGURING_BASEDN.get(baseDN, hostPort); |
| | | } |
| | |
| | | } |
| | | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | Set<String> replicatedSuffixes = new HashSet<>(); |
| | | Set<DN> replicatedSuffixes = new HashSet<>(); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | String dn = rep.getSuffix().getDN(); |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | replicatedSuffixes.add(dn); |
| | | } |
| | | } |
| | | |
| | | for (String dn1 : replicatedSuffixes) |
| | | for (DN dn1 : replicatedSuffixes) |
| | | { |
| | | if (!areDnsEqual(ADSContext.getAdministrationSuffixDN(), dn1) |
| | | && !areDnsEqual(Constants.SCHEMA_DN, dn1) |
| | | && !containsDN(uData.getBaseDNs(), dn1)) |
| | | if (!ADSContext.getAdministrationSuffixDN().equals(dn1) |
| | | && !Constants.SCHEMA_DN.equals(dn1) |
| | | && !uData.getBaseDNs().contains(dn1)) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | return true; |
| | | } |
| | | |
| | | private boolean containsDN(final Collection<String> dns, String dnToFind) |
| | | { |
| | | for (String dn : dns) |
| | | { |
| | | if (areDnsEqual(dn, dnToFind)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | private void addGlobalArguments(CommandBuilder commandBuilder, ReplicationUserData uData) |
| | | throws ArgumentException |
| | | { |
| | | List<String> baseDNs = uData.getBaseDNs(); |
| | | List<DN> baseDNs = uData.getBaseDNs(); |
| | | StringArgument baseDNsArg = |
| | | StringArgument.builder(OPTION_LONG_BASEDN) |
| | | .shortIdentifier(OPTION_SHORT_BASEDN) |
| | |
| | | .multiValued() |
| | | .valuePlaceholder(INFO_BASEDN_PLACEHOLDER.get()) |
| | | .buildArgument(); |
| | | for (String baseDN : baseDNs) |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | baseDNsArg.addValue(baseDN); |
| | | baseDNsArg.addValue(baseDN.toString()); |
| | | } |
| | | commandBuilder.addArgument(baseDNsArg); |
| | | |
| | |
| | | |
| | | private void updateAvailableAndReplicatedSuffixesForOneDomain( |
| | | ConnectionWrapper connDomain, ConnectionWrapper connOther, |
| | | Set<String> availableSuffixes, Set<String> alreadyReplicatedSuffixes) |
| | | Set<DN> availableSuffixes, Set<DN> alreadyReplicatedSuffixes) |
| | | { |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(connDomain); |
| | | int replicationPort = getReplicationPort(connOther); |
| | | boolean isReplicationServerConfigured = replicationPort != -1; |
| | | String replicationServer = getReplicationServer(connOther.getHostPort().getHost(), replicationPort); |
| | | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(connDomain); |
| | | for (ReplicaDescriptor replica : replicas) |
| | | { |
| | | final DN suffixDn = replica.getSuffix().getDN(); |
| | | if (!isReplicationServerConfigured) |
| | | { |
| | | if (replica.isReplicated()) |
| | | { |
| | | alreadyReplicatedSuffixes.add(replica.getSuffix().getDN()); |
| | | alreadyReplicatedSuffixes.add(suffixDn); |
| | | } |
| | | availableSuffixes.add(replica.getSuffix().getDN()); |
| | | availableSuffixes.add(suffixDn); |
| | | } |
| | | |
| | | if (!isReplicationServerConfigured) |
| | | { |
| | | availableSuffixes.add(replica.getSuffix().getDN()); |
| | | availableSuffixes.add(suffixDn); |
| | | } |
| | | else if (!replica.isReplicated()) |
| | | { |
| | | availableSuffixes.add(replica.getSuffix().getDN()); |
| | | availableSuffixes.add(suffixDn); |
| | | } |
| | | else if (containsIgnoreCase(replica.getReplicationServers(), replicationServer)) |
| | | { |
| | | alreadyReplicatedSuffixes.add(replica.getSuffix().getDN()); |
| | | alreadyReplicatedSuffixes.add(suffixDn); |
| | | } |
| | | else |
| | | { |
| | | availableSuffixes.add(replica.getSuffix().getDN()); |
| | | availableSuffixes.add(suffixDn); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void updateAvailableAndReplicatedSuffixesForNoDomain( |
| | | ConnectionWrapper conn1, ConnectionWrapper conn2, |
| | | Set<String> availableSuffixes, Set<String> alreadyReplicatedSuffixes) |
| | | Set<DN> availableSuffixes, Set<DN> alreadyReplicatedSuffixes) |
| | | { |
| | | int replicationPort1 = getReplicationPort(conn1); |
| | | boolean isReplicationServer1Configured = replicationPort1 != -1; |
| | |
| | | return null; |
| | | } |
| | | |
| | | private void addAllAvailableSuffixes(Collection<String> availableSuffixes, |
| | | private void addAllAvailableSuffixes(Collection<DN> availableSuffixes, |
| | | Set<SuffixDescriptor> suffixes, String rsToFind) |
| | | { |
| | | for (SuffixDescriptor suffix : suffixes) |
| | |
| | | |
| | | private void updateAvailableAndReplicatedSuffixesForNoDomainOneSense( |
| | | TopologyCache cache1, TopologyCache cache2, String replicationServer1, String replicationServer2, |
| | | Set<String> availableSuffixes, Set<String> alreadyReplicatedSuffixes) |
| | | Set<DN> availableSuffixes, Set<DN> alreadyReplicatedSuffixes) |
| | | { |
| | | for (SuffixDescriptor suffix : cache1.getSuffixes()) |
| | | { |
| | |
| | | boolean isFirstReplicated = false; |
| | | for (SuffixDescriptor suffix2 : cache2.getSuffixes()) |
| | | { |
| | | if (areDnsEqual(suffix.getDN(), suffix2.getDN())) |
| | | if (suffix.getDN().equals(suffix2.getDN())) |
| | | { |
| | | for (String rServer2 : suffix2.getReplicationServers()) |
| | | { |
| | |
| | | |
| | | private void updateBaseDnsWithNotEnoughReplicationServer(ADSContext adsCtx1, |
| | | ADSContext adsCtx2, EnableReplicationUserData uData, |
| | | Set<String> baseDNsWithNoReplicationServer, |
| | | Set<String> baseDNsWithOneReplicationServer) |
| | | Set<DN> baseDNsWithNoReplicationServer, Set<DN> baseDNsWithOneReplicationServer) |
| | | { |
| | | EnableReplicationServerData server1 = uData.getServer1(); |
| | | EnableReplicationServerData server2 = uData.getServer2(); |
| | |
| | | String repServer1 = getReplicationServer(server1.getHostName(), repPort1); |
| | | int repPort2 = getReplicationPort(adsCtx2.getConnection()); |
| | | String repServer2 = getReplicationServer(server2.getHostName(), repPort2); |
| | | for (String baseDN : uData.getBaseDNs()) |
| | | for (DN baseDN : uData.getBaseDNs()) |
| | | { |
| | | int nReplicationServers = 0; |
| | | for (SuffixDescriptor suffix : suffixes) |
| | | { |
| | | if (areDnsEqual(suffix.getDN(), baseDN)) |
| | | if (suffix.getDN().equals(baseDN)) |
| | | { |
| | | Set<String> replicationServers = suffix.getReplicationServers(); |
| | | nReplicationServers += replicationServers.size(); |
| | |
| | | return false; |
| | | } |
| | | |
| | | private boolean findReplicaInSuffix2(ReplicaDescriptor replica1, SuffixDescriptor suffix2, String suffix1DN, |
| | | private boolean findReplicaInSuffix2(ReplicaDescriptor replica1, SuffixDescriptor suffix2, DN suffix1DN, |
| | | Set<LocalizableMessage> commonDomainIDErrors) |
| | | { |
| | | if (!areDnsEqual(suffix2.getDN(), replica1.getSuffix().getDN())) |
| | | if (!suffix2.getDN().equals(replica1.getSuffix().getDN())) |
| | | { |
| | | // Conflicting domain names must apply to same suffix. |
| | | return false; |
| | |
| | | * @return <CODE>true</CODE> if the provided baseDN is replicated in the |
| | | * provided server, <CODE>false</CODE> otherwise. |
| | | */ |
| | | private boolean isBaseDNReplicated(ServerDescriptor server, String baseDN) |
| | | private boolean isBaseDNReplicated(ServerDescriptor server, DN baseDN) |
| | | { |
| | | return findReplicated(server.getReplicas(), baseDN) != null; |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if the provided baseDN is replicated between |
| | | * both servers, <CODE>false</CODE> otherwise. |
| | | */ |
| | | private boolean isBaseDNReplicated(ServerDescriptor server1, |
| | | ServerDescriptor server2, String baseDN) |
| | | private boolean isBaseDNReplicated(ServerDescriptor server1, ServerDescriptor server2, DN baseDN) |
| | | { |
| | | final ReplicaDescriptor replica1 = findReplicated(server1.getReplicas(), baseDN); |
| | | final ReplicaDescriptor replica2 = findReplicated(server2.getReplicas(), baseDN); |
| | |
| | | return false; |
| | | } |
| | | |
| | | private ReplicaDescriptor findReplicated(Set<ReplicaDescriptor> replicas, String baseDN) |
| | | private ReplicaDescriptor findReplicated(Set<ReplicaDescriptor> replicas, DN baseDN) |
| | | { |
| | | for (ReplicaDescriptor replica : replicas) |
| | | { |
| | | if (areDnsEqual(replica.getSuffix().getDN(), baseDN)) |
| | | if (replica.getSuffix().getDN().equals(baseDN)) |
| | | { |
| | | return replica; |
| | | } |