Search in sources :

Example 66 with Profile

use of io.fabric8.api.Profile in project fabric8 by jboss-fuse.

the class FabricManager method currentContainerConfigurationFiles.

/**
 * Returns a map of all the current configuration files in the profiles of
 * the current container with the file name as the key and the profile ID as
 * the value
 */
@Override
public Map<String, String> currentContainerConfigurationFiles() {
    String containerName = getCurrentContainerName();
    FabricServiceImpl service = fabricService;
    Container container = service.getContainer(containerName);
    if (container != null) {
        Profile[] profiles = container.getProfiles();
        return Profiles.getConfigurationFileNameMap(profiles);
    }
    return new HashMap<String, String>();
}
Also used : Container(io.fabric8.api.Container) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FabricServiceImpl(io.fabric8.service.FabricServiceImpl) Profile(io.fabric8.api.Profile)

Example 67 with Profile

use of io.fabric8.api.Profile in project fabric8 by jboss-fuse.

the class HealthCheck method healthList.

@Override
public List<HealthStatus> healthList() {
    List<HealthStatus> answer = new ArrayList<HealthStatus>();
    FabricStatus status = fabricService.getFabricStatus();
    Collection<ProfileStatus> statuses = status.getProfileStatusMap().values();
    for (ProfileStatus profile : statuses) {
        String id = profile.getProfile();
        int instances = profile.getCount();
        Integer minimum = profile.getMinimumInstances();
        Integer maximum = profile.getMaximumInstances();
        double healthPercent = profile.getHealth(instances);
        String level = "INFO";
        String message = "Profile " + id + " has health " + percentInstance.format(healthPercent);
        if (minimum != null) {
            if (instances <= 0) {
                level = "ERROR";
                message = "Profile " + id + " has no instances running! Should have at least " + minimum;
            } else if (instances < minimum) {
                level = "WARNING";
                message = "Profile " + id + " needs more instances running. Should have at least " + minimum + " but currently has only " + instances;
            }
        }
        if (maximum != null && level.equals("INFO") && instances > maximum) {
            level = "WARNING";
            message = "Profile " + id + " has too many instances running. Should have at most " + maximum + " but currently has only " + instances;
        }
        answer.add(new HealthStatus("io.fabric8.profileHealth", id, level, message, instances, minimum, maximum, healthPercent));
    }
    String worries = "";
    for (HealthStatus hs : answer) {
        if ("WARNING".equals(hs.getLevel()) || "ERROR".equals(hs.getLevel())) {
            worries += hs + " , ";
        }
    }
    if ("".equals(worries)) {
        this.currentStatus = "Good";
    } else {
        this.currentStatus = "Getting Worried {" + worries + " }";
    }
    return answer;
}
Also used : HealthStatus(io.fabric8.api.jmx.HealthStatus) ArrayList(java.util.ArrayList) ProfileStatus(io.fabric8.api.ProfileStatus) FabricStatus(io.fabric8.api.FabricStatus)

Example 68 with Profile

use of io.fabric8.api.Profile 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;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile) MQBrokerStatusDTO(io.fabric8.api.jmx.MQBrokerStatusDTO) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) Container(io.fabric8.api.Container) Version(io.fabric8.api.Version) FabricRequirements(io.fabric8.api.FabricRequirements)

Example 69 with Profile

use of io.fabric8.api.Profile 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;
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 70 with Profile

use of io.fabric8.api.Profile 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;
}
Also used : ProfileService(io.fabric8.api.ProfileService) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Profile(io.fabric8.api.Profile)

Aggregations

Profile (io.fabric8.api.Profile)125 Version (io.fabric8.api.Version)50 Container (io.fabric8.api.Container)49 ArrayList (java.util.ArrayList)37 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Test (org.junit.Test)32 FabricService (io.fabric8.api.FabricService)28 HashMap (java.util.HashMap)25 File (java.io.File)24 ProfileService (io.fabric8.api.ProfileService)23 Map (java.util.Map)22 IOException (java.io.IOException)19 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 HashSet (java.util.HashSet)12 GitVersion (io.fabric8.api.commands.GitVersion)11 FabricRequirements (io.fabric8.api.FabricRequirements)10 LinkedList (java.util.LinkedList)9 TreeMap (java.util.TreeMap)9 LockHandle (io.fabric8.api.LockHandle)8 Parser (io.fabric8.maven.util.Parser)8