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