Search in sources :

Example 6 with TopologySegment

use of com.sequenceiq.freeipa.client.model.TopologySegment 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 7 with TopologySegment

use of com.sequenceiq.freeipa.client.model.TopologySegment 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)

Example 8 with TopologySegment

use of com.sequenceiq.freeipa.client.model.TopologySegment 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());
}
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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with TopologySegment

use of com.sequenceiq.freeipa.client.model.TopologySegment 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());
}
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) Stack(com.sequenceiq.freeipa.entity.Stack) HashSet(java.util.HashSet) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with TopologySegment

use of com.sequenceiq.freeipa.client.model.TopologySegment 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);
    }
}
Also used : StringUtils(org.apache.commons.lang3.StringUtils) TopologySuffix(com.sequenceiq.freeipa.client.model.TopologySuffix) TopologySegment(com.sequenceiq.freeipa.client.model.TopologySegment)

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