Search in sources :

Example 26 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class UserService method findUserAndSetCrnIfExists.

private User findUserAndSetCrnIfExists(CloudbreakUser cloudbreakUser) {
    try {
        return transactionService.requiresNew(() -> {
            Optional<User> userByIdAndTenantName = userRepository.findByTenantNameAndUserId(cloudbreakUser.getTenant(), cloudbreakUser.getUserId());
            if (userByIdAndTenantName.isPresent()) {
                User user = userByIdAndTenantName.get();
                if (user.getUserCrn() == null) {
                    user.setUserCrn(cloudbreakUser.getUserCrn());
                    user = userRepository.save(user);
                }
                return user;
            }
            return null;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 27 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class WorkspaceService method getByIdForCurrentUser.

public Workspace getByIdForCurrentUser(Long id) {
    CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
    User user = userService.getOrCreate(cloudbreakUser);
    return get(id, user);
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Example 28 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class WorkspaceService method getForCurrentUser.

public Workspace getForCurrentUser() {
    CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
    User user = userService.getOrCreate(cloudbreakUser);
    return get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Example 29 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class StackCommonServiceTest method testStartInstancesInDefaultWorkspace.

@Test
public void testStartInstancesInDefaultWorkspace() {
    Stack stack = new Stack();
    stack.setType(StackType.WORKLOAD);
    when(stackService.findStackByNameOrCrnAndWorkspaceId(STACK_CRN, WORKSPACE_ID)).thenReturn(Optional.of(stack));
    CloudbreakUser cloudbreakUser = mock(CloudbreakUser.class);
    when(cloudbreakUser.getUserCrn()).thenReturn("crn:cdp:" + Crn.Service.AUTOSCALE.getName() + ":us-west-1:altus:user:__internal__actor__");
    when(restRequestThreadLocalService.getCloudbreakUser()).thenReturn(cloudbreakUser);
    when(stackUtil.stopStartScalingEntitlementEnabled(stack)).thenReturn(true);
    UpdateStackV4Request updateStackV4Request = new UpdateStackV4Request();
    updateStackV4Request.setWithClusterEvent(true);
    InstanceGroupAdjustmentV4Request instanceGroupAdjustmentV4Request = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustmentV4Request.setInstanceGroup("instanceGroup");
    instanceGroupAdjustmentV4Request.setScalingAdjustment(5);
    updateStackV4Request.setInstanceGroupAdjustment(instanceGroupAdjustmentV4Request);
    when(regionAwareInternalCrnGeneratorFactory.autoscale()).thenReturn(regionAwareInternalCrnGenerator);
    // Regular flow
    underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, ScalingStrategy.STOPSTART_FALLBACK_TO_REGULAR);
    verify(stackOperationService).updateNodeCountStartInstances(stack, updateStackV4Request.getInstanceGroupAdjustment(), true, ScalingStrategy.STOPSTART_FALLBACK_TO_REGULAR);
    // Null scaling strategy
    underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, null);
    verify(stackOperationService).updateNodeCountStartInstances(stack, updateStackV4Request.getInstanceGroupAdjustment(), true, ScalingStrategy.STOPSTART);
    // Status is set - Bad Request
    updateStackV4Request.setStatus(StatusRequest.FULL_SYNC);
    assertThrows(BadRequestException.class, () -> underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, null));
}
Also used : UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 30 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class ClusterTemplateV4RequestToClusterTemplateConverter method convert.

public ClusterTemplate convert(ClusterTemplateV4Request source) {
    if (source.getDistroXTemplate() == null) {
        throw new BadRequestException("The Datahub template cannot be null.");
    }
    if (StringUtils.isEmpty(source.getDistroXTemplate().getEnvironmentName())) {
        throw new BadRequestException("The environmentName cannot be null.");
    }
    ClusterTemplate clusterTemplate = new ClusterTemplate();
    CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
    User user = userService.getOrCreate(cloudbreakUser);
    Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
    clusterTemplate.setWorkspace(workspace);
    StackV4Request stackV4Request = stackV4RequestConverter.convert(source.getDistroXTemplate());
    stackV4Request.setType(StackType.TEMPLATE);
    Stack stack = stackV4RequestToStackConverter.convert(stackV4Request);
    prepareEmptyInstanceMetadata(stack);
    clusterTemplate.setStackTemplate(stack);
    clusterTemplate.setCloudPlatform(getCloudPlatform(source, stack));
    clusterTemplate.setName(source.getName());
    clusterTemplate.setDescription(source.getDescription());
    clusterTemplate.setDatalakeRequired(DatalakeRequired.OPTIONAL);
    clusterTemplate.setFeatureState(FeatureState.RELEASED);
    clusterTemplate.setStatus(ResourceStatus.USER_MANAGED);
    checkStackWhetherItsCapableOfProvidingCldrRuntimeVersion(stack);
    clusterTemplate.setClouderaRuntimeVersion(stack.getCluster().getBlueprint().getStackVersion());
    if (source.getType() == null) {
        clusterTemplate.setType(ClusterTemplateV4Type.OTHER);
    } else {
        clusterTemplate.setType(source.getType());
    }
    return clusterTemplate;
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)47 User (com.sequenceiq.cloudbreak.workspace.model.User)24 Test (org.junit.jupiter.api.Test)10 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)8 Optional (java.util.Optional)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.junit.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)3 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Collection (java.util.Collection)3 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2