use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group in project cloudbreak by hortonworks.
the class GrpcUmsClient method createGroup.
/**
* Create new user group if it does not exist.
*
* @param accountId the account ID
* @param groupName the newly created group name
* @param requestId an optional request Id
* @return the new or existing user group.
*/
public Group createGroup(String accountId, String groupName, Optional<String> requestId) {
UmsClient client = makeClient(channelWrapper.getChannel());
LOGGER.debug("Creating new user group '{}', for account '{}' using request ID '{}'...", groupName, accountId, requestId);
Group newGroup = client.createGroup(RequestIdUtil.getOrGenerate(requestId), accountId, groupName);
LOGGER.debug("New user group '{}' has been created for account '{}'.", groupName, accountId);
return newGroup;
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group in project cloudbreak by hortonworks.
the class MockGroupManagementService method createUserGroups.
private Map<String, Group> createUserGroups(String accountId) {
Map<String, Group> groups = new HashMap<>();
for (int i = 0; i < NUM_USER_GROUPS; i++) {
Group group = createGroup(accountId, "fakemockgroup" + i);
groups.put(group.getCrn(), group);
}
LOGGER.info("user groups for user: {}", groups);
return groups;
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group in project cloudbreak by hortonworks.
the class GrpcUmsClient method createGroup.
/**
* Create new user group if it does not exist.
*
* @param accountId the account ID
* @param groupName the newly created group name
* @param requestId an optional request Id
* @return the new or existing user group.
*/
public Group createGroup(String accountId, String groupName, Optional<String> requestId, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
LOGGER.debug("Creating new user group '{}', for account '{}' using request ID '{}'...", groupName, accountId, requestId);
Group newGroup = client.createGroup(RequestIdUtil.getOrGenerate(requestId), accountId, groupName);
LOGGER.debug("New user group '{}' has been created for account '{}'.", groupName, accountId);
return newGroup;
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group in project cloudbreak by hortonworks.
the class UmsClient method listGroups.
/**
* Wraps calls to ListGroups with an Account ID.
*
* @param requestId the request ID for the request
* @param accountId the account ID
* @param groupNameOrCrnList the groups to list. if null or empty then all groups will be listed
* @return the list of groups
*/
public List<Group> listGroups(String requestId, String accountId, List<String> groupNameOrCrnList) {
checkNotNull(requestId, "requestId should not be null.");
validateAccountIdWithWarning(accountId);
List<Group> groups = new ArrayList<>();
ListGroupsRequest.Builder requestBuilder = ListGroupsRequest.newBuilder().setAccountId(accountId).setPageSize(umsClientConfig.getListGroupsPageSize());
if (groupNameOrCrnList != null && !groupNameOrCrnList.isEmpty()) {
requestBuilder.addAllGroupNameOrCrn(groupNameOrCrnList);
}
ListGroupsResponse response;
do {
response = newStub(requestId).listGroups(requestBuilder.build());
groups.addAll(response.getGroupList());
requestBuilder.setPageToken(response.getNextPageToken());
} while (response.hasNextPageToken());
return groups;
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group in project cloudbreak by hortonworks.
the class UmsClient method createGroup.
/**
* Create new user group if it does not exist.
*
* @param requestId the request ID for the request
* @param accountId the account ID
* @param groupName the newly created group name
* @return the new or existing user group.
*/
public Group createGroup(String requestId, String accountId, String groupName) {
checkNotNull(requestId, "requestId should not be null.");
checkNotNull(groupName, "groupName should not be null.");
validateAccountIdWithWarning(accountId);
try {
CreateGroupResponse createGroupResponse = newStub(requestId).createGroup(CreateGroupRequest.newBuilder().setAccountId(accountId).setGroupName(groupName).build());
LOGGER.info("New user group has been created: \nId: {} \nCrn: {} \nName: {}.", createGroupResponse.getGroup().getGroupId(), createGroupResponse.getGroup().getCrn(), createGroupResponse.getGroup().getGroupName());
return createGroupResponse.getGroup();
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode().equals(io.grpc.Status.ALREADY_EXISTS.getCode())) {
Group existingGroup = listGroups(requestId, accountId, List.of(groupName)).stream().filter(foundGroup -> foundGroup.getGroupName().equals(groupName)).findAny().orElse(null);
LOGGER.info("User group already exists: \nId: {} \nCrn: {} \nName: {}.", existingGroup.getGroupId(), existingGroup.getCrn(), existingGroup.getGroupName());
return existingGroup;
} else {
throw e;
}
}
}
Aggregations