| | |
| | | printNewCommandBuilder(PURGE_HISTORICAL_SUBCMD_NAME, uData); |
| | | } |
| | | |
| | | try |
| | | { |
| | | return purgeHistoricalRemoteTask(conn, uData); |
| | | } |
| | | catch (ReplicationCliException rce) |
| | |
| | | logger.error(LocalizableMessage.raw("Complete error stack:"), rce); |
| | | return rce.getErrorCode(); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | close(conn); |
| | |
| | | TreeSet<DN> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> notReplicatedSuffixes = new TreeSet<>(); |
| | | |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | availableSuffixes.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notReplicatedSuffixes.add(dn); |
| | | } |
| | | } |
| | | partitionReplicasByReplicated(replicas, availableSuffixes, notReplicatedSuffixes); |
| | | |
| | | checkSuffixesForPurgeHistorical(suffixes, availableSuffixes, notReplicatedSuffixes, interactive); |
| | | } |
| | | |
| | | private void checkSuffixesForPurgeHistorical(Collection<DN> suffixes, |
| | | Collection<DN> availableSuffixes, |
| | | Collection<DN> notReplicatedSuffixes, |
| | | boolean interactive) |
| | | { |
| | | if (availableSuffixes.isEmpty()) |
| | | { |
| | | errPrintln(); |
| | |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyNotReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (notReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyNotReplicated.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notFound.add(dn); |
| | | } |
| | | } |
| | | } |
| | | determineSuffixesNotFoundAndAlreadyNotReplicated( |
| | | suffixes, availableSuffixes, notReplicatedSuffixes, notFound, alreadyNotReplicated); |
| | | suffixes.removeAll(notFound); |
| | | suffixes.removeAll(alreadyNotReplicated); |
| | | if (!notFound.isEmpty()) |
| | |
| | | } |
| | | } |
| | | |
| | | private void partitionReplicasByReplicated(Collection<ReplicaDescriptor> replicas, |
| | | Set<DN> replicatedSuffixes, Set<DN> notReplicatedSuffixes) |
| | | { |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | replicatedSuffixes.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notReplicatedSuffixes.add(dn); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void determineSuffixesNotFoundAndAlreadyNotReplicated(Collection<DN> suffixes, |
| | | Set<DN> availableSuffixes, Set<DN> notReplicatedSuffixes, Set<DN> notFound, Set<DN> alreadyNotReplicated) |
| | | { |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (notReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyNotReplicated.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notFound.add(dn); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void askConfirmations(Collection<DN> suffixes, |
| | | Collection<DN> availableSuffixes, Arg0 noSuffixAvailableMsg, |
| | | Arg0 noSuffixSelectedMsg, Arg1<Object> confirmationMsgPromt) |
| | |
| | | * @throws ReplicationCliException if there is a critical error reading the |
| | | * ADS. |
| | | */ |
| | | private boolean promptIfRequired(DisableReplicationUserData uData) |
| | | throws ReplicationCliException |
| | | private boolean promptIfRequired(DisableReplicationUserData uData) throws ReplicationCliException |
| | | { |
| | | boolean cancelled = false; |
| | | |
| | |
| | | |
| | | try |
| | | { |
| | | try |
| | | { |
| | | displayStatus(conn, uData); |
| | | return SUCCESSFUL; |
| | | } |
| | |
| | | logger.error(LocalizableMessage.raw("Complete error stack:"), rce); |
| | | return rce.getErrorCode(); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | close(conn); |
| | |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (alreadyReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyReplicated.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notFound.add(dn); |
| | | } |
| | | } |
| | | } |
| | | determineSuffixesNotFoundAndAlreadyNotReplicated( |
| | | suffixes, availableSuffixes, alreadyReplicatedSuffixes, notFound,alreadyReplicated); |
| | | suffixes.removeAll(notFound); |
| | | suffixes.removeAll(alreadyReplicated); |
| | | if (!notFound.isEmpty()) |
| | |
| | | TreeSet<DN> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> notReplicatedSuffixes = new TreeSet<>(); |
| | | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | availableSuffixes.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notReplicatedSuffixes.add(dn); |
| | | } |
| | | } |
| | | partitionReplicasByReplicated(getReplicas(conn), availableSuffixes, notReplicatedSuffixes); |
| | | if (availableSuffixes.isEmpty()) |
| | | { |
| | | if (displayErrors) |
| | |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyNotReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (notReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyNotReplicated.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notFound.add(dn); |
| | | } |
| | | } |
| | | } |
| | | determineSuffixesNotFoundAndAlreadyNotReplicated( |
| | | suffixes, availableSuffixes, notReplicatedSuffixes, notFound, alreadyNotReplicated); |
| | | suffixes.removeAll(notFound); |
| | | suffixes.removeAll(alreadyNotReplicated); |
| | | if (!notFound.isEmpty() && displayErrors) |
| | |
| | | TreeSet<DN> availableSuffixes = new TreeSet<>(); |
| | | TreeSet<DN> notReplicatedSuffixes = new TreeSet<>(); |
| | | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | availableSuffixes.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notReplicatedSuffixes.add(dn); |
| | | } |
| | | } |
| | | partitionReplicasByReplicated(getReplicas(conn), availableSuffixes, notReplicatedSuffixes); |
| | | if (availableSuffixes.isEmpty()) |
| | | { |
| | | println(); |
| | |
| | | // Verify that the provided suffixes are configured in the servers. |
| | | TreeSet<DN> notFound = new TreeSet<>(); |
| | | TreeSet<DN> alreadyNotReplicated = new TreeSet<>(); |
| | | for (DN dn : suffixes) |
| | | { |
| | | if (!availableSuffixes.contains(dn)) |
| | | { |
| | | if (notReplicatedSuffixes.contains(dn)) |
| | | { |
| | | alreadyNotReplicated.add(dn); |
| | | } |
| | | else |
| | | { |
| | | notFound.add(dn); |
| | | } |
| | | } |
| | | } |
| | | determineSuffixesNotFoundAndAlreadyNotReplicated( |
| | | suffixes, availableSuffixes, notReplicatedSuffixes, notFound, alreadyNotReplicated); |
| | | suffixes.removeAll(notFound); |
| | | suffixes.removeAll(alreadyNotReplicated); |
| | | if (!notFound.isEmpty()) |
| | |
| | | hmRepServers.put(baseDN, repServersForBaseDN); |
| | | |
| | | Set<Integer> ids = new HashSet<>(); |
| | | ids.addAll(getReplicationDomainIds(baseDN, serverDesc1)); |
| | | ids.addAll(getReplicationDomainIds(baseDN, serverDesc2)); |
| | | addReplicationDomainIds(ids, serverDesc1, baseDN); |
| | | addReplicationDomainIds(ids, serverDesc2, baseDN); |
| | | if (cache1 != null) |
| | | { |
| | | for (ServerDescriptor server : cache1.getServers()) |
| | | { |
| | | ids.addAll(getReplicationDomainIds(baseDN, server)); |
| | | addReplicationDomainIds(ids, server, baseDN); |
| | | } |
| | | } |
| | | if (cache2 != null) |
| | | { |
| | | for (ServerDescriptor server : cache2.getServers()) |
| | | { |
| | | ids.addAll(getReplicationDomainIds(baseDN, server)); |
| | | addReplicationDomainIds(ids, server, baseDN); |
| | | } |
| | | } |
| | | hmUsedReplicationDomainIds.put(baseDN, ids); |
| | |
| | | } |
| | | } |
| | | |
| | | private void addReplicationDomainIds(Set<Integer> replicationIds, ServerDescriptor serverDesc1, DN baseDN) |
| | | { |
| | | ReplicaDescriptor replica = findReplicated(baseDN, serverDesc1); |
| | | if (replica != null) |
| | | { |
| | | replicationIds.add(replica.getReplicationId()); |
| | | } |
| | | } |
| | | |
| | | private void addToSets(ServerDescriptor serverDesc, EnableReplicationServerData serverData, ConnectionWrapper conn, |
| | | final Set<String> twoReplServers, final Set<Integer> usedReplicationServerIds) |
| | | { |
| | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (ADSContext.getAdministrationSuffixDN().equals(dn)) |
| | | { |
| | | adsReplicated = true; |
| | |
| | | Set<DN> suffixesToDisable = new HashSet<>(); |
| | | if (uData.disableAll()) |
| | | { |
| | | for (ReplicaDescriptor replica : server.getReplicas()) |
| | | { |
| | | if (replica.isReplicated()) |
| | | { |
| | | suffixesToDisable.add(replica.getSuffix().getDN()); |
| | | } |
| | | } |
| | | addAllReplicated(suffixesToDisable, server.getReplicas()); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private void addAllReplicated(Set<DN> suffixesToDisable, Set<ReplicaDescriptor> replicas) |
| | | { |
| | | for (ReplicaDescriptor replica : replicas) |
| | | { |
| | | if (replica.isReplicated()) |
| | | { |
| | | suffixesToDisable.add(replica.getSuffix().getDN()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean isBaseDNSpecified(List<DN> baseDns, DN dnToFind) |
| | | { |
| | | for (DN baseDN : baseDns) |
| | |
| | | for (Set<ReplicaDescriptor> replicas : replicaLists) |
| | | { |
| | | ReplicaDescriptor replica = replicas.iterator().next(); |
| | | if (!replica.isReplicated() && dn.equals(replica.getSuffix().getDN())) |
| | | if (!replica.isReplicated() && replica.getSuffix().getDN().equals(dn)) |
| | | { |
| | | replicas.addAll(suffix.getReplicas()); |
| | | found = true; |
| | |
| | | |
| | | private Set<String> getAllReplicationServers(DN baseDN, ServerDescriptor server) |
| | | { |
| | | ReplicaDescriptor replica = findReplicaForSuffixDN(server.getReplicas(), baseDN); |
| | | Set<String> servers = new LinkedHashSet<>(); |
| | | for (ReplicaDescriptor replica : server.getReplicas()) |
| | | { |
| | | if (replica.getSuffix().getDN().equals(baseDN)) |
| | | if (replica != null) |
| | | { |
| | | servers.addAll(replica.getReplicationServers()); |
| | | break; |
| | | } |
| | | } |
| | | return servers; |
| | | } |
| | | |
| | | /** |
| | | * Retrieves all the replication domain IDs for a given baseDN in the |
| | | * ServerDescriptor. |
| | | * @param baseDN the base DN. |
| | | * @param server the ServerDescriptor. |
| | | * @return a Set containing the replication domain IDs for a given baseDN in |
| | | * the ServerDescriptor. |
| | | */ |
| | | private Set<Integer> getReplicationDomainIds(DN baseDN, ServerDescriptor server) |
| | | { |
| | | Set<Integer> ids = new HashSet<>(); |
| | | for (ReplicaDescriptor replica : server.getReplicas()) |
| | | { |
| | | if (replica.isReplicated() |
| | | && replica.getSuffix().getDN().equals(baseDN)) |
| | | { |
| | | ids.add(replica.getReplicationId()); |
| | | break; |
| | | } |
| | | } |
| | | return ids; |
| | | } |
| | | |
| | | /** |
| | | * Configures the server as a replication server by using the provided connection. |
| | | * The replication server listens to the provided port. |
| | | * @param conn the connection to the server that we want to configure. |
| | |
| | | filter.setSearchMonitoringInformation(false); |
| | | filter.addBaseDNToSearch(baseDN.toString()); |
| | | ServerDescriptor source = ServerDescriptor.createStandalone(connSource, filter); |
| | | for (ReplicaDescriptor replica : source.getReplicas()) |
| | | { |
| | | if (replica.getSuffix().getDN().equals(baseDN)) |
| | | ReplicaDescriptor replica = findReplicaForSuffixDN(source.getReplicas(), baseDN); |
| | | if (replica != null) |
| | | { |
| | | replicationId = replica.getReplicationId(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | catch (IOException ne) |
| | |
| | | } |
| | | |
| | | Collection<ReplicaDescriptor> replicas = getReplicas(conn); |
| | | Set<DN> replicatedSuffixes = new HashSet<>(); |
| | | for (ReplicaDescriptor rep : replicas) |
| | | { |
| | | DN dn = rep.getSuffix().getDN(); |
| | | if (rep.isReplicated()) |
| | | { |
| | | replicatedSuffixes.add(dn); |
| | | } |
| | | } |
| | | Set<DN> replicatedSuffixes = findAllReplicasForSuffixDN(replicas); |
| | | |
| | | for (DN dn1 : replicatedSuffixes) |
| | | { |
| | |
| | | */ |
| | | private boolean isBaseDNReplicated(ServerDescriptor server, DN baseDN) |
| | | { |
| | | return findReplicated(server.getReplicas(), baseDN) != null; |
| | | return findReplicaForSuffixDN(server.getReplicas(), baseDN) != null; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private boolean isBaseDNReplicated(ServerDescriptor server1, ServerDescriptor server2, DN baseDN) |
| | | { |
| | | final ReplicaDescriptor replica1 = findReplicated(server1.getReplicas(), baseDN); |
| | | final ReplicaDescriptor replica2 = findReplicated(server2.getReplicas(), baseDN); |
| | | final ReplicaDescriptor replica1 = findReplicaForSuffixDN(server1.getReplicas(), baseDN); |
| | | final ReplicaDescriptor replica2 = findReplicaForSuffixDN(server2.getReplicas(), baseDN); |
| | | if (replica1 != null && replica2 != null) |
| | | { |
| | | Set<String> replServers1 = replica1.getSuffix().getReplicationServers(); |
| | |
| | | return false; |
| | | } |
| | | |
| | | private ReplicaDescriptor findReplicated(Set<ReplicaDescriptor> replicas, DN baseDN) |
| | | private ReplicaDescriptor findReplicaForSuffixDN(Set<ReplicaDescriptor> replicas, DN suffixDN) |
| | | { |
| | | for (ReplicaDescriptor replica : replicas) |
| | | { |
| | | if (replica.getSuffix().getDN().equals(baseDN)) |
| | | if (replica.getSuffix().getDN().equals(suffixDN)) |
| | | { |
| | | return replica; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private Set<DN> findAllReplicasForSuffixDN(Collection<ReplicaDescriptor> replicas) |
| | | { |
| | | Set<DN> results = new HashSet<>(); |
| | | for (ReplicaDescriptor replica : replicas) |
| | | { |
| | | if (replica.isReplicated()) |
| | | { |
| | | results.add(replica.getSuffix().getDN()); |
| | | } |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | private ReplicaDescriptor findReplicated(DN baseDN, ServerDescriptor server) |
| | | { |
| | | for (ReplicaDescriptor replica : server.getReplicas()) |
| | | { |
| | | if (replica.isReplicated() && replica.getSuffix().getDN().equals(baseDN)) |
| | | { |
| | | return replica; |
| | | } |