Search in sources :

Example 11 with FlowChainLog

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);
}
Also used : FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) Test(org.junit.Test)

Example 12 with FlowChainLog

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;
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 13 with 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);
}
Also used : FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) Test(org.junit.Test)

Example 14 with FlowChainLog

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;
        }
    };
}
Also used : Optional(java.util.Optional) FlowLog(com.sequenceiq.flow.domain.FlowLog) StateContext(org.springframework.statemachine.StateContext) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) SdxFailedEvent(com.sequenceiq.datalake.flow.SdxFailedEvent) DatalakeStatusEnum(com.sequenceiq.datalake.entity.DatalakeStatusEnum) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 15 with FlowChainLog

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;
    }
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Aggregations

FlowChainLog (com.sequenceiq.flow.domain.FlowChainLog)18 FlowLog (com.sequenceiq.flow.domain.FlowLog)6 Test (org.junit.Test)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)3 SdxContext (com.sequenceiq.datalake.flow.SdxContext)3 FlowCheckResponse (com.sequenceiq.flow.api.model.FlowCheckResponse)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 Optional (java.util.Optional)3 Payload (com.sequenceiq.cloudbreak.common.event.Payload)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)2 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)2 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)2 List (java.util.List)2 Map (java.util.Map)2 Queue (java.util.Queue)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Sets (com.google.common.collect.Sets)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CrnParseException (com.sequenceiq.cloudbreak.auth.crn.CrnParseException)1