Search in sources :

Example 1 with CreateGroupResponse

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;
        }
    }
}
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

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 DeleteGroupRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.DeleteGroupRequest)1 DeleteGroupResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.DeleteGroupResponse)1 GetAccountRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountRequest)1 GetIdPMetadataForWorkloadSSORequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetIdPMetadataForWorkloadSSORequest)1 GetIdPMetadataForWorkloadSSOResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetIdPMetadataForWorkloadSSOResponse)1 GetRightsRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetRightsRequest)1 GetRightsResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetRightsResponse)1