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();
}
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);
}
}
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());
}
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);
}
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;
}
Aggregations