Search in sources :

Example 1 with ListGroupMembersResponse

use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupMembersResponse in project cloudbreak by hortonworks.

the class UmsClient method listMembersFromGroup.

/**
 * List members 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
 * @return list of user group member CRNs or NULL if the user group does not exist.
 */
public List<String> listMembersFromGroup(String requestId, String accountId, String groupName) {
    checkNotNull(requestId, "requestId should not be null.");
    checkNotNull(groupName, "groupName should not be null.");
    validateAccountIdWithWarning(accountId);
    try {
        ListGroupMembersRequest.Builder listGroupMembersRequest = ListGroupMembersRequest.newBuilder().setGroupNameOrCrn(groupName).setAccountId(accountId).setIncludeDeleted(false);
        ListGroupMembersResponse listGroupMembersResponse;
        List<String> members = new ArrayList<>();
        do {
            listGroupMembersResponse = newStub(requestId).listGroupMembers(listGroupMembersRequest.build());
            for (int i = 0; i < listGroupMembersResponse.getMemberCrnCount(); i++) {
                String memberCrn = listGroupMembersResponse.getMemberCrn(i);
                members.add(memberCrn);
            }
            listGroupMembersRequest.setPageToken(listGroupMembersResponse.getNextPageToken());
        } while (listGroupMembersResponse.hasNextPageToken());
        LOGGER.info("User group '{}' contains members: [{}]", groupName, members);
        return members;
    } catch (StatusRuntimeException e) {
        if (e.getStatus().getCode().equals(Status.NOT_FOUND.getCode())) {
            LOGGER.info("User group '{}' not found or has already been deleted.", groupName);
            return null;
        } else {
            throw e;
        }
    }
}
Also used : ListGroupMembersResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupMembersResponse) ListGroupMembersRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupMembersRequest) ArrayList(java.util.ArrayList) StatusRuntimeException(io.grpc.StatusRuntimeException)

Aggregations

ListGroupMembersRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupMembersRequest)1 ListGroupMembersResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupMembersResponse)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1