use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class StackStopRestartAction method restart.
@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
Payload stackPayload = (Payload) payload;
Stack stack = stackService.getById(stackPayload.getResourceId());
MDCBuilder.buildMdcContext(stack);
super.restart(flowParameters, flowChainId, event, payload);
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class Flow2Handler method handleFlowConflict.
private AcceptResult handleFlowConflict(String key, Payload payload, String flowChainId, Set<FlowLogIdWithTypeAndTimestamp> flowLogItems) {
AcceptResult acceptResult = null;
Optional<FlowLog> initFlowLog = flowLogService.findAllByFlowIdOrderByCreatedDesc(flowLogItems.iterator().next().getFlowId()).stream().min(Comparator.comparing(FlowLog::getCreated));
if (initFlowLog.isPresent()) {
LOGGER.info("Found previous init flow log: {}", initFlowLog.get());
if (NullUtil.allNotNull(initFlowLog.get().getFlowChainId(), flowChainId)) {
Optional<Pair<String, Payload>> previousTrigger = flowChains.getRootTriggerEvent(initFlowLog.get().getFlowChainId());
Optional<Pair<String, Payload>> currentTrigger = flowChains.getRootTriggerEvent(flowChainId);
if (previousTrigger.isPresent() && currentTrigger.isPresent()) {
if (isIdempotentTriggers(previousTrigger.get().getRight(), currentTrigger.get().getRight())) {
LOGGER.info("Idempotent flow chain trigger. Running {}, requested {}", previousTrigger, currentTrigger);
acceptResult = FlowAcceptResult.runningInFlowChain(previousTrigger.get().getLeft());
}
}
} else if (NullUtil.allNull(initFlowLog.get().getFlowChainId(), flowChainId)) {
Payload previousTrigger = FlowLogUtil.tryDeserializePayload(initFlowLog.get());
if (isIdempotentTriggers(previousTrigger, payload)) {
LOGGER.info("Idempotent flow trigger. Running {}, requested {}", previousTrigger, payload);
acceptResult = FlowAcceptResult.runningInFlow(initFlowLog.get().getFlowId());
}
}
}
if (acceptResult == null) {
LOGGER.info("Flow operation not allowed, other flow is running. Resource ID {}, event {}", payload.getResourceId(), key);
acceptResult = FlowAcceptResult.alreadyExistingFlow(flowLogItems);
}
flowChains.removeFullFlowChain(flowChainId, false);
return acceptResult;
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class Flow2Handler method accept.
@Override
public void accept(Event<? extends Payload> event) {
String key = (String) event.getKey();
Payload payload = event.getData();
String flowId = getFlowId(event);
String flowChainId = getFlowChainId(event);
String flowChainType = getFlowChainType(event);
String flowTriggerUserCrn = getFlowTriggerUserCrn(event);
String operationType = getFlowOperationType(event);
Span activeSpan = tracer.activeSpan();
SpanContext spanContext = event.getHeaders().get(FlowConstants.SPAN_CONTEXT);
String operationName = event.getKey().toString();
if (FlowTracingUtil.isActiveSpanReusable(activeSpan, spanContext, operationName)) {
LOGGER.debug("Reusing existing span. {}", activeSpan.context());
doAccept(event, key, payload, flowChainId, flowChainType, new FlowParameters(flowId, flowTriggerUserCrn, operationType, spanContext));
} else {
Span span = FlowTracingUtil.getSpan(tracer, operationName, spanContext, flowId, flowChainId, flowTriggerUserCrn);
spanContext = FlowTracingUtil.useOrCreateSpanContext(spanContext, span);
try (Scope ignored = tracer.activateSpan(span)) {
doAccept(event, key, payload, flowChainId, flowChainType, new FlowParameters(flowId, flowTriggerUserCrn, operationType, spanContext));
} finally {
span.finish();
}
}
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class FlowChainHandler method restoreFlowChain.
public void restoreFlowChain(String flowChainId) {
Optional<FlowChainLog> chainLog = flowLogService.findFirstByFlowChainIdOrderByCreatedDesc(flowChainId);
if (chainLog.isPresent()) {
String flowChainType = chainLog.get().getFlowChainType();
Queue<Selectable> queue = (Queue<Selectable>) JsonReader.jsonToJava(chainLog.get().getChain());
Payload triggerEvent = tryDeserializeTriggerEvent(chainLog.get());
FlowTriggerEventQueue chain = new FlowTriggerEventQueue(flowChainType, triggerEvent, queue);
if (chainLog.get().getParentFlowChainId() != null) {
chain.setParentFlowChainId(chainLog.get().getParentFlowChainId());
}
flowChains.putFlowChain(flowChainId, chainLog.get().getParentFlowChainId(), chain);
Selectable selectable = queue.peek();
if (selectable != null) {
OperationType operationType = flowChainOperationTypeConfig.getFlowTypeOperationTypeMap().getOrDefault(flowChainType, OperationType.UNKNOWN);
flowStatCache.putByFlowChainId(flowChainId, selectable.getResourceId(), operationType.name(), true);
}
if (chainLog.get().getParentFlowChainId() != null) {
restoreFlowChain(chainLog.get().getParentFlowChainId());
}
}
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class ExceptionCatcherEventHandlerTest method testAcceptWhenSuccessful.
@Test
public void testAcceptWhenSuccessful() {
Event<Payload> event = mock(Event.class);
Event.Headers headers = mock(Event.Headers.class);
Selectable sendEventObject = mock(Selectable.class);
underTest.initialize(SELECTOR, null, false, sendEventObject);
when(event.getHeaders()).thenReturn(headers);
when(sendEventObject.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(sendEventObject, eventBusEvent.getData());
}
Aggregations