use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User 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;
}
}
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User in project cloudbreak by hortonworks.
the class UmsClient method getUserWithList.
/**
* Wraps a call to ListUsers with crn filter, therefore a single response is expected.
*
* @param requestId the request ID for the request
* @param userCrn the user CRN
* @return the user
*/
public User getUserWithList(String requestId, String userCrn) {
checkNotNull(requestId, "requestId should not be null.");
checkNotNull(userCrn, "userCrn should not be null.");
Crn crn = Crn.fromString(userCrn);
String accountId = crn.getAccountId();
validateAccountIdWithWarning(accountId);
List<User> users = newStub(requestId).listUsers(ListUsersRequest.newBuilder().setAccountId(accountId).addUserIdOrCrn(userCrn).build()).getUserList();
checkSingleUserResponse(users, crn.getResource());
return users.get(0);
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User in project cloudbreak by hortonworks.
the class GrpcUmsClient method getUserDetails.
/**
* Retrieves user details from UMS.
*
* @param userCrn the CRN of the user
* @param requestId an optional request Id
* @return the user associated with this user CRN
*/
@Cacheable(cacheNames = "umsUserCache", key = "{ #userCrn }")
public User getUserDetails(String userCrn, Optional<String> requestId, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
LOGGER.debug("Getting user information for {} using request ID {}", userCrn, requestId);
User user = client.getUser(RequestIdUtil.getOrGenerate(requestId), userCrn);
LOGGER.debug("User information retrieved for userCrn: {}", user.getCrn());
return user;
}
Aggregations