use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class FreeIpaTopologyServiceTest method testUpdateReplicationTopology.
@MethodSource("testUpdateReplicationTopologyParameters")
@ParameterizedTest(name = "Run {index}: numNodes={0}, expectedSegmentsToAdd={1}, expectedSegmentsToRemove={2}")
void testUpdateReplicationTopology(int numNodes, int expectedSegmentsToAdd, int expectedSegmentsToRemove) throws FreeIpaClientException {
Set<InstanceMetaData> imSet = new HashSet<>();
for (int i = 0; i < numNodes; i++) {
InstanceMetaData im = new InstanceMetaData();
im.setDiscoveryFQDN(String.format("ipaserver%d.example.com", i));
imSet.add(im);
}
when(instanceMetaDataService.findNotTerminatedForStack(anyLong())).thenReturn(imSet);
TopologySuffix caSuffix = new TopologySuffix();
caSuffix.setCn("ca");
TopologySuffix domainSuffix = new TopologySuffix();
domainSuffix.setCn("domain");
when(freeIpaClient.findAllTopologySuffixes()).thenReturn(List.of(caSuffix, domainSuffix));
List<TopologySegment> topologySegments1 = new LinkedList<>();
for (int i = 1; i < numNodes; i++) {
TopologySegment segment = new TopologySegment();
segment.setLeftNode("ipaserver0.example.com");
segment.setRightNode(String.format("ipaserver%d.example.com", i));
topologySegments1.add(segment);
}
List<TopologySegment> topologySegments2 = new LinkedList<>();
topologySegments2.addAll(topologySegments1);
when(freeIpaClient.findTopologySegments(Mockito.anyString())).thenReturn(topologySegments1).thenReturn(topologySegments1).thenReturn(topologySegments2).thenReturn(topologySegments2);
if (expectedSegmentsToAdd > 0) {
when(freeIpaClient.addTopologySegment(Mockito.anyString(), Mockito.any())).thenReturn(new TopologySegment());
}
if (expectedSegmentsToRemove > 0) {
when(freeIpaClient.deleteTopologySegment(Mockito.anyString(), Mockito.any())).thenReturn(new TopologySegment());
}
underTest.updateReplicationTopology(1L, Set.of(), freeIpaClient);
Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToAdd)).addTopologySegment(Mockito.eq("ca"), Mockito.any());
Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToAdd)).addTopologySegment(Mockito.eq("domain"), Mockito.any());
Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToRemove)).deleteTopologySegment(Mockito.eq("ca"), Mockito.any());
Mockito.verify(freeIpaClient, Mockito.times(expectedSegmentsToRemove)).deleteTopologySegment(Mockito.eq("domain"), Mockito.any());
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetaDataServiceTest method testSaveInstanceAndGetUpdatedStackWhenNoAvailabilityZoneDataAvailable.
@Test
public void testSaveInstanceAndGetUpdatedStackWhenNoAvailabilityZoneDataAvailable() {
Stack stack = initializeStackWithInstanceGroup();
InstanceGroup instanceGroup = stack.getInstanceGroups().stream().findFirst().get();
FreeIpa freeIpa = new FreeIpa();
freeIpa.setHostname("ipa");
freeIpa.setDomain("dom");
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
InstanceTemplate template = mock(InstanceTemplate.class);
when(template.getGroupName()).thenReturn(GROUP_NAME);
when(template.getPrivateId()).thenReturn(INSTANCE_PRIVATE_ID_3);
List<CloudInstance> cloudInstances = List.of(new CloudInstance(INSTANCE_ID_3, template, null, "subnet-1", "az1"));
DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
when(cachedEnvironmentClientService.getByCrn(ENVIRONMENT_ID)).thenReturn(environmentResponse);
Map<String, String> subnetAzMap = Map.of();
when(multiAzCalculatorService.prepareSubnetAzMap(environmentResponse)).thenReturn(subnetAzMap);
Map<String, Integer> subnetUsage = Map.of();
when(multiAzCalculatorService.calculateCurrentSubnetUsage(subnetAzMap, instanceGroup)).thenReturn(subnetUsage);
Stack actualStack = underTest.saveInstanceAndGetUpdatedStack(stack, cloudInstances);
verify(instanceMetaDataRepository).save(any());
assertEquals(3, actualStack.getAllInstanceMetaDataList().size());
InstanceGroup actualInstanceGroup = actualStack.getInstanceGroups().stream().filter(ig -> GROUP_NAME.equals(ig.getGroupName())).findFirst().get();
InstanceMetaData instanceMetaData = actualInstanceGroup.getInstanceMetaData().stream().filter(im -> INSTANCE_PRIVATE_ID_3 == im.getPrivateId()).findFirst().get();
assertEquals("ipa3.dom", instanceMetaData.getDiscoveryFQDN());
verify(multiAzCalculatorService, times(0)).filterSubnetByLeastUsedAz(actualInstanceGroup, subnetAzMap);
verify(multiAzCalculatorService, times(0)).updateSubnetIdForSingleInstanceIfEligible(subnetAzMap, subnetUsage, instanceMetaData, actualInstanceGroup);
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetaDataServiceTest method testGetPrimaryGwInstance.
@Test
public void testGetPrimaryGwInstance() {
InstanceMetaData primaryGwInstance = underTest.getPrimaryGwInstance(createValidImSet());
assertEquals("pgw", primaryGwInstance.getInstanceId());
assertEquals(InstanceMetadataType.GATEWAY_PRIMARY, primaryGwInstance.getInstanceMetadataType());
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData 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.InstanceMetaData 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());
}
Aggregations