use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testRemoveGroupsSingle.
@Test
public void testRemoveGroupsSingle() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
Set<FmsGroup> groups = Set.of(new FmsGroup().withName("group1"), new FmsGroup().withName("group2"));
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_del"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response1, response2);
underTest.removeGroups(false, freeIpaClient, groups, 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("group1")), hasItem(hasItem("group2"))));
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 testAddUsersToGroupsSingle.
@Test
public void testAddUsersToGroupsSingle() 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> response = new RPCResponse<>();
Group result = new Group();
result.setMemberUser(List.copyOf(groupMapping.values()));
response.setResult(result);
when(freeIpaClient.invoke(eq("group_add_member"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response);
underTest.addUsersToGroups(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();
}
use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddGroupsSingle.
@Test
public void testAddGroupsSingle() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
FmsGroup group1 = new FmsGroup().withName(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP);
FmsGroup group2 = new FmsGroup().withName("group2");
Set<FmsGroup> groups = Set.of(group1, group2);
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_add"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response1, response2);
underTest.addGroups(false, freeIpaClient, groups, 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(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP)), hasItem(hasItem("group2"))));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertTrue(paramsList.get(0).isEmpty());
assertEquals(true, paramsList.get(1).get("nonposix"));
verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddUsersSingle.
@Test
public void testAddUsersSingle() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
FmsUser user1 = new FmsUser().withName("user1").withFirstName("User_1").withLastName("Test1").withState(FmsUser.State.ENABLED);
FmsUser user2 = new FmsUser().withName("user2").withFirstName("User_2").withLastName("Test2").withState(FmsUser.State.DISABLED);
Set<FmsUser> 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_add"), flagsCaptor.capture(), paramsCaptor.capture(), eq(User.class))).thenReturn(response1, response2);
underTest.addUsers(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(5)));
assertThat(paramsList, allOf(Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_1"), hasEntry("sn", "Test1"))), Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_2"), hasEntry("sn", "Test2")))));
verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.cloudbreak.client.RPCResponse in project cloudbreak by hortonworks.
the class FreeIpaClient method invoke.
public <T> RPCResponse<T> invoke(String method, List<Object> flags, Map<String, Object> params, Type resultType) throws FreeIpaClientException {
Map<String, Object> parameterMap = new HashMap<>();
if (params != null && !params.isEmpty()) {
parameterMap.putAll(params);
}
parameterMap.put("version", apiVersion);
LOGGER.debug("Issuing JSON-RPC request:\n\n method: {}\n flags: {}\n", method, flags);
ParameterizedType type = TypeUtils.parameterize(RPCResponse.class, resultType);
Span span = TracingUtil.initSpan(tracer, "FreeIpa", method);
try (Scope ignored = tracer.activateSpan(span)) {
RPCResponse<T> response = (RPCResponse<T>) jsonRpcHttpClient.invoke(method, List.of(flags, parameterMap), type);
LOGGER.debug("Response object: {}", response);
if (response == null) {
// when the cluster-proxy request times out.
throw new NullPointerException("JSON-RPC response is null");
}
return response;
} catch (ClusterProxyException e) {
String message = String.format("Invoke FreeIPA failed: %s", e.getLocalizedMessage());
LOGGER.warn(message);
OptionalInt responseCode = extractResponseCode(e);
span.setTag(TracingUtil.ERROR, true);
span.setTag(TracingUtil.MESSAGE, e.getLocalizedMessage());
throw FreeIpaClientExceptionUtil.convertToRetryableIfNeeded(new FreeIpaClientException(message, e, responseCode));
} catch (Exception e) {
String message = String.format("Invoke FreeIPA failed: %s", e.getLocalizedMessage());
LOGGER.warn(message);
OptionalInt responseCode = extractResponseCode(e);
span.setTag(TracingUtil.ERROR, true);
span.setTag(TracingUtil.MESSAGE, e.getLocalizedMessage());
throw FreeIpaClientExceptionUtil.convertToRetryableIfNeeded(new FreeIpaClientException(message, e, responseCode));
} catch (Throwable throwable) {
String message = String.format("Invoke FreeIPA failed: %s", throwable.getLocalizedMessage());
LOGGER.warn(message);
span.setTag(TracingUtil.ERROR, true);
span.setTag(TracingUtil.MESSAGE, throwable.getLocalizedMessage());
throw new FreeIpaClientException(message, throwable);
} finally {
span.finish();
}
}
Aggregations