/** * Gets the profile for the given name * * @throws java.lang.IllegalArgumentException if the profile does not exists */ public static Profile getProfile(Version ver, String name) { Profile p = ver.getRequiredProfile(name); if (p == null) { throw new IllegalArgumentException("Profile " + name + " does not exist."); } return p; }
/** * Gets the profile for the given name * * @throws java.lang.IllegalArgumentException if the profile does not exists */ public static Profile getProfile(Version ver, String name) { Profile p = ver.getRequiredProfile(name); if (p == null) { throw new IllegalArgumentException("Profile " + name + " does not exist."); } return p; }
@Override public String getConfigurationFile(String versionId, String profileId, String fileName) { return Base64.encodeBase64String(profileService.getVersion(versionId).getRequiredProfile(profileId).getFileConfigurations().get(fileName)); }
private static void recursiveAddProfiles(Version version, Set<String> result, List<String> profiles) { for (String profileId : profiles) { result.add(profileId); Profile profile = version.getRequiredProfile(profileId); List<String> parents = profile.getParentIds(); recursiveAddProfiles(version, result, parents); } }
private String getLastModified() { StringBuilder sb = new StringBuilder(); sb.append(self.getProfileHash()); for (String parentId : self.getParentIds()) { Profile parent = version.getRequiredProfile(parentId); sb.append("-").append(parent.getProfileHash()); } return sb.toString(); } }
@Override public Map<String, Object> getConfigurationFiles(String versionId, List<String> profileIds, String filename) { Pattern pattern = Pattern.compile(filename); Map<String, Object> answer = new TreeMap<String, Object>(); Version version = profileService.getVersion(versionId); for (String profileId : profileIds) { Profile profile = version.getRequiredProfile(profileId); if (profile != null) { Map<String, String> files = new TreeMap<String, String>(); Map<String, byte[]> configs = profile.getFileConfigurations(); for (Map.Entry<String, byte[]> configEntry : configs.entrySet()) { if (pattern.matcher(configEntry.getKey()).matches()) { files.put(configEntry.getKey(), Base64.encodeBase64String(configEntry.getValue())); } } answer.put(profileId, files); } } return answer; }
private static void recursiveAddProfiles(Version version, Set<String> result, List<String> profiles) { for (String profileId : profiles) { result.add(profileId); Profile profile = version.getRequiredProfile(profileId); List<String> parents = profile.getParentIds(); recursiveAddProfiles(version, result, parents); } }
@Override public Map<String, String> getProfileProperties(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) { answer = profile.getConfiguration(pid); } } return answer; }
@Override public Profile[] getProfiles() { Version version = getVersion(); List<String> profileIds = dataStore.getContainerProfiles(id); List<Profile> profiles = new ArrayList<Profile>(); for (String profileId : profileIds) { profiles.add(version.getRequiredProfile(profileId)); } if (profiles.isEmpty() && version != null) { Profile defaultProfile = version.getProfile(ZkDefs.DEFAULT_PROFILE); if (defaultProfile != null) { profiles.add(defaultProfile); } } return profiles.toArray(new Profile[profiles.size()]); }
@Path("profile/{profileId}") public ProfileResource version(@PathParam("profileId") String profileId) { if (Strings.isNotBlank(profileId) && version != null && version.hasProfile(profileId)) { Profile profile = version.getRequiredProfile(profileId); if (profile != null) { return new ProfileResource(this, profile); } } return null; }
@Path("profile/{profileId}") public ProfileResource version(@PathParam("profileId") String profileId) { if (Strings.isNotBlank(profileId) && version != null && version.hasProfile(profileId)) { Profile profile = version.getRequiredProfile(profileId); if (profile != null) { return new ProfileResource(this, profile); } } return null; }
public void refreshProfile(String versionId, String profileId) { Version version = profileService.getVersion(versionId); if (version != null) { Profile profile = version.getRequiredProfile(profileId); if (profile != null) { Profiles.refreshProfile(fabricService, profile); } } }
/** * Gets the profiles for upgrade/rollback * * @param existingProfiles the existing profiles * @param targetVersion the target version * @return the new profiles to be used */ public static Profile[] getProfilesForUpgradeOrRollback(Profile[] existingProfiles, Version targetVersion) { List<Profile> list = new ArrayList<Profile>(existingProfiles.length); for (Profile old : existingProfiles) { // get new profile Profile newProfile = targetVersion.getRequiredProfile(old.getId()); if (newProfile != null) { list.add(newProfile); } else { // we expect a profile with the new version to exist throw new IllegalArgumentException("Profile " + old.getId() + " with version " + targetVersion.getId() + " does not exists"); } } return list.toArray(new Profile[0]); }
/** * Returns the {@link Profile} objects for the given list of profile ids for the given version */ public static List<Profile> getProfiles(FabricService fabricService, Iterable<String> profileIds, String versionId) { ProfileService profileService = fabricService.adapt(ProfileService.class); Version version; if (versionId == null) { version = fabricService.getRequiredDefaultVersion(); } else { version = profileService.getRequiredVersion(versionId); } List<Profile> answer = new ArrayList<Profile>(); if (profileIds != null && version != null) { for (String profileId : profileIds) { Profile profile = version.getRequiredProfile(profileId); if (profile != null) { answer.add(profile); } } } return answer; }
private void fillParentProfiles(Profile profile, List<Profile> profiles) { if (!profiles.contains(profile)) { List<Profile> circularRelationship = new ArrayList<>(); for (String parentId : profile.getParentIds()) { if (version.hasProfile(parentId)){ Profile parent = version.getRequiredProfile(parentId); if (parent != null){ if ( !isCircularRelationship(profile, parent)){ fillParentProfiles(parent, profiles); } else { circularRelationship.add(parent); } } } else { LOGGER.error("Tried to load a profile[{}] not present in this version[{}]", parentId, version); } } profiles.add(profile); for(Profile p: circularRelationship){ fillParentProfiles(p, profiles); } } }
@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 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 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()); }
private Profile getOrCreateProfile(Version version, ProjectRequirements requirements) { String profileId = getProfileId(requirements); if (Strings.isEmpty(profileId)) { throw new IllegalArgumentException("No profile ID could be deduced for requirements: " + requirements); } // make sure the profileId is valid FabricValidations.validateProfileName(profileId); Profile profile; if (!version.hasProfile(profileId)) { LOG.info("Creating new profile " + profileId + " version " + version + " for requirements: " + requirements); String versionId = version.getId(); ProfileService profileService = fabricService.get().adapt(ProfileService.class); ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId); profile = profileService.createProfile(builder.getProfile()); } else { profile = version.getRequiredProfile(profileId); } return profile; }
@Override protected Object doExecute() throws Exception { Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion(); Profile profile = version.getRequiredProfile(profileId); // we can only change parents to existing profiles Profile[] parents = FabricCommand.getExistingProfiles(fabricService, version, parentIds); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile); List<String> oldParents = builder.getParents(); for (Profile parent : parents) { builder.addParent(parent.getId()); } //remove old parent profiles for (String oldParent : oldParents) { if (!parentIds.contains(oldParent)) { builder.removeParent(oldParent); } } profileService.updateProfile(builder.getProfile()); return null; }