Search in sources :

Example 1 with StackType

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.

the class ValidateCloudConfigHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ValidateCloudConfigRequest> event) {
    ValidateCloudConfigRequest data = event.getData();
    Stack stack = stackService.getByIdWithLists(data.getResourceId());
    String name = stack.getName();
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Credential credential = credentialConverter.convert(environment.getCredential());
    CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
    ValidationResult.ValidationResultBuilder validationBuilder = ValidationResult.builder();
    stackValidator.validate(stack, validationBuilder);
    Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
    measure(() -> {
        for (InstanceGroup instanceGroup : instanceGroups) {
            LOGGER.info("Validate template for {} name with {} instanceGroup.", name, instanceGroup.toString());
            StackType type = stack.getType();
            templateValidator.validate(credential, instanceGroup, stack, fromStackType(type == null ? null : type.name()), Optional.of(stack.getCreator()), validationBuilder);
        }
    }, LOGGER, "Stack's instance templates have been validated in {} ms for stack {}", name);
    multiAzValidator.validateMultiAzForStack(stack.getPlatformVariant(), instanceGroups, validationBuilder);
    ParametersValidationRequest parametersValidationRequest = parametersValidator.validate(stack.getCloudPlatform(), cloudCredential, stack.getParameters(), stack.getWorkspace().getId());
    parametersValidator.waitResult(parametersValidationRequest, validationBuilder);
    if (!StackType.LEGACY.equals(stack.getType())) {
        dataLakeValidator.validate(stack, validationBuilder);
    }
    environmentValidator.validate(stack, environment, stack.getType().equals(StackType.WORKLOAD), validationBuilder);
    ValidationResult validationResult = validationBuilder.build();
    if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
        LOGGER.debug("Stack request has validation error(s): {}.", validationResult.getFormattedErrors());
        throw new IllegalStateException(validationResult.getFormattedErrors());
    } else {
        LOGGER.debug("Stack validation has been finished without any error.");
        return new StackEvent(CloudConfigValidationEvent.VALIDATE_CLOUD_CONFIG_FINISHED_EVENT.selector(), data.getResourceId());
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ParametersValidationRequest(com.sequenceiq.cloudbreak.cloud.event.validation.ParametersValidationRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) CdpResourceType.fromStackType(com.sequenceiq.common.api.type.CdpResourceType.fromStackType) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ValidateCloudConfigRequest(com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)

Example 2 with StackType

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.

the class StackService method getByNameInWorkspaceWithEntries.

public StackV4Response getByNameInWorkspaceWithEntries(String name, Long workspaceId, Set<String> entries, User user, StackType stackType) {
    try {
        return transactionService.required(() -> {
            Workspace workspace = workspaceService.get(workspaceId, user);
            ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
            Optional<Stack> stack = findByNameAndWorkspaceIdWithLists(name, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
            if (stack.isEmpty()) {
                throw new NotFoundException(format(STACK_NOT_FOUND_BY_NAME_EXCEPTION_MESSAGE, name));
            }
            StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
            stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
            return stackResponse;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 3 with StackType

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.

the class ClouderaManagerSetupService method updateConfig.

@Override
public void updateConfig() {
    com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType stackType = stack.getType();
    try {
        ClouderaManagerResourceApi clouderaManagerResourceApi = clouderaManagerApiFactory.getClouderaManagerResourceApi(apiClient);
        ApiConfigList apiConfigList = new ApiConfigList().addItemsItem(removeRemoteParcelRepos()).addItemsItem(setHeader(stackType));
        clouderaManagerResourceApi.updateConfig("Updated configurations.", apiConfigList);
    } catch (ApiException e) {
        throw mapApiException(e);
    } catch (Exception e) {
        throw mapException(e);
    }
}
Also used : ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ApiException(com.cloudera.api.swagger.client.ApiException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) CloudStorageConfigurationFailedException(com.sequenceiq.cloudbreak.cm.exception.CloudStorageConfigurationFailedException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 4 with StackType

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.

the class StackCreatorService method determineStackTypeBasedOnTheUsedApi.

StackType determineStackTypeBasedOnTheUsedApi(Stack stack, boolean distroxRequest) {
    StackType stackType = stack.getType();
    boolean stackTypeIsWorkloadAndNotDistroXRequest = stack.getType() != null && StackType.WORKLOAD.equals(stack.getType()) && !distroxRequest;
    boolean stackTypeIsNullAndNotDistroXRequest = stack.getType() == null && !distroxRequest;
    if (stackTypeIsWorkloadAndNotDistroXRequest || stackTypeIsNullAndNotDistroXRequest) {
        stackType = StackType.LEGACY;
    }
    return stackType;
}
Also used : StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)

Example 5 with StackType

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.

the class StackCreatorService method createStack.

public StackV4Response createStack(User user, Workspace workspace, StackV4Request stackRequest, boolean distroxRequest) {
    long start = System.currentTimeMillis();
    String stackName = stackRequest.getName();
    nodeCountLimitValidator.validateProvision(stackRequest);
    measure(() -> validateRecipeExistenceOnInstanceGroups(stackRequest.getInstanceGroups(), workspace.getId()), LOGGER, "Check that recipes do exist took {} ms");
    measure(() -> ensureStackDoesNotExists(stackName, workspace), LOGGER, "Stack does not exist check took {} ms");
    Stack stackStub = measure(() -> stackV4RequestToStackConverter.convert(stackRequest), LOGGER, "Stack request converted to stack took {} ms for stack {}", stackName);
    stackStub.setWorkspace(workspace);
    stackStub.setCreator(user);
    StackType stackType = determineStackTypeBasedOnTheUsedApi(stackStub, distroxRequest);
    stackStub.setType(stackType);
    String platformString = stackStub.getCloudPlatform().toLowerCase();
    MDCBuilder.buildMdcContext(stackStub);
    Stack savedStack;
    try {
        Blueprint blueprint = measure(() -> determineBlueprint(stackRequest, workspace), LOGGER, "Blueprint determined in {} ms for stack {}", stackName);
        Future<StatedImage> imgFromCatalogFuture = determineImageCatalog(stackName, platformString, stackRequest, blueprint, user, workspace);
        hueWorkaroundValidatorService.validateForStackRequest(getHueHostGroups(blueprint.getBlueprintText()), stackStub.getName());
        savedStack = transactionService.required(() -> {
            Stack stack = measure(() -> stackDecorator.decorate(stackStub, stackRequest, user, workspace), LOGGER, "Decorate Stack with data took {} ms");
            DetailedEnvironmentResponse environment = measure(() -> ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> environmentClientService.getByCrn(stack.getEnvironmentCrn())), LOGGER, "Get Environment from Environment service took {} ms");
            if (stack.getOrchestrator() != null && stack.getOrchestrator().getApiEndpoint() != null) {
                measure(() -> stackService.validateOrchestrator(stack.getOrchestrator()), LOGGER, "Validate orchestrator took {} ms");
            }
            stack.setUseCcm(environment.getTunnel().useCcm());
            stack.setTunnel(environment.getTunnel());
            if (stackRequest.getCluster() != null) {
                measure(() -> setStackType(stack, blueprint), LOGGER, "Set stacktype for stack object took {} ms");
                measure(() -> clusterCreationService.validate(stackRequest.getCluster(), stack, user, workspace, environment), LOGGER, "Validate cluster rds and autotls took {} ms");
            }
            measure(() -> fillInstanceMetadata(environment, stack), LOGGER, "Fill up instance metadata took {} ms");
            StatedImage imgFromCatalog = measure(() -> getImageCatalog(imgFromCatalogFuture), LOGGER, "Select the correct image took {} ms");
            stackRuntimeVersionValidator.validate(stackRequest, imgFromCatalog.getImage(), stackType);
            Stack newStack = measure(() -> stackService.create(stack, platformString, imgFromCatalog, user, workspace, Optional.ofNullable(stackRequest.getResourceCrn())), LOGGER, "Save the remaining stack data took {} ms");
            try {
                LOGGER.info("Create cluster entity in the database with name {}.", stackName);
                long clusterSaveStart = System.currentTimeMillis();
                createClusterIfNeeded(user, stackRequest, newStack, stackName, blueprint);
                LOGGER.info("Cluster save took {} ms", System.currentTimeMillis() - clusterSaveStart);
            } catch (CloudbreakImageCatalogException | IOException | TransactionExecutionException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
            measure(() -> assignOwnerRoleOnDataHub(user, stackRequest, newStack), LOGGER, "assignOwnerRoleOnDataHub to stack took {} ms with name {}.", stackName);
            return newStack;
        });
    } catch (TransactionExecutionException e) {
        stackUnderOperationService.off();
        if (e.getCause() instanceof DataIntegrityViolationException) {
            String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage((DataIntegrityViolationException) e.getCause()));
            throw new BadRequestException(msg, e.getCause());
        }
        throw new TransactionRuntimeExecutionException(e);
    }
    StackV4Response response = measure(() -> stackToStackV4ResponseConverter.convert(savedStack), LOGGER, "Stack response has been created for stack took {} ms with name {}", stackName);
    LOGGER.info("Generated stack response after creation: {}", JsonUtil.writeValueAsStringSilentSafe(response));
    FlowIdentifier flowIdentifier = measure(() -> flowManager.triggerProvisioning(savedStack.getId()), LOGGER, "Stack triggerProvisioning took {} ms with name {}", stackName);
    response.setFlowIdentifier(flowIdentifier);
    metricService.submit(STACK_PREPARATION, System.currentTimeMillis() - start);
    return response;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Aggregations

StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)9 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)9 Test (org.junit.jupiter.api.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)4 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)4 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)3 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)3 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)3 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3 AutoscaleStackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 AutoscaleStack (com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack)2 ShowTerminatedClustersAfterConfig (com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig)2 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)1 ApiException (com.cloudera.api.swagger.client.ApiException)1