Search in sources :

Example 1 with Group

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;
}
Also used : Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) WorkloadAdministrationGroup(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup)

Example 2 with Group

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;
}
Also used : Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with Group

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;
}
Also used : Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) WorkloadAdministrationGroup(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup)

Example 4 with Group

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;
}
Also used : ListGroupsRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsRequest) Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) WorkloadAdministrationGroup(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup) ListGroupsResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsResponse) ArrayList(java.util.ArrayList)

Example 5 with Group

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;
        }
    }
}
Also used : ManagedChannel(io.grpc.ManagedChannel) LoggerFactory(org.slf4j.LoggerFactory) UserManagementGrpc(com.cloudera.thunderhead.service.usermanagement.UserManagementGrpc) PagingProto(com.cloudera.thunderhead.service.common.paging.PagingProto) ListGroupsForMemberRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsForMemberRequest) GetIdPMetadataForWorkloadSSOResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetIdPMetadataForWorkloadSSOResponse) MachineUser(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser) AddMemberToGroupResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.AddMemberToGroupResponse) ListMachineUsersRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListMachineUsersRequest) GrpcUtil(com.sequenceiq.cloudbreak.grpc.util.GrpcUtil) UmsAuthenticationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException) Status(io.grpc.Status) ListServicePrincipalCloudIdentitiesRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListServicePrincipalCloudIdentitiesRequest) GetUserSyncStateModelResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetUserSyncStateModelResponse) CreateAccessKeyRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyRequest) ListGroupMembersResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupMembersResponse) CrnChecker.warnIfAccountIdIsInternal(com.sequenceiq.cloudbreak.auth.altus.service.CrnChecker.warnIfAccountIdIsInternal) GetIdPMetadataForWorkloadSSORequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetIdPMetadataForWorkloadSSORequest) ListWorkloadAdministrationGroupsRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListWorkloadAdministrationGroupsRequest) Set(java.util.Set) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) GetRightsResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetRightsResponse) Sets(com.google.common.collect.Sets) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) CreateGroupResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateGroupResponse) List(java.util.List) AddMemberToGroupRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.AddMemberToGroupRequest) RemoveMemberFromGroupRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.RemoveMemberFromGroupRequest) UserManagementBlockingStub(com.cloudera.thunderhead.service.usermanagement.UserManagementGrpc.UserManagementBlockingStub) Optional(java.util.Optional) NullableScalarTypeProto(com.cloudera.thunderhead.service.NullableScalarTypeProto) ListWorkloadAdministrationGroupsForMemberRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListWorkloadAdministrationGroupsForMemberRequest) Account(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account) Actor(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Actor) ListGroupsResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsResponse) User(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User) Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) GetRightsRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetRightsRequest) CreateGroupRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateGroupRequest) UmsClientConfig(com.sequenceiq.cloudbreak.auth.altus.config.UmsClientConfig) ArrayList(java.util.ArrayList) ListGroupMembersRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupMembersRequest) ListMachineUsersResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListMachineUsersResponse) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) DeleteGroupResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.DeleteGroupResponse) ListWorkloadAdministrationGroupsResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListWorkloadAdministrationGroupsResponse) GetAccountRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountRequest) AltusMetadataInterceptor(com.sequenceiq.cloudbreak.grpc.altus.AltusMetadataInterceptor) GetUserSyncStateModelRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetUserSyncStateModelRequest) CreateAccessKeyResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse) RemoveMemberFromGroupResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.RemoveMemberFromGroupResponse) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) ListUsersResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListUsersResponse) CallingServiceNameInterceptor(com.sequenceiq.cloudbreak.grpc.altus.CallingServiceNameInterceptor) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) GetUserRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetUserRequest) ListUsersRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListUsersRequest) ListWorkloadAdministrationGroupsForMemberResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListWorkloadAdministrationGroupsForMemberResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) ListServicePrincipalCloudIdentitiesResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListServicePrincipalCloudIdentitiesResponse) ListGroupsForMemberResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsForMemberResponse) ListGroupsRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsRequest) RightsCheck(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.RightsCheck) WorkloadAdministrationGroup(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup) DeleteGroupRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.DeleteGroupRequest) Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) WorkloadAdministrationGroup(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup) CreateGroupResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateGroupResponse) StatusRuntimeException(io.grpc.StatusRuntimeException)

Aggregations

Group (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group)8 WorkloadAdministrationGroup (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup)6 GetRightsResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetRightsResponse)2 ListGroupsRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsRequest)2 ListGroupsResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsResponse)2 ListWorkloadAdministrationGroupsResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListWorkloadAdministrationGroupsResponse)2 UmsVirtualGroupRight (com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight)2 NullableScalarTypeProto (com.cloudera.thunderhead.service.NullableScalarTypeProto)1 PagingProto (com.cloudera.thunderhead.service.common.paging.PagingProto)1 UserManagementGrpc (com.cloudera.thunderhead.service.usermanagement.UserManagementGrpc)1 UserManagementBlockingStub (com.cloudera.thunderhead.service.usermanagement.UserManagementGrpc.UserManagementBlockingStub)1 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)1 Account (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account)1 Actor (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Actor)1 AddMemberToGroupRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.AddMemberToGroupRequest)1 AddMemberToGroupResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.AddMemberToGroupResponse)1 CreateAccessKeyRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyRequest)1 CreateAccessKeyResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse)1 CreateGroupRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateGroupRequest)1 CreateGroupResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateGroupResponse)1