Search in sources :

Example 11 with FabricRequirements

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

the class SshAutoScalerTest method testAllocateEquallyUsingTags.

@Test
public void testAllocateEquallyUsingTags() throws Exception {
    String[] mqBoxes = { "mq1", "mq2" };
    String[] esbBoxes = { "esb1", "esb2", "esb3", "esb4" };
    FabricRequirements requirements = new FabricRequirements();
    requirements.sshConfiguration().defaultUsername("root");
    for (String box : mqBoxes) {
        requirements.sshHost(box).tags("mq");
    }
    for (String box : esbBoxes) {
        requirements.sshHost(box).tags("esb");
    }
    requirements.profile(mqProfileId).minimumInstances(2).sshScaling().hostTags("mq");
    requirements.profile(exampleProfileId).minimumInstances(8).dependentProfiles(mqProfileId).sshScaling().hostTags("esb");
    HostProfileCounter hostProfileCounter = assertSshAutoScale(requirements);
    for (String box : mqBoxes) {
        assertHostHasProfileCount(hostProfileCounter, box, mqProfileId, 1);
    }
    for (String box : esbBoxes) {
        assertHostHasProfileCount(hostProfileCounter, box, exampleProfileId, 2);
    }
    dumpHostProfiles(hostProfileCounter);
}
Also used : FabricRequirements(io.fabric8.api.FabricRequirements) HostProfileCounter(io.fabric8.internal.autoscale.HostProfileCounter) Test(org.junit.Test)

Example 12 with FabricRequirements

use of io.fabric8.api.FabricRequirements 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 13 with FabricRequirements

use of io.fabric8.api.FabricRequirements 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 14 with FabricRequirements

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

the class SshAutoScalerTest method testMaximumProfileCountPerHost.

@Test
public void testMaximumProfileCountPerHost() throws Exception {
    String hostSmall = "small";
    String hostMedium = "medium";
    String hostBig = "big";
    FabricRequirements requirements = new FabricRequirements();
    requirements.sshConfiguration().defaultPath("/opt/fuse").defaultUsername("root").defaultPassword("adminuser").defaultPassPhrase("cheese");
    requirements.sshHost(hostSmall).hostName(hostSmall).maximumContainerCount(1);
    requirements.sshHost(hostMedium).hostName(hostMedium).maximumContainerCount(2);
    requirements.sshHost(hostBig).hostName(hostBig).maximumContainerCount(8);
    requirements.profile(mqProfileId).minimumInstances(2).maximumInstancesPerHost(1).sshScaling().hostPatterns("!small");
    requirements.profile(exampleProfileId).minimumInstances(5).dependentProfiles(mqProfileId);
    HostProfileCounter hostProfileCounter = assertSshAutoScale(requirements);
    assertHostHasProfileCount(hostProfileCounter, hostSmall, exampleProfileId, 1);
    assertHostHasProfileCount(hostProfileCounter, hostMedium, exampleProfileId, 1);
    assertHostHasProfileCount(hostProfileCounter, hostMedium, mqProfileId, 1);
    assertHostHasProfileCount(hostProfileCounter, hostBig, mqProfileId, 1);
    assertHostHasProfileCount(hostProfileCounter, hostBig, exampleProfileId, 3);
    dumpHostProfiles(hostProfileCounter);
}
Also used : FabricRequirements(io.fabric8.api.FabricRequirements) HostProfileCounter(io.fabric8.internal.autoscale.HostProfileCounter) Test(org.junit.Test)

Example 15 with FabricRequirements

use of io.fabric8.api.FabricRequirements 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)

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