public final class EmbeddedDirectoryServer extends Object
Modifier and Type | Method and Description |
---|---|
void |
configureReplication(ReplicationParameters parameters)
Configures replication between this directory server (first server) and another server
(second server).
|
EmbeddedDirectoryServer |
extractArchiveForSetup(File openDJZipFile)
Extracts the provided archive to the appropriate root directory of the server.
|
ManagementContext |
getConfiguration()
Returns the configuration of this server, which can be read or updated.
|
String |
getConfigVersion()
Returns the configuration version of the instance of the directory server as a String.
|
Connection |
getConnection()
Returns a connection to the embedded server that will be authenticated automatically with
the bind DN defined for this server.
|
Connection |
getConnection(Dn userDn)
Returns a connection to the embedded server that will be authenticated as the specified user.
|
String |
getDataVersion()
Returns the data version of the instance of the directory server as a String.
|
void |
importLDIF(ImportParameters parameters)
Imports LDIF data to the directory server, overwriting existing data.
|
DirectoryServerSetup |
initializeConfiguration()
Creates a directory server setup object pre-initialized with configuration and connection parameters provided
while creating this embedded directory server and returns the setup object to allow further configuration actions
such as backend creation or profile setup.
|
void |
initializeReplication(ReplicationParameters parameters)
Initializes replication between this server and another server.
|
boolean |
isReplicationRunning()
Indicates whether replication is currently running for the embedded server.
|
boolean |
isRunning()
Indicates whether this server is currently running.
|
static EmbeddedDirectoryServer |
manageEmbeddedDirectoryServer(ConfigParameters configParams,
ConnectionParameters connParams,
OutputStream out,
OutputStream err)
Creates an instance of an embedded directory server for any operation.
|
static EmbeddedDirectoryServer |
manageEmbeddedDirectoryServerForRestrictedOps(ConfigParameters configParams)
Creates an instance of an embedded directory server to perform a restricted set of operations that
do not need connection parameters.
|
static EmbeddedDirectoryServer |
manageEmbeddedDirectoryServerForRestrictedOps(ConfigParameters configParams,
OutputStream out,
OutputStream err)
Creates an instance of an embedded directory server to perform a restricted set of operations that
do not need connection parameters.
|
void |
rebuildIndex(RebuildIndexParameters parameters)
Rebuilds all the indexes of this server.
|
void |
restart(String className,
LocalizableMessage reason)
Restarts the directory server.
|
void |
setup(SetupParameters parameters)
Deprecated.
since 6.5.0 and OPENDJ-5507,
initializeConfiguration() should be use instead |
void |
start()
Starts this server.
|
void |
stop(String className,
LocalizableMessage reason)
Stops this server.
|
void |
upgrade(UpgradeParameters parameters)
Upgrades this server.
|
public static EmbeddedDirectoryServer manageEmbeddedDirectoryServer(ConfigParameters configParams, ConnectionParameters connParams, OutputStream out, OutputStream err)
configParams
- The basic configuration parameters for the server.connParams
- The connection parameters for the server.out
- Output stream used for feedback during operations on servererr
- Error stream used for feedback during operations on serverpublic static EmbeddedDirectoryServer manageEmbeddedDirectoryServerForRestrictedOps(ConfigParameters configParams, OutputStream out, OutputStream err)
The following operations won't be allowed because they require the connection parameters: setup,
configureReplication, initializeReplication, isReplicationRunning, importLDIF
and getInternalConnection without argument
(getInternalConnection(DN)
method is allowed).
To be able to perform any operation on the server, use the alternative manageEmbeddedDirectoryServer()
method.
configParams
- The basic configuration parameters for the server.out
- Output stream used for feedback during operations on servererr
- Error stream used for feedback during operations on serverpublic static EmbeddedDirectoryServer manageEmbeddedDirectoryServerForRestrictedOps(ConfigParameters configParams)
The following operations won't be allowed because they require the connection parameters: setup,
configureReplication, initializeReplication, isReplicationRunning, importLDIF
and getInternalConnection without argument
(getInternalConnection(DN)
method is allowed).
To be able to perform any operation on the server, use the alternative manageEmbeddedDirectoryServer()
method.
Standard out and error streams will be used for any output during operations on the embedded server.
configParams
- The basic configuration parameters for the server.public void configureReplication(ReplicationParameters parameters) throws EmbeddedDirectoryServerException
This method updates the configuration of the servers to replicate the data under the base DN specified in the parameters.
parameters
- The parameters for the replication.EmbeddedDirectoryServerException
- If a problem occurs.public String getConfigVersion() throws EmbeddedDirectoryServerException
EmbeddedDirectoryServerException
- If an error occurs while retrieving the versionpublic String getDataVersion() throws EmbeddedDirectoryServerException
EmbeddedDirectoryServerException
- If an error occurs while retrieving the versionpublic ManagementContext getConfiguration() throws EmbeddedDirectoryServerException
The returned object is an instance of ManagementContext
class, which allow access to the
root configuration object using its getRootConfiguration()
method.
Starting from the root configuration, it is possible to access any configuration object, in order
to perform read or update operations.
Note that ManagementContext
instance must be closed after usage. It is recommended to use
it inside a try-with-resource statement.
Example reading configuration:
try(ManagementContext config = server.getConfiguration()) {
List<String> syncProviders = config.getRootConfiguration().listSynchronizationProviders();
System.out.println("sync providers=" + syncProviders);
}
Example updating configuration:
try(ManagementContext config = server.getConfiguration()) { JEBackendCfgClient userRoot = (JEBackendCfgClient) config.getRootConfiguration().getBackend("userRoot"); userRoot.setBaseDN(Arrays.asList(DN.valueOf("dc=example,dc=com"))); userRoot.setDBCachePercent(70); // changes must be committed to be effective userRoot.commit(); }
EmbeddedDirectoryServerException
- If the retrieval of the configuration failspublic Connection getConnection() throws EmbeddedDirectoryServerException
This method is available only if connection parameters are provided for the server.
If the connection must be authenticated with another DN or if no connection parameters have been
provided, use the alternate method getConnection(Dn)
.
EmbeddedDirectoryServerException
- If the connection can't be returnedpublic Connection getConnection(Dn userDn) throws EmbeddedDirectoryServerException
userDn
- The user to be used for authentication to the serverEmbeddedDirectoryServerException
- If the connection can't be returnedpublic void importLDIF(ImportParameters parameters) throws EmbeddedDirectoryServerException
parameters
- The import parametersEmbeddedDirectoryServerException
- If the import failspublic void initializeReplication(ReplicationParameters parameters) throws EmbeddedDirectoryServerException
parameters
- The parameters for the replication.EmbeddedDirectoryServerException
- If a problem occurs.public boolean isReplicationRunning()
true
if replication is running, false
otherwisepublic boolean isRunning()
true
if the server is currently running, or false
if not.@Deprecated public void setup(SetupParameters parameters) throws EmbeddedDirectoryServerException
initializeConfiguration()
should be use instead
As a pre-requisite, the OpenDJ archive must have been previously extracted to some
directory. To extract an archive for setup, see extractArchiveForSetup()
.
parameters
- The setup parameters.EmbeddedDirectoryServerException
- If the setup fails for any reason.public DirectoryServerSetup initializeConfiguration() throws EmbeddedDirectoryServerException
As a pre-requisite, the OpenDJ archive must have been previously extracted to some
directory. To extract an archive for setup, see extractArchiveForSetup(File)
.
Once further configuration actions have been performed on the setup
object returned
by this method, embedded server must be setup by a call to Setup.setup()
:
Embedded DS setup examples can be found in opendj-embedded-server-examples/src/main/java/org/forgerock/opendj/examples/SetupServer.java.
setup
object already initialized with this
embedded server
configuration
and
connection
parameters and which can be used to create local backend or configure
server with setup profiles
and then must be use to setup
this embedded serverEmbeddedDirectoryServerException
- If the configuration initialization fails for any reason.public EmbeddedDirectoryServer extractArchiveForSetup(File openDJZipFile) throws EmbeddedDirectoryServerException
As the DJ archive includes the "opendj" directory, it is mandatory to have the root directory named after it when using this method.
openDJZipFile
- The OpenDJ server archive.embedded directory server
EmbeddedDirectoryServerException
- If the extraction of the archive fails.public void rebuildIndex(RebuildIndexParameters parameters) throws EmbeddedDirectoryServerException
This operation is done offline, hence the server must be stopped when calling this method.
parameters
- The parameters for rebuilding the indexes.EmbeddedDirectoryServerException
- If an error occurs.public void restart(String className, LocalizableMessage reason)
This will perform an in-core restart in which the existing server instance will be shut down, a new instance will be created, and it will be reinitialized and restarted.
className
- The name of the class that initiated the restart.reason
- A message explaining the reason for the restart.public void start() throws EmbeddedDirectoryServerException
EmbeddedDirectoryServerException
- If the server is already running, or if an error occurs during server initialization
or startup.public void stop(String className, LocalizableMessage reason)
className
- The name of the class that initiated the shutdown.reason
- A message explaining the reason for the shutdown.public void upgrade(UpgradeParameters parameters) throws EmbeddedDirectoryServerException
Upgrades the server configuration and application data so that it is compatible with the installed binaries.
parameters
- The upgrade parameters.EmbeddedDirectoryServerException
- If the upgrade failsCopyright 2010-2022 ForgeRock AS.