use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.RemoveMemberFromGroupResponse in project cloudbreak by hortonworks.
the class UmsClient method removeMemberFromGroup.
/**
* Remove member from the selected user group if it is exist.
*
* @param requestId the request ID for the request
* @param accountId the account ID
* @param groupName the group where user is going to be assigned
* @param memberCrn member (e.g., user) CRN
*/
public void removeMemberFromGroup(String requestId, String accountId, String groupName, String memberCrn) {
checkNotNull(requestId, "requestId should not be null.");
checkNotNull(groupName, "groupName should not be null.");
checkNotNull(memberCrn, "memberCrn should not be null.");
validateAccountIdWithWarning(accountId);
Crn crn = Crn.safeFromString(memberCrn);
Actor.Builder actor = Actor.newBuilder().setAccountId(accountId);
switch(crn.getResourceType()) {
case USER:
actor.setUserIdOrCrn(memberCrn);
LOGGER.info("Found user for member Crn: '{}'.", memberCrn);
break;
case MACHINE_USER:
actor.setMachineUserNameOrCrn(memberCrn);
LOGGER.info("Found machine user for member Crn: '{}'.", memberCrn);
break;
default:
throw new IllegalArgumentException(String.format("memberCrn %s is not a USER or MACHINE_USER", memberCrn));
}
try {
RemoveMemberFromGroupRequest.Builder removeMemberFromGroupRequest = RemoveMemberFromGroupRequest.newBuilder().setMember(actor.build()).setGroupNameOrCrn(groupName);
RemoveMemberFromGroupResponse removeMemberFromGroupResponse = newStub(requestId).removeMemberFromGroup(removeMemberFromGroupRequest.build());
LOGGER.info("User '{}' has been removed from the '{}' group successfully.", removeMemberFromGroupResponse.getMemberCrn(), groupName);
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode().equals(Status.NOT_FOUND.getCode())) {
LOGGER.info("User group '{}' or user '{}' not found or has already been deleted.", groupName, memberCrn);
} else {
throw e;
}
}
}
Aggregations