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 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); } }
@Override public void addProfiles(Profile... profiles) { List<Profile> addedProfiles = Arrays.asList(profiles); List<Profile> updatedProfileList = new LinkedList<Profile>(); for (Profile p : getProfiles()) { updatedProfileList.add(p); } ProfileService profileService = fabricService.adapt(ProfileService.class); for (Profile addedProfile : addedProfiles) { String versionId = addedProfile.getVersion(); String profileId = addedProfile.getId(); if (!profileService.hasProfile(versionId, profileId)) { throw new IllegalArgumentException("Profile " + profileId + " doesn't exist."); } else if (!updatedProfileList.contains(addedProfile)) { updatedProfileList.add(addedProfile); } } setProfiles(updatedProfileList.toArray(new Profile[updatedProfileList.size()])); }
@Override public boolean hasProfile(String versionId, String profileId) { Permit<ProfileService> permit = permitManager.get().aquirePermit(ProfileService.PERMIT, false); try { ProfileService service = permit.getInstance(); return service.hasProfile(versionId, profileId); } finally { permit.release(); } }
@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); } }
if (profileService.hasProfile(versionId, id)) { return Response.seeOther(location).entity("Profile already exists for id: " + id).build();
if (profileService.hasProfile(versionId, id)) { return Response.seeOther(location).entity("Profile already exists for id: " + id).build();
protected void printProfiles(ProfileService profileService, List<Profile> profiles, PrintStream out) { TablePrinter table = new TablePrinter(); table.columns("id", "# containers", "parents"); for (Profile profile : profiles) { String versionId = profile.getVersion(); String profileId = profile.getId(); // skip profiles that do not exists (they may have been deleted) if (profileService.hasProfile(versionId, profileId) && (hidden || !profile.isHidden())) { int active = fabricService.getAssociatedContainers(versionId, profileId).length; String parents = Strings.join(profile.getParentIds(), " "); table.row(profileId, activeContainerCountText(active), parents); } } table.print(); }