Penrose 0.9.8 Penrose Configuration API
This page explains how to create Penrose configuration in an embedded environment.
Creating Penrose Configuration
There are 2 ways to create Penrose configuration. You can create an empty configuration by instantiating the PenroseConfig class.
PenroseConfig penroseConfig = new PenroseConfig();
Or, you can create a default configuration with DefaultPenroseConfig.
PenroseConfig penroseConfig = new DefaultPenroseConfig();
This default configuration will include the default schemas, default adapters, and default partition. This will be explained below.
It is advised that you perform any configuration changes before starting Penrose. Changing the configuration while Penrose is running may either cause an unexpected behavior or would not be reflected until the next time Penrose is started.
Home Directory
Home directory determines where Penrose will look for the schema and configuration files. By default Penrose will run in the current directory.
penroseConfig.setHome("c:\\usr\\local\\penrose");
Root DN and Password
The root user has a full access to Penrose.
UserConfig rootUserConfig = penroseConfig.getRootUserConfig(); rootUserConfig.setDn("uid=admin,ou=secret"); rootUserConfig.setPassword("secret");
Services
If you create the configuration with DefaultPenroseConfig, it will include the following services:
- JMX Service
- LDAP Service
To add a service configuration:
String serviceName = "My Service"; String serviceClass = "com.example.MyService"; ServiceConfig serviceConfig = new ServiceConfig(serviceName, serviceClass); penroseConfig.addServiceConfig(serviceConfig);
To get a service configuration:
String serviceName = "My Service"; ServiceConfig serviceConfig = penroseConfig.getServiceConfig(serviceName);
To remove a service configuration:
String serviceName = "My Service"; penroseConfig.removeServiceConfig(serviceName);
Schemas
If you create the configuration with DefaultPenroseConfig, it will include the following schemas:
- autofs.schema
- corba.schema
- core.schema
- cosine.schema
- apache.schema
- collective.schema
- inetorgperson.schema
- java.schema
- krb5kdc.schema
- nis.schema
- system.schema
- apachedns.schema
To add a schema, create a SchemaConfig object with the schema name and relative path to the schema file from Penrose home directory. The schema file has to be there already.
String schemaName = "example"; String schemaPath = "schema/ext/example.schema"; SchemaConfig schemaConfig = new SchemaConfig(schemaName, schemaPath); penroseConfig.addSchemaConfig(schemaConfig);
You can remove a schema from Penrose configuration by specifying its name.
String schemaName = "example"; penroseConfig.removeSchemaConfig(schemaName);
If you are adding a custom schema, you will have to compile the schema to generate the bootstrap classes, then include the generated jar file in the class path.
See also Schema.
Adapters
If you create the configuration with DefaultPenroseConfig, it will include the following adapters:
- JDBC: org.safehaus.penrose.connector.JDBCAdapter
- JNDI: org.safehaus.penrose.connector.JNDIAdapter
See also Adapters.
To add an adapter, create an AdapterConfig object with the adapter name and class name. The adapter class has to be packaged in a jar file and placed in the lib/ext directory.
String adapterName = "My Adapter"; String adapterClass = "com.example.MyAdapter"; AdapterConfig adapterConfig = new AdapterConfig(adapterName, adapterClass); penroseConfig.addAdapterConfig(adapterConfig);
You can remove an adapter from Penrose configuration by specifying its name.
String adapterName = "My Adapter"; penroseConfig.removeAdapterConfig(adapterName);
Partitions
If you create the configuration with DefaultPenroseConfig, it will include the default partition located in the conf directory. See also Partition and Partition API.
To add a partition, create a PartitionConfig object with the partition name and relative path to the partition directory from Penrose home directory. The partition configuration XML files have to be there already.
String partitionName = "example"; String partitionPath = "partitions/example"; PartitionConfig partitionConfig = new PartitionConfig(partitionName, partitionPath); penroseConfig.addPartitionConfig(partitionConfig);
To get a partition config:
String partitionName = "example"; PartitionConfig partitionConfig = penroseConfig.getPartitionConfig(partitionName);
You can remove a partition from Penrose configuration by specifying its name.
String partitionName = "example"; penroseConfig.removePartitionConfig(partitionName);
Importing/Exporting Penrose Configuration
Penrose configuration can be imported from or exported to an XML file. To import the configuration:
PenroseConfigReader reader = new PenroseConfigReader("conf\\server.xml"); PenroseConfig penroseConfig = reader.read();
To export the configuration:
PenroseConfigWriter writer = new PenroseConfigWriter("conf\\server.xml"); reader.write(penroseConfig);