Search in sources :

Example 41 with TransactionExecutionException

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

the class Flow2Handler method restartFlow.

public void restartFlow(FlowLog flowLog) {
    if (notSupportedFlowType(flowLog)) {
        try {
            LOGGER.error("Flow type or payload is not present on the classpath anymore. Terminating the flow {}.", flowLog);
            flowLogService.terminate(flowLog.getResourceId(), flowLog.getFlowId());
            return;
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    }
    if (flowLog.getFlowType() != null) {
        Optional<FlowConfiguration<?>> flowConfig = flowConfigs.stream().filter(fc -> flowLog.isFlowType(fc.getClass())).findFirst();
        try {
            String flowChainType = flowChainLogService.getFlowChainType(flowLog.getFlowChainId());
            Payload payload = (Payload) JsonReader.jsonToJava(flowLog.getPayload());
            Flow flow = flowConfig.get().createFlow(flowLog.getFlowId(), flowLog.getFlowChainId(), payload.getResourceId(), flowChainType);
            runningFlows.put(flow, flowLog.getFlowChainId());
            flowStatCache.put(flow.getFlowId(), flowLog.getFlowChainId(), payload.getResourceId(), flowConfig.get().getFlowOperationType().name(), flow.getFlowConfigClass(), true);
            if (flowLog.getFlowChainId() != null) {
                flowChainHandler.restoreFlowChain(flowLog.getFlowChainId());
            }
            Map<Object, Object> variables = (Map<Object, Object>) JsonReader.jsonToJava(flowLog.getVariables());
            flow.initialize(flowLog.getCurrentState(), variables);
            RestartAction restartAction = flowConfig.get().getRestartAction(flowLog.getNextEvent());
            if (restartAction != null) {
                LOGGER.debug("Restarting flow with id: '{}', flow chain id: '{}', flow type: '{}', restart action: '{}'", flow.getFlowId(), flowLog.getFlowChainId(), flowLog.getFlowType().getClassValue().getSimpleName(), restartAction.getClass().getSimpleName());
                Span span = tracer.buildSpan(flowLog.getCurrentState()).ignoreActiveSpan().start();
                restartAction.restart(new FlowParameters(flowLog.getFlowId(), flowLog.getFlowTriggerUserCrn(), flowLog.getOperationType().name(), span.context()), flowLog.getFlowChainId(), flowLog.getNextEvent(), payload);
                return;
            }
        } catch (RuntimeException e) {
            String message = String.format("Flow could not be restarted with id: '%s', flow chain id: '%s' and flow type: '%s'", flowLog.getFlowId(), flowLog.getFlowChainId(), flowLog.getFlowType().getClassValue().getSimpleName());
            LOGGER.error(message, e);
        }
        try {
            flowLogService.terminate(flowLog.getResourceId(), flowLog.getFlowId());
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    }
}
Also used : FLOW_ID(com.sequenceiq.flow.core.FlowConstants.FLOW_ID) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) LoggerFactory(org.slf4j.LoggerFactory) JsonReader(com.cedarsoftware.util.io.JsonReader) IdempotentEvent(com.sequenceiq.cloudbreak.common.event.IdempotentEvent) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) Benchmark(com.sequenceiq.cloudbreak.util.Benchmark) FlowChains(com.sequenceiq.flow.core.chain.FlowChains) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Pair(org.apache.commons.lang3.tuple.Pair) InMemoryCleanup(com.sequenceiq.flow.cleanup.InMemoryCleanup) FLOW_CANCEL(com.sequenceiq.flow.core.FlowConstants.FLOW_CANCEL) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) FLOW_CHAIN_ID(com.sequenceiq.flow.core.FlowConstants.FLOW_CHAIN_ID) FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowStatCache(com.sequenceiq.flow.core.cache.FlowStatCache) FLOW_CHAIN_TYPE(com.sequenceiq.flow.core.FlowConstants.FLOW_CHAIN_TYPE) NullUtil(com.sequenceiq.cloudbreak.util.NullUtil) Resource(javax.annotation.Resource) Set(java.util.Set) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) UUID(java.util.UUID) FLOW_FINAL(com.sequenceiq.flow.core.FlowConstants.FLOW_FINAL) FLOW_OPERATION_TYPE(com.sequenceiq.flow.core.FlowConstants.FLOW_OPERATION_TYPE) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) FlowStateConstants(com.sequenceiq.flow.core.FlowState.FlowStateConstants) Span(io.opentracing.Span) Consumer(reactor.fn.Consumer) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Scope(io.opentracing.Scope) Payload(com.sequenceiq.cloudbreak.common.event.Payload) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) FlowLogIdWithTypeAndTimestamp(com.sequenceiq.flow.domain.FlowLogIdWithTypeAndTimestamp) Inject(javax.inject.Inject) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) FlowFinalizerCallback(com.sequenceiq.flow.core.config.FlowFinalizerCallback) FlowChainLogService(com.sequenceiq.flow.service.flowlog.FlowChainLogService) Event(reactor.bus.Event) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) FlowLogUtil(com.sequenceiq.cloudbreak.service.flowlog.FlowLogUtil) FlowNotFoundException(com.sequenceiq.flow.core.exception.FlowNotFoundException) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) SpanContext(io.opentracing.SpanContext) Component(org.springframework.stereotype.Component) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) FlowType(com.sequenceiq.flow.api.model.FlowType) NodeConfig(com.sequenceiq.flow.ha.NodeConfig) FlowConfiguration(com.sequenceiq.flow.core.config.FlowConfiguration) Comparator(java.util.Comparator) FlowChainHandler(com.sequenceiq.flow.core.chain.FlowChainHandler) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowConfiguration(com.sequenceiq.flow.core.config.FlowConfiguration) Span(io.opentracing.Span) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Payload(com.sequenceiq.cloudbreak.common.event.Payload) Map(java.util.Map)

Example 42 with TransactionExecutionException

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

the class ClusterOperationService method updateFailedNodes.

private void updateFailedNodes(Cluster cluster, Map<InstanceMetaData, Optional<String>> failedHostMetadata) throws TransactionExecutionException {
    if (!failedHostMetadata.isEmpty()) {
        Map<String, Optional<String>> hostNamesWithReason = failedHostMetadata.entrySet().stream().filter(e -> e.getKey().getDiscoveryFQDN() != null).collect(Collectors.toMap(e -> e.getKey().getDiscoveryFQDN(), e -> e.getValue()));
        Set<InstanceStatus> expectedStates = Set.of(SERVICES_HEALTHY, SERVICES_RUNNING);
        InstanceStatus newState = SERVICES_UNHEALTHY;
        ResourceEvent clusterEvent = CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT;
        ResourceEvent hostEvent = CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT;
        updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.of(hostEvent));
    }
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) SERVICES_RUNNING(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) Math.abs(java.lang.Math.abs) Measure(com.sequenceiq.cloudbreak.aspect.Measure) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) StatusRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Map(java.util.Map) CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) EnumSet(java.util.EnumSet) RecoveryMode(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode) CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) SERVICES_HEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY) FileSystemConfigService(com.sequenceiq.cloudbreak.service.filesystem.FileSystemConfigService) Collection(java.util.Collection) CLUSTER_STOP_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_STOP_IGNORED) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Sets(com.google.common.collect.Sets) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT) START_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) HashMap(java.util.HashMap) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StackStopRestrictionService(com.sequenceiq.cloudbreak.service.stack.StackStopRestrictionService) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ResourceType(com.sequenceiq.common.api.type.ResourceType) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DECOMMISSION_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) BlueprintValidator(com.sequenceiq.cloudbreak.template.validation.BlueprintValidator) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) IOException(java.io.IOException) CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotAllowedStatusUpdate(com.sequenceiq.cloudbreak.util.NotAllowedStatusUpdate) User(com.sequenceiq.cloudbreak.workspace.model.User) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CLUSTER_START_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_START_IGNORED) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) UsageLoggingUtil(com.sequenceiq.cloudbreak.util.UsageLoggingUtil) BlueprintValidatorFactory(com.sequenceiq.cloudbreak.service.blueprint.BlueprintValidatorFactory) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED) Collections(java.util.Collections) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Optional(java.util.Optional) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent)

Example 43 with TransactionExecutionException

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

the class ClusterOperationService method updateNewHealthyNodes.

private void updateNewHealthyNodes(Cluster cluster, Set<String> newHealthyNodes) throws TransactionExecutionException {
    if (!newHealthyNodes.isEmpty()) {
        Map<String, Optional<String>> hostNamesWithReason = newHealthyNodes.stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
        Set<InstanceStatus> expectedStates = EnumSet.of(SERVICES_UNHEALTHY, SERVICES_RUNNING, DECOMMISSION_FAILED, FAILED);
        InstanceStatus newState = SERVICES_HEALTHY;
        ResourceEvent clusterEvent = CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT;
        updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.empty());
    }
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) SERVICES_RUNNING(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) Math.abs(java.lang.Math.abs) Measure(com.sequenceiq.cloudbreak.aspect.Measure) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) StatusRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Map(java.util.Map) CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) EnumSet(java.util.EnumSet) RecoveryMode(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode) CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) SERVICES_HEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY) FileSystemConfigService(com.sequenceiq.cloudbreak.service.filesystem.FileSystemConfigService) Collection(java.util.Collection) CLUSTER_STOP_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_STOP_IGNORED) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Sets(com.google.common.collect.Sets) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT) START_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) HashMap(java.util.HashMap) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StackStopRestrictionService(com.sequenceiq.cloudbreak.service.stack.StackStopRestrictionService) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ResourceType(com.sequenceiq.common.api.type.ResourceType) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DECOMMISSION_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) BlueprintValidator(com.sequenceiq.cloudbreak.template.validation.BlueprintValidator) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) IOException(java.io.IOException) CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotAllowedStatusUpdate(com.sequenceiq.cloudbreak.util.NotAllowedStatusUpdate) User(com.sequenceiq.cloudbreak.workspace.model.User) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CLUSTER_START_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_START_IGNORED) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) UsageLoggingUtil(com.sequenceiq.cloudbreak.util.UsageLoggingUtil) BlueprintValidatorFactory(com.sequenceiq.cloudbreak.service.blueprint.BlueprintValidatorFactory) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED) Collections(java.util.Collections) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Optional(java.util.Optional) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent)

Example 44 with TransactionExecutionException

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

the class ClusterService method updateInstancesToZombie.

public void updateInstancesToZombie(Long stackId, Set<Node> unreachableNodes) {
    Set<String> unreachableInstanceIds = unreachableNodes.stream().map(Node::getInstanceId).collect(Collectors.toSet());
    LOGGER.debug("Update instance statuses to ZOMBIE, instanceIds: {}", unreachableInstanceIds);
    try {
        transactionService.required(() -> {
            Set<InstanceMetaData> notDeletedInstanceMetadatas = instanceMetaDataService.getNotDeletedAndNotZombieInstanceMetadataByStackId(stackId);
            notDeletedInstanceMetadatas.stream().filter(instanceMetadata -> unreachableInstanceIds.contains(instanceMetadata.getInstanceId())).forEach(instanceMetadata -> {
                instanceMetadata.setInstanceStatus(ZOMBIE);
                instanceMetaDataService.save(instanceMetadata);
            });
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CLUSTER_HOST_STATUS_UPDATED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_HOST_STATUS_UPDATED) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Arrays(java.util.Arrays) SERVICES_RUNNING(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) AltusMachineUserService(com.sequenceiq.cloudbreak.service.altus.AltusMachineUserService) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) Date(java.util.Date) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) LoggerFactory(org.slf4j.LoggerFactory) ClusterRepository(com.sequenceiq.cloudbreak.repository.cluster.ClusterRepository) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) Map(java.util.Map) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SERVICES_HEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY) FileSystemConfigService(com.sequenceiq.cloudbreak.service.filesystem.FileSystemConfigService) Collection(java.util.Collection) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) REPO_ID_TAG(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails.REPO_ID_TAG) Collectors(java.util.stream.Collectors) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ResourceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus) VALID(com.sequenceiq.common.api.type.CertExpirationState.VALID) ZOMBIE(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.ZOMBIE) HashSet(java.util.HashSet) Inject(javax.inject.Inject) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) GatewayService(com.sequenceiq.cloudbreak.service.gateway.GatewayService) Service(org.springframework.stereotype.Service) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) RuntimeVersionService(com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService) DatabaseType(com.sequenceiq.cloudbreak.api.endpoint.v4.database.base.DatabaseType) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) CustomConfigurations(com.sequenceiq.cloudbreak.domain.CustomConfigurations) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) HOST_CERT_EXPIRING(com.sequenceiq.common.api.type.CertExpirationState.HOST_CERT_EXPIRING) StringUtils(org.springframework.util.StringUtils) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 45 with TransactionExecutionException

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

the class HeartbeatServiceTest method init.

@Before
public void init() throws TransactionExecutionException {
    when(nodeConfig.isNodeIdSpecified()).thenReturn(true);
    when(nodeConfig.getId()).thenReturn(MY_ID);
    ReflectionTestUtils.setField(heartbeatService, "heartbeatThresholdRate", 70000);
    doAnswer(invocation -> {
        try {
            return ((Supplier<?>) invocation.getArgument(0)).get();
        } catch (RuntimeException e) {
            throw new TransactionExecutionException("", e);
        }
    }).when(transactionService).required(any(Supplier.class));
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Supplier(java.util.function.Supplier) Before(org.junit.Before)

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