From b4f8838b15342670c31753a484abf0129e3c9653 Mon Sep 17 00:00:00 2001
From: jcduff <jcduff@localhost>
Date: Thu, 23 Oct 2008 14:04:24 +0000
Subject: [PATCH] The commit will bring the following features : - An updated version of the underlying database. BDB JE 3.3 is now used. - Attribute API refactoring providing a better abstraction and offering improved performances. - A new GUI called the Control-Panel to replace the Status-Panel: the specifications for this GUI are available on OpenDS Wiki and contains a link to a mockup. See <https://www.opends.org/wiki/page/ControlPanelUISpecification>. - Some changes in the replication protocol to implement "Assured Replication Mode". The specifications are on OpenDS Wiki at <https://www.opends.org/wiki/page/AssuredMode> and section 7 described some of the replication changes required to support this. Assured Replication is not finished, but the main replication protocol changes to support it are done. As explained by Gilles on an email on the Dev mailing list (http://markmail.org/message/46rgo3meq3vriy4a), with these changes the newer versions of OpenDS may not be able to replicate with OpenDS 1.0 instances. - Support for Service Tags on the platforms where the functionality is available and enabled. Specifications are published at <https://www.opends.org/wiki/page/OpenDSServiceTagEnabled>. For more information on Service Tags see <http://wikis.sun.com/display/ServiceTag/Sun+Service+Tag+FAQ>. - The Admin Connector service. In order to provide agentry of the OpenDS server at any time, a new service has been added, dedicated to the administration, configuration and monitoring of the server. An overview of the Admin Connector service and it's use is available on the OpenDS wiki <https://www.opends.org/wiki/page/ManagingAdministrationTrafficToTheServer> - Updates to the various command line tools to support the Admin Connector service. - Some internal re-architecting of the server to put the foundation of future developments such as virtual directory services. The new NetworkGroups and WorkFlow internal services which have been specified in <https://www.opends.org/wiki/page/BasicOperationRoutingThroughNetworkGroup> are now implemented. - Many bug fixes...
---
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java | 153 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 122 insertions(+), 31 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
index db5dab6..29059ad 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
@@ -35,17 +35,19 @@
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.zip.DataFormatException;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.replication.common.ChangeNumber;
-import org.opends.server.types.AbstractOperation;
import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeBuilder;
+import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.LDAPException;
+import org.opends.server.types.ObjectClass;
import org.opends.server.types.RawAttribute;
import org.opends.server.types.operation.PostOperationAddOperation;
@@ -56,9 +58,8 @@
* This class is used to exchange Add operation between LDAP servers
* and replication servers.
*/
-public class AddMsg extends UpdateMessage
+public class AddMsg extends UpdateMsg
{
- private static final long serialVersionUID = -4905520652801395185L;
private byte[] encodedAttributes;
private String parentUniqueId;
@@ -74,48 +75,87 @@
AddContext ctx = (AddContext) op.getAttachment(SYNCHROCONTEXT);
this.parentUniqueId = ctx.getParentUid();
- // Encode the object classes (SET OF LDAPString).
- LinkedHashSet<AttributeValue> ocValues =
- new LinkedHashSet<AttributeValue>(op.getObjectClasses().size());
- for (String s : op.getObjectClasses().values())
+ this.encodedAttributes =
+ encodeAttributes(op.getObjectClasses(),
+ op.getUserAttributes(),
+ op.getOperationalAttributes());
+ }
+
+ private byte[] encodeAttributes(
+ Map<ObjectClass, String> objectClasses,
+ Map<AttributeType, List<Attribute>> userAttributes,
+ Map<AttributeType, List<Attribute>> operationalAttributes)
+ {
+ // Encode the object classes (SET OF LDAPString).
+ AttributeBuilder builder = new AttributeBuilder(
+ DirectoryServer.getObjectClassAttributeType());
+ builder.setInitialCapacity(objectClasses.size());
+ for (String s : objectClasses.values())
{
- ocValues.add(new AttributeValue(new ASN1OctetString(s),
+ builder.add(new AttributeValue(new ASN1OctetString(s),
new ASN1OctetString(toLowerCase(s))));
}
-
- Attribute attr = new Attribute(
- DirectoryServer.getObjectClassAttributeType(),
- "objectClass", ocValues);
+ Attribute attr = builder.toAttribute();
ArrayList<ASN1Element> elems = new ArrayList<ASN1Element>();
elems.add(new LDAPAttribute(attr).encode());
// Encode the user attributes (AttributeList).
- for (List<Attribute> list : op.getUserAttributes().values())
+ for (List<Attribute> list : userAttributes.values())
{
for (Attribute a : list)
{
- elems.add(new LDAPAttribute(a).encode());
+ if (!a.isVirtual())
+ elems.add(new LDAPAttribute(a).encode());
}
}
// Encode the operational attributes (AttributeList).
- for (List<Attribute> list : op.getOperationalAttributes().values())
+ for (List<Attribute> list : operationalAttributes.values())
{
for (Attribute a : list)
{
- elems.add(new LDAPAttribute(a).encode());
+ if (!a.isVirtual())
+ elems.add(new LDAPAttribute(a).encode());
}
}
// Encode the sequence.
- encodedAttributes = ASN1Element.encodeValue(elems);
+ return ASN1Element.encodeValue(elems);
}
/**
* Creates a new AddMessage.
*
+ * @param cn ChangeNumber of the add.
+ * @param dn DN of the added entry.
+ * @param uniqueId The Unique identifier of the added entry.
+ * @param parentId The unique Id of the parent of the added
+ * entry.
+ * @param objectClasses objectclass of the added entry.
+ * @param userAttributes user attributes of the added entry.
+ * @param operationalAttributes operational attributes of the added entry.
+ */
+ public AddMsg(ChangeNumber cn,
+ String dn,
+ String uniqueId,
+ String parentId,
+ Map<ObjectClass, String> objectClasses,
+ Map<AttributeType,List<Attribute>> userAttributes,
+ Map<AttributeType,List<Attribute>> operationalAttributes)
+ {
+ super (cn, uniqueId, dn);
+ this.parentUniqueId = parentId;
+
+ encodedAttributes = encodeAttributes(objectClasses,
+ userAttributes, operationalAttributes);
+ }
+
+
+ /**
+ * Creates a new AddMessage.
+ *
* @param cn ChangeNumber of the add.
* @param dn DN of the added entry.
* @param uniqueId The Unique identifier of the added entry.
@@ -132,7 +172,7 @@
Collection<Attribute> userAttributes,
Collection<Attribute> operationalAttributes)
{
- super (new AddContext(cn, uniqueId, parentId), dn);
+ super (cn, uniqueId, dn);
this.parentUniqueId = parentId;
ArrayList<ASN1Element> elems = new ArrayList<ASN1Element>();
@@ -158,9 +198,10 @@
public AddMsg(byte[] in) throws DataFormatException,
UnsupportedEncodingException
{
- super(in);
-
- int pos = decodeHeader(MSG_TYPE_ADD_REQUEST, in);
+ byte[] allowedPduTypes = new byte[2];
+ allowedPduTypes[0] = MSG_TYPE_ADD;
+ allowedPduTypes[1] = MSG_TYPE_ADD_V1;
+ int pos = decodeHeader(allowedPduTypes, in);
// read the parent unique Id
int length = getNextLength(in, pos);
@@ -188,7 +229,7 @@
* {@inheritDoc}
*/
@Override
- public AbstractOperation createOperation(
+ public AddOperationBasis createOperation(
InternalClientConnection connection, String newDn)
throws LDAPException, ASN1Exception
{
@@ -212,12 +253,7 @@
}
/**
- * Get the byte[] representation of this Message.
- *
- * @return the byte array representation of this Message.
- *
- * @throws UnsupportedEncodingException When the encoding of the message
- * failed because the UTF-8 encoding is not supported.
+ * {@inheritDoc}
*/
@Override
public byte[] getBytes() throws UnsupportedEncodingException
@@ -235,7 +271,7 @@
}
/* encode the header in a byte[] large enough to also contain the mods */
- byte [] resultByteArray = encodeHeader(MSG_TYPE_ADD_REQUEST, length);
+ byte [] resultByteArray = encodeHeader(MSG_TYPE_ADD, length);
int pos = resultByteArray.length - length;
@@ -258,7 +294,27 @@
@Override
public String toString()
{
- return ("ADD DN=(" + getDn() + ") CN=(" + getChangeNumber() + ")");
+ if (protocolVersion == ProtocolVersion.REPLICATION_PROTOCOL_V1)
+ {
+ return "AddMsg content: " +
+ "\nprotocolVersion: " + protocolVersion +
+ "\ndn: " + dn +
+ "\nchangeNumber: " + changeNumber +
+ "\nuniqueId: " + uniqueId +
+ "\nassuredFlag: " + assuredFlag;
+ }
+ if (protocolVersion == ProtocolVersion.REPLICATION_PROTOCOL_V2)
+ {
+ return "AddMsg content: " +
+ "\nprotocolVersion: " + protocolVersion +
+ "\ndn: " + dn +
+ "\nchangeNumber: " + changeNumber +
+ "\nuniqueId: " + uniqueId +
+ "\nassuredFlag: " + assuredFlag +
+ "\nassuredMode: " + assuredMode +
+ "\nsafeDataLevel: " + safeDataLevel;
+ }
+ return "!!! Unknown version: " + protocolVersion + "!!!";
}
/**
@@ -306,4 +362,39 @@
{
return encodedAttributes.length + 40;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getBytes_V1() throws UnsupportedEncodingException
+ {
+ int length = encodedAttributes.length;
+ byte[] byteParentId = null;
+ if (parentUniqueId != null)
+ {
+ byteParentId = parentUniqueId.getBytes("UTF-8");
+ length += byteParentId.length + 1;
+ }
+ else
+ {
+ length += 1;
+ }
+
+ /* encode the header in a byte[] large enough to also contain the mods */
+ byte [] resultByteArray = encodeHeader_V1(MSG_TYPE_ADD_V1, length);
+
+ int pos = resultByteArray.length - length;
+
+ if (byteParentId != null)
+ pos = addByteArray(byteParentId, resultByteArray, pos);
+ else
+ resultByteArray[pos++] = 0;
+
+ /* put the attributes */
+ for (int i=0; i<encodedAttributes.length; i++,pos++)
+ {
+ resultByteArray[pos] = encodedAttributes[i];
+ }
+ return resultByteArray;
+ }
}
--
Gitblit v1.10.0