Class 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 a Profile.ParameterValuesProvider object passed in argument of resolveParameterValues(ExecutionContext, SetupConfiguration, ParameterValuesProvider) method. Parameters can then be used in the profile.groovy script with their variable 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.

    • 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 file
        instancePath - 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 of setup profiles to test
        Throws:
        com.forgerock.opendj.cli.ArgumentException - If the provided collection contains profiles with the same 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 non null nor blank string representing the setup profile name
        folder - A Path 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • hasSameName

        public boolean hasSameName​(Profile profile)
        Returns true 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
      • getPath

        public Path getPath()
        Returns this profile path.
        Returns:
        This profile path
      • 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 calling loadParameterDefinitions()) before this method is not mandatory.

        Parameters:
        context - Whether the resolution happens during setup or post setup
        setupConfig - All configuration parameter already collected to setup the server.
        Each parameter will be added as build-in profile parameter
        parameterValuesProvider - A Profile.ParameterValuesProvider used for resolving parameter values
        Throws:
        com.forgerock.opendj.cli.ArgumentException - If an error occurs while resolving this profile parameter values
        SetupException - 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 run
        console - Console to be used by this profile to report logs and errors
        Throws:
        SetupException - If an error occurs during this profile execution