Search in sources :

Example 6 with ProfileRequirements

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

the class AutoScalers method requirementsSatisfied.

/**
 * Returns true if the requirements are satisfied for the given profile requirements; updating the auto scale status
 * accordingly
 */
public static boolean requirementsSatisfied(FabricService service, String version, FabricRequirements requirements, ProfileRequirements profileRequirement, AutoScaleStatus status) {
    String profile = profileRequirement.getProfile();
    List<String> dependentProfiles = profileRequirement.getDependentProfiles();
    if (dependentProfiles != null) {
        for (String dependentProfile : dependentProfiles) {
            ProfileRequirements dependentProfileRequirements = requirements.getOrCreateProfileRequirement(dependentProfile);
            Integer minimumInstances = dependentProfileRequirements.getMinimumInstances();
            if (minimumInstances != null) {
                List<Container> containers = Containers.aliveAndSuccessfulContainersForProfile(version, dependentProfile, service);
                int dependentSize = containers.size();
                if (minimumInstances > dependentSize) {
                    status.profileStatus(profile).missingDependency(dependentProfile, dependentSize, minimumInstances);
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Container(io.fabric8.api.Container) ProfileRequirements(io.fabric8.api.ProfileRequirements)

Example 7 with ProfileRequirements

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

the class SshAutoScalerTest method assertSshAutoScale.

public static HostProfileCounter assertSshAutoScale(FabricRequirements requirements, AutoScaleStatus status) {
    HostProfileCounter hostProfileCounter = new HostProfileCounter();
    String version = requirements.getVersion();
    if (Strings.isEmpty(version)) {
        version = "1.0";
    }
    List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
    for (ProfileRequirements profileRequirement : profileRequirements) {
        Integer minimumInstances = profileRequirement.getMinimumInstances();
        if (minimumInstances != null) {
            for (int i = 0; i < minimumInstances; i++) {
                String profileId = profileRequirement.getProfile();
                AutoScaleRequest request = new AutoScaleRequest(null, version, profileId, 1, requirements, profileRequirement, status);
                CreateSshContainerOptions.Builder builder = chooseHostContainerOptions(request, hostProfileCounter);
                assertNotNull("Should have found a builder for " + profileId, builder);
                String host = builder.getHost();
                hostProfileCounter.incrementContainers(host);
                hostProfileCounter.incrementProfileCount(host, profileId);
            }
        }
    }
    Map<String, CountingMap> hostToProfileCounts = hostProfileCounter.getHostToProfileCounts();
    assertProfilesUseSeparateHost(requirements, hostToProfileCounts);
    assertMaximumContainerCountNotExceeded(requirements, hostToProfileCounts);
    return hostProfileCounter;
}
Also used : CountingMap(io.fabric8.utils.CountingMap) ProfileRequirements(io.fabric8.api.ProfileRequirements) AutoScaleRequest(io.fabric8.api.AutoScaleRequest) HostProfileCounter(io.fabric8.internal.autoscale.HostProfileCounter)

Example 8 with ProfileRequirements

use of io.fabric8.api.ProfileRequirements 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 9 with ProfileRequirements

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

the class RequireProfileSetAction method updateRequirements.

@Override
protected boolean updateRequirements(FabricRequirements requirements) {
    if (v != null) {
        setVersion(v);
    } else {
        setVersion(getFabricService().getDefaultVersionId());
    }
    ProfileRequirements requirement = new ProfileRequirements(profile);
    if (minimumInstances != null) {
        requirement.setMinimumInstances(minimumInstances);
    }
    if (maximumInstances != null) {
        requirement.setMaximumInstances(maximumInstances);
    }
    if (dependentProfiles != null) {
        requirement.setDependentProfiles(dependentProfiles);
    }
    requirements.addOrUpdateProfileRequirements(requirement);
    return true;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements)

Example 10 with ProfileRequirements

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

the class FabricServiceImpl method validateRequirements.

/**
 * 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);
    }
}
Also used : ProfileService(io.fabric8.api.ProfileService) ProfileRequirements(io.fabric8.api.ProfileRequirements) Version(io.fabric8.api.Version) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

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