dsreplication: code cleanup
- backendName => backendId
- used more DNs
- Added a constructor for SuffixDescriptor
| | |
| | | private int replicationId = -1; |
| | | private int missingChanges = -1; |
| | | private long ageOfOldestMissingChange = -1; |
| | | private String backendName; |
| | | private String backendId; |
| | | private Set<String> objectClasses; |
| | | |
| | | /** |
| | |
| | | * Returns the name of the backend where this replica is defined. |
| | | * @return the name of the backend where this replica is defined. |
| | | */ |
| | | public String getBackendName() |
| | | public String getBackendId() |
| | | { |
| | | return backendName; |
| | | return backendId; |
| | | } |
| | | |
| | | /** |
| | | * Sets the name of the backend where this replica is defined. |
| | | * @param backendName the name of the backend. |
| | | * @param backendId the name of the backend. |
| | | */ |
| | | public void setBackendName(String backendName) |
| | | public void setBackendId(String backendId) |
| | | { |
| | | this.backendName = backendName; |
| | | this.backendId = backendId; |
| | | } |
| | | |
| | | /** |
| | |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | |
| | | { |
| | | SearchResultEntry sr = entryReader.readEntry(); |
| | | |
| | | String id = firstValueAsString(sr, "ds-cfg-backend-id"); |
| | | if (!isConfigBackend(id) || isSchemaBackend(id)) |
| | | String backendId = firstValueAsString(sr, "ds-cfg-backend-id"); |
| | | if (!isConfigBackend(backendId) || isSchemaBackend(backendId)) |
| | | { |
| | | Set<DN> baseDns = asSetOfDN(sr, "ds-cfg-base-dn"); |
| | | |
| | | Set<String> entries; |
| | | if (cacheFilter.searchMonitoringInformation()) |
| | | { |
| | | entries = getBaseDNEntryCount(conn, id); |
| | | entries = getBaseDNEntryCount(conn, backendId); |
| | | } |
| | | else |
| | | { |
| | |
| | | ReplicaDescriptor replica = new ReplicaDescriptor(); |
| | | replica.setServer(desc); |
| | | replica.setObjectClasses(asSetOfString(sr, ConfigConstants.ATTR_OBJECTCLASS)); |
| | | replica.setBackendName(id); |
| | | replica.setBackendId(backendId); |
| | | replica.setSuffix(new SuffixDescriptor(baseDn, replica)); |
| | | replica.setEntries(getNumberOfEntriesForBaseDn(entries, baseDn)); |
| | | |
| | | replicas.add(replica); |
| | | } |
| | | } |
| | | desc.setReplicas(replicas); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | SuffixDescriptor suffix = new SuffixDescriptor(); |
| | | suffix.setDN(baseDn); |
| | | suffix.setReplicas(newHashSet(replica)); |
| | | replica.setSuffix(suffix); |
| | | |
| | | int nEntries = -1; |
| | | private static int getNumberOfEntriesForBaseDn(Set<String> entries, DN baseDn) |
| | | { |
| | | for (String s : entries) |
| | | { |
| | | int index = s.indexOf(" "); |
| | |
| | | { |
| | | try |
| | | { |
| | | nEntries = Integer.parseInt(s.substring(0, index)); |
| | | return Integer.parseInt(s.substring(0, index)); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | replica.setEntries(nEntries); |
| | | } |
| | | } |
| | | desc.setReplicas(replicas); |
| | | } |
| | | } |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | private static boolean isAddReplica(TopologyCacheFilter cacheFilter, DN baseDn) |
| | |
| | | */ |
| | | package org.opends.admin.ads; |
| | | |
| | | import static java.util.Collections.*; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | |
| | | private final Set<ReplicaDescriptor> replicas = new HashSet<>(); |
| | | |
| | | /** |
| | | * Builds a new SuffixDescriptor. |
| | | * |
| | | * @param suffixDn |
| | | * the suffix DN |
| | | * @param replica |
| | | * the replica |
| | | */ |
| | | public SuffixDescriptor(DN suffixDn, ReplicaDescriptor replica) |
| | | { |
| | | this.suffixDN = suffixDn; |
| | | setReplicas(singleton(replica)); |
| | | } |
| | | |
| | | /** |
| | | * Returns the DN associated with this suffix descriptor. |
| | | * |
| | | * @return the DN associated with this suffix descriptor. |
| | |
| | | notifyListeners(getFormattedWithPoints(INFO_PROGRESS_CREATING_REPLICATED_BACKENDS.get())); |
| | | |
| | | // The keys are the backend IDs and the values the list of base DNs. |
| | | final Map<String, Set<String>> hmBackendSuffix = new HashMap<>(); |
| | | final Map<String, Set<DN>> hmBackendSuffix = new HashMap<>(); |
| | | final SuffixesToReplicateOptions suffixData = getUserData().getSuffixesToReplicateOptions(); |
| | | populateBackendsToCreate(hmBackendSuffix, suffixData.getSuffixes()); |
| | | createReplicatedBackends(hmBackendSuffix, suffixData.getSuffixBackendTypes()); |
| | |
| | | * configuration of the other server. The algorithm consists on putting the |
| | | * remote servers in a list and pick the backend as they appear on the list. |
| | | */ |
| | | private void populateBackendsToCreate(Map<String, Set<String>> hmBackendSuffix, Set<SuffixDescriptor> suffixes) |
| | | private void populateBackendsToCreate(Map<String, Set<DN>> hmBackendSuffix, Set<SuffixDescriptor> suffixes) |
| | | { |
| | | Set<ServerDescriptor> serverList = getServerListFromSuffixes(suffixes); |
| | | for (SuffixDescriptor suffix : suffixes) |
| | |
| | | final ReplicaDescriptor replica = retrieveReplicaForSuffix(serverList, suffix); |
| | | if (replica != null) |
| | | { |
| | | final String backendNameKey = getOrAddBackend(hmBackendSuffix, replica.getBackendName()); |
| | | hmBackendSuffix.get(backendNameKey).add(suffix.getDN().toString()); |
| | | final String backendId = getOrAddBackend(hmBackendSuffix, replica.getBackendId()); |
| | | hmBackendSuffix.get(backendId).add(suffix.getDN()); |
| | | } |
| | | } |
| | | } |
| | |
| | | return null; |
| | | } |
| | | |
| | | private String getOrAddBackend(Map<String, Set<String>> hmBackendSuffix, String backendName) |
| | | private String getOrAddBackend(Map<String, Set<DN>> hmBackendSuffix, String backendId) |
| | | { |
| | | for (String storedBackend : hmBackendSuffix.keySet()) |
| | | { |
| | | if (storedBackend.equalsIgnoreCase(backendName)) |
| | | if (storedBackend.equalsIgnoreCase(backendId)) |
| | | { |
| | | return storedBackend; |
| | | } |
| | | } |
| | | hmBackendSuffix.put(backendName, new HashSet<String>()); |
| | | return backendName; |
| | | hmBackendSuffix.put(backendId, new HashSet<DN>()); |
| | | return backendId; |
| | | } |
| | | |
| | | private void createReplicatedBackends(final Map<String, Set<String>> hmBackendSuffix, |
| | | private void createReplicatedBackends(final Map<String, Set<DN>> hmBackendSuffix, |
| | | final Map<String, BackendTypeUIAdapter> backendTypes) throws ApplicationException |
| | | { |
| | | try (ConnectionWrapper connection = createLocalConnection()) |
| | | { |
| | | final InstallerHelper helper = new InstallerHelper(); |
| | | for (String backendName : hmBackendSuffix.keySet()) |
| | | for (String backendId : hmBackendSuffix.keySet()) |
| | | { |
| | | helper.createBackend(connection, backendName, hmBackendSuffix.get(backendName), |
| | | backendTypes.get(backendName).getBackend()); |
| | | helper.createBackend(connection, backendId, hmBackendSuffix.get(backendId), |
| | | backendTypes.get(backendId).getBackend()); |
| | | } |
| | | } |
| | | catch (NamingException e) |
| | |
| | | import org.opends.server.tools.ConfigureDS; |
| | | import org.opends.server.tools.ConfigureWindowsService; |
| | | import org.opends.server.tools.JavaPropertiesTool; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.LDIFExportConfig; |
| | | import org.opends.server.types.OpenDsException; |
| | | import org.opends.server.util.LDIFException; |
| | |
| | | * @throws ApplicationException |
| | | * if something goes wrong. |
| | | */ |
| | | public void createBackend(ConnectionWrapper conn, String backendName, Set<String> baseDNs, |
| | | public void createBackend(ConnectionWrapper conn, String backendName, Set<DN> baseDNs, |
| | | ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType) |
| | | throws ApplicationException |
| | | { |
| | |
| | | RootCfgClient root = conn.getRootConfiguration(); |
| | | BackendCfgClient backend = root.createBackend(backendType, backendName, null); |
| | | backend.setEnabled(true); |
| | | backend.setBaseDN(toDNs(baseDNs)); |
| | | backend.setBaseDN(baseDNs); |
| | | backend.setBackendId(backendName); |
| | | backend.setWritabilityMode(BackendCfgDefn.WritabilityMode.ENABLED); |
| | | backend.commit(); |
| | |
| | | } |
| | | } |
| | | |
| | | private Set<DN> toDNs(Set<String> strings) throws DirectoryException |
| | | { |
| | | Set<DN> results = new HashSet<>(); |
| | | for (String s : strings) |
| | | { |
| | | results.add(DN.valueOf(s)); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | /** |
| | | * Configures the replication on a given server. |
| | | * @param conn the connection to the server where we want to configure |
| | |
| | | final Map<String, BackendTypeUIAdapter> backendTypes = new HashMap<>(); |
| | | for (SuffixDescriptor suffix : getSelectedSuffixes()) |
| | | { |
| | | final String backendName = suffix.getReplicas().iterator().next().getBackendName(); |
| | | backendTypes.put(backendName, (BackendTypeUIAdapter) backendTypeComboBoxes.get(backendName).getSelectedItem()); |
| | | final String backendId = suffix.getReplicas().iterator().next().getBackendId(); |
| | | backendTypes.put(backendId, (BackendTypeUIAdapter) backendTypeComboBoxes.get(backendId).getSelectedItem()); |
| | | } |
| | | return backendTypes; |
| | | } |
| | |
| | | final Map<String, Set<SuffixDescriptor>> backendToSuffixes = new HashMap<>(); |
| | | for (SuffixDescriptor suffix : orderedSuffixes) |
| | | { |
| | | final String backendName = suffix.getReplicas().iterator().next().getBackendName(); |
| | | if (!backendToSuffixes.containsKey(backendName)) |
| | | final String backendId = suffix.getReplicas().iterator().next().getBackendId(); |
| | | if (!backendToSuffixes.containsKey(backendId)) |
| | | { |
| | | backendToSuffixes.put(backendName, new LinkedHashSet<SuffixDescriptor>()); |
| | | backendToSuffixes.put(backendId, new LinkedHashSet<SuffixDescriptor>()); |
| | | } |
| | | backendToSuffixes.get(backendName).add(suffix); |
| | | backendToSuffixes.get(backendId).add(suffix); |
| | | } |
| | | |
| | | return backendToSuffixes; |
| | |
| | | backendTypeComboBox.setToolTipText(INFO_REPLICATED_SUFFIXES_BACKEND_TYPE_TOOLTIP.get().toString()); |
| | | final Set<String> objectClasses = backendData.getObjectClasses(); |
| | | backendTypeComboBox.setSelectedItem(getBackendTypeFromObjectClasses(objectClasses)); |
| | | backendTypeComboBoxes.put(backendData.getBackendName(), backendTypeComboBox); |
| | | backendTypeComboBoxes.put(backendData.getBackendId(), backendTypeComboBox); |
| | | checkBoxPanel.add(backendTypeComboBox, gbc); |
| | | gbc.insets = SUFFIXES_TO_REPLICATE_INSETS; |
| | | } |
| | |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | import static java.util.Collections.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | |
| | | { |
| | | for (BaseDNDescriptor baseDN : backend.getBaseDns()) |
| | | { |
| | | SuffixDescriptor suffix = new SuffixDescriptor(); |
| | | suffix.setDN(baseDN.getDn()); |
| | | |
| | | ReplicaDescriptor replica = new ReplicaDescriptor(); |
| | | |
| | | if (baseDN.getType() == BaseDNDescriptor.Type.REPLICATED) |
| | | { |
| | | replica.setReplicationId(baseDN.getReplicaID()); |
| | | } |
| | | else |
| | | { |
| | | replica.setReplicationId(-1); |
| | | } |
| | | replica.setBackendName(backend.getBackendID()); |
| | | replica.setSuffix(suffix); |
| | | suffix.setReplicas(singleton(replica)); |
| | | replica.setReplicationId( |
| | | baseDN.getType() == BaseDNDescriptor.Type.REPLICATED ? baseDN.getReplicaID() : -1); |
| | | replica.setBackendId(backend.getBackendID()); |
| | | replica.setSuffix(new SuffixDescriptor(baseDN.getDn(), replica)); |
| | | |
| | | replicas.add(replica); |
| | | } |