Search in sources :

Example 56 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class StackV4RequestToTemplatePreparationObjectConverter method convert.

public TemplatePreparationObject convert(StackV4Request source) {
    try {
        CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
        User user = userService.getOrCreate(cloudbreakUser);
        Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
        DetailedEnvironmentResponse environment = environmentClientService.getByCrn(source.getEnvironmentCrn());
        Credential credential = getCredential(source, environment);
        LdapView ldapConfig = getLdapConfig(source, environment);
        BaseFileSystemConfigurationsView fileSystemConfigurationView = getFileSystemConfigurationView(source, credential.getAttributes());
        Set<RDSConfig> rdsConfigs = getRdsConfigs(source, workspace);
        Blueprint blueprint = getBlueprint(source, workspace);
        Set<HostgroupView> hostgroupViews = getHostgroupViews(source);
        Gateway gateway = source.getCluster().getGateway() == null ? null : stackV4RequestToGatewayConverter.convert(source);
        BlueprintView blueprintView = blueprintViewProvider.getBlueprintView(blueprint);
        Optional<String> version = Optional.ofNullable(blueprintView.getVersion());
        GeneralClusterConfigs generalClusterConfigs = generalClusterConfigsProvider.generalClusterConfigs(source, cloudbreakUser.getEmail(), blueprintService.getBlueprintVariant(blueprint));
        String gatewaySignKey = null;
        if (gateway != null) {
            gatewaySignKey = gateway.getSignKey();
        }
        String envCrnForVirtualGroups = getEnvironmentCrnForVirtualGroups(environment);
        VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(envCrnForVirtualGroups, ldapConfig != null ? ldapConfig.getAdminGroup() : "");
        Builder builder = Builder.builder().withCloudPlatform(source.getCloudPlatform()).withRdsConfigs(rdsConfigs).withHostgroupViews(hostgroupViews).withGateway(gateway, gatewaySignKey, exposedServiceCollector.getAllKnoxExposed(version)).withBlueprintView(blueprintView).withFileSystemConfigurationView(fileSystemConfigurationView).withGeneralClusterConfigs(generalClusterConfigs).withLdapConfig(ldapConfig).withCustomInputs(source.getInputs()).withKerberosConfig(getKerberosConfig(source, environment)).withStackType(source.getType()).withVirtualGroupView(virtualGroupRequest);
        decorateBuilderWithPlacement(source, builder);
        decorateBuilderWithAccountMapping(source, environment, credential, builder);
        decorateBuilderWithProductDetails(source, builder);
        decorateDatalakeView(source, builder);
        return builder.build();
    } catch (BlueprintProcessingException | IOException e) {
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : BlueprintProcessingException(com.sequenceiq.cloudbreak.template.BlueprintProcessingException) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) BaseFileSystemConfigurationsView(com.sequenceiq.cloudbreak.template.filesystem.BaseFileSystemConfigurationsView) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintView(com.sequenceiq.cloudbreak.template.views.BlueprintView) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Builder(com.sequenceiq.cloudbreak.template.TemplatePreparationObject.Builder) IOException(java.io.IOException) LdapView(com.sequenceiq.cloudbreak.dto.LdapView) VirtualGroupRequest(com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) HostgroupView(com.sequenceiq.cloudbreak.template.views.HostgroupView) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 57 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class GatewayV4RequestToGatewayConverter method convert.

public Gateway convert(GatewayV4Request source) {
    ValidationResult validationResult = gatewayJsonValidator.validate(source);
    if (validationResult.hasError()) {
        throw new BadRequestException(validationResult.getFormattedErrors());
    }
    if (CollectionUtils.isEmpty(source.getTopologies())) {
        return null;
    }
    Gateway gateway = new Gateway();
    gatewayConvertUtil.setBasicProperties(source, gateway);
    gatewayConvertUtil.setTopologies(source, gateway);
    gatewayConvertUtil.setGatewayPathAndSsoProvider(source, gateway);
    CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
    User user = userService.getOrCreate(cloudbreakUser);
    Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
    gateway.setWorkspace(workspace);
    return gateway;
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 58 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class AuditEventService method getAuditEventsByWorkspaceId.

public List<AuditEventV4Response> getAuditEventsByWorkspaceId(Long workspaceId, String resourceType, Long resourceId, String resourceCrn) {
    User user = userService.getOrCreate(legacyRestRequestThreadLocalService.getCloudbreakUser());
    Workspace workspace = getWorkspaceService().get(workspaceId, user);
    List<AuditEventV4Response> auditEventV4Responses = getEventsForUserWithTypeAndResourceIdByWorkspace(workspace, resourceType, resourceId, resourceCrn);
    auditEventV4Responses.sort(new AuditEventComparator().reversed());
    return auditEventV4Responses;
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) AuditEventComparator(com.sequenceiq.cloudbreak.comparator.audit.AuditEventComparator) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) AuditEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response)

Example 59 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class BlueprintService method createWithInternalUser.

public Blueprint createWithInternalUser(Blueprint blueprint, Long workspaceId, String accountId) {
    validate(blueprint, true);
    blueprint.setResourceCrn(createCRN(accountId));
    try {
        return transactionService.required(() -> {
            Workspace workspace = getWorkspaceService().getByIdWithoutAuth(workspaceId);
            blueprint.setWorkspace(workspace);
            blueprint.setStatus(ResourceStatus.SERVICE_MANAGED);
            return super.pureSave(blueprint);
        });
    } catch (TransactionService.TransactionExecutionException e) {
        throw new TransactionService.TransactionRuntimeExecutionException(e);
    }
}
Also used : TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 60 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class BlueprintService method findAllByWorkspaceId.

@Override
public Set<Blueprint> findAllByWorkspaceId(Long workspaceId) {
    User user = getLoggedInUser();
    Workspace workspace = getWorkspaceService().get(workspaceId, user);
    return getAllAvailableInWorkspace(workspace);
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Aggregations

Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)75 User (com.sequenceiq.cloudbreak.workspace.model.User)26 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)17 Tenant (com.sequenceiq.cloudbreak.workspace.model.Tenant)12 CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)8 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)7 Before (org.junit.Before)7 Test (org.junit.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)4 Json (com.sequenceiq.cloudbreak.common.json.Json)4 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)4 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)4 ClusterTemplate (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)4 HashSet (java.util.HashSet)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4