directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1228186 - in /directory/apacheds/branches/apacheds-osgi: component-hub/src/main/java/org/apache/directory/server/component/hub/ component-hub/src/main/java/org/apache/directory/server/component/utilities/ service-osgi/src/main/java/org/apa...
Date Fri, 06 Jan 2012 13:54:47 GMT
Author: gokturk
Date: Fri Jan  6 13:54:46 2012
New Revision: 1228186

URL: http://svn.apache.org/viewvc?rev=1228186&view=rev
Log:
* EntryNormalizer helper is added to normalize the entries those will be added to raw partitions.
* service-osgi's ApacheDS.class is changed to read DirectoryService configuration earlier
to fetch the replicaId to feed the EntryNormalizer
* ComponentSchemaManager code is changed to use EntryNormalizer on entries before adding them
to SchemaPartition


Added:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/EntryNormalizer.java
  (with props)
Modified:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java
    directory/apacheds/branches/apacheds-osgi/service-osgi/src/main/java/org/apache/directory/server/ApacheDS.java

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java?rev=1228186&r1=1228185&r2=1228186&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
Fri Jan  6 13:54:46 2012
@@ -31,6 +31,7 @@ import org.apache.directory.server.compo
 import org.apache.directory.server.component.utilities.ADSComponentHelper;
 import org.apache.directory.server.component.utilities.ADSConstants;
 import org.apache.directory.server.component.utilities.ADSOSGIEventsHelper;
+import org.apache.directory.server.component.utilities.EntryNormalizer;
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.api.interceptor.Interceptor;
 import org.apache.directory.server.core.api.partition.Partition;

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java?rev=1228186&r1=1228185&r2=1228186&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentSchemaManager.java
Fri Jan  6 13:54:46 2012
@@ -31,6 +31,7 @@ import org.apache.directory.server.compo
 import org.apache.directory.server.component.schema.ComponentSchemaGenerator;
 import org.apache.directory.server.component.schema.DefaultComponentSchemaGenerator;
 import org.apache.directory.server.component.utilities.ADSSchemaConstants;
+import org.apache.directory.server.component.utilities.EntryNormalizer;
 
 import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
@@ -38,12 +39,17 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.api.schema.SchemaPartition;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Value;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.model.ldif.LdifReader;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.directory.shared.ldap.model.name.Ava;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -152,7 +158,9 @@ public class ComponentSchemaManager
 
         for ( LdifEntry le : schemaElements )
         {
-            AddOperationContext addContext = new AddOperationContext( null, le.getEntry()
);
+            Entry normalizedEntry = EntryNormalizer.normalizeEntry( le.getEntry() );
+            AddOperationContext addContext = new AddOperationContext( null, normalizedEntry
);
+
             schemaPartition.add( addContext );
         }
     }
@@ -196,12 +204,15 @@ public class ComponentSchemaManager
     {
         try
         {
-            InputStream is  = this.getClass().getResourceAsStream( "componenthub.ldif" );
-            LdifReader reader = new LdifReader( is );
+            LdifReader reader = new LdifReader( this.getClass().getResourceAsStream( "componenthub.ldif"
) );
 
             for ( LdifEntry le : reader )
             {
-                AddOperationContext addContext = new AddOperationContext( null, le.getEntry()
);
+
+                Entry normalizedEntry = EntryNormalizer.normalizeEntry( le.getEntry() );
+                
+                AddOperationContext addContext = new AddOperationContext( null, normalizedEntry
);
+
                 schemaPartition.add( addContext );
             }
         }

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/EntryNormalizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/EntryNormalizer.java?rev=1228186&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/EntryNormalizer.java
(added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/EntryNormalizer.java
Fri Jan  6 13:54:46 2012
@@ -0,0 +1,71 @@
+package org.apache.directory.server.component.utilities;
+
+
+import java.util.UUID;
+
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.csn.CsnFactory;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.util.DateUtils;
+
+
+/**
+ * Since ComponentHub is accessing raw schema and config partition references.
+ * Entries must be processed as NormalizationInterceptor and OperationalInterceptor do.
+ * This class provides normalization and attribution facilities for ldif formatted entries.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryNormalizer
+{
+    /** SchemaManager reference for normalizing */
+    private static SchemaManager schemaManager;
+    private static CsnFactory csnFactory;
+
+
+    /**
+     * Sets the SchemaManager reference for normalizing.
+     *
+     * @param schemaManager SchemaManager to use in normalizing.
+     */
+    public static void init( SchemaManager schemaManager, int replicaId )
+    {
+        EntryNormalizer.schemaManager = schemaManager;
+        csnFactory = new CsnFactory( replicaId );
+    }
+
+
+    /**
+     * Puts the operational attributes to given entry,
+     * and normalizes its Dn and Attribute names.
+     *
+     * @param entry Entry to be normalized.
+     * @return Normalized entry, null if error occurs.
+     */
+    public static Entry normalizeEntry( Entry entry )
+    {
+        // Put the operational attributes first.
+        entry.put( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+        entry.put( SchemaConstants.ENTRY_CSN_AT, csnFactory.newInstance().toString() );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        // This will cause the Dn and attribute names to be normalized,
+        Entry normalizedEntry;
+        try
+        {
+            normalizedEntry = new DefaultEntry( schemaManager, entry );
+        }
+        catch ( LdapException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+        return normalizedEntry;
+    }
+}

Propchange: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/EntryNormalizer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/apacheds/branches/apacheds-osgi/service-osgi/src/main/java/org/apache/directory/server/ApacheDS.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/service-osgi/src/main/java/org/apache/directory/server/ApacheDS.java?rev=1228186&r1=1228185&r2=1228186&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/service-osgi/src/main/java/org/apache/directory/server/ApacheDS.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/service-osgi/src/main/java/org/apache/directory/server/ApacheDS.java
Fri Jan  6 13:54:46 2012
@@ -36,6 +36,7 @@ import org.apache.directory.server.compo
 import org.apache.directory.server.component.hub.client.HubClientServers;
 import org.apache.directory.server.component.utilities.ADSConstants;
 import org.apache.directory.server.component.utilities.ADSOSGIEventsHelper;
+import org.apache.directory.server.component.utilities.EntryNormalizer;
 import org.apache.directory.server.config.ConfigPartitionReader;
 import org.apache.directory.server.config.LdifConfigExtractor;
 import org.apache.directory.server.config.beans.ConfigBean;
@@ -118,6 +119,9 @@ public class ApacheDS implements EventHa
     /** DirectoryService reference */
     private DirectoryService directoryService;
 
+    /** DirectoryServiceBean reference */
+    private DirectoryServiceBean directoryServiceBean;
+
     /** The SchemaPartition */
     private SchemaPartition schemaPartition;
 
@@ -237,22 +241,30 @@ public class ApacheDS implements EventHa
      */
     private void initiateComponentManagement() throws Exception
     {
+
         // Init SchemaPartition and 'Config Partition' for ComponentHub use.
         initSchemaManagerAndPartition();
         initConfigPartition();
 
-        new Thread(new Runnable()
+        // Read the configuration
+        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
+        ConfigBean configBean = cpReader.readConfig();
+
+        directoryServiceBean = configBean.getDirectoryServiceBean();
+        
+        EntryNormalizer.init( schemaManager, directoryServiceBean.getDsReplicaId() );
+
+        new Thread( new Runnable()
         {
-            
+
             @Override
             public void run()
             {
                 // Create the Component Hub object for component management.
                 componentHub = ComponentHub.createIPojoInstance( instanceDir, schemaPartition,
configPartition );
-                
+
             }
-        }).start();
-        
+        } ).start();
 
         // Instantiate HubClients for Interceptors and Partitions
         interceptorsManager = new HubClientInterceptors();
@@ -340,16 +352,10 @@ public class ApacheDS implements EventHa
 
     private void initDirectoryService() throws Exception
     {
-        // Read the configuration
-        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
-        ConfigBean configBean = cpReader.readConfig();
-
         LOG.info( "Initializing the DirectoryService..." );
 
         long startTime = System.currentTimeMillis();
 
-        DirectoryServiceBean directoryServiceBean = configBean.getDirectoryServiceBean();
-
         // Get the core interceptor and partitions list from HubClients.
         // Core ones must be set at the timt this method is called.
         List<Interceptor> coreInterceptors = interceptorsManager.getCoreInterceptors();



Mime
View raw message