Search in sources :

Example 1 with TopologySuffix

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());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TopologySuffix

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;
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment) HashSet(java.util.HashSet)

Example 3 with TopologySuffix

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));
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) FreeIpaServerDeletionPollerObject(com.sequenceiq.freeipa.service.freeipa.cleanup.FreeIpaServerDeletionPollerObject) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment) Test(org.junit.jupiter.api.Test)

Example 4 with TopologySuffix

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));
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) FreeIpaServerDeletionPollerObject(com.sequenceiq.freeipa.service.freeipa.cleanup.FreeIpaServerDeletionPollerObject) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment) Test(org.junit.jupiter.api.Test)

Example 5 with TopologySuffix

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());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TopologySuffix (com.sequenceiq.freeipa.client.model.TopologySuffix)9 TopologySegment (com.sequenceiq.freeipa.client.model.TopologySegment)8 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)4 LinkedList (java.util.LinkedList)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)3 HashSet (java.util.HashSet)3 FreeIpaServerDeletionPollerObject (com.sequenceiq.freeipa.service.freeipa.cleanup.FreeIpaServerDeletionPollerObject)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 StringUtils (org.apache.commons.lang3.StringUtils)1