Search in sources :

Example 81 with InstanceGroup

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

the class EmbeddedDatabaseServiceTest method createStack.

private Stack createStack(int volumeCount) {
    Stack stack = new Stack();
    InstanceGroup masterGroup = new InstanceGroup();
    masterGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setInstanceGroup(masterGroup);
    instanceMetaData.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
    masterGroup.setInstanceMetaData(Set.of(instanceMetaData));
    Template template = new Template();
    VolumeTemplate volumeTemplate = new VolumeTemplate();
    volumeTemplate.setVolumeCount(volumeCount);
    volumeTemplate.setUsageType(VolumeUsageType.DATABASE);
    template.setVolumeTemplates(Set.of(volumeTemplate));
    masterGroup.setTemplate(template);
    stack.setInstanceGroups(Set.of(masterGroup));
    stack.setCloudPlatform(CLOUDPLATFORM);
    return stack;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate)

Example 82 with InstanceGroup

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

the class EmbeddedDatabaseServiceTest method createStackWithoutTemplate.

private Stack createStackWithoutTemplate() {
    Stack stack = new Stack();
    InstanceGroup masterGroup = new InstanceGroup();
    masterGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setInstanceGroup(masterGroup);
    instanceMetaData.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
    masterGroup.setInstanceMetaData(Set.of(instanceMetaData));
    stack.setInstanceGroups(Set.of(masterGroup));
    return stack;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 83 with InstanceGroup

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

the class TelemetryAgentServiceTest method createStack.

private Stack createStack() {
    Stack stack = new Stack();
    stack.setId(1L);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceMetaData(createInstanceMetadataSet());
    instanceGroup.setTemplate(new Template());
    stack.setInstanceGroups(Set.of(instanceGroup));
    return stack;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 84 with InstanceGroup

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

the class StackDecoratorTest method createInstanceGroups.

private Set<InstanceGroup> createInstanceGroups(InstanceGroupType... types) {
    Set<InstanceGroup> groups = new LinkedHashSet<>(types.length);
    int i = 0;
    for (InstanceGroupType type : types) {
        InstanceGroup group = mock(InstanceGroup.class);
        when(group.getInstanceGroupType()).thenReturn(type);
        when(group.getGroupName()).thenReturn("name" + i);
        when(group.getNodeCount()).thenReturn(2);
        groups.add(group);
    }
    return groups;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 85 with InstanceGroup

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

the class MultiAzCalculatorServiceTest method testSubnetDistributionForWholeInstanceGroupWhenDeletedInstances.

@ParameterizedTest(name = "testSubnetDistributionForWholeInstanceGroupWhenDeletedInstances " + "with {0} platform when {1} subnets and {2} instances should result in {3} subnet counts")
@MethodSource("testSubnetDistributionForWholeInstanceGroupData")
public void testSubnetDistributionForWholeInstanceGroupWhenDeletedInstances(CloudPlatform cloudPlatform, int subnetCount, int instanceCount, List<Long> expectedCounts, boolean supported) {
    if (supported) {
        when(multiAzValidator.supportedForInstanceMetadataGeneration(any(InstanceGroup.class))).thenReturn(true);
    }
    InstanceGroup instanceGroup = instanceGroup(cloudPlatform, instanceCount, subnetCount);
    Set<InstanceMetaData> deletedInstancesWithPrepopulatedSubnetId = new HashSet<>();
    String subnetIdForDeletedInstances = cloudSubnetName(0);
    String availabilityZoneForDeletedInstances = cloudSubnetAz(0);
    if (subnetCount > 0) {
        InstanceMetaData instanceWithTerminationDate = instanceMetaData(instanceCount, subnetIdForDeletedInstances, availabilityZoneForDeletedInstances, null);
        instanceWithTerminationDate.setTerminationDate(1234L);
        deletedInstancesWithPrepopulatedSubnetId.add(instanceWithTerminationDate);
        deletedInstancesWithPrepopulatedSubnetId.add(instanceMetaData(instanceCount + 1, subnetIdForDeletedInstances, availabilityZoneForDeletedInstances, InstanceStatus.TERMINATED));
        deletedInstancesWithPrepopulatedSubnetId.add(instanceMetaData(instanceCount + 2, subnetIdForDeletedInstances, availabilityZoneForDeletedInstances, InstanceStatus.DELETED_BY_PROVIDER));
        deletedInstancesWithPrepopulatedSubnetId.add(instanceMetaData(instanceCount + 3, subnetIdForDeletedInstances, availabilityZoneForDeletedInstances, InstanceStatus.DELETED_ON_PROVIDER_SIDE));
    }
    instanceGroup.getAllInstanceMetaData().addAll(deletedInstancesWithPrepopulatedSubnetId);
    underTest.calculateByRoundRobin(subnetAzPairs(subnetCount), instanceGroup);
    List<Long> actualCounts = new ArrayList<>();
    for (int i = 0; i < subnetCount; i++) {
        int finalI = i;
        actualCounts.add(instanceGroup.getAllInstanceMetaData().stream().filter(instance -> instance.getSubnetId().equals(cloudSubnetName(finalI))).filter(instance -> !deletedInstancesWithPrepopulatedSubnetId.contains(instance)).count());
    }
    Collections.sort(expectedCounts);
    Collections.sort(actualCounts);
    Assertions.assertEquals(expectedCounts, actualCounts);
    deletedInstancesWithPrepopulatedSubnetId.forEach(instance -> {
        assertThat(instance.getSubnetId()).isEqualTo(subnetIdForDeletedInstances);
        assertThat(instance.getAvailabilityZone()).isEqualTo(availabilityZoneForDeletedInstances);
    });
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) Mock(org.mockito.Mock) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) MethodSource(org.junit.jupiter.params.provider.MethodSource) InjectMocks(org.mockito.InjectMocks) NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) MultiAzValidator(com.sequenceiq.cloudbreak.controller.validation.network.MultiAzValidator) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CollectionUtils(org.springframework.util.CollectionUtils) Assertions(org.junit.jupiter.api.Assertions) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Collections(java.util.Collections) ArrayList(java.util.ArrayList) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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