Search in sources :

Example 76 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowLogDBServiceTest method createFlowLog.

private FlowLog createFlowLog(String flowId) {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowId(flowId);
    flowLog.setFlowChainId(flowId + "chain");
    return flowLog;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

Example 77 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowLogDBServiceTest method cancelTooOldTerminationFlowForResourceTest.

@Test
public void cancelTooOldTerminationFlowForResourceTest() throws TransactionService.TransactionExecutionException {
    Set<FlowLogIdWithTypeAndTimestamp> flowLogs = new LinkedHashSet<>();
    FlowLogIdWithTypeAndTimestamp flowLog2 = mock(FlowLogIdWithTypeAndTimestamp.class);
    when(flowLog2.getFlowType()).thenReturn(ClassValue.of(Class.class));
    flowLogs.add(flowLog2);
    FlowLogIdWithTypeAndTimestamp flowLog1 = mock(FlowLogIdWithTypeAndTimestamp.class);
    when(flowLog1.getFlowType()).thenReturn(ClassValue.of(TerminationFlowConfig.class));
    when(flowLog1.getCreated()).thenReturn(9000L);
    when(flowLog1.getFlowId()).thenReturn("flow1");
    flowLogs.add(flowLog1);
    when(flowLogRepository.findAllRunningFlowLogByResourceId(eq(1L))).thenReturn(flowLogs);
    FlowLog realFlowLog1 = mock(FlowLog.class);
    when(realFlowLog1.getId()).thenReturn(10L);
    when(flowLogRepository.findFirstByFlowIdOrderByCreatedDesc(eq("flow1"))).thenReturn(Optional.of(realFlowLog1));
    when(applicationFlowInformation.getTerminationFlow()).thenReturn(Collections.singletonList(TerminationFlowConfig.class));
    when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> ((Supplier) invocation.getArguments()[0]).get());
    when(nodeConfig.getId()).thenReturn("node1");
    underTest.cancelTooOldTerminationFlowForResource(1L, 10000L);
    verify(flowLogRepository).finalizeByFlowId(eq("flow1"));
    verify(flowLogRepository, times(0)).finalizeByFlowId(eq("flow2"));
    verify(flowLogRepository).updateLastLogStatusInFlow(eq(10L), eq(StateStatus.SUCCESSFUL));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FlowLogIdWithTypeAndTimestamp(com.sequenceiq.flow.domain.FlowLogIdWithTypeAndTimestamp) FlowLog(com.sequenceiq.flow.domain.FlowLog) Supplier(java.util.function.Supplier) Test(org.junit.Test)

Example 78 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowLogDBServiceTest method createFlowLog.

private FlowLog createFlowLog(boolean pending, String flowId) {
    FlowLog flowLog = createFlowLog(flowId);
    flowLog.setFinalized(!pending);
    flowLog.setStateStatus(pending ? StateStatus.PENDING : StateStatus.SUCCESSFUL);
    return flowLog;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

Example 79 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog 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 80 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowRetryService method retry.

public RetryResponse retry(Long stackId) {
    RetryableStateResponse retryableStateResponse = getRetryableStateResponse(stackId);
    switch(retryableStateResponse.getState()) {
        case FLOW_PENDING:
            String flowPendingMessage = "Retry cannot be performed, because there is already an active flow.";
            LOGGER.info(flowPendingMessage + " stackId: {}", stackId);
            throw new BadRequestException(flowPendingMessage);
        case LAST_NOT_FAILED_OR_NOT_RETRYABLE:
            String notFailedOrNotRetryableMessage = "Retry cannot be performed. The last flow did not fail or not retryable." + retryableStateResponse.getLastKnownStateMessage();
            LOGGER.info(notFailedOrNotRetryableMessage + " stackId: {}", stackId);
            throw new BadRequestException(notFailedOrNotRetryableMessage);
        case NO_SUCCESSFUL_STATE:
            String noSuccessfulStateMessage = "Cannot restart previous flow because there is no successful state in the flow.";
            LOGGER.info(noSuccessfulStateMessage + " stackId: {}", stackId);
            throw new BadRequestException(noSuccessfulStateMessage);
        case RETRYABLE:
            FlowLog lastSuccessfulStateFlowLog = retryableStateResponse.getLastSuccessfulStateFlowLog();
            flow2Handler.restartFlow(lastSuccessfulStateFlowLog);
            if (lastSuccessfulStateFlowLog.getFlowChainId() != null) {
                return new RetryResponse(retryableStateResponse.getName(), new FlowIdentifier(FlowType.FLOW_CHAIN, lastSuccessfulStateFlowLog.getFlowChainId()));
            } else {
                return new RetryResponse(retryableStateResponse.getName(), new FlowIdentifier(FlowType.FLOW, lastSuccessfulStateFlowLog.getFlowId()));
            }
        default:
            throw new NotImplementedException("Retry state handling is not implemented: " + retryableStateResponse.getState());
    }
}
Also used : RetryResponse(com.sequenceiq.flow.domain.RetryResponse) FlowLog(com.sequenceiq.flow.domain.FlowLog) RetryableStateResponse(com.sequenceiq.flow.domain.RetryableStateResponse) NotImplementedException(org.apache.commons.lang3.NotImplementedException) BadRequestException(javax.ws.rs.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Aggregations

FlowLog (com.sequenceiq.flow.domain.FlowLog)92 Test (org.junit.jupiter.api.Test)25 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)21 List (java.util.List)13 FlowConfiguration (com.sequenceiq.flow.core.config.FlowConfiguration)12 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)11 Mockito.times (org.mockito.Mockito.times)11 Mockito.verify (org.mockito.Mockito.verify)11 Mockito.when (org.mockito.Mockito.when)11 HelloWorldFlowConfig (com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig)10 Map (java.util.Map)10 UUID (java.util.UUID)10 Collectors (java.util.stream.Collectors)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Clock (com.sequenceiq.cloudbreak.common.service.Clock)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)9 FlowRegister (com.sequenceiq.flow.core.FlowRegister)9 SecureRandom (java.security.SecureRandom)9 Random (java.util.Random)9