use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class FabricManager method containersForProfile.
@Override
public List<Map<String, Object>> containersForProfile(String versionId, String profileId, List<String> fields, boolean checkParents) {
Version version = profileService.getVersion(versionId);
Profile profile = version != null ? version.getRequiredProfile(profileId) : null;
Set<Map<String, Object>> answer = new LinkedHashSet<Map<String, Object>>();
if (profile != null) {
for (Container c : fabricService.getContainers()) {
for (Profile p : c.getProfiles()) {
if (p.equals(profile)) {
answer.add(BeanUtils.convertContainerToMap(fabricService, c, fields));
} else if (checkParents) {
HashSet<Profile> profileIDs = new HashSet<>();
getAllParentProfiles(version, p, profileIDs);
for (Profile pprofile : profileIDs) {
if (pprofile.equals(profile)) {
answer.add(BeanUtils.convertContainerToMap(fabricService, c, fields));
break;
}
}
}
}
}
}
return new ArrayList<>(answer);
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class FabricManager method createVersion.
@Override
public Map<String, Object> createVersion() {
Version latestVersion = getLatestVersion();
VersionSequence sequence = new VersionSequence(latestVersion.getId());
return createVersion(sequence.next().getName());
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class MQManager method loadBrokerStatus.
@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;
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class MQManager method createConfigDTOs.
public static List<MQBrokerConfigDTO> createConfigDTOs(MQService mqService, Profile profile) {
List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
Map<String, Map<String, String>> configurations = profile.getConfigurations();
Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
for (Map.Entry<String, Map<String, String>> entry : entries) {
String key = entry.getKey();
Map<String, String> configuration = entry.getValue();
if (isBrokerConfigPid(key)) {
String brokerName = getBrokerNameFromPID(key);
String profileId = profile.getId();
MQBrokerConfigDTO dto = new MQBrokerConfigDTO();
dto.setProfile(profileId);
dto.setBrokerName(brokerName);
String version = profile.getVersion();
dto.setVersion(version);
List<String> parentIds = profile.getParentIds();
if (parentIds.size() > 0) {
dto.setParentProfile(parentIds.get(0));
}
if (configuration != null) {
dto.setData(configuration.get(DATA));
dto.setConfigUrl(configuration.get(CONFIG_URL));
dto.setGroup(configuration.get(GROUP));
dto.setKind(BrokerKind.fromValue(configuration.get(KIND)));
dto.setMinimumInstances(Maps.integerValue(configuration, MINIMUM_INSTANCES));
dto.setNetworks(Maps.stringValues(configuration, NETWORKS));
dto.setNetworksUserName(configuration.get(NETWORK_USER_NAME));
dto.setNetworksPassword(configuration.get(NETWORK_PASSWORD));
dto.setReplicas(Maps.integerValue(configuration, REPLICAS));
for (Map.Entry<String, String> configurationEntry : configuration.entrySet()) {
if (configurationEntry.getKey().endsWith("-port")) {
dto.getPorts().put(configurationEntry.getKey().substring(0, configurationEntry.getKey().indexOf("-port")), configurationEntry.getValue());
}
}
}
answer.add(dto);
}
}
return answer;
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class MQManager method getActiveOrRequiredBrokerProfileMap.
private List<Profile> getActiveOrRequiredBrokerProfileMap(Version version, FabricRequirements requirements) {
IllegalArgumentAssertion.assertNotNull(fabricService, "fabricService");
List<Profile> answer = new ArrayList<Profile>();
if (version != null) {
ProfileService profileService = fabricService.adapt(ProfileService.class);
List<Profile> profiles = version.getProfiles();
for (Profile profile : profiles) {
String versionId = profile.getVersion();
String profileId = profile.getId();
if (!IGNORED_PROFILES.contains(profileId)) {
Profile overlay = profileService.getOverlayProfile(profile);
Map<String, Map<String, String>> configurations = overlay.getConfigurations();
Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
for (Map.Entry<String, Map<String, String>> entry : entries) {
String key = entry.getKey();
if (isBrokerConfigPid(key)) {
answer.add(overlay);
}
}
}
}
}
return answer;
}
Aggregations