use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class FreeIpaHealthCheckClient method invoke.
private <T> RPCResponse<T> invoke(String name, String path, Class<T> resultType) throws FreeIpaClientException {
Invocation.Builder builder = rpcTarget.path(path).request().headers(headers);
try (Response response = builder.get()) {
bufferResponseEntity(response);
processRpcListener(response);
checkResponseStatus(response);
return toRpcResponse(name, response, resultType);
} catch (FreeIpaClientException e) {
throw e;
} catch (Throwable throwable) {
String message = String.format("Invoke FreeIPA health check failed: %s", throwable.getLocalizedMessage());
LOGGER.warn(message);
throw new FreeIpaClientException(message, throwable);
}
}
use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class FreeIpaHealthCheckClient method toRpcResponse.
private <T> RPCResponse<T> toRpcResponse(String name, Response response, Class<T> resultType) {
T resultResponse = response.readEntity(resultType);
RPCResponse<T> rpcResponse = new RPCResponse<>();
RPCMessage rpcMessage = new RPCMessage();
rpcMessage.setName(name);
rpcMessage.setCode(response.getStatus());
rpcMessage.setMessage(response.readEntity(String.class));
rpcResponse.setSummary(name);
rpcResponse.setMessages(List.of(rpcMessage));
rpcResponse.setResult(resultResponse);
rpcResponse.setCount(1);
rpcResponse.setTruncated(Boolean.FALSE);
return rpcResponse;
}
use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testEnableUsersSingle.
@Test
public void testEnableUsersSingle() 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_enable"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Object.class))).thenReturn(response1, response2);
underTest.enableUsers(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();
}
use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testRemoveUsersSingle.
@Test
public void testRemoveUsersSingle() 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_del"), flagsCaptor.capture(), paramsCaptor.capture(), eq(User.class))).thenReturn(response1, response2);
underTest.removeUsers(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();
}
use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testRemoveUsersFromGroupsSingle.
@Test
public void testRemoveUsersFromGroupsSingle() throws Exception {
Multimap<String, String> groupMapping = setupGroupMapping(5, MAX_SUBJECTS_PER_REQUEST * 2);
Multimap<String, String> warnings = ArrayListMultimap.create();
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 Group());
RPCResponse<Object> response2 = new RPCResponse<>();
response2.setResult(new Group());
when(freeIpaClient.invoke(eq("group_remove_member"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response1, response2);
underTest.removeUsersFromGroups(false, freeIpaClient, groupMapping, warnings::put);
assertTrue(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
List<List<Object>> flagsList = flagsCaptor.getAllValues();
Map<String, Long> flagCount = flagsList.stream().flatMap(Collection::stream).map(o -> (String) o).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
assertEquals(5, flagCount.size());
assertTrue(flagCount.keySet().containsAll(Set.of("group1", "group2", "group3", "group4", "group0")));
flagCount.forEach((flag, count) -> assertEquals(2, count, flag + " size should be 2"));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertEquals(10, paramsList.size());
paramsList.forEach(map -> {
assertEquals(10, ((List<String>) map.get("user")).size());
assertTrue(((List<String>) map.get("user")).stream().allMatch(user -> user.startsWith("user")));
});
verify(interruptChecker, times(20)).throwTimeoutExIfInterrupted();
}
Aggregations