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"));
}
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 + "."));
}
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"));
}
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());
}
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;
}
Aggregations