Search in sources :

Example 1 with TopologySegment

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());
}
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 TopologySegment

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);
    }
}
Also used : FreeIpaClientExceptionUtil.ignoreNotFoundException(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Service(org.springframework.stereotype.Service) Map(java.util.Map) Retryable(org.springframework.retry.annotation.Retryable) LinkedHashSet(java.util.LinkedHashSet) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) Objects(java.util.Objects) List(java.util.List) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Predicate.not(java.util.function.Predicate.not) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment)

Example 3 with TopologySegment

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

Example 4 with TopologySegment

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;
}
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 5 with TopologySegment

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));
}
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)

Aggregations

TopologySegment (com.sequenceiq.freeipa.client.model.TopologySegment)11 TopologySuffix (com.sequenceiq.freeipa.client.model.TopologySuffix)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)6 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)5 HashSet (java.util.HashSet)5 LinkedList (java.util.LinkedList)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3 Stack (com.sequenceiq.freeipa.entity.Stack)3 StringUtils (org.apache.commons.lang3.StringUtils)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 FreeIpaClientExceptionUtil.ignoreNotFoundException (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundException)2 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)2 FreeIpaClientFactory (com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory)2 FreeIpaServerDeletionPollerObject (com.sequenceiq.freeipa.service.freeipa.cleanup.FreeIpaServerDeletionPollerObject)2 InstanceMetaDataService (com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2