use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateGroupResponse 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