Search in sources :

Example 1 with FlowLog

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

the class ExistingStackPatchService method apply.

/**
 * @param stack the stack to apply the patch for
 * @return whether the patch was applied successfully
 * @throws ExistingStackPatchApplyException when something unexpected goes wrong while applying the patch
 */
public boolean apply(Stack stack) throws ExistingStackPatchApplyException {
    if (flowLogService.isOtherFlowRunning(stack.getId())) {
        LOGGER.info("Another flow is running for stack {}, skipping patch apply to let the flow finish", stack.getResourceCrn());
        return false;
    } else {
        Optional<FlowLog> lastRetryableFailedFlow = flowRetryService.getLastRetryableFailedFlow(stack.getId());
        if (lastRetryableFailedFlow.isEmpty()) {
            try {
                LOGGER.info("Starting stack {} patching for {}", stack.getResourceCrn(), getStackPatchType());
                boolean success = checkedMeasure(() -> doApply(stack), LOGGER, "Existing stack patching took {} ms for stack {} and patch {}.", stack.getResourceCrn(), getStackPatchType());
                if (success) {
                    LOGGER.info("Stack {} was patched successfully for {}", stack.getResourceCrn(), getStackPatchType());
                    stackPatchRepository.save(new StackPatch(stack, getStackPatchType()));
                } else {
                    LOGGER.info("Stack {} was not patched for {}", stack.getResourceCrn(), getStackPatchType());
                }
                return success;
            } catch (ExistingStackPatchApplyException e) {
                throw e;
            } catch (Exception e) {
                String message = String.format("Something unexpected went wrong with stack %s while applying patch %s", stack.getResourceCrn(), getStackPatchType());
                throw new ExistingStackPatchApplyException(message, e);
            }
        } else {
            LOGGER.info("Stack {} has a retryable failed flow, skipping patch apply to preserve possible retry", stack.getResourceCrn());
            return false;
        }
    }
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) StackPatch(com.sequenceiq.cloudbreak.domain.stack.StackPatch)

Example 2 with FlowLog

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

the class CcmUpgradeFlowIntegrationTest method testCcmUpgradeWhenReRegisterFail.

@Test
public void testCcmUpgradeWhenReRegisterFail() {
    doThrow(new BadRequestException()).when(ccmUpgradeService).reregister(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(f -> f.getFinalized()), "flow has not finalized");
    verify(ccmUpgradeService, times(1)).prepare(STACK_ID);
    verify(ccmUpgradeService, times(1)).ccmUpgradeFailed(STACK_ID);
    verify(ccmUpgradeService, times(1)).reregister(STACK_ID);
    verify(ccmUpgradeService, never()).ccmUpgradePreparationFailed(STACK_ID);
    verify(ccmUpgradeService, never()).unregister(STACK_ID);
    verify(ccmUpgradeService, never()).removeAutoSsh(STACK_ID);
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) BeforeEach(org.junit.jupiter.api.BeforeEach) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) CcmRemoveAutoSshHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmRemoveAutoSshHandler) SecretService(com.sequenceiq.cloudbreak.service.secret.service.SecretService) MockReset(org.springframework.boot.test.mock.mockito.MockReset) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) Scheduler(org.quartz.Scheduler) TestConfiguration(org.springframework.boot.test.context.TestConfiguration) Mockito.doThrow(org.mockito.Mockito.doThrow) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Reporter(io.jaegertracing.spi.Reporter) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) FlowOperationStatisticsService(com.sequenceiq.flow.core.stats.FlowOperationStatisticsService) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) FlowChainLogRepository(com.sequenceiq.flow.repository.FlowChainLogRepository) CcmReregisterClusterToClusterProxyHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmReregisterClusterToClusterProxyHandler) Sampler(io.jaegertracing.spi.Sampler) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) BadRequestException(javax.ws.rs.BadRequestException) MockBean(org.springframework.boot.test.mock.mockito.MockBean) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) FlowLog(com.sequenceiq.flow.domain.FlowLog) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) EventBus(reactor.bus.EventBus) UUID(java.util.UUID) MpscDispatcher(reactor.core.dispatch.MpscDispatcher) Test(org.junit.jupiter.api.Test) TransactionMetricsService(com.sequenceiq.cloudbreak.common.service.TransactionMetricsService) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) FreeIpaV1Endpoint(com.sequenceiq.freeipa.api.v1.freeipa.stack.FreeIpaV1Endpoint) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Mockito.mock(org.mockito.Mockito.mock) FlowRegister(com.sequenceiq.flow.core.FlowRegister) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ConsumerNotFoundHandler(com.sequenceiq.flow.reactor.handler.ConsumerNotFoundHandler) Client(javax.ws.rs.client.Client) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackStatusFinalizer(com.sequenceiq.cloudbreak.core.flow2.StackStatusFinalizer) CCM_UPGRADE_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.ccm.upgrade.CcmUpgradeEvent.CCM_UPGRADE_EVENT) Inject(javax.inject.Inject) ConsumerCheckerEventBus(com.sequenceiq.flow.reactor.eventbus.ConsumerCheckerEventBus) ArgumentCaptor(org.mockito.ArgumentCaptor) ReactorNotifier(com.sequenceiq.cloudbreak.core.flow2.service.ReactorNotifier) FlowLogRepository(com.sequenceiq.flow.repository.FlowLogRepository) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) NotificationService(com.sequenceiq.notification.NotificationService) CcmUpgradePreparationHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmUpgradePreparationHandler) CbEventParameterFactory(com.sequenceiq.cloudbreak.core.flow2.service.CbEventParameterFactory) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Import(org.springframework.context.annotation.Import) CcmUnregisterHostsHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmUnregisterHostsHandler) Mockito.times(org.mockito.Mockito.times) InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) Mockito.when(org.mockito.Mockito.when) FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) EventBusSpec(reactor.bus.spec.EventBusSpec) ComponentScan(org.springframework.context.annotation.ComponentScan) Mockito.verify(org.mockito.Mockito.verify) MDCCleanerThreadPoolExecutor(com.sequenceiq.cloudbreak.logger.concurrent.MDCCleanerThreadPoolExecutor) Mockito.never(org.mockito.Mockito.never) CloudbreakFlowInformation(com.sequenceiq.cloudbreak.core.flow2.CloudbreakFlowInformation) Assertions(org.junit.jupiter.api.Assertions) Bean(org.springframework.context.annotation.Bean) Environment(reactor.Environment) 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 3 with FlowLog

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

the class CcmUpgradeFlowIntegrationTest method testCcmUpgradeWhenPrepFail.

@Test
public void testCcmUpgradeWhenPrepFail() {
    doThrow(new BadRequestException()).when(ccmUpgradeService).prepare(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(f -> f.getFinalized()), "flow has not finalized");
    verify(ccmUpgradeService, times(1)).prepare(STACK_ID);
    verify(ccmUpgradeService, times(1)).ccmUpgradePreparationFailed(STACK_ID);
    verify(ccmUpgradeService, never()).ccmUpgradeFailed(STACK_ID);
    verify(ccmUpgradeService, never()).reregister(STACK_ID);
    verify(ccmUpgradeService, never()).unregister(STACK_ID);
    verify(ccmUpgradeService, never()).removeAutoSsh(STACK_ID);
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) BeforeEach(org.junit.jupiter.api.BeforeEach) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) CcmRemoveAutoSshHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmRemoveAutoSshHandler) SecretService(com.sequenceiq.cloudbreak.service.secret.service.SecretService) MockReset(org.springframework.boot.test.mock.mockito.MockReset) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) Scheduler(org.quartz.Scheduler) TestConfiguration(org.springframework.boot.test.context.TestConfiguration) Mockito.doThrow(org.mockito.Mockito.doThrow) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Reporter(io.jaegertracing.spi.Reporter) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) FlowOperationStatisticsService(com.sequenceiq.flow.core.stats.FlowOperationStatisticsService) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) FlowChainLogRepository(com.sequenceiq.flow.repository.FlowChainLogRepository) CcmReregisterClusterToClusterProxyHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmReregisterClusterToClusterProxyHandler) Sampler(io.jaegertracing.spi.Sampler) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) BadRequestException(javax.ws.rs.BadRequestException) MockBean(org.springframework.boot.test.mock.mockito.MockBean) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) FlowLog(com.sequenceiq.flow.domain.FlowLog) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) EventBus(reactor.bus.EventBus) UUID(java.util.UUID) MpscDispatcher(reactor.core.dispatch.MpscDispatcher) Test(org.junit.jupiter.api.Test) TransactionMetricsService(com.sequenceiq.cloudbreak.common.service.TransactionMetricsService) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) FreeIpaV1Endpoint(com.sequenceiq.freeipa.api.v1.freeipa.stack.FreeIpaV1Endpoint) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Mockito.mock(org.mockito.Mockito.mock) FlowRegister(com.sequenceiq.flow.core.FlowRegister) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ConsumerNotFoundHandler(com.sequenceiq.flow.reactor.handler.ConsumerNotFoundHandler) Client(javax.ws.rs.client.Client) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackStatusFinalizer(com.sequenceiq.cloudbreak.core.flow2.StackStatusFinalizer) CCM_UPGRADE_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.ccm.upgrade.CcmUpgradeEvent.CCM_UPGRADE_EVENT) Inject(javax.inject.Inject) ConsumerCheckerEventBus(com.sequenceiq.flow.reactor.eventbus.ConsumerCheckerEventBus) ArgumentCaptor(org.mockito.ArgumentCaptor) ReactorNotifier(com.sequenceiq.cloudbreak.core.flow2.service.ReactorNotifier) FlowLogRepository(com.sequenceiq.flow.repository.FlowLogRepository) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) NotificationService(com.sequenceiq.notification.NotificationService) CcmUpgradePreparationHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmUpgradePreparationHandler) CbEventParameterFactory(com.sequenceiq.cloudbreak.core.flow2.service.CbEventParameterFactory) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Import(org.springframework.context.annotation.Import) CcmUnregisterHostsHandler(com.sequenceiq.cloudbreak.reactor.handler.cluster.upgrade.ccm.CcmUnregisterHostsHandler) Mockito.times(org.mockito.Mockito.times) InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) Mockito.when(org.mockito.Mockito.when) FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) EventBusSpec(reactor.bus.spec.EventBusSpec) ComponentScan(org.springframework.context.annotation.ComponentScan) Mockito.verify(org.mockito.Mockito.verify) MDCCleanerThreadPoolExecutor(com.sequenceiq.cloudbreak.logger.concurrent.MDCCleanerThreadPoolExecutor) Mockito.never(org.mockito.Mockito.never) CloudbreakFlowInformation(com.sequenceiq.cloudbreak.core.flow2.CloudbreakFlowInformation) Assertions(org.junit.jupiter.api.Assertions) Bean(org.springframework.context.annotation.Bean) Environment(reactor.Environment) 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 4 with FlowLog

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

the class TerminationTriggerService method handleIfStackIsNotTerminated.

private void handleIfStackIsNotTerminated(Stack stack, boolean forced) {
    LOGGER.info("stack {} in environment {} is not deleted. Current termination request is {}", stack.getName(), stack.getEnvironmentCrn(), getForcedOrNotString(forced));
    Optional<FlowLog> optionalFlowLog = findLatestTerminationFlowLogWithInitState(stack);
    if (optionalFlowLog.isPresent()) {
        FlowLog flowLog = optionalFlowLog.get();
        LOGGER.debug("Found termination flowlog with id [{}] and payload [{}]", flowLog.getFlowId(), flowLog.getPayload());
        handleIfFlowLogExistsForTermination(stack, forced, flowLog);
    } else {
        LOGGER.debug("Couldn't find termination FlowLog with 'INIT_STATE'. Triggering termination");
        fireTerminationEvent(stack, forced);
    }
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

Example 5 with FlowLog

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

the class Flow2Handler method handleFlowConflict.

private AcceptResult handleFlowConflict(String key, Payload payload, String flowChainId, Set<FlowLogIdWithTypeAndTimestamp> flowLogItems) {
    AcceptResult acceptResult = null;
    Optional<FlowLog> initFlowLog = flowLogService.findAllByFlowIdOrderByCreatedDesc(flowLogItems.iterator().next().getFlowId()).stream().min(Comparator.comparing(FlowLog::getCreated));
    if (initFlowLog.isPresent()) {
        LOGGER.info("Found previous init flow log: {}", initFlowLog.get());
        if (NullUtil.allNotNull(initFlowLog.get().getFlowChainId(), flowChainId)) {
            Optional<Pair<String, Payload>> previousTrigger = flowChains.getRootTriggerEvent(initFlowLog.get().getFlowChainId());
            Optional<Pair<String, Payload>> currentTrigger = flowChains.getRootTriggerEvent(flowChainId);
            if (previousTrigger.isPresent() && currentTrigger.isPresent()) {
                if (isIdempotentTriggers(previousTrigger.get().getRight(), currentTrigger.get().getRight())) {
                    LOGGER.info("Idempotent flow chain trigger. Running {}, requested {}", previousTrigger, currentTrigger);
                    acceptResult = FlowAcceptResult.runningInFlowChain(previousTrigger.get().getLeft());
                }
            }
        } else if (NullUtil.allNull(initFlowLog.get().getFlowChainId(), flowChainId)) {
            Payload previousTrigger = FlowLogUtil.tryDeserializePayload(initFlowLog.get());
            if (isIdempotentTriggers(previousTrigger, payload)) {
                LOGGER.info("Idempotent flow trigger. Running {}, requested {}", previousTrigger, payload);
                acceptResult = FlowAcceptResult.runningInFlow(initFlowLog.get().getFlowId());
            }
        }
    }
    if (acceptResult == null) {
        LOGGER.info("Flow operation not allowed, other flow is running. Resource ID {}, event {}", payload.getResourceId(), key);
        acceptResult = FlowAcceptResult.alreadyExistingFlow(flowLogItems);
    }
    flowChains.removeFullFlowChain(flowChainId, false);
    return acceptResult;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) Pair(org.apache.commons.lang3.tuple.Pair)

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