public VersionResource(FabricResource fabricResource, Version version) { super(fabricResource, "/version/" + version.getId() + "/"); this.fabricResource = fabricResource; this.version = version; }
@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; }
/** * Get the patch profile for a specified patch id from a {@link Version} * Returns <code>null</code> if no matching profile was found */ protected static Profile getPatchProfile(Version version, String patchId) { return version.getProfile("patch-" + patchId); }
public String call(Git git, GitContext context) throws Exception { String versionId = version.getId(); IllegalStateAssertion.assertNull(checkoutProfileBranch(git, context, versionId, null), "Version already exists: " + versionId); GitHelpers.checkoutTag(git, GitHelpers.ROOT_TAG); createOrCheckoutVersion(git, version.getId()); setVersionAttributes(git, context, versionId, version.getAttributes()); context.commitMessage("Create version: " + version); for (Profile profile : version.getProfiles()) { createOrUpdateProfile(context, null, profile, new HashSet<String>()); } return versionId; } };
public String call(Git git, GitContext context) throws Exception { String versionId = version.getId(); GitHelpers.checkoutTag(git, GitHelpers.ROOT_TAG); createOrCheckoutVersion(git, version.getId()); setVersionAttributes(git, context, versionId, attributes); context.commitMessage("Create version: " + version); Set<String> alreadyProcessedProfiles = new HashSet<String>(); for (Profile profile : version.getProfiles()) { createOrUpdateProfile(context, null, profile,alreadyProcessedProfiles); } return versionId; } };
/** * Sets the list of parent profile IDs */ private void setParentProfileIds(ProfileBuilder builder, Version version, Profile profile, List<String> parentProfileIds) { List<String> list = new ArrayList<>(); for (String parentProfileId : parentProfileIds) { if (version.hasProfile(parentProfileId)) { list.add(parentProfileId); } else { LOG.warn("Could not find parent profile: " + parentProfileId + " in version " + version.getId()); } } builder.setParents(list); }
Map<String, Object> doGetProfile(Version version, String profileId, List<String> fields, boolean mandatory) { Profile profile; if (mandatory) { profile = version.getRequiredProfile(profileId); } else { profile = version.getProfile(profileId); } if (profile == null) { return null; } Map<String, Object> answer = BeanUtils.convertProfileToMap(fabricService, profile, fields); String iconURLField = "iconURL"; if (fields.contains(iconURLField) && !profile.isOverlay()) { // TODO this could move to Profile.getIconURL() but that would require // introducing profileService into ProfileImpl and the ProfileBuilder stuff String restApi = restApiUrl(); if (restApi != null && restApi.length() > 0) { // turn REST into relative URI so it works with docker containers etc (avoids local ports etc) try { URL url = new URL(restApi); restApi = url.getPath(); } catch (MalformedURLException e) { // Ignore } String icon = getIconURL(version, version.getId(), profile, profileId, restApi); answer.put(iconURLField, icon); } } return answer; }
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; }
/** * 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; }
private void manageProfile(TaskContext context) { Container current = fabricService.get().getCurrentContainer(); ProfileData profileData = createProfileData(context); String profileId = context.getConfiguration().get(TEMPLATE_PROFILE_PROPERTY_NAME) + "-" + name; Version version = current.getVersion(); try { if (lock.acquire(60, TimeUnit.SECONDS)) { if (profileData.isEmpty()) { if (version.hasProfile(profileId)) { //Just delete the profile version.getProfile(profileId).delete(true); } return; } else if (!version.hasProfile(profileId)) { //Create the profile fabricService.get().getDataStore().createProfile(version.getId(), profileId); } Profile managedProfile = version.getProfile(profileId); //managedProfile.setConfigurations(profileData.getConfigs()); managedProfile.setFileConfigurations(profileData.getFiles()); current.addProfiles(managedProfile); } else { throw new TimeoutException("Timed out waiting for lock"); } } catch (Exception e) { LOGGER.error("Error managing work items.", e); } finally { releaseLock(); } }
/** * 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]); }
/** * Checks if container requires upgrade/rollback operation. */ private boolean requiresUpgrade(Version version) { boolean requiresUpgrade = false; if (version.getId().compareTo(getVersionId()) == 0) { return false; } for (Profile oldProfile : getProfiles()) { Profile newProfile = version.getProfile(oldProfile.getId()); if (newProfile != null && !Profiles.agentConfigurationEquals(fabricService, oldProfile, newProfile)) { requiresUpgrade = true; break; } } return requiresUpgrade; }
protected void printVersions(Container[] containers, List<String> versions, String defaultVersionId, PrintStream out) { TablePrinter table = new TablePrinter(); table.columns("version", "default", "# containers", "description"); // they are sorted in the correct order by default for (String versionId : versions) { boolean isDefault = versionId.equals(defaultVersionId); Version version = profileService.getRequiredVersion(versionId); int active = countContainersByVersion(containers, version); String description = version.getAttributes().get(Version.DESCRIPTION); table.row(version.getId(), (isDefault ? "true" : ""), activeContainerCountText(active), description); } table.print(); }
public List<ProfileState> getProfileStates() { List<ProfileState> result = new ArrayList<>(); for (Profile prf : delegate.getProfiles()) { result.add(new ProfileState(prf)); } return result; }
@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()]); }
@Override public void stop(TaskContext context) { Container current = fabricService.get().getCurrentContainer(); Version version = current.getVersion(); String profileId = context.getConfiguration().get(TEMPLATE_PROFILE_PROPERTY_NAME) + "-" + name; if (version.hasProfile(profileId)) { //Just delete the profile version.getProfile(profileId).delete(true); } }
@Override public ProfileBuilder addOptions(ProfileBuilder builder) { List<String> missingProfiles = new ArrayList<>(); List<String> profileIds = dataStore.getContainerProfiles(cntId); LOGGER.debug("Building container overlay for {} with profile: {}", cntId, profileIds); for (String profileId : profileIds) { if (version.hasProfile(profileId)) { builder.addParent(profileId); } else { missingProfiles.add(profileId); } } if (!missingProfiles.isEmpty()) { LOGGER.warn("Container overlay has missing profiles: {}", missingProfiles); builder.addAttribute("missing.profiles", missingProfiles.toString()); // builder.addConfiguration(Constants.AGENT_PID, "disabled", "true"); } return builder; } }
@Override public VersionBuilder from(Version version) { setAttributes(version.getAttributes()); addProfiles(version.getProfiles()); return this; }
public List<String> getProfiles() { return delegate.getProfileIds(); }
public Map<String, String> getAttributes() { return delegate.getAttributes(); }