Search in sources :

Example 41 with RPCResponse

use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.

the class UserRemoveOperationTest method testInvoke.

@Test
public void testInvoke() throws FreeIpaClientException {
    RPCResponse<Object> rpcResponse = new RPCResponse<>();
    rpcResponse.setResult(new User());
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
    UserRemoveOperation.create(USER_NAME).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("user_del"), anyList(), any(), any());
}
Also used : User(com.sequenceiq.freeipa.client.model.User) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) Test(org.junit.jupiter.api.Test)

Example 42 with RPCResponse

use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.

the class FreeipaChecker method checkStatus.

private Pair<Map<InstanceMetaData, DetailedStackStatus>, String> checkStatus(Stack stack, Set<InstanceMetaData> checkableInstances) throws Exception {
    return checkedMeasure(() -> {
        Map<InstanceMetaData, DetailedStackStatus> statuses = new HashMap<>();
        List<RPCResponse<Boolean>> responses = new LinkedList<>();
        LOGGER.info("Checking FreeIPA status for instance IDs {}", checkableInstances.stream().map(InstanceMetaData::getInstanceId).collect(Collectors.toList()));
        for (InstanceMetaData instanceMetaData : checkableInstances) {
            try {
                RPCResponse<Boolean> response = checkedMeasure(() -> freeIpaInstanceHealthDetailsService.checkFreeIpaHealth(stack, instanceMetaData), LOGGER, ":::Auto sync::: FreeIPA health check ran in {}ms");
                responses.add(response);
                DetailedStackStatus newDetailedStackStatus;
                if (response.getResult()) {
                    newDetailedStackStatus = DetailedStackStatus.AVAILABLE;
                } else {
                    newDetailedStackStatus = DetailedStackStatus.UNHEALTHY;
                }
                LOGGER.info("FreeIpa health check reported {} for {}", newDetailedStackStatus, instanceMetaData);
                statuses.put(instanceMetaData, newDetailedStackStatus);
            } catch (Exception e) {
                LOGGER.info("FreeIpaClientException occurred during status fetch for {}: {}", instanceMetaData, e.getMessage(), e);
                statuses.put(instanceMetaData, DetailedStackStatus.UNREACHABLE);
            }
        }
        String message = getMessages(responses);
        return Pair.of(statuses, message);
    }, LOGGER, ":::Auto sync::: freeipa server status is checked in {}ms");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) HashMap(java.util.HashMap) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) LinkedList(java.util.LinkedList)

Example 43 with RPCResponse

use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.

the class CdpNodeStatusMonitorClient method toRpcResponse.

private <T> RPCResponse<T> toRpcResponse(String name, Response response, Function<String, T> builderFunc) {
    RPCResponse<T> rpcResponse = new RPCResponse<>();
    String message = response.readEntity(String.class);
    rpcResponse.setResult(builderFunc.apply(message));
    RPCMessage rpcMessage = new RPCMessage();
    rpcMessage.setName(name);
    rpcMessage.setCode(response.getStatus());
    rpcMessage.setMessage(message);
    rpcResponse.setSummary(name);
    rpcResponse.setMessages(List.of(rpcMessage));
    rpcResponse.setCount(1);
    rpcResponse.setTruncated(Boolean.FALSE);
    return rpcResponse;
}
Also used : RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) RPCMessage(com.sequenceiq.cloudbreak.client.RPCMessage)

Aggregations

RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)43 Test (org.junit.jupiter.api.Test)31 Map (java.util.Map)17 Group (com.sequenceiq.freeipa.client.model.Group)12 User (com.sequenceiq.freeipa.client.model.User)10 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)9 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)9 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)9 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)9 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)9 Mock (org.mockito.Mock)9 Mockito.verify (org.mockito.Mockito.verify)9 Mockito.when (org.mockito.Mockito.when)9 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)9 RPCMessage (com.sequenceiq.cloudbreak.client.RPCMessage)8 List (java.util.List)8 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)7 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)7 SudoRule (com.sequenceiq.freeipa.client.model.SudoRule)6 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)6