use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method calculateByRoundRobinTestWhenCloudInstanceAndPreferredAvailabilityZones.
@ParameterizedTest(name = "calculateByRoundRobinTestWhenCloudInstance " + "with {0} platform when {1} subnets, {2} instances, {3} subnet counts and preferred subnets {6} should result in {5} subnet / AZ")
@MethodSource("calculateByRoundRobinTestWhenCloudInstanceDataAndPreferredAvailabilityZones")
public void calculateByRoundRobinTestWhenCloudInstanceAndPreferredAvailabilityZones(CloudPlatform cloudPlatform, int subnetCount, int instanceCount, List<Integer> existingCounts, boolean supported, Set<Integer> expectedPermissibleSubnetIdIndexes, Set<Integer> preferredSubnetIdIndexes) {
if (supported) {
when(multiAzValidator.supportedForInstanceMetadataGeneration(any(InstanceGroup.class))).thenReturn(true);
}
InstanceGroup instanceGroup = instanceGroup(cloudPlatform, instanceCount, subnetCount);
initSubnetIdAndAvailabilityZoneForInstances(existingCounts, instanceGroup);
InstanceMetaData instanceMetaData = new InstanceMetaData();
List<String> preferredSubnetIds = preferredSubnetIdIndexes.stream().map(index -> cloudSubnet(index).getName()).collect(Collectors.toList());
NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails(preferredSubnetIds);
underTest.calculateByRoundRobin(subnetAzPairs(subnetCount), instanceGroup, instanceMetaData, networkScaleDetails);
verifyCloudInstance(expectedPermissibleSubnetIdIndexes, instanceMetaData);
verifySubnetIdAndAvailabilityZoneForInstancesAreUnchanged(existingCounts, instanceGroup, Set.of());
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method calculateByRoundRobinTestWhenCloudInstanceAndNoSubnetIds.
@ParameterizedTest(name = "{0}")
@MethodSource("calculateByRoundRobinTestWhenCloudInstanceAndNoSubnetIdsDataProvider")
void calculateByRoundRobinTestWhenCloudInstanceAndNoSubnetIds(String testCaseName, boolean disableNetwork, boolean disableAttributes, boolean disableSubnetIdsAttribute, boolean prepopulateCloudInstanceSubnet) {
InstanceGroup instanceGroup = instanceGroup(CloudPlatform.AWS, SINGLE_INSTANCE, NO_SUBNETS);
if (disableNetwork) {
instanceGroup.setInstanceGroupNetwork(null);
} else if (disableAttributes) {
instanceGroup.getInstanceGroupNetwork().setAttributes(null);
} else if (disableSubnetIdsAttribute) {
instanceGroup.getInstanceGroupNetwork().setAttributes(new Json(Map.of()));
}
String cloudInstanceSubnetId = prepopulateCloudInstanceSubnet ? SUBNET_ID : null;
String cloudInstanceAvailabilityZone = prepopulateCloudInstanceSubnet ? AVAILABILITY_ZONE : null;
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setSubnetId(cloudInstanceSubnetId);
instanceMetaData.setAvailabilityZone(cloudInstanceAvailabilityZone);
underTest.calculateByRoundRobin(subnetAzPairs(NO_SUBNETS), instanceGroup, instanceMetaData, NetworkScaleDetails.getEmpty());
verifyCloudInstance(cloudInstanceSubnetId == null ? Set.of() : Set.of(cloudInstanceSubnetId), cloudInstanceAvailabilityZone == null ? Set.of() : Set.of(cloudInstanceAvailabilityZone), instanceMetaData);
instanceGroup.getAllInstanceMetaData().forEach(instance -> {
assertThat(instance.getSubnetId()).isNull();
assertThat(instance.getAvailabilityZone()).isNull();
});
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method calculateByRoundRobinTestWhenCloudInstanceAndDeletedInstances.
@ParameterizedTest(name = "calculateByRoundRobinTestWhenCloudInstanceAndDeletedInstances " + "with {0} platform when {1} subnets and {2} instances and {3} subnet counts should result in {5} subnet / AZ")
@MethodSource("calculateByRoundRobinTestWhenCloudInstanceData")
public void calculateByRoundRobinTestWhenCloudInstanceAndDeletedInstances(CloudPlatform cloudPlatform, int subnetCount, int instanceCount, List<Integer> existingCounts, boolean supported, Set<Integer> expectedPermissibleSubnetIdIndexes) {
if (supported) {
when(multiAzValidator.supportedForInstanceMetadataGeneration(any(InstanceGroup.class))).thenReturn(true);
}
InstanceGroup instanceGroup = instanceGroup(cloudPlatform, instanceCount, subnetCount);
initSubnetIdAndAvailabilityZoneForInstances(existingCounts, instanceGroup);
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);
InstanceMetaData instanceMetaData = new InstanceMetaData();
underTest.calculateByRoundRobin(subnetAzPairs(subnetCount), instanceGroup, instanceMetaData, NetworkScaleDetails.getEmpty());
verifyCloudInstance(expectedPermissibleSubnetIdIndexes, instanceMetaData);
verifySubnetIdAndAvailabilityZoneForInstancesAreUnchanged(existingCounts, instanceGroup, deletedInstancesWithPrepopulatedSubnetId);
deletedInstancesWithPrepopulatedSubnetId.forEach(instance -> {
assertThat(instance.getSubnetId()).isEqualTo(subnetIdForDeletedInstances);
assertThat(instance.getAvailabilityZone()).isEqualTo(availabilityZoneForDeletedInstances);
});
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method testSubnetDistributionForWholeInstanceGroupWhen5InstancesWithPrepopulatedKnownSubnetId.
@ParameterizedTest(name = "testSubnetDistributionForWholeInstanceGroupWhen5InstancesWithPrepopulatedKnownSubnetId " + "with {0} platform when {1} subnets and {2} instances should result in {3} subnet counts")
@MethodSource("testSubnetDistributionForWholeInstanceGroupWhen5InstancesWithPrepopulatedKnownSubnetIdData")
public void testSubnetDistributionForWholeInstanceGroupWhen5InstancesWithPrepopulatedKnownSubnetId(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> extraInstancesWithPrepopulatedSubnetId = new HashSet<>();
String subnetIdForExtraInstances = cloudSubnetName(0);
String availabilityZoneForExtraInstances = cloudSubnetAz(0);
if (subnetCount > 0) {
for (int i = 0; i < 5; i++) {
extraInstancesWithPrepopulatedSubnetId.add(instanceMetaData(instanceCount + i, subnetIdForExtraInstances, availabilityZoneForExtraInstances, null));
}
}
instanceGroup.getAllInstanceMetaData().addAll(extraInstancesWithPrepopulatedSubnetId);
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))).count());
}
Collections.sort(expectedCounts);
Collections.sort(actualCounts);
Assertions.assertEquals(expectedCounts, actualCounts);
extraInstancesWithPrepopulatedSubnetId.forEach(instance -> {
assertThat(instance.getSubnetId()).isEqualTo(subnetIdForExtraInstances);
assertThat(instance.getAvailabilityZone()).isEqualTo(availabilityZoneForExtraInstances);
});
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method calculateByRoundRobinTestWhenWholeInstanceGroupAndNoSubnetIds.
@ParameterizedTest(name = "{0}")
@MethodSource("calculateByRoundRobinTestWhenWholeInstanceGroupAndNoSubnetIdsDataProvider")
void calculateByRoundRobinTestWhenWholeInstanceGroupAndNoSubnetIds(String testCaseName, boolean disableNetwork, boolean disableAttributes, boolean disableSubnetIdsAttribute) {
InstanceGroup instanceGroup = instanceGroup(CloudPlatform.AWS, SINGLE_INSTANCE, NO_SUBNETS);
if (disableNetwork) {
instanceGroup.setInstanceGroupNetwork(null);
} else if (disableAttributes) {
instanceGroup.getInstanceGroupNetwork().setAttributes(null);
} else if (disableSubnetIdsAttribute) {
instanceGroup.getInstanceGroupNetwork().setAttributes(new Json(Map.of()));
}
underTest.calculateByRoundRobin(subnetAzPairs(NO_SUBNETS), instanceGroup);
instanceGroup.getAllInstanceMetaData().forEach(instance -> {
assertThat(instance.getSubnetId()).isNull();
assertThat(instance.getAvailabilityZone()).isNull();
});
}
Aggregations