Le 03/02/2017 à 14:04, Ralph Carlson Jr a écrit :
> I have a question about creating partitions. Is there any way to create a
> partition in apacheds using java api like (
> http://directory.apache.org/apacheds/gen-docs/2.0.0-M23/apidocs/) or the
> standard java ldap api's. I understand I will have to restart the service.
> I know and have created them using Apache Directory Studio but I assume
> that program must be using some java api to create the partitions. The only
> examples I can find online are using older versions of the api and supply
> local folder paths which I never give Apache Directory Studio when I use it
> to create partitions.
Hi Raph,
this is not exactly a question for the API mailing list, but I can see
why you are asking there. The answer is not straight forward : the API
is somehow Server agnostic, so, no, there is no *simple* way to create
an ApacheDS partition using the api.
Having said that, it is be possible to create a partition in a ApacheDS
config using the API. FTR, Studio can do that routinely. The class in
charge of loading teh configuration in Studio is ;
http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/jobs/LoadConfigurationRunnable.java?revision=1686070&view=markup
and teh one in charge of saving it is
http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/jobs/SaveConfigurationRunnable.java?revision=1670493&view=markup
The entry point can be either readSingleFileConfiguration( File ) if you
have all teh config stored in a single file, and
readMultiFileConfigureation( File ) if it's a hierarchy of LDIF files.
Once the partition has been loaded, you have access to any part of it as
Java objects (xxxBean), like PartitionBean, IndexBean, etc. (the
complete list is available here :
http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/).
Adding a partition is all about feeding a new instance of a
Jdbm/MavibotPartition :
JdbmPartitionBean newPartitionBean = new JdbmPartitionBean();
newPartitionBean.setPartitionId( newId );
try
{
newPartitionBean.setPartitionSuffix( new Dn( "dc=" + newId +
",dc=com" ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
catch ( LdapInvalidDnException e1 )
{
// Will never happen
}
// Default values
newPartitionBean.setPartitionCacheSize( 100 );
newPartitionBean.setJdbmPartitionOptimizerEnabled( true );
newPartitionBean.setPartitionSyncOnWrite( true );
newPartitionBean.setContextEntry( getContextEntryLdif(
newPartitionBean.getPartitionSuffix() ) );
List indexes = new ArrayList();
indexes.add( createJdbmIndex( "apacheAlias", 100 ) ); //$NON-NLS-1$
indexes.add( createJdbmIndex( "apacheOneAlias", 100 ) );
//$NON-NLS-1$
indexes.add( createJdbmIndex( "apacheOneLevel", 100 ) );
//$NON-NLS-1$
indexes.add( createJdbmIndex( "apachePresence", 100 ) );
//$NON-NLS-1$
indexes.add( createJdbmIndex( "apacheRdn", 100 ) ); //$NON-NLS-1$
indexes.add( createJdbmIndex( "apacheSubAlias", 100 ) );
//$NON-NLS-1$
indexes.add( createJdbmIndex( "apacheSubLevel", 100 ) );
//$NON-NLS-1$
indexes.add( createJdbmIndex( "dc", 100 ) ); //$NON-NLS-1$
indexes.add( createJdbmIndex( "entryCSN", 100 ) ); //$NON-NLS-1$
indexes.add( createJdbmIndex( "entryUUID", 100 ) ); //$NON-NLS-1$
indexes.add( createJdbmIndex( "krb5PrincipalName", 100 ) );
//$NON-NLS-1$
indexes.add( createJdbmIndex( "objectClass", 100 ) ); //$NON-NLS-1$
indexes.add( createJdbmIndex( "ou", 100 ) ); //$NON-NLS-1$
indexes.add( createJdbmIndex( "uid", 100 ) ); //$NON-NLS-1$
newPartitionBean.setIndexes( indexes );
and then add the newly created partition into the DirectoryServiceBean :
List partitions =
directoryServiceBean.getPartitions();
// Adding the partition
partitions.add( newPartitionBean );
directoryServiceBean.setPartitions( partitions );
--
Emmanuel Lecharny
Symas.com
directory.apache.org