public static void assignProfileToContainers(FabricService fabricService, Profile profile, String[] assignContainers) { for (String containerName : assignContainers) { try { Container container = fabricService.getContainer(containerName); if (container == null) { LOG.warn("Failed to assign profile to " + containerName + ": profile doesn't exists"); } else { Set<Profile> profiles = new HashSet<Profile>(Arrays.asList(container.getProfiles())); profiles.add(profile); container.setProfiles(profiles.toArray(new Profile[profiles.size()])); LOG.info("Profile successfully assigned to " + containerName); } } catch (Exception e) { LOG.warn("Failed to assign profile to " + containerName + ": " + e.getMessage()); } } }
@Override public void applyProfilesToContainers(String version, List<String> profiles, List<String> containers) { Profile[] p = stringsToProfiles(version, profiles); for (String container : containers) { fabricService.getContainer(container).setProfiles(p); } }
public static void renameProfile(FabricService fabricService, String versionId, String sourceId, String targetId, boolean force) { ProfileService profileService = fabricService.adapt(ProfileService.class); Profile sourceProfile = profileService.getRequiredProfile(versionId, sourceId); LOGGER.info("renameProfile: {} => {}", sourceProfile, targetId); // [TODO] delete/create profile must be done in an atomic operation maybeDeleteProfile(fabricService, versionId, targetId, force); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(sourceProfile); Profile targetProfile = profileService.createProfile(builder.identity(targetId).getProfile()); // TODO: what about child profiles ? for (Container container : fabricService.getAssociatedContainers(versionId, sourceId)) { Profile[] containerProfiles = container.getProfiles(); Set<Profile> profileSet = new HashSet<Profile>(Arrays.asList(containerProfiles)); profileSet.remove(sourceProfile); profileSet.add(targetProfile); container.setProfiles(profileSet.toArray(new Profile[profileSet.size()])); } maybeDeleteProfile(fabricService, versionId, sourceId, true); }
public static void renameProfile(FabricService fabricService, String versionId, String sourceId, String targetId, boolean force) { ProfileService profileService = fabricService.adapt(ProfileService.class); Profile sourceProfile = profileService.getRequiredProfile(versionId, sourceId); LOGGER.info("renameProfile: {} => {}", sourceProfile, targetId); // [TODO] delete/create profile must be done in an atomic operation maybeDeleteProfile(fabricService, versionId, targetId, force); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(sourceProfile); Profile targetProfile = profileService.createProfile(builder.identity(targetId).getProfile()); // TODO: what about child profiles ? for (Container container : fabricService.getAssociatedContainers(versionId, sourceId)) { Profile[] containerProfiles = container.getProfiles(); Set<Profile> profileSet = new HashSet<Profile>(Arrays.asList(containerProfiles)); profileSet.remove(sourceProfile); profileSet.add(targetProfile); container.setProfiles(profileSet.toArray(new Profile[profileSet.size()])); } maybeDeleteProfile(fabricService, versionId, sourceId, true); }
protected Object doExecute() throws Exception { FabricValidations.validateContainerName(container); FabricValidations.validateProfileNames(profiles); Container cont = FabricCommand.getContainer(fabricService, container); // we can only change to existing profiles Profile[] profs = FabricCommand.getExistingProfiles(fabricService, cont.getVersion(), profiles); cont.setProfiles(profs); return null; }