Search in sources :

Example 6 with FlowLog

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

the class Flow2Handler method retryLastFailedFlowFromStart.

/**
 * Retry the failed flow completely
 *
 * @param resourceId Datalake ID
 * @return Identifier of flow or a flow chain
 */
public FlowIdentifier retryLastFailedFlowFromStart(Long resourceId) {
    FlowLog firstSuccessfulStateLog = getFirstRetryableStateLogfromLatestFlow(resourceId);
    LOGGER.info("Trying to restart flow {}", firstSuccessfulStateLog.getFlowType().getName());
    restartFlow(firstSuccessfulStateLog);
    LOGGER.info("Restarted flow : {}", firstSuccessfulStateLog.getFlowType().getName());
    if (firstSuccessfulStateLog.getFlowChainId() != null) {
        return new FlowIdentifier(FlowType.FLOW_CHAIN, firstSuccessfulStateLog.getFlowChainId());
    } else {
        return new FlowIdentifier(FlowType.FLOW, firstSuccessfulStateLog.getFlowId());
    }
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 7 with FlowLog

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

the class TerminationTriggerServiceTest method whenStackNotDeletedAndNotForcedTerminationFlowLogAndForcedShouldTerminate.

@Test
public void whenStackNotDeletedAndNotForcedTerminationFlowLogAndForcedShouldTerminate() {
    FlowLog flowLog = getTerminationFlowLog(false);
    when(flowLogService.findAllByResourceIdAndFinalizedIsFalseOrderByCreatedDesc(anyLong())).thenReturn(List.of(flowLog));
    setupKerberized();
    underTest.triggerTermination(getAvailableStack(), true);
    verifyTerminationEventFired(true, true, false);
    verify(flowCancelService).cancelFlowSilently(flowLog);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Test(org.junit.Test)

Example 8 with FlowLog

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

the class TerminationTriggerServiceTest method whenStackNotDeletedAndNotTerminationFlowLogAndKerbAndForcedShouldTerminate.

@Test
public void whenStackNotDeletedAndNotTerminationFlowLogAndKerbAndForcedShouldTerminate() {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowType(ClassValue.of(StackCreationFlowConfig.class));
    when(flowLogService.findAllByResourceIdAndFinalizedIsFalseOrderByCreatedDesc(anyLong())).thenReturn(List.of(flowLog));
    setupKerberized();
    underTest.triggerTermination(getAvailableStack(), true);
    verifyTerminationEventFired(true, true, false);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) StackCreationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationFlowConfig) Test(org.junit.Test)

Example 9 with FlowLog

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

the class TerminationTriggerServiceTest method getTerminationFlowLog.

private FlowLog getTerminationFlowLog(boolean forced) {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowType(ClassValue.of(StackTerminationFlowConfig.class));
    flowLog.setCurrentState("INIT_STATE");
    TerminationEvent event = new TerminationEvent("selector", 1L, forced ? TerminationType.FORCED : TerminationType.REGULAR);
    flowLog.setPayload(JsonWriter.objectToJson(event));
    flowLog.setPayloadType(ClassValue.of(TerminationEvent.class));
    return flowLog;
}
Also used : StackTerminationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationFlowConfig) FlowLog(com.sequenceiq.flow.domain.FlowLog) TerminationEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationEvent)

Example 10 with FlowLog

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

the class TerminationTriggerServiceTest method whenStackNotDeletedAndNotTerminationFlowLogAndNotKerbAndNotForcedShouldTerminate.

@Test
public void whenStackNotDeletedAndNotTerminationFlowLogAndNotKerbAndNotForcedShouldTerminate() {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowType(ClassValue.of(StackCreationFlowConfig.class));
    when(flowLogService.findAllByResourceIdAndFinalizedIsFalseOrderByCreatedDesc(anyLong())).thenReturn(List.of(flowLog));
    setupNotKerberized();
    underTest.triggerTermination(getAvailableStack(), false);
    verifyTerminationEventFired(false, false, false);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) StackCreationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationFlowConfig) Test(org.junit.Test)

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