use of com.sequenceiq.flow.core.config.FlowConfiguration in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testRestartFlow.
@Test
public void testRestartFlow() throws TransactionExecutionException {
FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID);
Payload payload = new TestPayload(STACK_ID);
flowLog.setPayloadType(ClassValue.of(TestPayload.class));
flowLog.setPayload(JsonWriter.objectToJson(payload));
when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
ReflectionTestUtils.setField(helloWorldFlowConfig, "defaultRestartAction", defaultRestartAction);
setUpFlowConfigCreateFlow(helloWorldFlowConfig);
List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
underTest.restartFlow(FLOW_ID);
ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class);
ArgumentCaptor<FlowParameters> flowParamsCaptor = ArgumentCaptor.forClass(FlowParameters.class);
verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID);
verify(flowLogService, never()).terminate(STACK_ID, FLOW_ID);
verify(defaultRestartAction, times(1)).restart(flowParamsCaptor.capture(), eq(FLOW_CHAIN_ID), eq(NEXT_EVENT), payloadCaptor.capture());
Payload captorValue = payloadCaptor.getValue();
assertEquals(STACK_ID, captorValue.getResourceId());
FlowParameters flowParameters = flowParamsCaptor.getValue();
assertEquals(FLOW_ID, flowParameters.getFlowId());
assertEquals(FLOW_TRIGGER_USERCRN, flowParameters.getFlowTriggerUserCrn());
}
use of com.sequenceiq.flow.core.config.FlowConfiguration in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testRestartFlowNoRestartAction.
@Test
public void testRestartFlowNoRestartAction() throws TransactionExecutionException {
FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID);
Payload payload = new TestPayload(STACK_ID);
flowLog.setPayloadType(ClassValue.of(TestPayload.class));
flowLog.setPayload(JsonWriter.objectToJson(payload));
when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
setUpFlowConfigCreateFlow(helloWorldFlowConfig);
List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
underTest.restartFlow(FLOW_ID);
verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID);
verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID);
verify(defaultRestartAction, never()).restart(any(), any(), any(), any());
}
use of com.sequenceiq.flow.core.config.FlowConfiguration 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.flow.core.config.FlowConfiguration in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testRestartFlowNoRestartActionNoFlowChainId.
@Test
public void testRestartFlowNoRestartActionNoFlowChainId() throws TransactionExecutionException {
FlowLog flowLog = createFlowLog(null);
Payload payload = new TestPayload(STACK_ID);
flowLog.setPayloadType(ClassValue.of(TestPayload.class));
flowLog.setPayload(JsonWriter.objectToJson(payload));
when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
setUpFlowConfigCreateFlow(helloWorldFlowConfig);
List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
underTest.restartFlow(FLOW_ID);
verify(flowChainHandler, never()).restoreFlowChain(FLOW_CHAIN_ID);
verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID);
verify(defaultRestartAction, never()).restart(any(), any(), any(), any());
}
Aggregations