mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Fabio Pistolesi
25.29.2016 73858cdc49e11e8c20767ea2a66d566142956d4b
Add Partition as representation of a distributed service from discovery mechanisms
1 files added
1 files modified
162 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/discovery/Partition.java 148 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/discovery/ServiceDiscoveryMechanism.java 14 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/discovery/Partition.java
New file
@@ -0,0 +1,148 @@
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2016 ForgeRock AS.
 */
package org.opends.server.discovery;
import static org.forgerock.util.Utils.*;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.forgerock.util.Options;
import org.forgerock.util.Reject;
import org.opends.server.types.HostPort;
/**
 * Named set of servers defining a distributed service.
 *
 * A distribution load balancer expects data to be split up into shards referred to as "partitions",
 * each partition exposing the same set of naming contexts, but only a sub-set of the data.
 * For example, a distribution might have two partitions, the first containing all users whose name begins with A-M,
 * and the second containing all users whose name begins with N-Z.
 * Both partitions have the same naming contexts, e.g:
 *              dc=example,dc=com - unsharded parent naming context replicated across all servers.
 *                                  Contains data common to all partitions, such as ACIs, groups, etc
 *    ou=people,dc=example,dc=com - sharded naming context whose content (the users) is split up according
 *                                  to some function, e.g. consistent hashing.
 *
 * @see ServiceDiscoveryMechanism#getPartitions(Collection)
 */
public final class Partition
{
  /** A server from a partition. */
  public static class Server
  {
    private final HostPort hostPort;
    /** Connection options for ConnectionFactory. */
    private final Options options;
    /**
     * Builds a server for a partition.
     * @param hostPort
     *          the host and port to use when contacting the server
     * @param options
     *          the connection options to use for connecting to the server
     */
    Server(HostPort hostPort, Options options)
    {
      Reject.ifNull(hostPort);
      this.hostPort = hostPort;
      this.options = Options.unmodifiableCopyOf(options);
    }
    @Override
    public final int hashCode()
    {
      return hostPort.hashCode();
    }
    @Override
    public final boolean equals(Object obj)
    {
      if (this == obj)
      {
        return true;
      }
      if (!(obj instanceof Server))
      {
        return false;
      }
      return hostPort.equals(((Server) obj).getHostPort());
    }
    /**
     * Returns the host port for this server.
     *
     * @return the host port for this server
     */
    public final HostPort getHostPort()
    {
      return hostPort;
    }
    /**
     * Return the connections options for this server.
     *
     * @return the connections options for this server.
     */
    public final Options getOptions()
    {
      return options;
    }
  }
  private final String partitionId;
  private final Set<Server> primaryServers;
  private final Set<Server> secondaryServers;
  Partition(String partitionId, Collection<Server> primaryServers, Collection<Server> secondaryServers)
  {
    this.partitionId = partitionId;
    this.primaryServers = Collections.unmodifiableSet(new LinkedHashSet<>(primaryServers));
    this.secondaryServers = Collections.unmodifiableSet(new LinkedHashSet<>(secondaryServers));
  }
  /**
   * Returns the set of primary server to use.
   *
   * @return the set of primary server to use.
   */
  public Set<Server> getPrimaryServers()
  {
    return primaryServers;
  }
  /**
   * Returns the set of fallback servers to use.
   *
   * @return the set of fallback servers to use
   */
  public Set<Server> getSecondaryServers()
  {
    return secondaryServers;
  }
  /**
   * Returns the ID for the partition.
   *
   * @return the ID for the partition
   */
  public String getPartitionId()
  {
    return partitionId;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/discovery/ServiceDiscoveryMechanism.java
@@ -16,10 +16,13 @@
package org.opends.server.discovery;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.server.config.server.ServiceDiscoveryMechanismCfg;
import org.opends.server.core.ServerContext;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
 * Maintains a set of {@code Partition}s keeping it up to date according to a specific
@@ -76,4 +79,15 @@
   * @param listener the listener to de-register
   */
  void deregisterChangeListener(ServiceDiscoveryChangeListener listener);
  /**
   * Returns the list of partitions.
   * Each @see Partition will only contain servers that are known to expose the provided list of base DNs.
   * An empty list of base DNs will result in all partitions and all servers being returned.
   * In other words, an empty list of base DNs implies that all servers contain exactly the same base DNs.
   *
   * @param baseDNs the baseDNs for which to retrieve the partitions
   * @return the partitions that can serve the provided base DNs
   */
  Set<Partition> getPartitions(Collection<DN> baseDNs);
}