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

gbellato
20.46.2007 7cd71b6b2385b5bdd7bd3d845a56468c1fa16af2
small improvement in the replication monitoring

The replication monitoring was showing information for
- the replication domains
- the remote LDAP servers connected to the replication server
- the remote replication server connected to the replication server

but does not show any information for a local replication server.
A replication server that is started but does not have any server connected yet
therefore does not publish any monitoring information.

This changes add a new monitoring entry that fixes this lack and also change the names
of the monitoring entries of the server connected to the replication server to include the
"remote" keyword.

As an example, the monitoring information of a server that is also its replication server now looks like this :

dn: cn=Replication Server 8989 1,cn=monitor
objectClass: extensibleObject
objectClass: top
objectClass: ds-monitor-entry
replication server id: 1
replication server port: 8989
base-dn: dc=example,dc=com
cn: Replication Server 8989 1

dn: cn=Replication plugin dc=example\,dc=com,cn=monitor
objectClass: extensibleObject
objectClass: top
objectClass: ds-monitor-entry
lost-connections: 0
connected-to: localhost/127.0.0.1:8989
resolved-naming-conflicts: 0
replayed-updates: 0
base-dn: dc=example,dc=com
unresolved-naming-conflicts: 0
max-send-window: 100
max-rcv-window: 100
resolved-modify-conflicts: 0
current-send-window: 100
cn: Replication plugin dc=example,dc=com
pending-updates: 0
sent-updates: 0
received-updates: 0
current-rcv-window: 100
replayed-updates-ok: 0

dn: cn=Remote LDAP Server dc=example\,dc=com furon 1,cn=monitor
objectClass: extensibleObject
objectClass: top
objectClass: ds-monitor-entry
approximate-delay: 0
max-waiting-changes: 10000
update-sent: 0
waiting-changes: 0
update-received: 0
base-dn: dc=example,dc=com
update-waiting-acks: 0
max-send-window: 100
ack-received: 0
max-rcv-window: 100
current-send-window: 100
cn: Remote LDAP Server dc=example,dc=com furon 1
server-id: 1
LDAP-Server: furon
current-rcv-window: 100
ack-sent: 0
2 files added
2 files modified
258 ■■■■ changed files
opends/src/server/org/opends/server/replication/server/ReplicationServer.java 119 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServerConnectThread.java 68 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServerListenThread.java 67 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ServerHandler.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -41,17 +41,22 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.opends.server.admin.server.ConfigurationChangeListener;
import org.opends.server.admin.std.server.ReplicationServerCfg;
import org.opends.server.api.ConfigurableComponent;
import org.opends.server.api.DirectoryThread;
import org.opends.server.api.MonitorProvider;
import org.opends.server.config.ConfigAttribute;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.replication.protocol.SocketSession;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.ConfigChangeResult;
import org.opends.server.types.DN;
import org.opends.server.types.ErrorLogCategory;
@@ -70,7 +75,7 @@
 *
 * It is responsible for creating the replication server cache and managing it
 */
public class ReplicationServer
public class ReplicationServer extends MonitorProvider
  implements Runnable, ConfigurableComponent,
             ConfigurationChangeListener<ReplicationServerCfg>
{
@@ -81,8 +86,6 @@
  private Thread myListenThread;
  private Thread myConnectThread;
  private boolean runListen = true;
  /* The list of replication servers configured by the administrator */
  private Collection<String> replicationServers;
@@ -115,8 +118,9 @@
  public ReplicationServer(ReplicationServerCfg configuration)
         throws ConfigException
  {
    super("Replication Server" + configuration.getReplicationPort());
    shutdown = false;
    runListen = true;
    replicationPort = configuration.getReplicationPort();
    replicationServerId = (short) configuration.getReplicationServerId();
    replicationServers = configuration.getReplicationServer();
@@ -148,6 +152,7 @@
    initialize(replicationServerId, replicationPort);
    configuration.addChangeListener(this);
    configDn = configuration.dn();
    DirectoryServer.registerMonitorProvider(this);
  }
  /**
@@ -186,20 +191,6 @@
    return null;
  }
  /**
   * spawn the listen thread and the connect thread.
   * Used a a workaround because there can be only one run method
   */
  public void run()
  {
    if (runListen)
    {
      runListen = false;
      runListen();
    }
    else
      runConnect();
  }
  /**
   * The run method for the Listen thread.
@@ -208,7 +199,7 @@
   * and spawn further thread responsible for handling those connections
   */
  private void runListen()
  void runListen()
  {
    Socket newSocket = null;
    while (shutdown == false)
@@ -240,7 +231,7 @@
   * to all the other replication servers and if not attempts to
   * make the connection.
   */
  private void runConnect()
  void runConnect()
  {
    while (shutdown == false)
    {
@@ -368,9 +359,11 @@
      /*
       * create working threads
       */
      myListenThread = new DirectoryThread(this, "Replication Server Listener");
      myListenThread =
        new ReplicationServerListenThread("Replication Server Listener", this);
      myListenThread.start();
      myConnectThread = new DirectoryThread(this, "Replication Server Connect");
      myConnectThread =
        new ReplicationServerConnectThread("Replication Server Connect", this);
      myConnectThread.start();
    } catch (DatabaseException e)
@@ -407,7 +400,7 @@
   * @param baseDn The base Dn for which the ReplicationCache must be returned.
   * @return The ReplicationCache associated to the base DN given in parameter.
   */
  public ReplicationCache getReplicationCache(DN baseDn)
  ReplicationCache getReplicationCache(DN baseDn)
  {
    ReplicationCache replicationCache;
@@ -455,6 +448,7 @@
    }
    dbEnv.shutdown();
    DirectoryServer.deregisterMonitorProvider(getMonitorInstanceName());
  }
@@ -468,7 +462,7 @@
   *         DN given in parameter.
   * @throws DatabaseException in case of underlying database problem.
   */
  public DbHandler newDbHandler(short id, DN baseDn) throws DatabaseException
  DbHandler newDbHandler(short id, DN baseDn) throws DatabaseException
  {
    return new DbHandler(id, baseDn, this, dbEnv);
  }
@@ -480,7 +474,7 @@
   * @return  The time after which changes must be deleted from the
   *          persistent storage (in milliseconds).
   */
  public long getTrimage()
  long getTrimage()
  {
    return trimAge * 1000;
  }
@@ -535,4 +529,77 @@
  {
    return true;
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void initializeMonitorProvider(ConfigEntry configEntry)
  {
    // Nothing to do for now
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public String getMonitorInstanceName()
  {
    return "Replication Server " + this.replicationPort + " "
           + replicationServerId;
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public long getUpdateInterval()
  {
    /* we don't wont to do polling on this monitor */
    return 0;
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void updateMonitorData()
  {
    // As long as getUpdateInterval() returns 0, this will never get called
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public ArrayList<Attribute> getMonitorData()
  {
    /*
     * publish the server id and the port number.
     */
    ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(new Attribute("replication server id",
        String.valueOf(serverId)));
    attributes.add(new Attribute("replication server port",
        String.valueOf(replicationPort)));
    /*
     * Add all the base DNs that are known by this replication server.
     */
    AttributeType baseType=
      DirectoryServer.getAttributeType("base-dn", true);
    LinkedHashSet<AttributeValue> baseValues =
      new LinkedHashSet<AttributeValue>();
    for (DN base : baseDNs.keySet())
    {
      baseValues.add(new AttributeValue(baseType, base. toString()));
    }
    Attribute bases = new Attribute(baseType, "base-dn", baseValues);
    attributes.add(bases);
    return attributes;
  }
}
opends/src/server/org/opends/server/replication/server/ReplicationServerConnectThread.java
New file
@@ -0,0 +1,68 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2007 Sun Microsystems, Inc.
 */
package org.opends.server.replication.server;
import org.opends.server.api.DirectoryThread;
/**
 * This Class is used to create a thread that is responsible for
 * opening connection from this replication server to the other
 * Replication Servers.
 */
public class ReplicationServerConnectThread extends DirectoryThread
{
  /**
   * The Replication Server that created this thread.
   */
  private ReplicationServer server;
  /**
   * Creates a new instance of this directory thread with the
   * specified name.
   *
   * @param  threadName  The human-readable name to use for this
   *                     thread for debugging purposes.
   * @param  server      The ReplicationServer that will be called to
   *                     handle the connections.
   */
  public ReplicationServerConnectThread(
      String threadName, ReplicationServer server)
  {
    super(threadName);
    this.server = server;
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void run()
  {
    server.runConnect();
  }
}
opends/src/server/org/opends/server/replication/server/ReplicationServerListenThread.java
New file
@@ -0,0 +1,67 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2007 Sun Microsystems, Inc.
 */
package org.opends.server.replication.server;
import org.opends.server.api.DirectoryThread;
/**
 * This Class is used to create a thread that is responsible for listening
 * on the Replication Server thread and accept new incomng connections
 * from other replication servers or from LDAP servers.
 */
public class ReplicationServerListenThread extends DirectoryThread
{
  /**
   * The Replication Server that created this thread.
   */
  private ReplicationServer server;
  /**
   * Creates a new instance of this directory thread with the
   * specified name.
   *
   * @param  threadName  The human-readable name to use for this
   *                     thread for debugging purposes.
   * @param  server      The ReplicationServer that will be called to
   *                     handle the connections.
   */
  public ReplicationServerListenThread(
      String threadName, ReplicationServer server)
  {
    super(threadName);
    this.server = server;
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void run()
  {
    server.runListen();
  }
}
opends/src/server/org/opends/server/replication/server/ServerHandler.java
@@ -1137,9 +1137,9 @@
                 " " + serverURL + " " + String.valueOf(serverId);
    if (serverIsLDAPserver)
      return "LDAP Server " + str;
      return "Remote LDAP Server " + str;
    else
      return "Replication Server " + str;
      return "Remote Replication Server " + str;
  }
  /**