You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2009/07/21 21:31:06 UTC
svn commit: r796504 - in
/directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools:
ApachedsTools.java BaseCommand.java IndexCommand.java ToolCommand.java
Author: kayyagari
Date: Tue Jul 21 19:31:06 2009
New Revision: 796504
URL: http://svn.apache.org/viewvc?rev=796504&view=rev
Log:
o fixed the index building command
o added a bunch of new options to (ex. the instance path value)
o added instance layout support in the toolcommand
o commented the code which is loading server.xml using spring (this will go away in the next version)
Modified:
directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java
directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java
directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java
Modified: directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java?rev=796504&r1=796503&r2=796504&view=diff
==============================================================================
--- directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java (original)
+++ directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java Tue Jul 21 19:31:06 2009
@@ -20,14 +20,11 @@
package org.apache.directory.server.tools;
+import java.io.File;
import java.io.IOException;
-import java.net.URL;
import java.util.Properties;
import org.apache.commons.cli.CommandLine;
-import org.apache.directory.server.configuration.ApacheDS;
-import org.springframework.context.ApplicationContext;
-import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
/**
@@ -98,14 +95,14 @@
if ( cmdline.getOptionValue( 'i' ) != null )
{
cmd.setLayout( cmdline.getOptionValue( 'i' ) );
- if ( !cmd.isQuietEnabled() )
- {
- System.out.println( "loading settings from: " + cmd.getLayout().getConfigurationFile() );
- }
- ApplicationContext factory = null;
- URL configUrl = cmd.getLayout().getConfigurationFile().toURL();
- factory = new FileSystemXmlApplicationContext( configUrl.toString() );
- cmd.setApacheDS( ( ApacheDS ) factory.getBean( "apacheDS" ) );
+// if ( !cmd.isQuietEnabled() )
+// {
+// System.out.println( "loading settings from: " + cmd.getLayout().getConfigurationFile() );
+// }
+// ApplicationContext factory = null;
+// URL configUrl = cmd.getLayout().getConfigurationFile().toURL();
+// factory = new FileSystemXmlApplicationContext( configUrl.toString() );
+// cmd.setApacheDS( ( ApacheDS ) factory.getBean( "apacheDS" ) );
}
else if ( cmdline.hasOption( 'c' ) )
{
@@ -113,6 +110,11 @@
System.exit( 1 );
}
+ if ( cmdline.getOptionValue( 'z' ) != null )
+ {
+ cmd.setInstanceLayout( new InstanceLayout( new File( cmdline.getOptionValue( 'z' ) ) ) );
+ }
+
cmd.execute( cmdline );
}
Modified: directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java?rev=796504&r1=796503&r2=796504&view=diff
==============================================================================
--- directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java (original)
+++ directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java Tue Jul 21 19:31:06 2009
@@ -104,6 +104,8 @@
Option op = new Option( "i", "install-path", true, "path to installation directory" );
getGlobal().addOption( op );
+ op = new Option( "z", "instance-path", true, "path to ADS instance directory" );
+ getGlobal().addOption( op );
op = new Option( "b", "banner", false, "suppress banner print outs" );
getGlobal().addOption( op );
op = new Option( "d", "debug", false, "toggle debug mode" );
Modified: directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java?rev=796504&r1=796503&r2=796504&view=diff
==============================================================================
--- directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java (original)
+++ directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java Tue Jul 21 19:31:06 2009
@@ -21,13 +21,6 @@
import java.io.File;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
import jdbm.helper.MRU;
import jdbm.recman.BaseRecordManager;
@@ -36,35 +29,26 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
-import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.constants.ApacheSchemaConstants;
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmMasterTable;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
-import org.apache.directory.server.core.schema.PartitionSchemaLoader;
import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-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.registries.DefaultOidRegistry;
import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.Tuple;
-import org.apache.directory.shared.ldap.MultiException;
+import org.apache.directory.server.xdbm.tools.IndexDialog;
+import org.apache.directory.server.xdbm.tools.IndexUtils;
import org.apache.directory.shared.ldap.cursor.Cursor;
-import org.apache.directory.shared.ldap.exception.LdapConfigurationException;
-import org.apache.directory.shared.ldap.exception.LdapNamingException;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -78,6 +62,7 @@
private Registries bootstrapRegistries = new DefaultRegistries( "bootstrap", new BootstrapSchemaLoader(),
new DefaultOidRegistry() );
+ private DirectoryService directoryService;
public IndexCommand()
{
@@ -91,106 +76,53 @@
// --------------------------------------------------------------------
// Load the bootstrap schemas to start up the schema partition
// --------------------------------------------------------------------
+ directoryService = new DefaultDirectoryService();
+ directoryService.setWorkingDirectory( getInstanceLayout().getPartitionsDir() );
+ directoryService.startup();
- // setup temporary loader and temp registry
- BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
- OidRegistry oidRegistry = new DefaultOidRegistry();
- final Registries registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-
- // load essential bootstrap schemas
- Set<Schema> bootstrapSchemas = new HashSet<Schema>();
- bootstrapSchemas.add( new ApachemetaSchema() );
- bootstrapSchemas.add( new ApacheSchema() );
- bootstrapSchemas.add( new CoreSchema() );
- bootstrapSchemas.add( new SystemSchema() );
- loader.loadWithDependencies( bootstrapSchemas, registries );
-
- // run referential integrity tests
- List<Throwable> errors = registries.checkRefInteg();
-
- if ( !errors.isEmpty() )
- {
- MultiException e = new MultiException();
- for ( Throwable t : errors )
- {
- e.addThrowable( t );
- }
-
- throw e;
- }
-
- SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
- // --------------------------------------------------------------------
- // Initialize schema partition or bomb out if we cannot find it on disk
- // --------------------------------------------------------------------
-
- // If not present then we need to abort
- File schemaDirectory = new File( getLayout().getPartitionsDirectory(), "schema" );
- if ( !schemaDirectory.exists() )
- {
- throw new LdapConfigurationException( "The following schema directory from "
- + "the installation layout could not be found:\n\t" + schemaDirectory );
- }
-
- JdbmPartition schemaPartition = new JdbmPartition();
- schemaPartition.setId( "schema" );
- schemaPartition.setCacheSize( 1000 );
-
- DbFileListing listing;
- try
- {
- listing = new DbFileListing();
- }
- catch ( IOException e )
- {
- throw new LdapNamingException( "Got IOException while trying to read DBFileListing: " + e.getMessage(),
- ResultCodeEnum.OTHER );
- }
-
- Set<Index<?,ServerEntry>> indexedAttributes = new HashSet<Index<?,ServerEntry>>();
-
- for ( String attributeId : listing.getIndexedAttributes() )
- {
- indexedAttributes.add( new JdbmIndex( attributeId ) );
- }
-
- schemaPartition.setIndexedAttributes( indexedAttributes );
- schemaPartition.setSuffix( ServerDNConstants.OU_SCHEMA_DN );
-
- DirectoryService directoryService = new DefaultDirectoryService();
- schemaPartition.init( directoryService );
-
- // --------------------------------------------------------------------
- // Initialize schema subsystem and reset registries
- // --------------------------------------------------------------------
-
- PartitionSchemaLoader schemaLoader = new PartitionSchemaLoader( schemaPartition, registries );
- Registries globalRegistries = new DefaultRegistries( "global", schemaLoader, oidRegistry );
- schemaLoader.loadEnabled( globalRegistries );
+ Registries globalRegistries = directoryService.getRegistries();//registries;//
SerializableComparator.setRegistry( globalRegistries.getComparatorRegistry() );
+
return globalRegistries;
}
public void execute( CommandLine cmdline ) throws Exception
{
- getLayout().verifyInstallation();
+// getLayout().verifyInstallation();
bootstrapRegistries = loadRegistries();
String[] partitions = cmdline.getOptionValues( 'p' );
String attribute = cmdline.getOptionValue( 'a' );
-
+ String indexDirPath = cmdline.getOptionValue( 'w' );
+
for ( int ii = 0; ii < partitions.length; ii++ )
{
- File partitionDirectory = new File( getLayout().getPartitionsDirectory(), partitions[ii] );
- buildIndex( partitionDirectory, bootstrapRegistries.getAttributeTypeRegistry().lookup( attribute ) );
+ File partitionDirectory = partitionDirectory = new File( getInstanceLayout().getPartitionsDir(), partitions[ii] );
+ File indexDir = null;
+
+ if( indexDirPath != null )
+ {
+ indexDir = new File( indexDirPath );
+ }
+
+ AttributeType attrType = bootstrapRegistries.getAttributeTypeRegistry().lookup( attribute );
+
+ System.out.println( "building index for attribute type: " + attrType + ", of the partition: " + partitions[ii] );
+ if( indexDir != null )
+ {
+ System.out.println( "The index file location is: " + indexDir.getAbsolutePath() );
+ }
+
+ buildIndex( partitionDirectory, indexDir, attrType );
}
+
+ directoryService.shutdown();
}
@SuppressWarnings("unchecked")
- private void buildIndex( File partitionDirectory, AttributeType attributeType ) throws Exception
+ private void buildIndex( File partitionDirectory, File indexDirectory, AttributeType attributeType ) throws Exception
{
if ( !partitionDirectory.exists() )
{
@@ -206,10 +138,26 @@
JdbmMasterTable<ServerEntry> master = new JdbmMasterTable<ServerEntry>( recMan, bootstrapRegistries );
JdbmIndex index = new JdbmIndex();
index.setAttributeId( attributeType.getName() );
- index.setWkDirPath( partitionDirectory );
- index.setCacheSize( 1000 );
- index.setNumDupLimit( 1000 );
- index.init( attributeType, partitionDirectory );
+ index.setCacheSize( JdbmIndex.DEFAULT_INDEX_CACHE_SIZE );
+ index.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT );
+
+ if( indexDirectory == null )
+ {
+ indexDirectory = partitionDirectory;
+ }
+
+ index.setWkDirPath( indexDirectory );
+ index.init( attributeType, indexDirectory );
+
+ IndexUtils.printContents( index );
+
+ JdbmIndex existenceIdx = new JdbmIndex();
+ existenceIdx.setAttributeId( ApacheSchemaConstants.APACHE_EXISTENCE_AT_OID );
+ existenceIdx.setCacheSize( JdbmIndex.DEFAULT_INDEX_CACHE_SIZE );
+ existenceIdx.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT );
+
+ existenceIdx.setWkDirPath( partitionDirectory );
+ existenceIdx.init( bootstrapRegistries.getAttributeTypeRegistry().lookup( ApacheSchemaConstants.APACHE_EXISTENCE_AT_OID ), partitionDirectory );
Cursor<Tuple<Long,ServerEntry>> list = master.cursor();
@@ -217,9 +165,9 @@
{
Tuple<Long,ServerEntry> tuple = list.get();
Long id = tuple.getKey();
- Attributes entry = ( Attributes ) tuple.getValue();
+ DefaultServerEntry entry = ( DefaultServerEntry ) tuple.getValue();
- Attribute attr = AttributeUtils.getAttribute( entry, attributeType );
+ EntryAttribute attr = entry.get( attributeType );
if ( attr == null )
{
continue;
@@ -227,11 +175,16 @@
for ( int ii = 0; ii < attr.size(); ii++ )
{
- index.add( attr.get( ii ), id );
+ index.add( attr.get( ii ).get(), id );
}
+
+ existenceIdx.add( attributeType.getOid(), id );
}
index.sync();
+ index.close();
+ existenceIdx.sync();
+ existenceIdx.close();
}
@@ -250,6 +203,10 @@
op = new Option( "i", "install-path", true, "path to apacheds installation directory" );
op.setRequired( true );
opts.addOption( op );
+ op = new Option( "w", "index-path", true, "path to the directory where index should be stored" );
+ op.setRequired( false );
+ opts.addOption( op );
+
return opts;
}
}
Modified: directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java?rev=796504&r1=796503&r2=796504&view=diff
==============================================================================
--- directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java (original)
+++ directory/apacheds/trunk/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java Tue Jul 21 19:31:06 2009
@@ -44,6 +44,7 @@
private InstallationLayout layout;
private ApacheDS apacheDS;
+ private InstanceLayout instanceLayout;
protected ToolCommand( String name )
{
@@ -81,6 +82,18 @@
}
+ public void setInstanceLayout( InstanceLayout instanceLayout )
+ {
+ this.instanceLayout = instanceLayout;
+ }
+
+
+ public InstanceLayout getInstanceLayout()
+ {
+ return instanceLayout;
+ }
+
+
public InstallationLayout getLayout()
{
return layout;