use of com.sequenceiq.cloudbreak.common.event.Payload 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.event.Payload in project cloudbreak by hortonworks.
the class EnvironmentFillInMemoryStateStoreRestartAction method restart.
@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
LOGGER.debug("Restoring MDC context and InMemoryStateStore entry for flow: '{}', flow chain: '{}', event: '{}'", flowParameters.getFlowId(), flowChainId, event);
Payload envPayload = (Payload) payload;
Optional<Environment> environment = environmentService.getById(envPayload.getResourceId());
environment.ifPresent(env -> restart(flowParameters, flowChainId, event, payload, env));
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class ExceptionCatcherEventHandlerTest method testAcceptWhenNoEventNotification.
@Test
public void testAcceptWhenNoEventNotification() {
Event<Payload> event = mock(Event.class);
Event.Headers headers = mock(Event.Headers.class);
Payload payload = mock(Payload.class);
Selectable failureEvent = mock(Selectable.class);
underTest.initialize(SELECTOR, failureEvent, false, null);
when(event.getData()).thenReturn(payload);
when(payload.getResourceId()).thenReturn(RESOURCE_ID);
when(event.getHeaders()).thenReturn(headers);
when(failureEvent.selector()).thenReturn(SELECTOR);
underTest.accept(event);
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq(SELECTOR), eventCaptor.capture());
Event eventBusEvent = eventCaptor.getValue();
assertNotNull(eventBusEvent);
assertEquals(failureEvent, eventBusEvent.getData());
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class ExceptionCatcherEventHandlerTest method testAcceptWhenException.
@Test
public void testAcceptWhenException() {
Event<Payload> event = mock(Event.class);
Event.Headers headers = mock(Event.Headers.class);
Payload payload = mock(Payload.class);
Selectable failureEvent = mock(Selectable.class);
underTest.initialize(SELECTOR, failureEvent, true, null);
when(event.getData()).thenReturn(payload);
when(payload.getResourceId()).thenReturn(RESOURCE_ID);
when(event.getHeaders()).thenReturn(headers);
when(failureEvent.selector()).thenReturn(SELECTOR);
underTest.accept(event);
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq(SELECTOR), eventCaptor.capture());
Event eventBusEvent = eventCaptor.getValue();
assertNotNull(eventBusEvent);
assertEquals(failureEvent, eventBusEvent.getData());
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class FlowCancelServiceTest method testCancelRunningFlows.
@Test
public void testCancelRunningFlows() {
Map<String, Object> parameters = Map.of();
when(eventParameterFactory.createEventParameters(1L)).thenReturn(parameters);
when(eventFactory.createEventWithErrHandler(eq(parameters), any(Payload.class))).thenAnswer(invocation -> {
Payload payload = invocation.getArgument(1, Payload.class);
Assert.assertEquals(Long.valueOf(1L), payload.getResourceId());
return new Event<>(payload);
});
underTest.cancelRunningFlows(1L);
verify(reactor, times(1)).notify(eq(FlowConstants.FLOW_CANCEL), any(Event.class));
}
Aggregations