Search in sources :

Example 1 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class StackOperationService method start.

@VisibleForTesting
FlowIdentifier start(Stack stack, Cluster cluster, boolean updateCluster) {
    FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
    environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.startable());
    dataLakeStatusCheckerService.validateRunningState(stack);
    if (stack.isAvailable()) {
        eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), STACK_START_IGNORED);
    } else if (stack.isReadyForStart() || stack.isStartFailed()) {
        Stack startStack = stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.START_REQUESTED);
        flowIdentifier = flowManager.triggerStackStart(stack.getId());
        if (updateCluster && cluster != null) {
            clusterOperationService.updateStatus(startStack, StatusRequest.STARTED);
        }
    } else {
        throw NotAllowedStatusUpdate.stack(stack).to(DetailedStackStatus.START_REQUESTED).badRequest();
    }
    return flowIdentifier;
}
Also used : FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier 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 FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier 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 FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class ClusterOperationService method stop.

private FlowIdentifier stop(Stack stack, Cluster cluster) {
    StopRestrictionReason reason = stackStopRestrictionService.isInfrastructureStoppable(stack);
    FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
    if (stack.isStopped()) {
        eventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_STOP_IGNORED);
    } else if (reason != StopRestrictionReason.NONE) {
        throw new BadRequestException(String.format("Cannot stop a cluster '%s'. Reason: %s", cluster.getId(), reason.getReason()));
    } else if (!stack.isReadyForStop() && !stack.isStopFailed()) {
        throw NotAllowedStatusUpdate.cluster(stack).to(STOPPED).expectedIn(AVAILABLE).badRequest();
    } else {
        clusterService.updateClusterStatusByStackId(stack.getId(), DetailedStackStatus.STOP_REQUESTED);
        flowIdentifier = flowManager.triggerClusterStop(stack.getId());
    }
    return flowIdentifier;
}
Also used : StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 5 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxBackupRestoreService method triggerDatalakeBackupFlow.

private SdxBackupResponse triggerDatalakeBackupFlow(Long clusterId, String backupLocation, String backupName) {
    String selector = DATALAKE_TRIGGER_BACKUP_EVENT.event();
    String userId = ThreadBasedUserCrnProvider.getUserCrn();
    DatalakeTriggerBackupEvent startEvent = new DatalakeTriggerBackupEvent(selector, clusterId, userId, backupLocation, backupName, DatalakeBackupFailureReason.USER_TRIGGERED);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeBackupFlow(startEvent);
    return new SdxBackupResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
Also used : FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxBackupResponse(com.sequenceiq.sdx.api.model.SdxBackupResponse) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)

Aggregations

FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)150 Test (org.junit.jupiter.api.Test)55 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)15 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)14 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)14 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)10 Supplier (java.util.function.Supplier)10 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)9 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)7 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)7