Search in sources :

Example 11 with TransactionExecutionException

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

the class ClusterService method updateClusterMetadata.

public Cluster updateClusterMetadata(Long stackId) {
    Stack stack = stackService.getById(stackId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    if (!connector.clusterStatusService().isClusterManagerRunning()) {
        Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
        InstanceMetaData cmInstance = updateClusterManagerHostStatus(notTerminatedInstanceMetaDatas);
        eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), CLUSTER_HOST_STATUS_UPDATED, Arrays.asList(cmInstance.getDiscoveryFQDN(), cmInstance.getInstanceStatus().name()));
        return stack.getCluster();
    } else {
        ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(stack.getCluster().getId()));
        updateClusterCertExpirationState(stack.getCluster(), extendedHostStatuses.isAnyCertExpiring());
        try {
            return transactionService.required(() -> {
                Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
                List<InstanceMetaData> updatedInstanceMetaData = updateInstanceStatuses(notTerminatedInstanceMetaDatas, extendedHostStatuses);
                instanceMetaDataService.saveAll(updatedInstanceMetaData);
                fireHostStatusUpdateNotification(stack, updatedInstanceMetaData);
                return stack.getCluster();
            });
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 12 with TransactionExecutionException

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

the class ClusterService method updateInstancesToRunning.

public void updateInstancesToRunning(Long stackId, Set<Node> reachableNodes) {
    try {
        transactionService.required(() -> {
            List<InstanceMetaData> createdInstances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(InstanceMetaData::isCreated).collect(Collectors.toList());
            for (InstanceMetaData instanceMetaData : createdInstances) {
                if (reachableNodes.stream().anyMatch(node -> node.getHostname().equals(instanceMetaData.getDiscoveryFQDN()))) {
                    instanceMetaData.setInstanceStatus(SERVICES_RUNNING);
                    instanceMetaDataService.save(instanceMetaData);
                }
            }
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 13 with TransactionExecutionException

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

the class StackService method getAllForAutoscale.

public Set<AutoscaleStackV4Response> getAllForAutoscale() {
    try {
        return transactionService.required(() -> {
            Set<AutoscaleStack> aliveOnes = stackRepository.findAliveOnesWithClusterManager();
            Set<AutoscaleStack> aliveNotUnderDeletion = Optional.ofNullable(aliveOnes).orElse(Set.of()).stream().filter(stack -> !DELETE_IN_PROGRESS.equals(stack.getStackStatus())).collect(Collectors.toSet());
            return aliveNotUnderDeletion.stream().map(a -> autoscaleStackToAutoscaleStackResponseJsonConverter.convert(a)).collect(Collectors.toSet());
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) FluentClusterType(com.sequenceiq.cloudbreak.telemetry.fluent.FluentClusterType) StackToStackV4RequestConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cli.StackToStackV4RequestConverter) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) Measure(com.sequenceiq.cloudbreak.aspect.Measure) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) StackClusterStatusView(com.sequenceiq.cloudbreak.domain.projection.StackClusterStatusView) Duration(java.time.Duration) Map(java.util.Map) EnumSet(java.util.EnumSet) Component(com.sequenceiq.cloudbreak.domain.stack.Component) AccountTagClientService(com.sequenceiq.cloudbreak.service.environment.tag.AccountTagClientService) StackIdViewToStackResponseConverter(com.sequenceiq.cloudbreak.converter.stack.StackIdViewToStackResponseConverter) Set(java.util.Set) JobResource(com.sequenceiq.cloudbreak.quartz.model.JobResource) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) LocalDateTime(java.time.LocalDateTime) Supplier(java.util.function.Supplier) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) AccountTagValidationFailed(com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Service(org.springframework.stereotype.Service) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) StackResponseDecorator(com.sequenceiq.cloudbreak.service.decorator.StackResponseDecorator) CDH_PRODUCT_DETAILS(com.sequenceiq.cloudbreak.common.type.ComponentType.CDH_PRODUCT_DETAILS) CloudConstants(com.sequenceiq.cloudbreak.common.type.CloudConstants) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) StackTtlView(com.sequenceiq.cloudbreak.domain.projection.StackTtlView) IOException(java.io.IOException) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) SdxClientService(com.sequenceiq.cloudbreak.service.datalake.SdxClientService) CostTagging(com.sequenceiq.cloudbreak.tag.CostTagging) NetworkConfigurationValidator(com.sequenceiq.cloudbreak.controller.validation.network.NetworkConfigurationValidator) StackToStackV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.StackToStackV4ResponseConverter) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) AutoscaleStackToAutoscaleStackResponseJsonConverter(com.sequenceiq.cloudbreak.converter.stack.AutoscaleStackToAutoscaleStackResponseJsonConverter) LoggerFactory(org.slf4j.LoggerFactory) AccountTelemetryClientService(com.sequenceiq.cloudbreak.service.environment.telemetry.AccountTelemetryClientService) ServiceProviderConnectorAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) OpenSshPublicKeyValidator(com.sequenceiq.cloudbreak.service.environment.credential.OpenSshPublicKeyValidator) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) Tunnel(com.sequenceiq.common.api.type.Tunnel) ResourceWithId(com.sequenceiq.authorization.service.list.ResourceWithId) PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) StackStatusView(com.sequenceiq.cloudbreak.domain.projection.StackStatusView) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) StackCrnView(com.sequenceiq.cloudbreak.domain.projection.StackCrnView) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) OrchestratorService(com.sequenceiq.cloudbreak.service.orchestrator.OrchestratorService) Network(com.sequenceiq.cloudbreak.domain.Network) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StackPlatformVariantView(com.sequenceiq.cloudbreak.domain.projection.StackPlatformVariantView) StackStatusService(com.sequenceiq.cloudbreak.service.stackstatus.StackStatusService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) AuthorizationResourceNamesProvider(com.sequenceiq.authorization.service.AuthorizationResourceNamesProvider) CloudStorageFolderResolverService(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.CloudStorageFolderResolverService) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) PayloadContextProvider(com.sequenceiq.flow.core.PayloadContextProvider) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) StackValidation(com.sequenceiq.cloudbreak.domain.stack.StackValidation) ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) User(com.sequenceiq.cloudbreak.workspace.model.User) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) ResourceBasicView(com.sequenceiq.cloudbreak.common.dal.ResourceBasicView) DELETE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.DELETE_IN_PROGRESS) ResourceIdProvider(com.sequenceiq.flow.core.ResourceIdProvider) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StringUtils.substringBefore(org.apache.commons.lang3.StringUtils.substringBefore) Collections(java.util.Collections) StackListItem(com.sequenceiq.cloudbreak.domain.projection.StackListItem) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 14 with TransactionExecutionException

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

the class StackService method getJsonById.

public StackV4Response getJsonById(Long id, Collection<String> entry) {
    try {
        return transactionService.required(() -> {
            Stack stack = getByIdWithLists(id);
            StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack);
            stackResponse = stackResponseDecorator.decorate(stackResponse, stack, entry);
            return stackResponse;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : 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) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 15 with TransactionExecutionException

use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException 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)

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