Search in sources :

Example 21 with TransactionExecutionException

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

the class Flow2Handler method handleFlowControlEvent.

private void handleFlowControlEvent(String key, Payload payload, FlowParameters flowParameters, String flowChainId) throws TransactionExecutionException {
    String flowId = flowParameters.getFlowId();
    LOGGER.debug("flow control event arrived: key: {}, flowid: {}, usercrn: {}, payload: {}", key, flowId, flowParameters.getFlowTriggerUserCrn(), payload);
    Flow flow = runningFlows.get(flowId);
    if (flow != null) {
        MutableBoolean flowCancelled = new MutableBoolean(false);
        try {
            updateFlowLogStatusInTransaction(key, payload, flowParameters, flowChainId, flow, flowCancelled);
        } catch (TransactionExecutionException e) {
            LOGGER.error("Can't update flow status: {}", flowId);
            throw e;
        }
        if (!flowCancelled.booleanValue()) {
            LOGGER.debug("Send event: key: {}, flowid: {}, usercrn: {}, payload: {}", key, flowId, flowParameters.getFlowTriggerUserCrn(), payload);
            flow.sendEvent(key, flowParameters.getFlowTriggerUserCrn(), payload, flowParameters.getSpanContext(), flowParameters.getFlowOperationType());
        }
    } else {
        LOGGER.debug("Cancelled flow finished running. Resource ID {}, flow ID {}, event {}", payload.getResourceId(), flowId, key);
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 22 with TransactionExecutionException

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

the class Flow2Handler method createNewFailedFlow.

private void createNewFailedFlow(String key, Payload payload, FlowParameters flowParameters, String flowChainId, FlowConfiguration<?> flowConfig) throws TransactionExecutionException {
    transactionService.required(() -> {
        try {
            String flowId = UUID.randomUUID().toString();
            addFlowParameters(flowParameters, flowId, flowChainId, flowConfig);
            flowLogService.save(flowParameters, flowChainId, key, payload, null, flowConfig.getClass(), FlowStateConstants.INIT_STATE);
            flowLogService.close(payload.getResourceId(), flowId, true);
            flowChains.removeFullFlowChain(flowChainId, false);
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    });
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 23 with TransactionExecutionException

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

the class TerminationService method requestDeletion.

public void requestDeletion(Long stackId, List<String> instanceIds) {
    try {
        transactionService.required(() -> {
            Stack stack = stackService.getByIdWithListsInTransaction(stackId);
            requestDeletionForInstances(stack, instanceIds);
        });
    } catch (TransactionExecutionException ex) {
        LOGGER.info("Failed to request deletion for cluster infrastructure.");
        throw new TerminationFailedException(ex);
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TerminationFailedException(com.sequenceiq.freeipa.flow.stack.termination.TerminationFailedException) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 24 with TransactionExecutionException

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

the class HeartbeatService method heartbeat.

private void heartbeat(boolean unLeaderIt) {
    if (periscopeNodeConfig.isNodeIdSpecified()) {
        String nodeId = periscopeNodeConfig.getId();
        try {
            retryService.testWith2SecDelayMax5Times(() -> {
                try {
                    PeriscopeNode self = periscopeNodeRepository.findById(nodeId).orElse(new PeriscopeNode(nodeId));
                    self.setLastUpdated(clock.getCurrentTimeMillis());
                    if (unLeaderIt) {
                        self.setLeader(false);
                    }
                    periscopeNodeRepository.save(self);
                } catch (RuntimeException e) {
                    LOGGER.error("Failed to update the heartbeat timestamp", e);
                    throw new ActionFailedException(e.getMessage());
                }
                return Boolean.TRUE;
            });
        } catch (ActionFailedException af) {
            LOGGER.error("Failed to update the heartbeat timestamp 5 times for node {}: {}", nodeId, af.getMessage());
            try {
                transactionService.required(() -> {
                    clusterRepository.deallocateClustersOfNode(nodeId);
                    return null;
                });
            } catch (TransactionExecutionException e) {
                LOGGER.error("Unable to deallocate clusters", e);
            }
        }
    }
}
Also used : PeriscopeNode(com.sequenceiq.periscope.domain.PeriscopeNode) ActionFailedException(com.sequenceiq.cloudbreak.service.Retry.ActionFailedException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)

Example 25 with TransactionExecutionException

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

the class LeaderElectionService method leaderElection.

@Scheduled(initialDelay = 35000L, fixedDelay = 30000L)
public void leaderElection() {
    if (periscopeNodeConfig.isNodeIdSpecified()) {
        long leaders = periscopeNodeRepository.countByLeaderIsTrueAndLastUpdatedIsGreaterThan(clock.getCurrentTimeMillis() - heartbeatThresholdRate);
        if (leaders == 0L) {
            metricService.submit(MetricType.LEADER, 0);
            LOGGER.info("There is no active leader available");
            resetTimer();
            try {
                transactionService.required(() -> {
                    periscopeNodeRepository.deallocateLeader();
                    PeriscopeNode me = periscopeNodeRepository.findById(periscopeNodeConfig.getId()).orElseThrow(notFound("Periscope node", periscopeNodeConfig.getId()));
                    me.setLeader(true);
                    periscopeNodeRepository.save(me);
                    return null;
                });
            } catch (TransactionExecutionException e) {
                LOGGER.error("Failed to select node as leader, something went wrong. Message: {}", e.getMessage());
                return;
            }
            metricService.submit(MetricType.LEADER, 1);
            LOGGER.info("Selected {} as leader", periscopeNodeConfig.getId());
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    try {
                        long limit = clock.getCurrentTimeMillis() - heartbeatThresholdRate;
                        List<PeriscopeNode> activeNodes = periscopeNodeRepository.findAllByLastUpdatedIsGreaterThan(limit);
                        if (!activeNodes.isEmpty()) {
                            reallocateOrphanClusters(activeNodes);
                            cleanupInactiveNodesByActiveNodes(activeNodes);
                        }
                    } catch (RuntimeException e) {
                        LOGGER.error("Error happend during fetching cluster allocating them to nodes", e);
                    }
                }
            }, LEADER_TASK_DELAY, STACK_COLLECTOR_PERIOD);
        }
    }
}
Also used : PeriscopeNode(com.sequenceiq.periscope.domain.PeriscopeNode) TimerTask(java.util.TimerTask) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) List(java.util.List) Scheduled(org.springframework.scheduling.annotation.Scheduled)

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