Search in sources :

Example 31 with FabricRequirements

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

the class SshAutoScalerTest method assertProfilesUseSeparateHost.

/**
 * lets assert that no host has more than its maximum number of containers
 */
public static void assertProfilesUseSeparateHost(FabricRequirements requirements, Map<String, CountingMap> hostToProfileCounts) {
    for (Map.Entry<String, CountingMap> entry : hostToProfileCounts.entrySet()) {
        String hostName = entry.getKey();
        CountingMap counts = entry.getValue();
        Set<String> keys = counts.keySet();
        for (String profileId : keys) {
            int count = counts.count(profileId);
            // lets see if we have a maximum number of profile count
            ProfileRequirements profileRequirement = requirements.getOrCreateProfileRequirement(profileId);
            Integer maximum = profileRequirement.getMaximumInstancesPerHost();
            if (maximum != null) {
                assertTrue("Host " + hostName + " has " + count + " instances of " + profileId + " but this is configured to have a maximium of " + maximum + " per host", count <= maximum);
            }
        }
    }
}
Also used : CountingMap(io.fabric8.utils.CountingMap) ProfileRequirements(io.fabric8.api.ProfileRequirements) CountingMap(io.fabric8.utils.CountingMap) Map(java.util.Map)

Example 32 with FabricRequirements

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

the class FabricManager method requirementsJson.

@Override
public void requirementsJson(String json) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    Object value = mapper.reader(FabricRequirements.class).readValue(json);
    if (value instanceof FabricRequirements) {
        requirements((FabricRequirements) value);
    } else {
        throw new IOException("Failed to parse FabricRequirements from JSON. Got " + value + ". JSON: " + json);
    }
}
Also used : FabricRequirements(io.fabric8.api.FabricRequirements) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 33 with FabricRequirements

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

the class SshAutoScaler method chooseHostContainerOptions.

/**
 * This method is public for easier testing
 */
public static CreateSshContainerOptions.Builder chooseHostContainerOptions(AutoScaleRequest request, HostProfileCounter hostProfileCounter) {
    CreateSshContainerOptions.Builder builder = CreateSshContainerOptions.builder();
    FabricRequirements requirements = request.getFabricRequirements();
    ProfileRequirements profileRequirements = request.getProfileRequirements();
    SshScalingRequirements sshScalingRequirements = profileRequirements.getSshScalingRequirements();
    List<SshHostConfiguration> hosts = requirements.getSshHosts();
    SortedSet<LoadSortedHostConfiguration<SshHostConfiguration>> sortedHostConfigurations = AutoScalers.filterHosts(profileRequirements, sshScalingRequirements, hostProfileCounter, hosts);
    SshHostConfiguration sshHostConfig = null;
    if (!sortedHostConfigurations.isEmpty()) {
        LoadSortedHostConfiguration<SshHostConfiguration> first = sortedHostConfigurations.first();
        sshHostConfig = first.getConfiguration();
    }
    if (sshHostConfig == null) {
        LOG.warn("Could not create version " + request.getVersion() + " profile " + request.getProfile() + " as no matching hosts could be found for " + sshScalingRequirements);
        request.getProfileAutoScaleStatus().noSuitableHost("" + sshScalingRequirements);
        return null;
    }
    builder.configure(sshHostConfig, requirements, profileRequirements);
    return builder;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) SshHostConfiguration(io.fabric8.api.SshHostConfiguration) FabricRequirements(io.fabric8.api.FabricRequirements) LoadSortedHostConfiguration(io.fabric8.internal.autoscale.LoadSortedHostConfiguration) SshScalingRequirements(io.fabric8.api.SshScalingRequirements)

Example 34 with FabricRequirements

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

the class SshAutoScaler method createContainers.

@Override
public void createContainers(AutoScaleRequest request) throws Exception {
    int count = request.getDelta();
    String profile = request.getProfile();
    String version = request.getVersion();
    FabricService fabricService = request.getFabricService();
    Container[] containers = fabricService.getContainers();
    FabricRequirements requirements = request.getFabricRequirements();
    List<? extends HostConfiguration> hostConfigurations = requirements.getSshHosts();
    HostProfileCounter hostProfileCounter = new HostProfileCounter();
    AutoScalers.createHostToProfileScaleMap(hostProfileCounter, hostConfigurations, containers);
    for (int i = 0; i < count; i++) {
        CreateSshContainerOptions.Builder builder = null;
        NameValidator nameValidator = Containers.createNameValidator(containers);
        String name = Containers.createAutoScaleContainerName(containers, profile, containerProvider.getScheme(), nameValidator);
        if (fabricService != null) {
            builder = createAutoScaleOptions(request, fabricService, hostProfileCounter);
        }
        if (builder != null) {
            final CreateSshContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);
            CreateSshContainerOptions options = configuredBuilder.name(name).build();
            LOG.info("Creating container name " + name + " version " + version + " profile " + profile + " " + count + " container(s)");
            fabricService.createContainers(options);
        }
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) NameValidator(io.fabric8.api.NameValidator) FabricRequirements(io.fabric8.api.FabricRequirements) HostProfileCounter(io.fabric8.internal.autoscale.HostProfileCounter)

Aggregations

FabricRequirements (io.fabric8.api.FabricRequirements)21 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 Container (io.fabric8.api.Container)8 FabricService (io.fabric8.api.FabricService)5 Profile (io.fabric8.api.Profile)5 HostProfileCounter (io.fabric8.internal.autoscale.HostProfileCounter)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Map (java.util.Map)4 ProfileService (io.fabric8.api.ProfileService)3 CountingMap (io.fabric8.utils.CountingMap)3 HashSet (java.util.HashSet)3 AutoScaleProfileStatus (io.fabric8.api.AutoScaleProfileStatus)2 AutoScaleRequest (io.fabric8.api.AutoScaleRequest)2 ContainerAutoScaler (io.fabric8.api.ContainerAutoScaler)2 FabricException (io.fabric8.api.FabricException)2 SshHostConfiguration (io.fabric8.api.SshHostConfiguration)2 Version (io.fabric8.api.Version)2 MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)2