Search in sources :

Example 11 with ProfileRequirements

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

the class MQManager method createStatusDTO.

protected MQBrokerStatusDTO createStatusDTO(Profile profile, MQBrokerConfigDTO configDTO, ProfileRequirements profileRequirements, Container container) {
    MQBrokerStatusDTO answer = new MQBrokerStatusDTO(configDTO);
    if (container != null) {
        answer.setContainer(container.getId());
        answer.setAlive(container.isAlive());
        answer.setProvisionResult(container.getProvisionResult());
        answer.setProvisionStatus(container.getProvisionStatus());
        answer.setJolokiaUrl(container.getJolokiaUrl());
    }
    if (profileRequirements != null) {
        Integer minimumInstances = profileRequirements.getMinimumInstances();
        if (minimumInstances != null) {
            answer.setMinimumInstances(minimumInstances);
        }
    }
    return answer;
}
Also used : MQBrokerStatusDTO(io.fabric8.api.jmx.MQBrokerStatusDTO)

Example 12 with ProfileRequirements

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

the class MQManager method createOrUpdateProfile.

/**
 * Creates or updates the broker profile for the given DTO and updates the requirements so that the
 * minimum number of instances of the profile is updated
 */
public static Profile createOrUpdateProfile(MQBrokerConfigDTO dto, FabricService fabricService, RuntimeProperties runtimeProperties) throws IOException {
    FabricRequirements requirements = fabricService.getRequirements();
    MQService mqService = createMQService(fabricService, runtimeProperties);
    Map<String, String> configuration = new HashMap<String, String>();
    List<String> properties = dto.getProperties();
    String version = dto.version();
    boolean changeInCurrentVersion = requirements.getVersion().equals(dto.getVersion());
    if (properties != null) {
        for (String entry : properties) {
            String[] parts = entry.split("=", 2);
            if (parts.length == 2) {
                configuration.put(parts[0], parts[1]);
            } else {
                configuration.put(parts[0], "");
            }
        }
    }
    String data = dto.getData();
    String profileName = dto.profile();
    try {
        FabricValidations.validateProfileName(profileName);
    } 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;
    }
    String brokerName = dto.getBrokerName();
    if (data == null) {
        // lets use a relative path so we work on any karaf container
        data = "${runtime.data}" + brokerName;
    }
    configuration.put(DATA, data);
    for (Map.Entry<String, String> port : dto.getPorts().entrySet()) {
        configuration.put(port.getKey() + "-port", port.getValue());
    }
    BrokerKind kind = dto.kind();
    configuration.put(KIND, kind.toString());
    String config = dto.getConfigUrl();
    if (config != null) {
        configuration.put(CONFIG_URL, mqService.getConfig(version, config));
    }
    String group = dto.getGroup();
    if (group != null) {
        configuration.put(GROUP, group);
    }
    Maps.setStringValues(configuration, NETWORKS, dto.getNetworks());
    String networksUserName = dto.getNetworksUserName();
    if (networksUserName != null) {
        configuration.put(NETWORK_USER_NAME, networksUserName);
    }
    String networksPassword = dto.getNetworksPassword();
    if (networksPassword != null) {
        configuration.put(NETWORK_PASSWORD, networksPassword);
    }
    String parentProfile = dto.getParentProfile();
    if (parentProfile != null) {
        configuration.put(PARENT, parentProfile);
    }
    Boolean ssl = dto.getSsl();
    if (ssl != null) {
        configuration.put(SSL, ssl.toString());
    }
    Integer replicas = dto.getReplicas();
    if (replicas != null) {
        configuration.put(REPLICAS, replicas.toString());
    }
    Integer minInstances = dto.getMinimumInstances();
    if (minInstances != null) {
        configuration.put(MINIMUM_INSTANCES, minInstances.toString());
    }
    Profile profile = mqService.createOrUpdateMQProfile(version, profileName, brokerName, configuration, dto.kind().equals(BrokerKind.Replicated));
    String profileId = profile.getId();
    ProfileRequirements profileRequirement = requirements.getOrCreateProfileRequirement(profileId);
    Integer minimumInstances = profileRequirement.getMinimumInstances();
    // lets reload the DTO as we may have inherited some values from the parent profile
    List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);
    // lets assume 2 required instances for master/slave unless folks use
    // N+1 or replicated
    int requiredInstances = 2;
    if (list.size() == 1) {
        MQBrokerConfigDTO loadedDTO = list.get(0);
        requiredInstances = loadedDTO.requiredInstances();
    } else {
        // assume N+1 broker as there's more than one broker in the profile; so lets set the required size to N+1
        requiredInstances = list.size() + 1;
    }
    if (changeInCurrentVersion && (minimumInstances == null || minimumInstances.intValue() < requiredInstances)) {
        profileRequirement.setMinimumInstances(requiredInstances);
        fabricService.setRequirements(requirements);
    }
    String clientProfile = dto.clientProfile();
    if (Strings.isNotBlank(clientProfile)) {
        String clientParentProfile = dto.getClientParentProfile();
        if (Strings.isNullOrBlank(clientParentProfile)) {
            clientParentProfile = "mq-client-base";
        }
        mqService.createOrUpdateMQClientProfile(version, clientProfile, group, clientParentProfile);
    }
    return profile;
}
Also used : MQService(io.fabric8.api.MQService) ProfileRequirements(io.fabric8.api.ProfileRequirements) BrokerKind(io.fabric8.api.jmx.BrokerKind) HashMap(java.util.HashMap) Profile(io.fabric8.api.Profile) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) FabricRequirements(io.fabric8.api.FabricRequirements) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with ProfileRequirements

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

the class ChildAutoScaler method getChildScalingRequirements.

protected ChildScalingRequirements getChildScalingRequirements(AutoScaleRequest request) {
    ChildScalingRequirements scalingRequirements = null;
    ProfileRequirements profileRequirements = request.getProfileRequirements();
    if (profileRequirements != null) {
        scalingRequirements = profileRequirements.getChildScalingRequirements();
    }
    return scalingRequirements;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) ChildScalingRequirements(io.fabric8.api.ChildScalingRequirements)

Example 14 with ProfileRequirements

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

the class ProfileScalingTest method doAssertProfileMinimumSize.

protected void doAssertProfileMinimumSize(FabricService fabricService, String profile, Integer expected) throws IOException {
    // lests add a little but of time to make sure that the ZK / Git cache has updated correctly
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    // ignore
    }
    FabricRequirements requirements = fabricService.getRequirements();
    ProfileRequirements profileRequirements = requirements.getOrCreateProfileRequirement(profile);
    Assert.assertNotNull("Should have profile requirements for profile " + profile, profileRequirements);
    Assert.assertEquals("profile " + profile + " minimum instances", expected, profileRequirements.getMinimumInstances());
    System.out.println("Profile " + profile + " now has requirements " + profileRequirements);
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) FabricRequirements(io.fabric8.api.FabricRequirements) IOException(java.io.IOException)

Example 15 with ProfileRequirements

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

the class AutoScaleController method stopContainers.

protected void stopContainers(List<Container> containers, ContainerAutoScaler autoScaler, FabricRequirements requirements, ProfileRequirements profileRequirement, AutoScaleStatus status, int delta) {
    final String profile = profileRequirement.getProfile();
    AutoScaleProfileStatus profileStatus = status.profileStatus(profile);
    // TODO sort the containers using some kind of requirements sorting order
    List<Container> sorted = new ArrayList<>(containers);
    // lets stop the ones at the end of the list by default
    Collections.reverse(sorted);
    List<String> stoppingContainerIds = new ArrayList<>();
    for (int i = 0; i < delta; i++) {
        if (i >= sorted.size()) {
            break;
        }
        Container container = sorted.get(i);
        stoppingContainerIds.add(container.getId());
        profileStatus.stoppingContainers(stoppingContainerIds);
        container.stop(true);
    }
}
Also used : Container(io.fabric8.api.Container) AutoScaleProfileStatus(io.fabric8.api.AutoScaleProfileStatus) ArrayList(java.util.ArrayList)

Aggregations

ProfileRequirements (io.fabric8.api.ProfileRequirements)15 FabricRequirements (io.fabric8.api.FabricRequirements)8 Container (io.fabric8.api.Container)5 ArrayList (java.util.ArrayList)4 FabricService (io.fabric8.api.FabricService)3 Profile (io.fabric8.api.Profile)3 AutoScaleProfileStatus (io.fabric8.api.AutoScaleProfileStatus)2 AutoScaleRequest (io.fabric8.api.AutoScaleRequest)2 ContainerAutoScaler (io.fabric8.api.ContainerAutoScaler)2 ProfileService (io.fabric8.api.ProfileService)2 Version (io.fabric8.api.Version)2 MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)2 MQBrokerStatusDTO (io.fabric8.api.jmx.MQBrokerStatusDTO)2 CountingMap (io.fabric8.utils.CountingMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Feature (io.fabric8.agent.model.Feature)1 AutoScaleStatus (io.fabric8.api.AutoScaleStatus)1 ChildScalingRequirements (io.fabric8.api.ChildScalingRequirements)1