public List<Profile> getActiveOrRequiredBrokerProfileMap() { return getActiveOrRequiredBrokerProfileMap(fabricService.getDefaultVersion()); }
@Override protected Object doExecute() throws Exception { Version ver = version != null ? profileService.getVersion(version) : fabricService.getDefaultVersion(); if (ver == null) { if (version != null) { System.out.println("Version " + version + " does not exist!"); } else { System.out.println("No default version available!"); } return null; } fabricService.adapt(ProfileRegistry.class).exportProfiles(ver.getId(), outputZipFileName.getAbsolutePath(), wildcard); System.out.println("Exported profiles to " + outputZipFileName.getCanonicalPath()); return null; } }
@Override protected Object doExecute() throws Exception { Version ver = version != null ? profileService.getVersion(version) : fabricService.getDefaultVersion(); if (ver == null) { if (version != null) { System.out.println("Version " + version + " does not exist!"); } else { System.out.println("No default version available!"); } return null; } fabricService.adapt(ProfileRegistry.class).importProfiles(ver.getId(), profileUrls); System.out.println("Imported profiles into version " + ver.getId()); return null; } }
@Override protected Object doExecute() throws Exception { Version version = profileService.getRequiredVersion(versionId); StringBuilder sb = new StringBuilder(); for (Container container : fabricService.getContainers()) { if (version.equals(container.getVersion())) { if (sb.length() > 0) { sb.append(", "); } sb.append(container.getId()); } } IllegalStateAssertion.assertTrue(sb.length() == 0, "Version " + versionId + " is still used by the following containers: " + sb.toString()); Version currentDefault = fabricService.getDefaultVersion(); if (version.compareTo(currentDefault) == 0) { System.out.println("Default Version " + version + " can't get deleted."); } else { profileService.deleteVersion(versionId); } return null; } }
@Override protected Object doExecute() throws Exception { // do not validate the old name in case a profile was created somehow with invalid name // but validate the new name try { FabricValidations.validateProfileName(newName); } 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; } Version version; if (versionId != null) { version = profileService.getRequiredVersion(versionId); } else { version = fabricService.getDefaultVersion(); } if (!version.hasProfile(profileName)) { System.out.println("Profile " + profileName + " not found."); return null; } else if (version.hasProfile(newName)) { if (!force) { System.out.println("New name " + newName + " already exists. Use --force if you want to overwrite."); return null; } } Profiles.renameProfile(fabricService, versionId, profileName, newName, force); return null; }
@Override protected Object doExecute() throws Exception { Version ver = version != null ? profileService.getVersion(version) : fabricService.getDefaultVersion(); if (ver == null) { if (version != null) {
/** * Validates the requirements to ensure the profiles exist etc. and * removes those for a profile that does not exist. */ public static void validateRequirements(FabricService fabricService, FabricRequirements requirements) { ProfileService profileService = fabricService.adapt(ProfileService.class); String versionId = requirements.getVersion(); Version version; if (!Strings.isNullOrEmpty(versionId)) { version = profileService.getRequiredVersion(versionId); } else { version = fabricService.getDefaultVersion(); } Set<String> profileIds = new HashSet<>(Profiles.profileIds(version.getProfiles())); List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements(); List<String> profilesToBeRemoved = new ArrayList<>(); for (ProfileRequirements profileRequirement : profileRequirements) { try { validateProfileRequirements(fabricService, requirements, profileRequirement, profileIds); } catch (IllegalArgumentException e) { LOGGER.info("Removing {}; {}", profileRequirement, e.getMessage()); profilesToBeRemoved.add(profileRequirement.getProfile()); } } for(String profile : profilesToBeRemoved){ requirements.removeProfileRequirements(profile); } }
@Override public List<MQBrokerStatusDTO> loadBrokerStatus(String versionId) throws Exception { FabricRequirements requirements = fabricService.getRequirements(); List<MQBrokerStatusDTO> answer = new ArrayList<MQBrokerStatusDTO>(); Version version = versionId == null ? fabricService.getDefaultVersion() : profileService.getVersion(versionId); Container[] containers = fabricService.getContainers(); List<Profile> values = getActiveOrRequiredBrokerProfileMap(version, requirements); for (Profile profile : values) { List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile); for (MQBrokerConfigDTO configDTO : list) { ProfileRequirements profileRequirements = requirements.findProfileRequirements(profile.getId()); int count = 0; for (Container container : containers) { if (Containers.containerHasProfile(container, profile)) { MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, container); count++; answer.add(status); } } // if there are no containers yet, lets create a record anyway if (count == 0) { MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, null); answer.add(status); } } } addMasterSlaveStatus(answer); return answer; }