Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 46758 invoked from network); 8 Dec 2009 15:01:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Dec 2009 15:01:47 -0000 Received: (qmail 67431 invoked by uid 500); 8 Dec 2009 15:01:47 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 67369 invoked by uid 500); 8 Dec 2009 15:01:47 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 67360 invoked by uid 99); 8 Dec 2009 15:01:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Dec 2009 15:01:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Dec 2009 15:01:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C06652388998; Tue, 8 Dec 2009 15:01:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r888423 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/... Date: Tue, 08 Dec 2009 15:01:15 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091208150115.C06652388998@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Tue Dec 8 15:01:15 2009 New Revision: 888423 URL: http://svn.apache.org/viewvc?rev=888423&view=rev Log: o Implemented the disable( Schema... ) method o Added some test for this method o Fixed some methods signature Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=888423&r1=888422&r2=888423&view=diff ============================================================================== --- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java (original) +++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java Tue Dec 8 15:01:15 2009 @@ -212,6 +212,32 @@ } + /** + * Delete all the schemaObjects for a given schema from the registries + */ + private void deleteSchemaObjects( Schema schema, Registries registries ) throws Exception + { + Map> schemaObjects = registries.getObjectBySchemaName(); + Set content = schemaObjects.get( StringTools.toLowerCase( schema.getSchemaName() ) ); + + List toBeDeleted = new ArrayList(); + + // Buid an intermediate list to avoid concurrent modifications + for ( SchemaObjectWrapper schemaObjectWrapper : content ) + { + toBeDeleted.add( schemaObjectWrapper.get() ); + } + + for ( SchemaObject schemaObject : toBeDeleted ) + { + registries.delete( errors, schemaObject ); + } + + // TODO Add some listener handling at this point + //notifyListenerOrRegistries( schema, registries ); + } + + //----------------------------------------------------------------------- // API methods //----------------------------------------------------------------------- @@ -251,20 +277,68 @@ /** * {@inheritDoc} */ - public boolean disable( Schema... schemas ) + public boolean disable( Schema... schemas ) throws Exception { - // TODO Auto-generated method stub - return false; + boolean disabled = false; + + // Reset the errors if not null + if ( errors != null ) + { + errors.clear(); + } + + // Work on a cloned and relaxed registries + Registries clonedRegistries = cloneRegistries(); + clonedRegistries.setRelaxed(); + + for ( Schema schema : schemas ) + { + unload( clonedRegistries, schema ); + } + + // Build the cross references + errors = clonedRegistries.buildReferences(); + + // Destroy the clonedRegistry + clonedRegistries.clear(); + + if ( errors.isEmpty() ) + { + // Ok no errors. Check the registries now + errors = clonedRegistries.checkRefInteg(); + + if ( errors.isEmpty() ) + { + // We are golden : let's apply the schemas in the real registries + for ( Schema schema : schemas ) + { + unload( registries, schema ); + schema.disable(); + } + + // Build the cross references + errors = registries.buildReferences(); + registries.setStrict(); + + disabled = true; + } + } + + // clear the cloned registries + clonedRegistries.clear(); + + return disabled; } /** * {@inheritDoc} */ - public boolean disable( String... schemas ) + public boolean disable( String... schemaNames ) throws Exception { - // TODO Auto-generated method stub - return false; + Schema[] schemas = toArray( schemaNames ); + + return disable( schemas ); } @@ -368,9 +442,10 @@ /** * {@inheritDoc} */ - public boolean enable( String... schemas ) throws Exception + public boolean enable( String... schemaNames ) throws Exception { - return enable( toArray( schemas ) ); + Schema[] schemas = toArray( schemaNames ); + return enable( schemas ); } @@ -501,9 +576,11 @@ /** * {@inheritDoc} */ - public boolean load( String... schemas ) throws Exception + public boolean load( String... schemaNames ) throws Exception { - return load( toArray( schemas ) ); + Schema[] schemas = toArray( schemaNames ); + + return load( schemas ); } @@ -559,6 +636,42 @@ /** + * Unload the schema from the registries. We will unload everything accordingly to the two flags : + * - isRelaxed + * - disabledAccepted + * + * @param registries + * @param schemas + * @return + * @throws Exception + */ + private boolean unload( Registries registries, Schema schema ) throws Exception + { + if ( schema == null ) + { + LOG.info( "The schema is null" ); + return false; + } + + // First avoid unloading twice the same schema + if ( !registries.isSchemaLoaded( schema.getSchemaName() ) ) + { + return true; + } + + if ( schema.isEnabled() ) + { + LOG.info( "Unloading {} schema: \n{}", schema.getSchemaName(), schema ); + + deleteSchemaObjects( schema, registries ); + registries.schemaUnloaded( schema ); + } + + return true; + } + + + /** * Add all the Schema's AttributeTypes */ private void addAttributeTypes( Schema schema, Registries registries ) throws Exception @@ -791,9 +904,11 @@ /** * {@inheritDoc} */ - public boolean loadDisabled( String... schemas ) throws Exception + public boolean loadDisabled( String... schemaNames ) throws Exception { - return loadDisabled( toArray( schemas ) ); + Schema[] schemas = toArray( schemaNames ); + + return loadDisabled( schemas ); } @@ -810,9 +925,9 @@ /** * {@inheritDoc} */ - public boolean loadRelaxed( String... schemas ) throws Exception + public boolean loadRelaxed( String... schemaNames ) throws Exception { - // TODO Auto-generated method stub + Schema[] schemas = toArray( schemaNames ); return false; } Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java?rev=888423&r1=888422&r2=888423&view=diff ============================================================================== --- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java (original) +++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java Tue Dec 8 15:01:15 2009 @@ -24,12 +24,15 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.List; +import javax.naming.NamingException; + import org.apache.commons.io.FileUtils; import org.apache.directory.shared.ldap.schema.SchemaManager; import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor; @@ -202,6 +205,47 @@ } + /** + * Disable an enabled schema + */ + @Test + public void testDisableEnabled() throws Exception + { + schemaManager.loadAllEnabled(); + + assertTrue( schemaManager.enable( "nis" ) ); + assertTrue( schemaManager.isEnabled( "nis" ) ); + + assertEquals( 11, schemaManager.getRegistries().getLoadedSchemas().size() ); + + assertTrue( schemaManager.disable( "nis" ) ); + + try + { + schemaManager.lookupAttributeTypeRegistry( "gecos" ); + fail(); + } + catch ( NamingException ne ) + { + // Expected + } + + assertTrue( schemaManager.getErrors().isEmpty() ); + assertEquals( 261, schemaManager.getAttributeTypeRegistry().size() ); + assertEquals( 48, schemaManager.getComparatorRegistry().size() ); + assertEquals( 48, schemaManager.getMatchingRuleRegistry().size() ); + assertEquals( 50, schemaManager.getNormalizerRegistry().size() ); + assertEquals( 88, schemaManager.getObjectClassRegistry().size() ); + assertEquals( 66, schemaManager.getSyntaxCheckerRegistry().size() ); + assertEquals( 71, schemaManager.getLdapSyntaxRegistry().size() ); + assertEquals( 468, schemaManager.getOidRegistry().size() ); + + assertEquals( 10, schemaManager.getRegistries().getLoadedSchemas().size() ); + assertNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) ); + + } + + @Test public void testEnableNonExisting() { Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java?rev=888423&r1=888422&r2=888423&view=diff ============================================================================== --- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java (original) +++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java Tue Dec 8 15:01:15 2009 @@ -264,6 +264,7 @@ * * @param schemas The list of schemas to enable * @return true if the Registries is still consistent, false otherwise. + * @throws If something went wrong */ boolean enable( Schema... schemas ) throws Exception; @@ -277,6 +278,7 @@ * * @param schemas The list of schema name to enable * @return true if the Registries is still consistent, false otherwise. + * @throws If something went wrong */ boolean enable( String... schemas ) throws Exception; @@ -336,8 +338,9 @@ * * @param schemas The list of schemas to disable * @return true if the Registries is still consistent, false otherwise. + * @throws If something went wrong */ - boolean disable( Schema... schemas ); + boolean disable( Schema... schemas ) throws Exception; /** @@ -349,8 +352,9 @@ * * @param schemas The list of schema names to disable * @return true if the Registries is still consistent, false otherwise. + * @throws If something went wrong */ - boolean disable( String... schemas ); + boolean disable( String... schemas ) throws Exception; /**