Search in sources :

Example 31 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class StackStartStopService method finishStackStop.

public void finishStackStop(StackStartStopContext context, StopInstancesResult stopInstancesResult) {
    Stack stack = context.getStack();
    try {
        transactionService.required(() -> updateInstancesToStopped(stack, stopInstancesResult.getResults().getResults()));
    } catch (TransactionExecutionException e) {
        LOGGER.error("Error occurred during the finish stack stop: {}", e.getMessage(), e);
        throw new TransactionRuntimeExecutionException(e);
    }
    validateResourceResults(context.getCloudContext(), stopInstancesResult.getErrorDetails(), stopInstancesResult.getResults(), false);
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STOPPED, "Cluster infrastructure stopped successfully.");
    flowMessageService.fireEventAndLog(stack.getId(), STOPPED.name(), STACK_INFRASTRUCTURE_STOPPED);
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 32 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class TerminationService method finalizeTermination.

public void finalizeTermination(Long stackId, boolean force) {
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    Date now = new Date();
    cleanupFreeIpa(stack);
    String terminatedName = stack.getName() + DELIMITER + now.getTime();
    Cluster cluster = stack.getCluster();
    try {
        LOGGER.info("Starting to update the stack and cluster to delete completed");
        transactionService.required(() -> {
            if (cluster != null) {
                try {
                    clusterTerminationService.finalizeClusterTermination(cluster.getId(), force);
                } catch (TransactionExecutionException e) {
                    throw e.getCause();
                }
            }
            terminateInstanceGroups(stack);
            terminateMetaDataInstances(stack);
            updateToDeleteCompleted(stack.getId(), terminatedName, "Stack was terminated successfully.");
            return null;
        });
    } catch (TransactionExecutionException ex) {
        LOGGER.info("Failed to terminate cluster infrastructure. Stack id {}", stack.getId());
        deleteOnlyIfForced(stack, force, terminatedName);
        throw new TerminationFailedException(ex);
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Date(java.util.Date) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 33 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class ClusterTemplateService method listInWorkspaceAndCleanUpInvalids.

public Set<ClusterTemplateViewV4Response> listInWorkspaceAndCleanUpInvalids(Long workspaceId, String accountId) {
    try {
        boolean internalTenant = entitlementService.internalTenant(accountId);
        Set<ClusterTemplateView> views = transactionService.required(() -> clusterTemplateViewService.findAllActive(workspaceId, internalTenant));
        Set<ClusterTemplateViewV4Response> responses = transactionService.required(() -> views.stream().map(v -> clusterTemplateViewToClusterTemplateViewV4ResponseConverter.convert(v)).collect(toSet()));
        environmentServiceDecorator.prepareEnvironments(responses);
        cleanUpInvalidClusterDefinitions(workspaceId, responses);
        return responses.stream().filter(this::isUsableClusterTemplate).filter(this::isClusterTemplateHasValidCloudPlatform).collect(toSet());
    } catch (TransactionExecutionException e) {
        LOGGER.warn("Unable to find cluster definitions due to {}", e.getMessage());
        LOGGER.warn("Unable to find cluster definitions", e);
        throw new CloudbreakServiceException("Unable to obtain cluster definitions!");
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) ClusterTemplateViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)

Example 34 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class ClusterTemplateService method createForLoggedInUser.

public ClusterTemplate createForLoggedInUser(ClusterTemplate resource, Long workspaceId, String accountId, String creator) {
    if (internalClusterTemplateValidator.isInternalTemplateInNotInternalTenant(entitlementService.internalTenant(accountId), resource.getFeatureState())) {
        throw new AccessDeniedException("You can not create Internal Template for an outsider organization");
    }
    resource.setResourceCrn(createCRN(accountId));
    try {
        return transactionService.required(() -> {
            ClusterTemplate created = super.createForLoggedInUser(resource, workspaceId);
            ownerAssignmentService.assignResourceOwnerRoleIfEntitled(creator, resource.getResourceCrn(), accountId);
            return created;
        });
    } catch (TransactionExecutionException e) {
        if (e.getCause() instanceof BadRequestException) {
            throw e.getCause();
        }
        throw new TransactionService.TransactionRuntimeExecutionException(e);
    }
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 35 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.

the class SdxService method createSdx.

private Pair<SdxCluster, FlowIdentifier> createSdx(final String userCrn, final String name, final SdxClusterRequest sdxClusterRequest, final StackV4Request internalStackV4Request, final ImageSettingsV4Request imageSettingsV4Request) {
    LOGGER.info("Creating SDX cluster with name {}", name);
    String accountId = getAccountIdFromCrn(userCrn);
    validateSdxRequest(name, sdxClusterRequest.getEnvironment(), accountId);
    DetailedEnvironmentResponse environment = validateAndGetEnvironment(sdxClusterRequest.getEnvironment());
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
    ImageV4Response imageV4Response = imageCatalogService.getImageResponseFromImageRequest(imageSettingsV4Request, cloudPlatform);
    validateInternalSdxRequest(internalStackV4Request, sdxClusterRequest);
    validateRuntimeAndImage(sdxClusterRequest, environment, imageSettingsV4Request, imageV4Response);
    String runtimeVersion = getRuntime(sdxClusterRequest, internalStackV4Request, imageV4Response);
    validateCcmV2Requirement(environment, runtimeVersion);
    SdxCluster sdxCluster = validateAndCreateNewSdxCluster(userCrn, name, runtimeVersion, sdxClusterRequest.getClusterShape(), sdxClusterRequest.isEnableRangerRaz(), sdxClusterRequest.isEnableMultiAz(), environment);
    setTagsSafe(sdxClusterRequest, sdxCluster);
    if (isCloudStorageConfigured(sdxClusterRequest)) {
        validateCloudStorageRequest(sdxClusterRequest.getCloudStorage(), environment);
        String trimmedBaseLocation = StringUtils.stripEnd(sdxClusterRequest.getCloudStorage().getBaseLocation(), "/");
        sdxCluster.setCloudStorageBaseLocation(trimmedBaseLocation);
        sdxCluster.setCloudStorageFileSystemType(sdxClusterRequest.getCloudStorage().getFileSystemType());
        sdxClusterRequest.getCloudStorage().setBaseLocation(trimmedBaseLocation);
    } else if (!CloudPlatform.YARN.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.GCP.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.MOCK.equalsIgnoreCase(cloudPlatform.name()) && internalStackV4Request == null) {
        throw new BadRequestException("Cloud storage parameter is required.");
    }
    externalDatabaseConfigurer.configure(cloudPlatform, sdxClusterRequest.getExternalDatabase(), sdxCluster);
    updateStackV4RequestWithEnvironmentCrnIfNotExistsOnIt(internalStackV4Request, environment.getCrn());
    StackV4Request stackRequest = getStackRequest(sdxClusterRequest.getClusterShape(), sdxClusterRequest.isEnableRangerRaz(), internalStackV4Request, cloudPlatform, runtimeVersion, imageSettingsV4Request);
    overrideDefaultTemplateValues(stackRequest, sdxClusterRequest.getCustomInstanceGroups(), accountId);
    validateRecipes(sdxClusterRequest, stackRequest, userCrn);
    prepareCloudStorageForStack(sdxClusterRequest, stackRequest, sdxCluster, environment);
    prepareDefaultSecurityConfigs(internalStackV4Request, stackRequest, cloudPlatform);
    prepareProviderSpecificParameters(stackRequest, sdxClusterRequest, cloudPlatform);
    updateStackV4RequestWithRecipes(sdxClusterRequest, stackRequest);
    stackRequest.setResourceCrn(sdxCluster.getCrn());
    sdxCluster.setStackRequest(stackRequest);
    MDCBuilder.buildMdcContext(sdxCluster);
    SdxCluster savedSdxCluster;
    try {
        savedSdxCluster = transactionService.required(() -> {
            SdxCluster created = sdxClusterRepository.save(sdxCluster);
            ownerAssignmentService.assignResourceOwnerRoleIfEntitled(created.getInitiatorUserCrn(), created.getCrn(), created.getAccountId());
            sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.REQUESTED, "Datalake requested", created);
            return created;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerSdxCreation(savedSdxCluster);
    return Pair.of(savedSdxCluster, flowIdentifier);
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Aggregations

TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)56 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)34 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)26 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)17 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)12 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)10 List (java.util.List)10 Set (java.util.Set)10 Inject (javax.inject.Inject)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)9 Optional (java.util.Optional)9 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)8 Collection (java.util.Collection)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 Service (org.springframework.stereotype.Service)8 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)7 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)7