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);
}
}
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);
}
});
}
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);
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations