Search in sources :

Example 31 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class FreeipaClientTestServiceTest method testCheckUsersInGroup.

@Test
public void testCheckUsersInGroup() throws FreeIpaClientException {
    JsonRpcClientException jsonRpcException = new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "group not found", null);
    FreeIpaClientException notFound = new FreeIpaClientException("Invoke FreeIPA failed", jsonRpcException);
    when(freeIpaClient.groupShow(OTHER_USER_OR_GROUP)).thenThrow(notFound);
    when(freeIpaClient.groupShow(ADMIN_GROUP)).thenReturn(createGroup(ADMIN_GROUP, ADMIN_USER));
    assertTrue(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(ADMIN_USER), ADMIN_GROUP)));
    assertFalse(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(OTHER_USER_OR_GROUP), ADMIN_GROUP)));
    assertFalse(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(ADMIN_USER, OTHER_USER_OR_GROUP), ADMIN_GROUP)));
    assertFalse(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(ADMIN_USER), OTHER_USER_OR_GROUP)));
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 32 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordAddEmptyModListIgnored.

@Test
public void testARecordAddEmptyModListIgnored() throws FreeIpaClientException {
    AddDnsARecordRequest request = new AddDnsARecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setHostname("Asdf");
    request.setIp("1.1.1.2");
    request.setCreateReverse(true);
    Stack stack = createStack();
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FreeIpa freeIpa = createFreeIpa();
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    JsonRpcClientException noModEx = new JsonRpcClientException(FreeIpaErrorCodes.EMPTY_MODLIST.getValue(), "no modifications to be performed", null);
    when(freeIpaClient.addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse())).thenThrow(new FreeIpaClientException("can't create", noModEx));
    underTest.addDnsARecord(ACCOUNT_ID, request);
    verify(freeIpaClient).addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 33 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordAddNotFound.

@Test
public void testARecordAddNotFound() throws FreeIpaClientException {
    AddDnsARecordRequest request = new AddDnsARecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setHostname("Asdf");
    request.setIp("1.1.1.2");
    request.setCreateReverse(true);
    Stack stack = createStack();
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FreeIpa freeIpa = createFreeIpa();
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    when(freeIpaClient.showDnsRecord(DOMAIN, request.getHostname())).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
    underTest.addDnsARecord(ACCOUNT_ID, request);
    verify(freeIpaClient).addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 34 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException 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 35 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException 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

JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)43 Test (org.junit.jupiter.api.Test)40 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)38 Map (java.util.Map)13 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)10 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)8 Stack (com.sequenceiq.freeipa.entity.Stack)7 Host (com.sequenceiq.freeipa.client.model.Host)6 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 HashSet (java.util.HashSet)5 Optional (java.util.Optional)5 Role (com.sequenceiq.freeipa.client.model.Role)4 Service (com.sequenceiq.freeipa.client.model.Service)4 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)3 ServiceKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest)3 ServiceKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabResponse)3 Privilege (com.sequenceiq.freeipa.client.model.Privilege)3 Set (java.util.Set)3 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)2