Search in sources :

Example 1 with CountingMap

use of io.fabric8.utils.CountingMap in project fabric8 by jboss-fuse.

the class HostProfileCounter method incrementProfilesCount.

public void incrementProfilesCount(String hostAlias, List<String> profileIds) {
    CountingMap counts = profileCounts(hostAlias);
    counts.incrementAll(profileIds);
}
Also used : CountingMap(io.fabric8.utils.CountingMap)

Example 2 with CountingMap

use of io.fabric8.utils.CountingMap in project fabric8 by jboss-fuse.

the class HostProfileCounter method decrementProfilesCount.

public void decrementProfilesCount(String hostAlias, List<String> profileIds) {
    CountingMap counts = profileCounts(hostAlias);
    counts.decrementAll(profileIds);
}
Also used : CountingMap(io.fabric8.utils.CountingMap)

Example 3 with CountingMap

use of io.fabric8.utils.CountingMap in project fabric8 by jboss-fuse.

the class SshAutoScalerTest method assertMaximumContainerCountNotExceeded.

/**
 * lets assert that no host has more than its maximum number of containers
 */
public static void assertMaximumContainerCountNotExceeded(FabricRequirements requirements, Map<String, CountingMap> hostToProfileCounts) {
    for (Map.Entry<String, CountingMap> entry : hostToProfileCounts.entrySet()) {
        String hostName = entry.getKey();
        CountingMap counts = entry.getValue();
        int total = counts.total();
        SshConfiguration sshConfiguration = requirements.getSshConfiguration();
        assertNotNull("Should have a sshConfiguration!", sshConfiguration);
        SshHostConfiguration hostConfiguration = sshConfiguration.getHost(hostName);
        assertNotNull("Should have a hosts configuration for host " + hostName, hostConfiguration);
        Integer maximumContainerCount = hostConfiguration.getMaximumContainerCount();
        if (maximumContainerCount != null) {
            assertTrue("Host " + hostName + " has a maximum container count of " + maximumContainerCount + " but was " + total, total <= maximumContainerCount);
        }
    }
}
Also used : CountingMap(io.fabric8.utils.CountingMap) SshConfiguration(io.fabric8.api.SshConfiguration) SshHostConfiguration(io.fabric8.api.SshHostConfiguration) CountingMap(io.fabric8.utils.CountingMap) Map(java.util.Map)

Example 4 with CountingMap

use of io.fabric8.utils.CountingMap 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 5 with CountingMap

use of io.fabric8.utils.CountingMap in project fabric8 by jboss-fuse.

the class AutoScalers method createHostToProfileScaleMap.

public static Map<String, CountingMap> createHostToProfileScaleMap(HostProfileCounter hostContainerCounts, List<? extends HostConfiguration> hostConfigurations, Container[] containers) {
    Map<String, CountingMap> answer = new HashMap<>();
    if (containers != null) {
        if (containers != null) {
            for (Container container : containers) {
                String hostAlias = findHostAlias(hostConfigurations, container);
                if (hostAlias != null) {
                    hostContainerCounts.incrementContainers(hostAlias);
                    List<String> profileIds = Profiles.profileIds(container.getProfiles());
                    hostContainerCounts.incrementProfilesCount(hostAlias, profileIds);
                }
            }
        }
    }
    return answer;
}
Also used : CountingMap(io.fabric8.utils.CountingMap) Container(io.fabric8.api.Container) HashMap(java.util.HashMap)

Aggregations

CountingMap (io.fabric8.utils.CountingMap)8 Map (java.util.Map)3 ProfileRequirements (io.fabric8.api.ProfileRequirements)2 AutoScaleRequest (io.fabric8.api.AutoScaleRequest)1 Container (io.fabric8.api.Container)1 SshConfiguration (io.fabric8.api.SshConfiguration)1 SshHostConfiguration (io.fabric8.api.SshHostConfiguration)1 HostProfileCounter (io.fabric8.internal.autoscale.HostProfileCounter)1 HashMap (java.util.HashMap)1