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");
}
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");
}
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;
}
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;
}
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;
}
Aggregations