use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method testCalculateRoundRobin.
@Test
public void testCalculateRoundRobin() {
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
instanceGroupNetwork.setAttributes(Json.silent(Map.of(SUBNET_IDS, List.of(SUB_1, SUB_2, "ONLYINIG"))));
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
InstanceMetaData deletedInstance = createInstanceMetadata(SUB_1);
deletedInstance.setInstanceStatus(InstanceStatus.TERMINATED);
instanceGroup.setInstanceMetaData(Set.of(createInstanceMetadata(null), createInstanceMetadata(null), createInstanceMetadata(null), createInstanceMetadata(SUB_2), createInstanceMetadata(null), createInstanceMetadata(" "), createInstanceMetadata("IGNORED"), deletedInstance));
when(multiAzValidator.supportedForInstanceMetadataGeneration(instanceGroup)).thenReturn(Boolean.TRUE);
underTest.calculateByRoundRobin(SUBNET_AZ_PAIRS, instanceGroup);
assertEquals(3, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_1.equals(im.getSubnetId()) && "AZ1".equals(im.getAvailabilityZone())).count());
assertEquals(2, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_2.equals(im.getSubnetId()) && "AZ2".equals(im.getAvailabilityZone())).count());
assertEquals(3, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> SUB_2.equals(im.getSubnetId())).count());
assertEquals(1, instanceGroup.getNotDeletedInstanceMetaDataSet().stream().filter(im -> "IGNORED".equals(im.getSubnetId())).count());
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzCalculatorServiceTest method testUpdateSubnetIdForSingleInstanceIfEligibleDontModifyExisting.
@Test
public void testUpdateSubnetIdForSingleInstanceIfEligibleDontModifyExisting() {
InstanceGroup instanceGroup = new InstanceGroup();
when(multiAzValidator.supportedForInstanceMetadataGeneration(instanceGroup)).thenReturn(Boolean.TRUE);
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setSubnetId("ASDF");
underTest.updateSubnetIdForSingleInstanceIfEligible(SUBNET_AZ_PAIRS, new HashMap<>(Map.of(SUB_1, 2, SUB_2, 1)), instanceMetaData, instanceGroup);
assertEquals("ASDF", instanceMetaData.getSubnetId());
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzValidatorTest method instanceGroup.
private InstanceGroup instanceGroup(Set<String> subnetIds) {
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork(subnetIds));
return instanceGroup;
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class MultiAzValidator method collectSubnetIds.
private Set<String> collectSubnetIds(Iterable<InstanceGroup> instanceGroups) {
Set<String> allSubnetIds = new HashSet<>();
for (InstanceGroup instanceGroup : instanceGroups) {
InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
if (instanceGroupNetwork != null) {
Json attributes = instanceGroupNetwork.getAttributes();
if (attributes != null) {
List<String> subnetIds = (List<String>) attributes.getMap().getOrDefault(NetworkConstants.SUBNET_IDS, new ArrayList<>());
allSubnetIds.addAll(subnetIds);
}
}
}
return allSubnetIds;
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class TelemetryAgentServiceTest method createInstanceMetadataSet.
private Set<InstanceMetaData> createInstanceMetadataSet() {
Set<InstanceMetaData> instanceMetaDataSet = new HashSet<>();
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setId(1L);
InstanceGroup instanceGroup = new InstanceGroup();
Template template = new Template();
instanceGroup.setTemplate(template);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaDataSet.add(instanceMetaData);
return instanceMetaDataSet;
}
Aggregations