Search in sources :

Example 16 with Host

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

the class KeytabCommonServiceTest method testAddHost.

@Test
public void testAddHost() throws FreeIpaClientException {
    FreeIpaClient ipaClient = mock(FreeIpaClient.class);
    RoleRequest roleRequest = new RoleRequest();
    Host host = new Host();
    when(ipaClient.showHost(HOST)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null)));
    when(ipaClient.addHost(HOST)).thenReturn(host);
    Host result = underTest.addHost(HOST, roleRequest, ipaClient);
    verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
    ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
    ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
    verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
    assertTrue(serviceCaptor.getValue().isEmpty());
    assertEquals(host, hostCaptor.getValue().get());
    assertEquals(host, result);
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Optional(java.util.Optional) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Example 17 with Host

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

the class KeytabCommonServiceTest method testAddHostAlreadyExists.

@Test
public void testAddHostAlreadyExists() throws FreeIpaClientException {
    FreeIpaClient ipaClient = mock(FreeIpaClient.class);
    RoleRequest roleRequest = new RoleRequest();
    Host host = new Host();
    when(ipaClient.showHost(HOST)).thenReturn(host);
    Host result = underTest.addHost(HOST, roleRequest, ipaClient);
    verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
    ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
    ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
    verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
    assertTrue(serviceCaptor.getValue().isEmpty());
    assertEquals(host, hostCaptor.getValue().get());
    assertEquals(host, result);
}
Also used : Optional(java.util.Optional) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Host(com.sequenceiq.freeipa.client.model.Host) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Example 18 with Host

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

the class KeytabCommonServiceTest method testAddHostDuplicateEntry.

@Test
public void testAddHostDuplicateEntry() throws FreeIpaClientException {
    FreeIpaClient ipaClient = mock(FreeIpaClient.class);
    RoleRequest roleRequest = new RoleRequest();
    Host host = new Host();
    when(ipaClient.showHost(HOST)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(host);
    when(ipaClient.addHost(HOST)).thenThrow(new FreeIpaClientException("duplicate", new JsonRpcClientException(DUPLICATE_ENTRY.getValue(), "duplicate", null)));
    Host result = underTest.addHost(HOST, roleRequest, ipaClient);
    verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
    ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
    ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
    verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
    assertTrue(serviceCaptor.getValue().isEmpty());
    assertEquals(host, hostCaptor.getValue().get());
    assertEquals(host, result);
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Optional(java.util.Optional) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Example 19 with Host

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

the class HostDeletionServiceTest method expectDeleteExceptionWhenOneFailedDeletion.

@Test(expected = DeleteException.class)
public void expectDeleteExceptionWhenOneFailedDeletion() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    Host host1 = new Host();
    host1.setFqdn("host1");
    Host host2 = new Host();
    host2.setFqdn("host2");
    when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
    when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException("not handled"));
    underTest.deleteHostsWithDeleteException(freeIpaClient, hosts);
}
Also used : FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) Test(org.junit.Test)

Example 20 with Host

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

the class HostDeletionServiceTest method testOneAlreadyDeleted.

@Test
public void testOneAlreadyDeleted() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    Host host1 = new Host();
    host1.setFqdn("host1");
    Host host2 = new Host();
    host2.setFqdn("host2");
    when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
    String message = "already deleted";
    when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException(message, new JsonRpcClientException(NOT_FOUND, message, null)));
    Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);
    assertEquals(2, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().contains(host1.getFqdn()));
    assertTrue(result.getFirst().contains(host2.getFqdn()));
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Host (com.sequenceiq.freeipa.client.model.Host)25 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)13 Test (org.junit.jupiter.api.Test)13 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)12 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)10 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)5 Role (com.sequenceiq.freeipa.client.model.Role)5 KeytabCache (com.sequenceiq.freeipa.entity.KeytabCache)5 Set (java.util.Set)5 Test (org.junit.Test)5 Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)4 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)4 HostKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest)4 HostKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse)4 Privilege (com.sequenceiq.freeipa.client.model.Privilege)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Optional (java.util.Optional)4