Search in sources :

Example 16 with RPCResponse

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

the class UserSyncOperationsTest method testDisableUsersSingle.

@Test
public void testDisableUsersSingle() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    Set<String> users = Set.of("user1", "user2");
    ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
    RPCResponse<Object> response1 = new RPCResponse<>();
    response1.setResult(new User());
    RPCResponse<Object> response2 = new RPCResponse<>();
    response2.setResult(new User());
    when(freeIpaClient.invoke(eq("user_disable"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Object.class))).thenReturn(response1, response2);
    underTest.disableUsers(false, freeIpaClient, users, warnings::put);
    assertTrue(warnings.isEmpty());
    verifyNoInteractions(batchPartitionSizeProperties);
    verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
    List<List<Object>> flagsList = flagsCaptor.getAllValues();
    assertThat(flagsList, allOf(hasItem(hasItem("user1")), hasItem(hasItem("user2"))));
    List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
    assertThat(paramsList, everyItem(aMapWithSize(0)));
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : User(com.sequenceiq.freeipa.client.model.User) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) List(java.util.List) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 17 with RPCResponse

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

the class FreeIpaInstanceHealthDetailsService method toBooleanRpcResponse.

private RPCResponse<Boolean> toBooleanRpcResponse(RPCResponse<CheckResult> nodeHealth) {
    RPCMessage rpcMessage = createRpcMessageFromCheckResult(nodeHealth);
    RPCResponse<Boolean> response = new RPCResponse<>();
    response.setSummary(nodeHealth.getSummary());
    response.setResult(isHealthCheckPassing(nodeHealth));
    response.setCount(nodeHealth.getCount());
    response.setTruncated(nodeHealth.getTruncated());
    response.setMessages(List.of(rpcMessage));
    response.setCompleted(nodeHealth.getCompleted());
    response.setFailed(nodeHealth.getFailed());
    response.setValue(nodeHealth.getValue());
    return response;
}
Also used : RPCMessage(com.sequenceiq.cloudbreak.client.RPCMessage) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse)

Example 18 with RPCResponse

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

the class CdpNodeStatusMonitorClient method invoke.

private <T> RPCResponse<T> invoke(String name, String path, Function<String, T> buildProtoFunction, boolean acceptNotFound, boolean skipObjectMapping) throws CdpNodeStatusMonitorClientException {
    Builder builder = rpcTarget.path(path).request().headers(headers);
    try (Response response = builder.get()) {
        bufferResponseEntity(response);
        processRpcListener(response);
        checkResponseStatus(response);
        return toRpcResponse(name, response, buildProtoFunction, skipObjectMapping);
    } catch (CdpNodeStatusMonitorClientException e) {
        if (acceptNotFound) {
            LOGGER.debug("Get 404 from node status response for {}, but it is accepted as an empty response.", path);
            return null;
        } else {
            throw e;
        }
    } catch (Throwable throwable) {
        String message = String.format("Invoke node status check failed: %s", throwable.getLocalizedMessage());
        LOGGER.warn(message);
        throw new CdpNodeStatusMonitorClientException(message, throwable);
    }
}
Also used : RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) Response(javax.ws.rs.core.Response) Builder(javax.ws.rs.client.Invocation.Builder)

Example 19 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, boolean skipObjectMapping) {
    RPCResponse<T> rpcResponse = new RPCResponse<>();
    String message = response.readEntity(String.class);
    if (!skipObjectMapping) {
        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)

Example 20 with RPCResponse

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

the class WorkloadCredentialServiceTest method getRpcResponse.

private RPCResponse<Object> getRpcResponse() {
    RPCResponse<Object> response = new RPCResponse<>();
    response.setResult(new User());
    return response;
}
Also used : User(com.sequenceiq.freeipa.client.model.User) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse)

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