Class Profile
- java.lang.Object
-
- org.forgerock.opendj.setup.model.Profile
-
- All Implemented Interfaces:
Comparable<Profile>
public final class Profile extends Object implements Comparable<Profile>
Represents a setup profile.Goal of setup profile is to allow a highly customizable setup of a directory server instance.
A setup profile is uniquely identified by its name and its version (e.g am-cts and 6.5). It uses groovy script for collecting parameters (parameters.groovy) and executing actions (profile.groovy. Executed by the setup tool, the profile script provides a domain specific language to allow to easily:
- Create a backend
- Import initial LDIF data in the backend
- Add custom schema into the directory server
- Create indexes
- Rebuild indexes
- Run
dsconfig
tool to perform other configuration actions
Setup profile use
parameters
to allow using properties in resource files (such as LDIF data), parameter values must be provided using aProfile.ParameterValuesProvider
object passed in argument ofresolveParameterValues(ExecutionContext, SetupConfiguration, ParameterValuesProvider)
method. Parameters can then be used in the profile.groovy script with theirvariable names
.Setup profile actions are all run in offline mode, if setup tool should start the server, it will be started after the profile.groovy script execution.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Profile.DnParameter
Represents a parameter whose value is associated to a bind DN property in server configuration.class
Profile.DomainParameter
Represents a parameter whose value is a domain automatically converted into aDN object
.static class
Profile.EnumConstant<T3>
Represents a constant defined in anenumeration parameter
.class
Profile.EnumParameter<T3>
Represents a parameter with an enumeration of allowed constants.static class
Profile.ExecutionContext
Represents when a profileruns
.class
Profile.HostPortParameter
Represents a parameter whose value is a remote server host and port.class
Profile.NumberParameter<N extends Number>
Represents a parameter whose value is a number.class
Profile.Parameter<P extends Profile.Parameter<P,T>,T>
Represents parameters that are defined in parameters.groovy and can be used in the profile.groovy script.class
Profile.ParameterFactory
Factory class which groups methods used for creating newProfile.Parameter
.static class
Profile.ParameterValues
Profile.ParameterValuesProvider
base implementation which can be used to pass profile parameter values.static interface
Profile.ParameterValuesProvider
Interface used by the setup model to retrieve profile parameter values.static interface
Profile.ParameterVisitor<R,P,E extends Exception>
A visitor ofparameters
, in the style of the visitor design pattern.class
Profile.PasswordParameter
Represents a parameter whose value is a password.class
Profile.PathParameter
Represents a parameter which contains aPath
value.static interface
Profile.SetupConfiguration
Represents the configuration of the setup associated to this profile.class
Profile.StringParameter
Represents a parameter whose value is a string.
-
Field Summary
Fields Modifier and Type Field Description static Pattern
PROFILE_NAME_PATTERN
Defines characters allowed in a profile name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SortedSet<Profile>
availableProfiles()
Returns the setup profiles available within the running binaries path.static SortedMap<String,SortedSet<Profile>>
availableProfilesGroupedByFriendlyName()
Returns the setup profiles available within the running binaries path, sorted and grouped by user friendly names.int
compareTo(Profile other)
static void
createProfileVersionFile(Collection<Profile> profiles, Path instancePath)
Creates a config/profile.version file in the provided instance path referencing provided profiles.boolean
equals(Object obj)
String
getName()
Returns this profile name.Path
getPath()
Returns this profile path.String
getUserFriendlyName()
Returns this profile user friendly name.com.forgerock.opendj.util.Version
getVersion()
Returns this profile version.int
hashCode()
boolean
hasSameName(Profile profile)
Returnstrue
if this profile has the same name as the provided profile.Collection<Profile.Parameter<?,?>>
loadParameterDefinitions()
Returns all parameters associated to this profile.static Profile
newSetupProfile(String name, Path folder)
Creates and returns a new setup profile associated to the provided parameters.static Profile.ParameterValues
parameters()
Entry point method to programmatically define profile parameters values.static void
rejectIfContainsDuplicatedProfiles(Collection<Profile> profiles)
Ensures that provided profiles collection does not contain one (or more) profile(s) with the same name.void
resolveParameterValues(Profile.ExecutionContext context, Profile.SetupConfiguration setupConfig, Profile.ParameterValuesProvider parameterValuesProvider)
Resolves this profile parameter values using the provided value provider.void
run(Path configFilePath, SetupConsole console)
Runs this profile.String
toString()
-
-
-
Field Detail
-
PROFILE_NAME_PATTERN
public static final Pattern PROFILE_NAME_PATTERN
Defines characters allowed in a profile name.
-
-
Method Detail
-
createProfileVersionFile
public static void createProfileVersionFile(Collection<Profile> profiles, Path instancePath) throws SetupException
Creates a config/profile.version file in the provided instance path referencing provided profiles.- Parameters:
profiles
- Collection of profiles to register into the fileinstancePath
- Path of the server instance where the file should be created- Throws:
SetupException
- If any errors occur while writing the file
-
rejectIfContainsDuplicatedProfiles
public static void rejectIfContainsDuplicatedProfiles(Collection<Profile> profiles) throws com.forgerock.opendj.cli.ArgumentException
Ensures that provided profiles collection does not contain one (or more) profile(s) with the same name.- Parameters:
profiles
- Collection ofsetup profiles
to test- Throws:
com.forgerock.opendj.cli.ArgumentException
- If the provided collection contains profiles with thesame name
-
parameters
public static Profile.ParameterValues parameters()
Entry point method to programmatically define profile parameters values.Profile.ParameterValues
returned object should be used as follow:final SetupConfiguration = new SetupConfiguration() { ... } amCts.resolveParameterValues( setupConfiguration, parameters().set("parameterVariableName", parameterValue) .set("anotherParameter", "anotherValue");
- Returns:
- a
Profile.ParameterValues
object for programmatically set parameter values
-
availableProfiles
public static SortedSet<Profile> availableProfiles()
Returns the setup profiles available within the running binaries path.Returned profiles are sorted by name first, then by most recent version.
- Returns:
- the setup
profiles
available within the running binaries path
-
availableProfilesGroupedByFriendlyName
public static SortedMap<String,SortedSet<Profile>> availableProfilesGroupedByFriendlyName()
Returns the setup profiles available within the running binaries path, sorted and grouped by user friendly names.Returned profile map keys (profile name) are sorted alphabetically, associated values (profile sets) are sorted by most recent version.
- Returns:
- the setup
profiles
available within the running binaries path, sorted and grouped by user friendly names
-
newSetupProfile
public static Profile newSetupProfile(String name, Path folder) throws com.forgerock.opendj.cli.ArgumentException
Creates and returns a new setup profile associated to the provided parameters.- Parameters:
name
- A nonnull
nor blank string representing the setup profile namefolder
- APath
representing the setup profile folder. Last folder of this path must represent the profile version (e.g /path/to/profile/6.0.0, /path/to/profile/6-5)- Returns:
- A new
setup profile
associated to the provided parameters - Throws:
com.forgerock.opendj.cli.ArgumentException
- If the provided folder parameter does not reference a valid setup profile folder
-
compareTo
public int compareTo(Profile other)
- Specified by:
compareTo
in interfaceComparable<Profile>
-
hasSameName
public boolean hasSameName(Profile profile)
Returnstrue
if this profile has the same name as the provided profile.Note that
equals(Object)
method checks for both the name and the version.- Parameters:
profile
-Profile
to test- Returns:
true
if this profile has the same name as the provided profile,false
otherwise
-
getName
public String getName()
Returns this profile name.- Returns:
- A string representing this
profile
name
-
getUserFriendlyName
public String getUserFriendlyName()
Returns this profile user friendly name.User friendly name should be written in a name.txt file in the profile folder or its parent. If user friendly name cannot be retrieved, this method returns the profile ID (name:version)
- Returns:
- A
LocalizableMessage
representing the profile user friendly name
-
getVersion
public com.forgerock.opendj.util.Version getVersion()
Returns this profile version.- Returns:
- This
profile
version
-
loadParameterDefinitions
public Collection<Profile.Parameter<?,?>> loadParameterDefinitions() throws SetupException
Returns all parameters associated to this profile.Profile parameters must be declared in the parameters.groovy script which must be located in the profile directory.
This method will run the parameters.groovy script and will load in memory all parameter definitions, regardless whether they are enabled.
This method does not resolve parameter values.- Returns:
- A collection containing all
parameters
associated to this profile - Throws:
SetupException
- If an error occurs while running the parameters.groovy script- See Also:
resolveParameterValues(ExecutionContext, SetupConfiguration, ParameterValuesProvider)
-
resolveParameterValues
public void resolveParameterValues(Profile.ExecutionContext context, Profile.SetupConfiguration setupConfig, Profile.ParameterValuesProvider parameterValuesProvider) throws com.forgerock.opendj.cli.ArgumentException, SetupException
Resolves this profile parameter values using the provided value provider.Profile parameters must be declared in the parameters.groovy script which must be located in the profile directory.
This method always try to load parameter definitions before resolving their values (i.e callingloadParameterDefinitions()
) before this method is not mandatory.- Parameters:
context
- Whether the resolution happens during setup or post setupsetupConfig
- All configuration parameter already collected to setup the server.
Each parameter will be added as build-in profile parameterparameterValuesProvider
- AProfile.ParameterValuesProvider
used for resolving parameter values- Throws:
com.forgerock.opendj.cli.ArgumentException
- If an error occurs while resolving this profile parameter valuesSetupException
- If an error occurs while running the parameters.groovy script while loading parameters
-
run
public void run(Path configFilePath, SetupConsole console) throws SetupException
Runs this profile.This profile parameter values must have been
resolved
before this method is called.- Parameters:
configFilePath
- Configuration file path of the server on which the profile should be runconsole
- Console to be used by this profile to report logs and errors- Throws:
SetupException
- If an error occurs during this profile execution
-
-