You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/04/03 07:01:51 UTC
svn commit: r525035 - in /directory/apacheds/branches/1.5-pre-release:
bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/
core-unit/src/main/java/org/apache/directory/server/core/unit/
core-unit/src/test/java/org/ap...
Author: akarasulu
Date: Mon Apr 2 22:01:50 2007
New Revision: 525035
URL: http://svn.apache.org/viewvc?view=rev&rev=525035
Log:
Fix for DIRSERVER-893: schema changes should now persist across restarts
Added:
directory/apacheds/branches/1.5-pre-release/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceITest.java (with props)
Modified:
directory/apacheds/branches/1.5-pre-release/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
directory/apacheds/branches/1.5-pre-release/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
directory/apacheds/branches/1.5-pre-release/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
directory/apacheds/branches/1.5-pre-release/mitosis/ (props changed)
Modified: directory/apacheds/branches/1.5-pre-release/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.5-pre-release/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java?view=diff&rev=525035&r1=525034&r2=525035
==============================================================================
--- directory/apacheds/branches/1.5-pre-release/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java (original)
+++ directory/apacheds/branches/1.5-pre-release/bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java Mon Apr 2 22:01:50 2007
@@ -42,7 +42,8 @@
public class DbFileListing
{
Map<String, DbFileType> name2type = new HashMap<String, DbFileType>();
- private static final String BASE_PATH = DbFileListing.class.getName().substring( 0, DbFileListing.class.getName().lastIndexOf( "." ) + 1 ).replace( '.', '/' );
+ private static final String BASE_PATH = DbFileListing.class.getName()
+ .substring( 0, DbFileListing.class.getName().lastIndexOf( "." ) + 1 ).replace( '.', '/' );
public DbFileListing() throws IOException
Modified: directory/apacheds/branches/1.5-pre-release/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.5-pre-release/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java?view=diff&rev=525035&r1=525034&r2=525035
==============================================================================
--- directory/apacheds/branches/1.5-pre-release/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java (original)
+++ directory/apacheds/branches/1.5-pre-release/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java Mon Apr 2 22:01:50 2007
@@ -43,6 +43,7 @@
import org.apache.directory.server.core.configuration.Configuration;
import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
import org.apache.directory.server.core.configuration.ShutdownConfiguration;
+import org.apache.directory.server.core.configuration.SyncConfiguration;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.ldif.Entry;
import org.apache.directory.shared.ldap.ldif.LdifReader;
@@ -217,6 +218,17 @@
registries = DirectoryService.getInstance().getConfiguration().getRegistries();
}
+
+ /**
+ * Restarts the server without loading data when it has been shutdown.
+ */
+ protected void restart() throws NamingException
+ {
+ configuration = new MutableStartupConfiguration();
+ configuration.setShutdownHookEnabled( false );
+ setContextRoots( username, password, configuration );
+ }
+
/**
* Deletes the Eve working directory.
@@ -310,14 +322,10 @@
/**
- * Sets the system context root to null.
- *
- * @see junit.framework.TestCase#tearDown()
+ * Issues a shutdown request to the server.
*/
- protected void tearDown() throws Exception
+ protected void shutdown()
{
- super.tearDown();
-
Hashtable<String,Object> env = new Hashtable<String,Object>();
env.put( Context.PROVIDER_URL, "ou=system" );
@@ -333,9 +341,45 @@
}
catch ( Exception e )
{
- }
+ }
sysRoot = null;
Runtime.getRuntime().gc();
+ }
+
+
+ /**
+ * Issues a sync request to the server.
+ */
+ protected void sync()
+ {
+ Hashtable<String,Object> env = new Hashtable<String,Object>();
+
+ env.put( Context.PROVIDER_URL, "ou=system" );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.directory.server.core.jndi.CoreContextFactory" );
+ env.putAll( new SyncConfiguration().toJndiEnvironment() );
+ env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+
+ try
+ {
+ new InitialContext( env );
+ }
+ catch ( Exception e )
+ {
+ }
+ }
+
+
+ /**
+ * Sets the system context root to null.
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ shutdown();
testEntries.clear();
ldifPath = null;
loadClass = null;
Added: directory/apacheds/branches/1.5-pre-release/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.5-pre-release/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceITest.java?view=auto&rev=525035
==============================================================================
--- directory/apacheds/branches/1.5-pre-release/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceITest.java (added)
+++ directory/apacheds/branches/1.5-pre-release/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceITest.java Mon Apr 2 22:01:50 2007
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.core.schema;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.core.unit.AbstractAdminTestCase;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.parser.AttributeTypeDescriptionSchemaParser;
+
+
+/**
+ * An integration test class for testing persistence for various operations
+ * on the subschemaSubentry with server restarts.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SchemaPersistenceITest extends AbstractAdminTestCase
+{
+ private static final String SUBSCHEMA_SUBENTRY = "subschemaSubentry";
+ private static final AttributeTypeDescriptionSchemaParser attributeTypeDescriptionSchemaParser =
+ new AttributeTypeDescriptionSchemaParser();
+
+
+ /**
+ * Tests to see if an attributeType is persisted when added, then server
+ * is shutdown, then restarted again.
+ */
+ public void testAddAttributeTypePersistence() throws Exception
+ {
+ enableSchema( "nis" );
+ List<String> descriptions = new ArrayList<String>();
+
+ // -------------------------------------------------------------------
+ // test successful add with everything
+ // -------------------------------------------------------------------
+
+ modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "attributeTypes" );
+
+ descriptions.clear();
+ descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'type0' " +
+ "OBSOLETE SUP 2.5.4.41 " +
+ "EQUALITY caseExactIA5Match " +
+ "ORDERING octetStringOrderingMatch " +
+ "SUBSTR caseExactIA5SubstringsMatch COLLECTIVE " +
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 " +
+ "SINGLE-VALUE USAGE userApplications X-SCHEMA 'nis' )" );
+ descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'type1' 'altName' ) " +
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 " +
+ "NO-USER-MODIFICATION USAGE directoryOperation X-SCHEMA 'nis' )" );
+
+ modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+
+ // sync operation happens anyway on shutdowns but just to make sure we can do it again
+ super.sync();
+
+ super.shutdown();
+ super.restart();
+
+ AttributesImpl attrs = new AttributesImpl( "objectClass", "metaSchema" );
+ attrs.put( "cn", "blah" );
+ schemaRoot.createSubcontext( "cn=blah", attrs );
+
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+ checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+ }
+
+
+ // -----------------------------------------------------------------------
+ // Private Utility Methods
+ // -----------------------------------------------------------------------
+
+
+ private void modify( int op, List<String> descriptions, String opAttr ) throws Exception
+ {
+ LdapDN dn = new LdapDN( getSubschemaSubentryDN() );
+ Attribute attr = new AttributeImpl( opAttr );
+ for ( String description : descriptions )
+ {
+ attr.add( description );
+ }
+
+ Attributes mods = new AttributesImpl();
+ mods.put( attr );
+
+ rootDSE.modifyAttributes( dn, op, mods );
+ }
+
+
+ private void enableSchema( String schemaName ) throws NamingException
+ {
+ // now enable the test schema
+ ModificationItemImpl[] mods = new ModificationItemImpl[1];
+ Attribute attr = new AttributeImpl( "m-disabled", "FALSE" );
+ mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+ super.schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
+ }
+
+
+ /**
+ * Get's the subschemaSubentry attribute value from the rootDSE.
+ *
+ * @return the subschemaSubentry distinguished name
+ * @throws NamingException if there are problems accessing the RootDSE
+ */
+ private String getSubschemaSubentryDN() throws NamingException
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ controls.setReturningAttributes( new String[]{ SUBSCHEMA_SUBENTRY } );
+
+ NamingEnumeration<SearchResult> results = rootDSE.search( "", "(objectClass=*)", controls );
+ SearchResult result = results.next();
+ results.close();
+ Attribute subschemaSubentry = result.getAttributes().get( SUBSCHEMA_SUBENTRY );
+ return ( String ) subschemaSubentry.get();
+ }
+
+
+ /**
+ * Gets the subschemaSubentry attributes for the global schema.
+ *
+ * @return all operational attributes of the subschemaSubentry
+ * @throws NamingException if there are problems accessing this entry
+ */
+ private Attributes getSubschemaSubentryAttributes() throws NamingException
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ controls.setReturningAttributes( new String[]{ "+", "*" } );
+
+ NamingEnumeration<SearchResult> results = rootDSE.search( getSubschemaSubentryDN(),
+ "(objectClass=*)", controls );
+ SearchResult result = results.next();
+ results.close();
+ return result.getAttributes();
+ }
+
+
+ private void checkAttributeTypePresent( String oid, String schemaName, boolean isPresent ) throws Exception
+ {
+ // -------------------------------------------------------------------
+ // check first to see if it is present in the subschemaSubentry
+ // -------------------------------------------------------------------
+
+ Attributes attrs = getSubschemaSubentryAttributes();
+ Attribute attrTypes = attrs.get( "attributeTypes" );
+ AttributeTypeDescription attributeTypeDescription = null;
+ for ( int ii = 0; ii < attrTypes.size(); ii++ )
+ {
+ String desc = ( String ) attrTypes.get( ii );
+ if ( desc.indexOf( oid ) != -1 )
+ {
+ attributeTypeDescription = attributeTypeDescriptionSchemaParser.parseAttributeTypeDescription( desc );
+ break;
+ }
+ }
+
+ if ( isPresent )
+ {
+ assertNotNull( attributeTypeDescription );
+ assertEquals( oid, attributeTypeDescription.getNumericOid() );
+ }
+ else
+ {
+ assertNull( attributeTypeDescription );
+ }
+
+ // -------------------------------------------------------------------
+ // check next to see if it is present in the schema partition
+ // -------------------------------------------------------------------
+
+ attrs = null;
+
+ if ( isPresent )
+ {
+ attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=attributeTypes,cn=" + schemaName );
+ assertNotNull( attrs );
+ }
+ else
+ {
+ try
+ {
+ attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=attributeTypes,cn=" + schemaName );
+ fail( "should never get here" );
+ }
+ catch( NamingException e )
+ {
+ }
+ assertNull( attrs );
+ }
+
+ // -------------------------------------------------------------------
+ // check to see if it is present in the attributeTypeRegistry
+ // -------------------------------------------------------------------
+
+ if ( isPresent )
+ {
+ assertTrue( registries.getAttributeTypeRegistry().hasAttributeType( oid ) );
+ }
+ else
+ {
+ assertFalse( registries.getAttributeTypeRegistry().hasAttributeType( oid ) );
+ }
+ }
+}
Propchange: directory/apacheds/branches/1.5-pre-release/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceITest.java
------------------------------------------------------------------------------
svn:executable = *
Modified: directory/apacheds/branches/1.5-pre-release/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.5-pre-release/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?view=diff&rev=525035&r1=525034&r2=525035
==============================================================================
--- directory/apacheds/branches/1.5-pre-release/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/1.5-pre-release/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Mon Apr 2 22:01:50 2007
@@ -20,6 +20,7 @@
package org.apache.directory.server.core;
+import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;
@@ -57,6 +58,7 @@
import org.apache.directory.server.schema.bootstrap.CoreSchema;
import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.bootstrap.SystemSchema;
+import org.apache.directory.server.schema.bootstrap.partition.DbFileListing;
import org.apache.directory.server.schema.bootstrap.partition.SchemaPartitionExtractor;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.server.schema.registries.DefaultOidRegistry;
@@ -66,6 +68,7 @@
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException;
import org.apache.directory.shared.ldap.exception.LdapConfigurationException;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
import org.apache.directory.shared.ldap.ldif.Entry;
import org.apache.directory.shared.ldap.message.AttributeImpl;
@@ -806,17 +809,21 @@
// If not present extract schema partition from jar
// --------------------------------------------------------------------
- SchemaPartitionExtractor extractor = null;
- try
- {
- extractor = new SchemaPartitionExtractor( startupConfiguration.getWorkingDirectory() );
- extractor.extract();
- }
- catch ( IOException e )
+ File schemaDirectory = new File( startupConfiguration.getWorkingDirectory(), "schema" );
+ SchemaPartitionExtractor extractor = null;
+ if ( ! schemaDirectory.exists() )
{
- NamingException ne = new NamingException( "Failed to extract pre-loaded schema partition." );
- ne.setRootCause( e );
- throw ne;
+ try
+ {
+ extractor = new SchemaPartitionExtractor( startupConfiguration.getWorkingDirectory() );
+ extractor.extract();
+ }
+ catch ( IOException e )
+ {
+ NamingException ne = new NamingException( "Failed to extract pre-loaded schema partition." );
+ ne.setRootCause( e );
+ throw ne;
+ }
}
// --------------------------------------------------------------------
@@ -826,7 +833,19 @@
MutablePartitionConfiguration schemaPartitionConfig = new MutablePartitionConfiguration();
schemaPartitionConfig.setName( "schema" );
schemaPartitionConfig.setCacheSize( 1000 );
- schemaPartitionConfig.setIndexedAttributes( extractor.getDbFileListing().getIndexedAttributes() );
+
+ DbFileListing listing = null;
+ try
+ {
+ listing = new DbFileListing();
+ }
+ catch( IOException e )
+ {
+ throw new LdapNamingException( "Got IOException while trying to read DBFileListing: " + e.getMessage(),
+ ResultCodeEnum.OTHER );
+ }
+
+ schemaPartitionConfig.setIndexedAttributes( listing.getIndexedAttributes() );
schemaPartitionConfig.setOptimizerEnabled( true );
schemaPartitionConfig.setSuffix( "ou=schema" );
Propchange: directory/apacheds/branches/1.5-pre-release/mitosis/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Apr 2 22:01:50 2007
@@ -1,4 +1,5 @@
*.iml
+*.log
target
.classpath
.project