Search in sources :

Example 61 with InstanceGroup

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

the class InstanceMetaDataServiceTest method saveInstanceAndGetUpdatedStackTestWhenSubnetAndAvailabilityZoneAndRackIdAndRoundRobinAndExistingInstance.

@ParameterizedTest(name = "{0}")
@MethodSource("saveInstanceAndGetUpdatedStackTestWhenSubnetAndAvailabilityZoneAndRackIdAndRoundRobinDataProvider")
void saveInstanceAndGetUpdatedStackTestWhenSubnetAndAvailabilityZoneAndRackIdAndRoundRobinAndExistingInstance(String testCaseName, boolean save, List<String> hostnames, String subnetId, String availabilityZone, String rackId) {
    Stack stack = stack(INSTANCE_GROUP_COUNT);
    InstanceMetaData existingInstance = new InstanceMetaData();
    existingInstance.setPrivateId(1234L);
    existingInstance.setInstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING);
    existingInstance.setInstanceGroup(stack.getInstanceGroups().iterator().next());
    existingInstance.setDiscoveryFQDN("existing.foo.org");
    existingInstance.setSubnetId("subnetId-existing");
    existingInstance.setAvailabilityZone("availabilityZone-existing");
    existingInstance.setRackId("/rackId-existing");
    stack.getInstanceGroups().iterator().next().getAllInstanceMetaData().add(existingInstance);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(environmentClientService.getByCrn(ENVIRONMENT_CRN)).thenReturn(environment);
    Map<String, String> subnetAzPairs = Map.of();
    when(multiAzCalculatorService.prepareSubnetAzMap(environment)).thenReturn(subnetAzPairs);
    doAnswer(invocation -> {
        InstanceMetaData instanceMetaData = invocation.getArgument(2, InstanceMetaData.class);
        instanceMetaData.setSubnetId(subnetId);
        instanceMetaData.setAvailabilityZone(availabilityZone);
        return null;
    }).when(multiAzCalculatorService).calculateByRoundRobin(eq(subnetAzPairs), any(InstanceGroup.class), any(InstanceMetaData.class), any());
    when(multiAzCalculatorService.determineRackId(subnetId, availabilityZone)).thenReturn(rackId);
    Stack result = underTest.saveInstanceAndGetUpdatedStack(stack, Map.of(groupName(INSTANCE_GROUP_COUNT - 1), INSTANCE_GROUP_COUNT), Map.of(groupName(INSTANCE_GROUP_COUNT - 1), new LinkedHashSet<>(hostnames)), save, false, NetworkScaleDetails.getEmpty());
    assertThat(result).isSameAs(stack);
    Set<InstanceGroup> resultInstanceGroups = result.getInstanceGroups();
    assertThat(resultInstanceGroups).isNotNull();
    assertThat(resultInstanceGroups).hasSize(INSTANCE_GROUP_COUNT);
    verifyInstances(resultInstanceGroups, hostnames, subnetId, availabilityZone, rackId, existingInstance, INSTANCE_GROUP_COUNT);
    verifyRepositorySave(resultInstanceGroups, save);
    boolean foundExistingInstance = stack.getInstanceGroups().iterator().next().getAllInstanceMetaData().stream().anyMatch(instance -> instance == existingInstance);
    assertThat(foundExistingInstance).overridingErrorMessage("Could not find existingInstance").isTrue();
    assertThat(existingInstance.getPrivateId()).isEqualTo(1234L);
    assertThat(existingInstance.getInstanceStatus()).isEqualTo(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING);
    assertThat(existingInstance.getInstanceGroup()).isEqualTo(stack.getInstanceGroups().iterator().next());
    assertThat(existingInstance.getDiscoveryFQDN()).isEqualTo("existing.foo.org");
    assertThat(existingInstance.getSubnetId()).isEqualTo("subnetId-existing");
    assertThat(existingInstance.getAvailabilityZone()).isEqualTo("availabilityZone-existing");
    assertThat(existingInstance.getRackId()).isEqualTo("/rackId-existing");
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) LinkedHashSet(java.util.LinkedHashSet) 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 62 with InstanceGroup

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

the class AllHostPublicDnsEntryServiceTest method getComponentLocationWhenPrimaryGatewayIsNotTheOnlyNodeWithinGatewayHostGroup.

@Test
void getComponentLocationWhenPrimaryGatewayIsNotTheOnlyNodeWithinGatewayHostGroup() {
    Stack stack = TestUtil.stack();
    InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance();
    InstanceGroup gatewayInstanceGroup = primaryGatewayInstance.getInstanceGroup();
    InstanceMetaData otherGatewayInstanceMetadata = new InstanceMetaData();
    otherGatewayInstanceMetadata.setDiscoveryFQDN("something.new");
    otherGatewayInstanceMetadata.setInstanceGroup(gatewayInstanceGroup);
    otherGatewayInstanceMetadata.setInstanceStatus(InstanceStatus.SERVICES_RUNNING);
    Set<InstanceMetaData> updatedIM = gatewayInstanceGroup.getNotTerminatedAndNotZombieInstanceMetaDataSet();
    updatedIM.add(otherGatewayInstanceMetadata);
    gatewayInstanceGroup.replaceInstanceMetadata(updatedIM);
    Map<String, List<String>> result = underTest.getComponentLocation(stack);
    Assertions.assertTrue(result.containsKey(primaryGatewayInstance.getInstanceGroupName()), "Result should contain primary gateway's group name");
    Assertions.assertTrue(resultContainsInstanceMetadata(otherGatewayInstanceMetadata, result), "Result should contain other gateway's instance metadata");
    Assertions.assertFalse(resultContainsInstanceMetadata(primaryGatewayInstance, result), "Result should not contain primary gateway's instance metadata");
    Assertions.assertEquals(3, result.size(), "Result should contain all instance group");
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) List(java.util.List) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 63 with InstanceGroup

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

the class BaseDnsEntryServiceTest method getInstanceGroup1.

private InstanceGroup getInstanceGroup1() {
    InstanceGroup ig1 = new InstanceGroup();
    ig1.setInstanceGroupType(InstanceGroupType.CORE);
    InstanceMetaData imd1 = new InstanceMetaData();
    imd1.setPrivateId(1L);
    imd1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    imd1.setDiscoveryFQDN(FQDN_1);
    imd1.setPublicIp(PUBLIC_IP_1);
    InstanceMetaData imd2 = new InstanceMetaData();
    imd2.setPrivateId(2L);
    imd2.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    imd2.setDiscoveryFQDN(FQDN_2);
    imd2.setPublicIp(PUBLIC_IP_2);
    ig1.setInstanceMetaData(Set.of(imd1, imd2));
    return ig1;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 64 with InstanceGroup

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

the class BaseDnsEntryServiceTest method getInstanceGroup2.

private InstanceGroup getInstanceGroup2() {
    InstanceGroup ig2 = new InstanceGroup();
    ig2.setInstanceGroupType(InstanceGroupType.CORE);
    InstanceMetaData imd3 = new InstanceMetaData();
    imd3.setPrivateId(3L);
    imd3.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    imd3.setDiscoveryFQDN(FQDN_3);
    imd3.setPublicIp(PUBLIC_IP_3);
    ig2.setInstanceMetaData(Set.of(imd3));
    return ig2;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 65 with InstanceGroup

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

the class LoggingAgentAutoRestartPatchServiceTest method createInstanceGroup.

private InstanceGroup createInstanceGroup() {
    InstanceMetaData instanceMetaData = createInstanceMetaData();
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName("master");
    instanceGroup.setInstanceMetaData(Set.of(instanceMetaData));
    instanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    Template template = new Template();
    template.setInstanceType("myInstanceType");
    instanceGroup.setTemplate(template);
    return instanceGroup;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template)

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