use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.
the class FlowChainLogServiceTest method testFlowChainLogWithFlowChainType.
@Test
public void testFlowChainLogWithFlowChainType() {
// This is mainly for flows launched before 2.39
FlowChainLog flowChainLog = new FlowChainLog();
flowChainLog.setFlowChainType("flowChainType");
when(flowLogRepository.findFirstByFlowChainIdOrderByCreatedDesc(any())).thenReturn(Optional.of(flowChainLog));
String flowChainType = underTest.getFlowChainType("chainId");
assertEquals("flowChainType", flowChainType);
}
use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.
the class FlowChainLogServiceTest method flowChainLog.
private FlowChainLog flowChainLog(String flowChanId, boolean hasEventInQueue, Long created) {
FlowChainLog flowChainLog = flowChainLog(flowChanId, flowChanId + FLOWCHAIN_PARENT_SUFFIX, created);
Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
if (hasEventInQueue) {
flowEventChain.add(new TestEvent());
}
flowChainLog.setChain(JsonWriter.objectToJson(flowEventChain));
return flowChainLog;
}
use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.
the class FlowChainLogServiceTest method testFindAllFlowChainsInTree.
@Test
public void testFindAllFlowChainsInTree() {
FlowChainLog flowChainLogA = flowChainLog("A", NO_PARENT, 1);
FlowChainLog flowChainLogB = flowChainLog("B", flowChainLogA.getFlowChainId(), 2);
FlowChainLog flowChainLogC = flowChainLog("C", flowChainLogA.getFlowChainId(), 3);
FlowChainLog flowChainLogD = flowChainLog("D", flowChainLogC.getFlowChainId(), 4);
FlowChainLog flowChainLogE = flowChainLog("E", flowChainLogC.getFlowChainId(), 5);
setUpParent(flowChainLogB, flowChainLogA);
setUpChildren(flowChainLogA, List.of(flowChainLogC, flowChainLogB));
setUpChildren(flowChainLogC, List.of(flowChainLogE, flowChainLogD));
List<FlowChainLog> result = underTest.collectRelatedFlowChains(flowChainLogB);
assertEquals(List.of(flowChainLogA, flowChainLogB, flowChainLogC, flowChainLogD, flowChainLogE), result);
}
use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.
the class SdxStopActions method failedAction.
@Bean(name = "SDX_STOP_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractSdxAction<>(SdxFailedEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxFailedEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxFailedEvent payload, Map<Object, Object> variables) throws Exception {
Exception exception = payload.getException();
DatalakeStatusEnum failedStatus = DatalakeStatusEnum.STOP_FAILED;
LOGGER.info("Update SDX status to {} for resource: {}", failedStatus, payload.getResourceId(), exception);
String statusReason = "SDX stop failed";
if (exception.getMessage() != null) {
statusReason = exception.getMessage();
}
Flow flow = getFlow(context.getFlowParameters().getFlowId());
flow.setFlowFailed(payload.getException());
// If this is part of DL resize, mark failure as such in order to enable proper recovery.
Optional<FlowLog> lastFlowLog = flowLogService.getLastFlowLog(context.getFlowParameters().getFlowId());
if (lastFlowLog.isPresent()) {
Optional<FlowChainLog> flowChainLog = flowChainLogService.findFirstByFlowChainIdOrderByCreatedDesc(lastFlowLog.get().getFlowChainId());
if (flowChainLog.isPresent() && flowChainLog.get().getFlowChainType().equals(DatalakeResizeFlowEventChainFactory.class.getSimpleName())) {
statusReason = "Datalake resize failure: " + statusReason;
}
}
eventSenderService.notifyEvent(context, ResourceEvent.SDX_STOP_FAILED);
sdxStatusService.setStatusForDatalakeAndNotify(failedStatus, statusReason, payload.getResourceId());
sendEvent(context, SDX_STOP_FAILED_HANDLED_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(SdxFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return null;
}
};
}
use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.
the class FlowService method getFlowChainStateSafe.
public FlowCheckResponse getFlowChainStateSafe(List<Long> resourceIdList, String chainId) {
FlowCheckResponse flowCheckResponse = new FlowCheckResponse();
flowCheckResponse.setFlowChainId(chainId);
List<FlowChainLog> flowChains = flowChainLogService.findByFlowChainIdOrderByCreatedDesc(chainId);
if (!flowChains.isEmpty()) {
LOGGER.info("Checking if there is an active flow based on flow chain id {}", chainId);
List<FlowChainLog> relatedChains = getRelatedFlowChainLogs(flowChains);
Set<String> relatedChainIds = relatedChains.stream().map(FlowChainLog::getFlowChainId).collect(toSet());
Set<String> relatedFlowIds = flowLogDBService.getFlowIdsByChainIds(relatedChainIds);
List<FlowLog> relatedFlowLogs = flowLogDBService.getFlowLogsByFlowIdsCreatedDesc(relatedFlowIds);
validateResourceId(relatedFlowLogs, resourceIdList);
flowCheckResponse.setHasActiveFlow(!completed("Flow chain", chainId, relatedChains, relatedFlowLogs));
flowCheckResponse.setLatestFlowFinalizedAndFailed(isFlowInFailedState(relatedFlowLogs, failHandledEvents));
return flowCheckResponse;
} else {
flowCheckResponse.setHasActiveFlow(Boolean.FALSE);
return flowCheckResponse;
}
}
Aggregations