use of com.sequenceiq.freeipa.client.model.TopologySuffix 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.TopologySuffix 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.TopologySuffix 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));
}
use of com.sequenceiq.freeipa.client.model.TopologySuffix in project cloudbreak by hortonworks.
the class FreeIplaServiceDeletionListenerTaskTest method testCheckStatusTrue.
@Test
void testCheckStatusTrue() throws Exception {
FreeIpaServerDeletionPollerObject pollerObject = new FreeIpaServerDeletionPollerObject(1L, Set.of("example0.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));
assertTrue(underTest.checkStatus(pollerObject));
}
use of com.sequenceiq.freeipa.client.model.TopologySuffix in project cloudbreak by hortonworks.
the class FreeIpaTopologyServiceTest method testUpdateReplicationTopologyForDownscaleAndSegmentIsNotPresent.
@Test
void testUpdateReplicationTopologyForDownscaleAndSegmentIsNotPresent() 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);
String message = "already deleted";
when(freeIpaClient.deleteTopologySegment(Mockito.anyString(), Mockito.any())).thenThrow(new FreeIpaClientException(message, new JsonRpcClientException(NOT_FOUND, message, null)));
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());
}
Aggregations