Search in sources :

Example 31 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class ClusterUpscaleServiceTest method newHostGroup.

private HostGroup newHostGroup(String name, InstanceMetaData... instances) {
    HostGroup hostGroup = new HostGroup();
    hostGroup.setName(name);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceMetaData(Set.of(instances));
    hostGroup.setInstanceGroup(instanceGroup);
    return hostGroup;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 32 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class StackCreatorServiceTest method testFillInstanceMetadataWhenManager.

@Test
public void testFillInstanceMetadataWhenManager() {
    Stack stack = new Stack();
    InstanceGroup managerGroup = getARequestGroup("manager", 1, InstanceGroupType.GATEWAY);
    InstanceGroup gatewayGroup = getARequestGroup("gateway", 2, InstanceGroupType.CORE);
    InstanceGroup computeGroup = getARequestGroup("compute", 0, InstanceGroupType.CORE);
    InstanceGroup workerGroup = getARequestGroup("worker", 3, InstanceGroupType.CORE);
    InstanceGroup masterGroup = getARequestGroup("master", 2, InstanceGroupType.CORE);
    stack.setInstanceGroups(Set.of(masterGroup, workerGroup, computeGroup, managerGroup, gatewayGroup));
    when(multiAzCalculatorService.prepareSubnetAzMap(environmentResponse)).thenReturn(Map.of());
    doNothing().when(multiAzCalculatorService).calculateByRoundRobin(anyMap(), any(InstanceGroup.class));
    underTest.fillInstanceMetadata(environmentResponse, stack);
    Map<String, Set<InstanceMetaData>> hostGroupInstances = stack.getInstanceGroups().stream().collect(Collectors.toMap(InstanceGroup::getGroupName, InstanceGroup::getAllInstanceMetaData));
    long privateIdStart = 0L;
    validateInstanceMetadataPrivateId("manager", 1, privateIdStart, hostGroupInstances.get("manager"));
    validateInstanceMetadataSubnetAndAvailabilityZoneAndRackId("manager", 1, hostGroupInstances.get("manager"), null, null, null);
    privateIdStart = 1L;
    validateInstanceMetadataPrivateId("compute", 0, privateIdStart, hostGroupInstances.get("compute"));
    validateInstanceMetadataSubnetAndAvailabilityZoneAndRackId("compute", 0, hostGroupInstances.get("compute"), null, null, null);
    privateIdStart = 1L;
    validateInstanceMetadataPrivateId("gateway", 2, privateIdStart, hostGroupInstances.get("gateway"));
    validateInstanceMetadataSubnetAndAvailabilityZoneAndRackId("gateway", 2, hostGroupInstances.get("gateway"), null, null, null);
    privateIdStart = 3L;
    validateInstanceMetadataPrivateId("master", 2, privateIdStart, hostGroupInstances.get("master"));
    validateInstanceMetadataSubnetAndAvailabilityZoneAndRackId("master", 2, hostGroupInstances.get("master"), null, null, null);
    privateIdStart = 5L;
    validateInstanceMetadataPrivateId("worker", 3, privateIdStart, hostGroupInstances.get("worker"));
    validateInstanceMetadataSubnetAndAvailabilityZoneAndRackId("worker", 3, hostGroupInstances.get("worker"), null, null, null);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class StackCreatorServiceTest method fillInstanceMetadataTestWhenSubnetAndAvailabilityZoneAndRackIdAndRoundRobin.

@ParameterizedTest(name = "{0}")
@MethodSource("fillInstanceMetadataTestWhenSubnetAndAvailabilityZoneAndRackIdAndRoundRobinDataProvider")
public void fillInstanceMetadataTestWhenSubnetAndAvailabilityZoneAndRackIdAndRoundRobin(String testCaseName, String subnetId, String availabilityZone) {
    Stack stack = new Stack();
    InstanceGroup workerGroup = getARequestGroup("worker", 3, InstanceGroupType.CORE);
    stack.setInstanceGroups(Set.of(workerGroup));
    Map<String, String> subnetAzPairs = Map.of();
    when(multiAzCalculatorService.prepareSubnetAzMap(environmentResponse)).thenReturn(subnetAzPairs);
    doAnswer(invocation -> {
        InstanceGroup instanceGroup = invocation.getArgument(1, InstanceGroup.class);
        instanceGroup.getAllInstanceMetaData().forEach(instanceMetaData -> {
            instanceMetaData.setSubnetId(subnetId);
            instanceMetaData.setAvailabilityZone(availabilityZone);
        });
        return null;
    }).when(multiAzCalculatorService).calculateByRoundRobin(subnetAzPairs, workerGroup);
    when(multiAzCalculatorService.determineRackId(subnetId, availabilityZone)).thenReturn("/fooRack");
    underTest.fillInstanceMetadata(environmentResponse, stack);
    Map<String, Set<InstanceMetaData>> hostGroupInstances = stack.getInstanceGroups().stream().collect(Collectors.toMap(InstanceGroup::getGroupName, InstanceGroup::getAllInstanceMetaData));
    long privateIdStart = 0L;
    validateInstanceMetadataPrivateId("worker", 3, privateIdStart, hostGroupInstances.get("worker"));
    validateInstanceMetadataSubnetAndAvailabilityZoneAndRackId("worker", 3, hostGroupInstances.get("worker"), subnetId, availabilityZone, "/fooRack");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 34 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class StackCreatorServiceTest method fillInstanceMetadataTestWhenSubnetAndAvailabilityZoneAndRackIdAndStackFallback.

@Test
public void fillInstanceMetadataTestWhenSubnetAndAvailabilityZoneAndRackIdAndStackFallback() {
    Stack stack = new Stack();
    InstanceGroup workerGroup = getARequestGroup("worker", 3, InstanceGroupType.CORE);
    stack.setInstanceGroups(Set.of(workerGroup));
    Network network = new Network();
    network.setAttributes(Json.silent(Map.of("subnetId", "subnet-1")));
    stack.setNetwork(network);
    Map<String, String> subnetAzPairs = Map.of("subnet-1", "az-1");
    when(multiAzCalculatorService.prepareSubnetAzMap(environmentResponse)).thenReturn(subnetAzPairs);
    doNothing().when(multiAzCalculatorService).calculateByRoundRobin(subnetAzPairs, workerGroup);
    when(multiAzCalculatorService.determineRackId("subnet-1", "az-1")).thenReturn("/fooRack");
    underTest.fillInstanceMetadata(environmentResponse, stack);
    Map<String, Set<InstanceMetaData>> hostGroupInstances = stack.getInstanceGroups().stream().collect(Collectors.toMap(InstanceGroup::getGroupName, InstanceGroup::getAllInstanceMetaData));
    long privateIdStart = 0L;
    validateInstanceMetadataPrivateId("worker", 3, privateIdStart, hostGroupInstances.get("worker"));
    validateInstanceMetadataSubnetAndAvailabilityZoneAndRackId("worker", 3, hostGroupInstances.get("worker"), "subnet-1", "az-1", "/fooRack");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Network(com.sequenceiq.cloudbreak.domain.Network) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class StopStartDownscaleDecommissionViaCMHandlerTest method getInstancesToDecommission.

private List<InstanceMetaData> getInstancesToDecommission(int count) {
    List<InstanceMetaData> instances = new ArrayList<>(count);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(INSTANCE_GROUP_NAME);
    for (int i = 0; i < count; i++) {
        InstanceMetaData instanceMetaData = new InstanceMetaData();
        instanceMetaData.setInstanceId(INSTANCE_ID_PREFIX + i);
        instanceMetaData.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
        instanceMetaData.setInstanceGroup(instanceGroup);
        instanceMetaData.setDiscoveryFQDN(INSTANCE_ID_PREFIX + i);
        instanceMetaData.setPrivateId((long) i);
        instances.add(instanceMetaData);
    }
    return instances;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArrayList(java.util.ArrayList) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)288 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)132 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)93 Test (org.junit.jupiter.api.Test)91 HashSet (java.util.HashSet)68 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)47 Template (com.sequenceiq.cloudbreak.domain.Template)45 Test (org.junit.Test)44 Json (com.sequenceiq.cloudbreak.common.json.Json)38 Set (java.util.Set)37 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)34 ArrayList (java.util.ArrayList)31 LinkedHashSet (java.util.LinkedHashSet)31 Map (java.util.Map)28 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)27 List (java.util.List)26 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)25 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22