Search in sources :

Example 51 with FlowLog

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

the class TerminationTriggerServiceTest method whenStackNotDeletedAndNotTerminationFlowLogAndNotKerbAndForcedShouldTerminate.

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

Example 52 with FlowLog

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

the class UpgradeCcmFlowIntegrationTest method testCcmUpgradeWhenTunnelUpdateFail.

@Test
public void testCcmUpgradeWhenTunnelUpdateFail() throws CloudbreakOrchestratorException {
    doThrow(new BadRequestException()).when(upgradeCcmService).updateTunnel(STACK_ID);
    FlowIdentifier flowIdentifier = triggerFlow();
    letItFlow(flowIdentifier);
    ArgumentCaptor<FlowLog> flowLog = ArgumentCaptor.forClass(FlowLog.class);
    verify(flowLogRepository, times(2)).save(flowLog.capture());
    Assertions.assertTrue(flowLog.getAllValues().stream().anyMatch(FlowLog::getFinalized), "flow has not finalized");
    InOrder inOrder = Mockito.inOrder(upgradeCcmService);
    inOrder.verify(upgradeCcmService, times(1)).updateTunnel(STACK_ID);
    inOrder.verify(upgradeCcmService, times(1)).ccmUpgradeFailed(STACK_ID, CLUSTER_ID, Tunnel.CCM);
    verify(upgradeCcmService, never()).pushSaltState(STACK_ID, CLUSTER_ID);
    verify(upgradeCcmService, never()).reconfigureNginx(STACK_ID);
    verify(upgradeCcmService, never()).registerClusterProxy(STACK_ID);
    verify(upgradeCcmService, never()).healthCheck(STACK_ID);
    verify(upgradeCcmService, never()).deregisterAgent(STACK_ID, Tunnel.CCM);
    verify(upgradeCcmService, never()).removeAgent(STACK_ID, Tunnel.CCM);
}
Also used : InOrder(org.mockito.InOrder) FlowLog(com.sequenceiq.flow.domain.FlowLog) BadRequestException(javax.ws.rs.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 53 with FlowLog

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

the class DatalakeRestoreActionsTest method testGetNewSdxIdForResizeCreateFlowContext.

@Test
public void testGetNewSdxIdForResizeCreateFlowContext() throws Exception {
    SdxCluster sdxCluster = genCluster();
    FlowParameters flowParameters = new FlowParameters(FLOW_ID, null, null);
    when(sdxService.getByNameInAccount(eq(USER_CRN), eq(DATALAKE_NAME))).thenReturn(sdxCluster);
    when(flowLogService.getLastFlowLog(anyString())).thenReturn(Optional.of(new FlowLog()));
    FlowChainLog flowChainLog = new FlowChainLog();
    flowChainLog.setFlowChainType(DatalakeResizeFlowEventChainFactory.class.getSimpleName());
    when(flowChainLogService.findFirstByFlowChainIdOrderByCreatedDesc(any())).thenReturn(Optional.of(flowChainLog));
    DatalakeTriggerRestoreEvent event = new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), OLD_SDX_ID, DATALAKE_NAME, USER_CRN, null, BACKUP_LOCATION, null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE);
    AbstractAction action = (AbstractAction) underTest.triggerDatalakeRestore();
    initActionPrivateFields(action);
    AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
    SdxContext context = (SdxContext) testSupport.createFlowContext(flowParameters, null, event);
    Assert.assertEquals(NEW_SDX_ID, context.getSdxId());
    Assert.assertEquals(USER_CRN, context.getUserId());
    Assert.assertEquals(FLOW_ID, context.getFlowId());
    Assert.assertEquals(NEW_SDX_ID, event.getDrStatus().getSdxClusterId());
    flowChainLog.setFlowChainType(DatalakeUpgradeFlowEventChainFactory.class.getSimpleName());
    context = (SdxContext) testSupport.createFlowContext(flowParameters, null, event);
    Assert.assertEquals(OLD_SDX_ID, context.getSdxId());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) DatalakeUpgradeFlowEventChainFactory(com.sequenceiq.datalake.flow.chain.DatalakeUpgradeFlowEventChainFactory) FlowLog(com.sequenceiq.flow.domain.FlowLog) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DatalakeResizeFlowEventChainFactory(com.sequenceiq.datalake.flow.chain.DatalakeResizeFlowEventChainFactory) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) AbstractAction(com.sequenceiq.flow.core.AbstractAction) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Test(org.junit.jupiter.api.Test)

Example 54 with FlowLog

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

the class FlowLogUtil method isFlowFailHandled.

public static boolean isFlowFailHandled(List<FlowLog> flowLogs, Set<String> failHandledEvents) {
    if (flowLogs.size() > 2) {
        FlowLog lastFlowLog = flowLogs.get(0);
        FlowLog secondLastFlowLog = flowLogs.get(1);
        LOGGER.debug("Last two log items: {}, {}", lastFlowLog, secondLastFlowLog);
        return lastFlowLog.getFinalized() && failHandledEvents.contains(secondLastFlowLog.getNextEvent());
    }
    return false;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

Example 55 with FlowLog

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

the class FlowLogUtil method isFlowInFailedState.

public static boolean isFlowInFailedState(List<FlowLog> flowLogs, Set<String> failHandledEvents) {
    if (flowLogs.size() > 2) {
        FlowLog lastFlowLog = flowLogs.get(0);
        FlowLog secondLastFlowLog = flowLogs.get(1);
        LOGGER.debug("Last two log items: {}, {}", lastFlowLog, secondLastFlowLog);
        return lastFlowLog.getFinalized() && (failHandledEvents.contains(secondLastFlowLog.getNextEvent()) || StateStatus.FAILED.equals(secondLastFlowLog.getStateStatus()));
    }
    return false;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

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