Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Profile

Thomas Diesler edited this page May 23, 2014 · 33 revisions

Working with Profiles

A Profile is an identifiable set of configuration and resource items that can be applied to a Container.

A Profile has the following properties.

Clients can obtain instances of profiles from the ProfileManager.

Managing Profile

The ProfileManager is the central entry point for working with profiles. It contains operations to

  • Add, update, remove profiles
  • Find profiles by given identifiers

Profile instances returned by the ProfileManager are shallow immutable objects. They represent the state of physical profile at a moment in time.

There is the notion of LinkedProfile which gives access to the complete hierarchy of a given Profile (including its parent profiles). LinkedProfileVersion gives access to the complete hierarchy of all Profiles associated with a given version.

Effective Profile

From the ProfileManager you can obtain the effective profile for a given profile. This would be the flat profile representation of a given profile and the transitive tree of its parents. Child items override parent items based on identity.

ProfileManager manager = ProfileManagerLocator.getProfileManager();
Profile effectiveFoo = manager.getEffectiveProfile(version, "foo");

Creating a Profile

To create a profile, a client would use a ProfileBuilder and pass the so built Profile to the ProfileManager like this

// Building the profile
Profile profile = ProfileBuilder.Factory.create("foo")
   .addConfigurationItem("some.pid", Collections.singletonMap("foo", "bar"))
   .getProfile();

// Adding the profile to a version
ProfileManager manager = ProfileManagerLocator.getProfileManager();
profile = manager.addProfile(version, profile);

Every builder (not just for Profiles) supports the use of OptionsProvider. An OptionsProvider can take its information from an arbitrary source and invoke methods on a builder. This decouples data format from the Fabric8 builders.

Here is an example that builds a profile from JMX composite data.

Profile profile = ProfileBuilder.Factory.create()
   .addOptions(new CompositeDataOptionsProvider(cdata));
   profileBuilder.getProfile();

class CompositeDataOptionsProvider implements OptionsProvider<ProfileBuilder> {

    public ProfileBuilder addBuilderOptions(ProfileBuilder builder) {
        Profile profile = ProfileOpenType.getProfile(cdata);
        builder.identity(profile.getIdentity());
        builder.addAttributes(profile.getAttributes());
        ...
        return builder;
    }
}

Updating a Profile

Profile update uses a copy => modify => publish approach.

Obtain a deep copy of the Profile you want to update

Use the ProfileBuilder to modify that Profile (possibly including its parents)

Publish the updated Profile again through the ProfileManager.

Profile updateProfile = ProfileBuilder.Factory.createFrom(version, identity)
        .addConfigurationItem("some.pid", Collections.singletonMap("xxx", "zzz"))
        .getProfile();

Profile profile = prfManager.updateProfile(updateProfile, profileListener);

Updating a Profile hierarchy may be a lengthy operation, especially when that profile needs to be provisioned to many containers. Therefore, this is conceptually an asynchronous operation. Throughout the API it possible to pass along an event listener when an asynchronous operation is invoked. In the example above, we pass along a ProfileEventListener that will receive ProfileEvent#UPDATED when done.

Removing a Profile

// Removing the profile to a version
ProfileManager manager = ProfileManagerLocator.getProfileManager();
manager.removeProfile(version, profile.getIdentity());

A profile that is associated with an active container cannot be removed.

Clone this wiki locally