use of com.sequenceiq.freeipa.client.model.TopologySegment 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.client.model.TopologySegment in project cloudbreak by hortonworks.
the class FreeIpaTopologyService method createMissingSegments.
private void createMissingSegments(FreeIpaClient freeIpaClient, String topologySuffixCn, Set<TopologySegment> topology) throws FreeIpaClientException {
Set<UnorderedPair> existingTopology = freeIpaClient.findTopologySegments(topologySuffixCn).stream().map(segment -> new UnorderedPair(segment.getLeftNode(), segment.getRightNode())).collect(Collectors.toSet());
Set<TopologySegment> segmentsToAdd = topology.stream().filter(segment -> !existingTopology.contains(new UnorderedPair(segment.getLeftNode(), segment.getRightNode()))).collect(Collectors.toSet());
for (TopologySegment segment : segmentsToAdd) {
freeIpaClient.addTopologySegment(topologySuffixCn, segment);
}
}
use of com.sequenceiq.freeipa.client.model.TopologySegment in project cloudbreak by hortonworks.
the class FreeIpaTopologyService method convertUnorderedPairToTopologySegment.
private TopologySegment convertUnorderedPairToTopologySegment(UnorderedPair pair) {
TopologySegment s = new TopologySegment();
s.setDirection("both");
s.setLeftNode(pair.getLeft());
s.setRightNode(pair.getRight());
s.setCn(String.format("%s-to-%s", pair.getLeft(), pair.getRight()));
return s;
}
use of com.sequenceiq.freeipa.client.model.TopologySegment in project cloudbreak by hortonworks.
the class FreeIpaServerDeletionListenerTask method checkStatus.
@Override
public boolean checkStatus(FreeIpaServerDeletionPollerObject freeIpaServerDeletionPollerObject) {
boolean finished = false;
// The IPA server delete continues running after the API returns. The last step is for FreeIPA to delete the topology segments.
try {
Long stackId = freeIpaServerDeletionPollerObject.getStackId();
Set<String> hosts = freeIpaServerDeletionPollerObject.getHosts();
FreeIpaClient client = freeIpaClientFactory.getFreeIpaClientForStackId(stackId);
List<TopologySuffix> topologySuffixes = client.findAllTopologySuffixes();
Set<TopologySegment> remainingSegments = new HashSet<>();
for (TopologySuffix topologySuffix : topologySuffixes) {
remainingSegments.addAll(client.findTopologySegments(topologySuffix.getCn()).stream().filter(s -> hosts.contains(s.getRightNode()) || hosts.contains(s.getLeftNode())).collect(Collectors.toList()));
}
if (remainingSegments.isEmpty()) {
LOGGER.debug("All pending topology segments have been deleted");
finished = true;
} else {
LOGGER.debug("The following topology segments are still pending deletion [{}]", remainingSegments);
}
} catch (Exception e) {
LOGGER.debug("An exception occurred while waiting for FreeIPA server deletion to complete", e);
}
return finished;
}
use of com.sequenceiq.freeipa.client.model.TopologySegment in project cloudbreak by hortonworks.
the class FreeIplaServiceDeletionListenerTaskTest method testCheckStatusFalse.
@Test
void testCheckStatusFalse() throws Exception {
FreeIpaServerDeletionPollerObject pollerObject = new FreeIpaServerDeletionPollerObject(1L, Set.of("example1.com"));
FreeIpaClient client = mock(FreeIpaClient.class);
TopologySuffix suffix = new TopologySuffix();
suffix.setCn("ca");
TopologySegment segment = new TopologySegment();
segment.setRightNode("example1.com");
segment.setLeftNode("example2.com");
when(freeIpaClientFactory.getFreeIpaClientForStackId(anyLong())).thenReturn(client);
when(client.findAllTopologySuffixes()).thenReturn(List.of(suffix));
when(client.findTopologySegments(any())).thenReturn(List.of(segment));
assertFalse(underTest.checkStatus(pollerObject));
}
Aggregations