use of com.sequenceiq.freeipa.client.model.TopologySuffix in project cloudbreak by hortonworks.
the class FreeIpaTopologyServiceTest method testUpdateReplicationTopologyForDownscale.
@Test
void testUpdateReplicationTopologyForDownscale() throws FreeIpaClientException {
InstanceMetaData im1 = new InstanceMetaData();
InstanceMetaData im2 = new InstanceMetaData();
im1.setDiscoveryFQDN("ipaserver1.example.com");
im2.setDiscoveryFQDN("ipaserver2.example.com");
Set<InstanceMetaData> imSet = Set.of(im1, im2);
when(instanceMetaDataService.findNotTerminatedForStack(anyLong())).thenReturn(imSet);
TopologySuffix caSuffix = new TopologySuffix();
caSuffix.setCn("ca");
when(freeIpaClient.findAllTopologySuffixes()).thenReturn(List.of(caSuffix));
List<TopologySegment> topologySegments = new LinkedList<>();
TopologySegment segment = new TopologySegment();
segment.setLeftNode("ipaserver1.example.com");
segment.setRightNode("ipaserver2.example.com");
topologySegments.add(segment);
when(freeIpaClient.findTopologySegments(Mockito.anyString())).thenReturn(topologySegments);
when(freeIpaClient.deleteTopologySegment(Mockito.anyString(), Mockito.any())).thenReturn(new TopologySegment());
underTest.updateReplicationTopology(1L, Set.of("ipaserver2.example.com"), freeIpaClient);
Mockito.verify(freeIpaClient, Mockito.never()).addTopologySegment(Mockito.any(), Mockito.any());
Mockito.verify(freeIpaClient, Mockito.times(1)).deleteTopologySegment(Mockito.eq("ca"), Mockito.any());
}
use of com.sequenceiq.freeipa.client.model.TopologySuffix in project cloudbreak by hortonworks.
the class FreeIpaTopologyServiceTest method testUpdateReplicationTopologyWithRetry.
@MethodSource("testUpdateReplicationTopologyParameters")
@ParameterizedTest(name = "Run {index}: numNodes={0}, expectedSegmentsToAdd={1}, expectedSegmentsToRemove={2}")
void testUpdateReplicationTopologyWithRetry(int numNodes, int expectedSegmentsToAdd, int expectedSegmentsToRemove) throws FreeIpaClientException {
Stack stack = new Stack();
stack.setId(1L);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
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.updateReplicationTopologyWithRetry(stack, Set.of());
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.client.model.TopologySuffix in project cloudbreak by hortonworks.
the class FreeIpaTopologyService method updateReplicationTopology.
public void updateReplicationTopology(Long stackId, Set<String> fqdnsToExclude, FreeIpaClient freeIpaClient) throws FreeIpaClientException {
Set<String> allNodesFqdn = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().map(InstanceMetaData::getDiscoveryFQDN).filter(StringUtils::isNotBlank).filter(not(fqdnsToExclude::contains)).collect(Collectors.toSet());
Set<TopologySegment> topology = generateTopology(allNodesFqdn).stream().map(this::convertUnorderedPairToTopologySegment).collect(Collectors.toSet());
List<TopologySuffix> topologySuffixes = freeIpaClient.findAllTopologySuffixes();
for (TopologySuffix topologySuffix : topologySuffixes) {
createMissingSegments(freeIpaClient, topologySuffix.getCn(), topology);
removeExtraSegments(freeIpaClient, topologySuffix.getCn(), topology);
}
}
use of com.sequenceiq.freeipa.client.model.TopologySuffix in project cloudbreak by hortonworks.
the class TopologySuffixFindResponse method handleInternal.
@Override
protected Set<TopologySuffix> handleInternal(List<CloudVmMetaDataStatus> metadatas, String body) {
TopologySuffix suffix = new TopologySuffix();
suffix.setCn("dummy");
suffix.setDn("dummy");
return Set.of(suffix);
}
Aggregations