use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.
the class AbstractStackFailureAction method createFlowContext.
@Override
protected StackFailureContext createFlowContext(String flowId, StateContext<S, E> stateContext, StackFailureEvent payload) {
Flow flow = getFlow(flowId);
StackView stack = stackService.getByIdView(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
flow.setFlowFailed(payload.getException());
return new StackFailureContext(flowId, stack);
}
use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.
the class StackTerminationService method handleStackTerminationError.
public void handleStackTerminationError(StackView stackView, StackFailureEvent payload, boolean forced, Boolean deleteDependencies) {
String stackUpdateMessage;
Msg eventMessage;
DetailedStackStatus status;
if (!forced) {
Exception errorDetails = payload.getException();
stackUpdateMessage = "Termination failed: " + errorDetails.getMessage();
status = DetailedStackStatus.DELETE_FAILED;
eventMessage = Msg.STACK_INFRASTRUCTURE_DELETE_FAILED;
stackUpdater.updateStackStatus(stackView.getId(), status, stackUpdateMessage);
LOGGER.error("Error during stack termination flow: ", errorDetails);
} else {
terminationService.finalizeTermination(stackView.getId(), true);
clusterService.updateClusterStatusByStackId(stackView.getId(), DELETE_COMPLETED);
stackUpdateMessage = "Stack was force terminated.";
status = DetailedStackStatus.DELETE_COMPLETED;
eventMessage = Msg.STACK_FORCED_DELETE_COMPLETED;
if (deleteDependencies) {
dependecyDeletionService.deleteDependencies(stackView);
}
}
flowMessageService.fireEventAndLog(stackView.getId(), eventMessage, status.name(), stackUpdateMessage);
if (stackView.getClusterView() != null && stackView.getClusterView().getEmailNeeded()) {
String ambariIp = stackUtil.extractAmbariIp(stackView);
if (forced) {
emailSenderService.sendTerminationSuccessEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), ambariIp, stackView.getClusterView().getName());
} else {
emailSenderService.sendTerminationFailureEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), ambariIp, stackView.getClusterView().getName());
}
flowMessageService.fireEventAndLog(stackView.getId(), Msg.STACK_NOTIFICATION_EMAIL, status.name());
}
}
use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.
the class ReactorFlowManagerTest method shouldReturnTheNextFailureTransition.
@Test
public void shouldReturnTheNextFailureTransition() {
InstanceGroupAdjustmentJson instanceGroupAdjustment = new InstanceGroupAdjustmentJson();
HostGroupAdjustmentJson hostGroupAdjustment = new HostGroupAdjustmentJson();
underTest.triggerProvisioning(stackId);
underTest.triggerClusterInstall(stackId);
underTest.triggerClusterReInstall(stackId);
underTest.triggerStackStop(stackId);
underTest.triggerStackStart(stackId);
underTest.triggerClusterStop(stackId);
underTest.triggerClusterStart(stackId);
underTest.triggerTermination(stackId, false, false);
underTest.triggerTermination(stackId, false, true);
underTest.triggerStackUpscale(stackId, instanceGroupAdjustment, true);
underTest.triggerStackDownscale(stackId, instanceGroupAdjustment);
underTest.triggerStackRemoveInstance(stackId, "hostgroup", "hostname");
underTest.triggerClusterUpscale(stackId, hostGroupAdjustment);
underTest.triggerClusterDownscale(stackId, hostGroupAdjustment);
underTest.triggerClusterSync(stackId);
underTest.triggerStackSync(stackId);
underTest.triggerFullSync(stackId);
underTest.triggerClusterCredentialReplace(stackId, "admin", "admin1");
underTest.triggerClusterCredentialUpdate(stackId, "admin1");
underTest.triggerClusterTermination(stackId, false, false);
underTest.triggerClusterTermination(stackId, true, false);
underTest.triggerClusterUpgrade(stackId);
underTest.triggerManualRepairFlow(stackId);
underTest.triggerStackRepairFlow(stackId, new UnhealthyInstances());
underTest.triggerClusterRepairFlow(stackId, new HashMap<>(), true);
underTest.triggerEphemeralUpdate(stackId);
// Not start from 0 because flow cancellations
int count = 5;
for (Method method : underTest.getClass().getDeclaredMethods()) {
if (method.getName().startsWith("trigger")) {
count++;
}
}
verify(reactor, times(count)).notify((Object) anyObject(), any(Event.class));
}
use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.
the class Flow2ConfigTest method testFlowConfigurationMapInit.
@Test
public void testFlowConfigurationMapInit() {
List<FlowConfiguration<?>> flowConfigs = new ArrayList<>();
flowConfigs.add(new StackSyncFlowConfig());
flowConfigs.add(new StackTerminationFlowConfig());
given(this.flowConfigs.iterator()).willReturn(flowConfigs.iterator());
Map<String, FlowConfiguration<?>> flowConfigMap = underTest.flowConfigurationMap();
assertEquals("Not all flow type appeared in map!", countEvents(flowConfigs), flowConfigMap.size());
}
use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.
the class Flow2Handler method restartFlow.
public void restartFlow(String flowId) {
FlowLog flowLog = flowLogRepository.findFirstByFlowIdOrderByCreatedDesc(flowId);
if (RESTARTABLE_FLOWS.contains(flowLog.getFlowType())) {
Optional<FlowConfiguration<?>> flowConfig = flowConfigs.stream().filter(fc -> fc.getClass().equals(flowLog.getFlowType())).findFirst();
Payload payload = (Payload) JsonReader.jsonToJava(flowLog.getPayload());
Flow flow = flowConfig.get().createFlow(flowId, payload.getStackId());
runningFlows.put(flow, flowLog.getFlowChainId());
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) {
restartAction.restart(flowId, flowLog.getFlowChainId(), flowLog.getNextEvent(), payload);
return;
}
}
flowLogService.terminate(flowLog.getStackId(), flowId);
}
Aggregations