Search in sources :

Example 1 with IpaServer

use of com.sequenceiq.freeipa.client.model.IpaServer in project cloudbreak by hortonworks.

the class HostDeletionServiceTest method successfulRemoveServersIfAllHostReturned.

@Test
public void successfulRemoveServersIfAllHostReturned() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    IpaServer ipaServer1 = new IpaServer();
    ipaServer1.setCn("host1");
    IpaServer ipaServer2 = new IpaServer();
    ipaServer2.setCn("host2");
    when(freeIpaClient.findAllServers()).thenReturn(Set.of(ipaServer1, ipaServer2));
    Pair<Set<String>, Map<String, String>> result = underTest.removeServers(freeIpaClient, hosts);
    assertTrue(result.getSecond().isEmpty());
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().contains(ipaServer1.getCn()));
    assertTrue(result.getFirst().contains(ipaServer2.getCn()));
    verify(freeIpaClient).deleteServer(eq("host1"));
    verify(freeIpaClient).deleteServer(eq("host2"));
}
Also used : Set(java.util.Set) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) Map(java.util.Map) Test(org.junit.Test)

Example 2 with IpaServer

use of com.sequenceiq.freeipa.client.model.IpaServer in project cloudbreak by hortonworks.

the class UpdateDnsSoaRecordsHandlerTest method testResultContainsServerFqdns.

@Test
void testResultContainsServerFqdns() throws Exception {
    String zoneName = "example.com.";
    String fqdn1 = "foo1.example.com";
    String fqdn2 = "foo2.example.com";
    FreeIpaClient mockIpaClient = mock(FreeIpaClient.class);
    IpaServer mockIpaServer1 = mock(IpaServer.class);
    IpaServer mockIpaServer2 = mock(IpaServer.class);
    DnsZone dnsZone = mock(DnsZone.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(any())).thenReturn(mockIpaClient);
    when(mockIpaClient.findAllServers()).thenReturn(Set.of(mockIpaServer1, mockIpaServer2));
    Mockito.lenient().when(mockIpaServer1.getFqdn()).thenReturn(fqdn1);
    when(mockIpaServer2.getFqdn()).thenReturn(fqdn2);
    when(mockIpaClient.findAllDnsZone()).thenReturn(Set.of(dnsZone));
    when(dnsZone.getIdnssoamname()).thenReturn(fqdn1 + ".");
    when(dnsZone.getIdnsname()).thenReturn(zoneName);
    CleanupEvent cleanupEvent = new CleanupEvent(1L, Set.of(), Set.of(fqdn1), Set.of(), Set.of(), Set.of(), "", "", "", "");
    UpdateDnsSoaRecordsRequest request = new UpdateDnsSoaRecordsRequest(cleanupEvent);
    underTest.accept(new Event<>(request));
    verify(eventBus).notify(eq("UPDATEDNSSOARECORDSRESPONSE"), any(Event.class));
    verify(mockIpaClient).setDnsZoneAuthoritativeNameserver(eq(zoneName), eq(fqdn2 + "."));
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) Event(reactor.bus.Event) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Test(org.junit.jupiter.api.Test)

Example 3 with IpaServer

use of com.sequenceiq.freeipa.client.model.IpaServer in project cloudbreak by hortonworks.

the class HostDeletionServiceTest method successfulRemoveServersIfOneServerHostReturned.

@Test
public void successfulRemoveServersIfOneServerHostReturned() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    IpaServer ipaServer = new IpaServer();
    ipaServer.setCn("host1");
    when(freeIpaClient.findAllServers()).thenReturn(Set.of(ipaServer));
    Pair<Set<String>, Map<String, String>> result = underTest.removeServers(freeIpaClient, hosts);
    assertTrue(result.getSecond().isEmpty());
    assertEquals(1, result.getFirst().size());
    assertEquals(ipaServer.getCn(), result.getFirst().iterator().next());
    verify(freeIpaClient).deleteServer(eq("host1"));
}
Also used : Set(java.util.Set) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) Map(java.util.Map) Test(org.junit.Test)

Example 4 with IpaServer

use of com.sequenceiq.freeipa.client.model.IpaServer in project cloudbreak by hortonworks.

the class CollectAdditionalHostnamesHandlerTest method testResultContainsServerFqdns.

@Test
void testResultContainsServerFqdns() throws Exception {
    String fqdn1 = "foo1.example.com";
    String fqdn2 = "foo2.example.com";
    FreeIpaClient mockIpaClient = Mockito.mock(FreeIpaClient.class);
    IpaServer mockIpaServer1 = Mockito.mock(IpaServer.class);
    IpaServer mockIpaServer2 = Mockito.mock(IpaServer.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(any())).thenReturn(mockIpaClient);
    when(mockIpaClient.findAllServers()).thenReturn(Set.of(mockIpaServer1, mockIpaServer2));
    when(mockIpaServer1.getFqdn()).thenReturn(fqdn1);
    when(mockIpaServer2.getFqdn()).thenReturn(fqdn2);
    CollectAdditionalHostnamesRequest request = new CollectAdditionalHostnamesRequest(1L);
    underTest.accept(new Event<>(request));
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(eq("COLLECTADDITIONALHOSTNAMESRESPONSE"), eventCaptor.capture());
    Event event = eventCaptor.getValue();
    assertTrue(event.getData() instanceof CollectAdditionalHostnamesResponse);
    CollectAdditionalHostnamesResponse response = (CollectAdditionalHostnamesResponse) event.getData();
    assertEquals(Set.of(fqdn1, fqdn2), response.getHostnames());
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) CollectAdditionalHostnamesRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest) CollectAdditionalHostnamesResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesResponse) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test)

Example 5 with IpaServer

use of com.sequenceiq.freeipa.client.model.IpaServer in project cloudbreak by hortonworks.

the class CollectAdditionalHostnamesHandler method getHostnamesFromFreeIpaServers.

private Set<String> getHostnamesFromFreeIpaServers(Long stackId) throws FreeIpaClientException {
    FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStackId(stackId);
    Set<String> fqdns = freeIpaClient.findAllServers().stream().map(IpaServer::getFqdn).filter(Objects::nonNull).collect(Collectors.toSet());
    LOGGER.debug("Found [{}] hostnames from registered FreeIPA servers", fqdns);
    return fqdns;
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer)

Aggregations

IpaServer (com.sequenceiq.freeipa.client.model.IpaServer)6 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)4 Map (java.util.Map)3 Set (java.util.Set)3 Event (reactor.bus.Event)3 DnsZone (com.sequenceiq.freeipa.client.model.DnsZone)2 UpdateDnsSoaRecordsRequest (com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 EventSelectorUtil (com.sequenceiq.flow.event.EventSelectorUtil)1 ExceptionCatcherEventHandler (com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler)1 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 CleanupEvent (com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent)1 DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT (com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT)1 DownscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)1 CollectAdditionalHostnamesRequest (com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest)1 CollectAdditionalHostnamesResponse (com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesResponse)1 UpdateDnsSoaRecordsResponse (com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse)1