Search in sources :

Example 26 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class VersionResource method createProfile.

/**
 * Creates a new profile.
 * <br>
 * For example send this JSON to be able to create a new profile:
 *
 * <code>
 * { "id": "myNewProfile", "parents": ["containers-tomcat"] }
 * </code>
 */
@POST
public Response createProfile(ProfileDTO profileDTO) throws URISyntaxException {
    Objects.notNull(profileDTO, "profileDTO");
    FabricService fabricService = getFabricService();
    Objects.notNull(fabricService, "fabricService");
    ProfileService profileService = getProfileService();
    Objects.notNull(profileService, "profileService");
    String id = profileDTO.getId();
    if (Strings.isNullOrBlank(id)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("No id specified for the profile to be created").build();
    }
    URI location = new URI(getBaseUri() + "profile/" + id);
    // lets check it doesn't already exist
    String versionId = version.getId();
    if (profileService.hasProfile(versionId, id)) {
        return Response.seeOther(location).entity("Profile already exists for id: " + id).build();
    }
    // lets override whatever the version is set to
    profileDTO.setVersion(versionId);
    // create the profile
    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, id);
    profileDTO.populateBuilder(fabricService, profileService, builder);
    Profile profile = builder.getProfile();
    profileService.createProfile(profile);
    return Response.created(location).build();
}
Also used : ProfileService(io.fabric8.api.ProfileService) FabricService(io.fabric8.api.FabricService) URI(java.net.URI) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile) POST(javax.ws.rs.POST)

Example 27 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class ProfileDTO method populateBuilder.

/**
 * Uses the profile DTO as input to the builder
 */
public void populateBuilder(FabricService fabricService, ProfileService profileService, ProfileBuilder builder) {
    System.out.println("Parents are: " + parents);
    if (parents != null && parents.size() > 0 && version != null) {
        List<Profile> parentProfiles = Profiles.getProfiles(fabricService, parents, version);
        System.out.println("Found parents: " + parentProfiles);
        for (Profile parent : parentProfiles) {
            builder.addParent(parent.getId());
        }
    }
    builder.setOverlay(overlay);
    // TODO builder doesn't expose it
    // builder.setAbstractProfile(abstractProfile);
    builder.setLocked(locked);
    if (attributes != null) {
        builder.setAttributes(attributes);
    }
    if (bundles != null) {
        builder.setBundles(bundles);
    }
    if (fabs != null) {
        builder.setBundles(fabs);
    }
    if (features != null) {
        builder.setBundles(features);
    }
    if (repositories != null) {
        builder.setBundles(repositories);
    }
    if (overrides != null) {
        builder.setBundles(overrides);
    }
}
Also used : Profile(io.fabric8.api.Profile)

Example 28 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class FabricManager method setProfileSystemProperties.

@Override
public void setProfileSystemProperties(String versionId, String profileId, Map<String, String> systemProperties) {
    Version version = profileService.getVersion(versionId);
    Profile profile = version.getRequiredProfile(profileId);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    Map<String, String> profileProperties = builder.getConfiguration(Constants.AGENT_PID);
    // remove those that are not present in passed systemProperties
    for (Iterator<Map.Entry<String, String>> iterator = profileProperties.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, String> entry = iterator.next();
        if (entry.getKey().startsWith("system.")) {
            String propertyName = entry.getKey().substring("system.".length());
            if (!systemProperties.containsKey(propertyName)) {
                iterator.remove();
            }
        }
    }
    // add changed
    for (String k : systemProperties.keySet()) {
        profileProperties.put("system." + k, systemProperties.get(k));
    }
    builder.addConfiguration(Constants.AGENT_PID, profileProperties);
    profileService.updateProfile(builder.getProfile());
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Profile(io.fabric8.api.Profile)

Example 29 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class FabricManager method setConfigurationFile.

@Override
public void setConfigurationFile(String versionId, String profileId, String fileName, String data) {
    Profile profile = profileService.getRequiredProfile(versionId, profileId);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    builder.addFileConfiguration(fileName, Base64.decodeBase64(data));
    // ENTESB-2315: profile equality doesn't consider change of resources contents
    profileService.updateProfile(builder.getProfile(), true);
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 30 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class FabricManager method setProfileProperty.

@Override
public String setProfileProperty(String versionId, String profileId, String pid, String propertyName, String value) {
    Version version = profileService.getVersion(versionId);
    Profile profile = version.getRequiredProfile(profileId);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    Map<String, String> profileProperties = builder.getConfiguration(pid);
    String answer = profileProperties.put(propertyName, value);
    builder.addConfiguration(pid, profileProperties);
    profileService.updateProfile(builder.getProfile());
    return answer;
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Aggregations

ProfileBuilder (io.fabric8.api.ProfileBuilder)35 Profile (io.fabric8.api.Profile)33 Version (io.fabric8.api.Version)12 ProfileService (io.fabric8.api.ProfileService)4 GitVersion (io.fabric8.api.commands.GitVersion)3 Test (org.junit.Test)3 VersionBuilder (io.fabric8.api.VersionBuilder)2 ProjectRequirements (io.fabric8.deployer.dto.ProjectRequirements)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Feature (io.fabric8.agent.model.Feature)1 FabricException (io.fabric8.api.FabricException)1 FabricRequirements (io.fabric8.api.FabricRequirements)1 FabricService (io.fabric8.api.FabricService)1 LockHandle (io.fabric8.api.LockHandle)1 ProfileRegistry (io.fabric8.api.ProfileRegistry)1 ProfileRequirements (io.fabric8.api.ProfileRequirements)1 ProfileState (io.fabric8.api.mxbean.ProfileState)1