public static boolean agentConfigurationEquals(FabricService fabricService, Profile thisProfile, Profile otherProfile) { ProfileService profileService = fabricService.adapt(ProfileService.class); Profile thisOverlay = profileService.getOverlayProfile(thisProfile); Profile otherOverlay = profileService.getOverlayProfile(otherProfile); return thisOverlay.getConfiguration(Constants.AGENT_PID).equals(otherOverlay.getConfiguration(Constants.AGENT_PID)); }
@Override public void renameProfile(String versionId, String profileId, String newId, boolean force) { Version v = profileService.getVersion(versionId); if (v != null) { Profiles.renameProfile(fabricService, versionId, profileId, newId, force); } }
public static void copyProfile(FabricService fabricService, String versionId, String sourceId, String targetId, boolean force) { ProfileService profileService = fabricService.adapt(ProfileService.class); Profile sourceProfile = profileService.getRequiredProfile(versionId, sourceId); LOGGER.info("copyProfile: {} => {}", sourceProfile, targetId); // [TODO] delete/create profile must be done in an atomic operation maybeDeleteProfile(fabricService, versionId, targetId, force); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(sourceProfile); profileService.createProfile(builder.identity(targetId).getProfile()); }
private static void maybeDeleteProfile(FabricService fabricService, String versionId, String targetId, boolean force) { ProfileService profileService = fabricService.adapt(ProfileService.class); if (force && profileService.hasProfile(versionId, targetId)) { profileService.deleteProfile(fabricService, versionId, targetId, force); } }
private Version getLatestVersion() { List<String> versions = profileService.getVersions(); IllegalStateAssertion.assertFalse(versions.isEmpty(), "No versions available"); String latestId = versions.get(versions.size() - 1); return profileService.getRequiredVersion(latestId); }
@Override public Map<String, String> getOverlayProfileProperties(String versionId, String profileId, String pid) { Map<String, String> answer = null; Version version = profileService.getVersion(versionId); if (version != null) { Profile profile = version.getRequiredProfile(profileId); if (profile != null) { Profile overlayProfile = profileService.getOverlayProfile(profile); answer = overlayProfile.getConfiguration(pid); } } return answer; }
@Override public Profile createOrUpdateMQProfile(String versionId, String profileId, String brokerName, Map<String, String> configs, boolean replicated) { Version version = profileService.getRequiredVersion(versionId); builder.addParent(parentProfile.getId()); overlay = profileService.getOverlayProfile(parentProfile); } else { Profile profile = version.getRequiredProfile(profileId); builder = ProfileBuilder.Factory.createFrom(profile); config = builder.getConfiguration(pidName); overlay = profileService.getOverlayProfile(profile); return create ? profileService.createProfile(profile) : profileService.updateProfile(profile);
@Override protected Object doExecute() throws Exception { profileService.getRequiredVersion(versionId); String defaultId = fabricService.getDefaultVersionId(); if (versionId.compareTo(defaultId) == 0) { System.out.println("Version " + versionId + " is already default version"); } else { fabricService.setDefaultVersionId(versionId); System.out.println("Changed default version from " + defaultId + " to " + versionId); } return null; } }
public static Map<String, String> getOverlayConfiguration(FabricService fabricService, Iterable<String> profileIds, String versionId, String pid, String environment) { Map<String, String> overlayConfig = new HashMap<String, String>(); ProfileService profileService = fabricService.adapt(ProfileService.class); // this should only be null in test cases if (profileService != null) { Version version = null; if (versionId == null) { version = fabricService.getRequiredDefaultVersion(); } else { version = profileService.getRequiredVersion(versionId); } if (profileIds != null) { for (String profileId : profileIds) { Profile profile = version.getRequiredProfile(profileId); Profile overlay = profileService.getOverlayProfile(profile); Map<String, String> profileConfig = overlay.getConfiguration(pid); if (profileConfig != null) { overlayConfig.putAll(profileConfig); } } } } return overlayConfig; }
@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); }
@Override public Profile createOrUpdateMQClientProfile(String versionId, String profileId, String group, String parentProfileName) { Version version = profileService.getRequiredVersion(versionId); return create ? profileService.createProfile(profile) : profileService.updateProfile(profile);
@Override @Deprecated // Creates a profile with empty content. Is this meaningful? public Map<String, Object> createProfile(String versionId, String profileId) { ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId); Profile profile = profileService.createProfile(builder.getProfile()); return getProfile(versionId, profile.getId()); }
List<String> versions = profileService.getVersions(); if (versions.size() > 0) { latestVersion = versions.get(versions.size() - 1); sourceId = latestVersion; } else { IllegalStateAssertion.assertTrue(profileService.hasVersion(parentVersion), "Cannot find parent version: " + parentVersion); sourceId = parentVersion; if (sourceId != null) { Map<String, String> attributes = description != null ? Collections.singletonMap(Version.DESCRIPTION, description) : null; targetVersion = profileService.createVersionFrom(sourceId, versionId, attributes); System.out.println("Created version: " + versionId + " as copy of: " + sourceId); } else { builder.addAttribute(Version.DESCRIPTION, description); targetVersion = profileService.createVersion(builder.getVersion()); System.out.println("Create version: " + versionId);
@Override protected Object doExecute() throws Exception { try { FabricValidations.validateProfileName(profileId); } catch (IllegalArgumentException e) { // we do not want exception in the server log, so print the error message to the console System.out.println(e.getMessage()); return null; } if (versionId != null) { profileService.getRequiredVersion(versionId); } else { versionId = fabricService.getDefaultVersionId(); } // we can only use existing parent profiles Profile[] parents = FabricCommand.getExistingProfiles(fabricService, versionId, this.parents); ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId); for (Profile parent : parents) { builder.addParent(parent.getId()); } profileService.createProfile(builder.getProfile()); return null; }
if (profileService.hasProfile(versionId, id)) { return Response.seeOther(location).entity("Profile already exists for id: " + id).build(); profileDTO.populateBuilder(fabricService, profileService, builder); Profile profile = builder.getProfile(); profileService.createProfile(profile); return Response.created(location).build();
@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; }
@Override public void applyVersionToContainers(String targetVersion, List<String> containerIds) { Version version = profileService.getVersion(targetVersion); for (String containerId : containerIds) { Container container = fabricService.getContainer(containerId); List<Profile> profiles = Arrays.asList(container.getProfiles()); for (Profile profile : profiles) { if (!profileService.hasProfile(version.getId(), profile.getId())) { String noVersionForProfile = String.format("Can't upgrade container %s since profile %s does not have version %s", containerId, profile.getId(), version.getId()); throw new IllegalStateException(noVersionForProfile); } } container.setVersion(version); } }
for (String ver : profileService.getVersions()) { Version version = profileService.getVersion(ver); if (version != null) { Profile profile = version.getProfile("default");
@Override protected Object doExecute() throws Exception { // do not validate the name in case a profile was created somehow with invalid name ProfileService profileService = fabricService.adapt(ProfileService.class); Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion(); boolean deleted = false; for (Profile profile : version.getProfiles()) { String versionId = profile.getVersion(); String profileId = profile.getId(); if (name.equals(profileId)) { profileService.deleteProfile(fabricService, versionId, profileId, force); deleted = true; } } if (!deleted) { System.out.println("Profile " + name + " not found."); } return null; }
@Override public void setConfigurationValue(String versionId, String profileId, String pid, String key, String value) { assertValid(); Version version = profileService.get().getRequiredVersion(versionId); Profile profile = version.getRequiredProfile(profileId); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile); Map<String, String> config = builder.getConfiguration(pid); config.put(key, value); builder.addConfiguration(pid, config); profileService.get().updateProfile(builder.getProfile()); }