Search in sources :

Example 6 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.

the class DatalakeBackupActions method datalakeFullBackupInProgress.

@Bean(name = "DATALAKE_FULL_BACKUP_IN_PROGRESS_STATE")
public Action<?, ?> datalakeFullBackupInProgress() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Full datalake backup is in progress for {} ", payload.getResourceId());
            String operationId = (String) variables.get(OPERATION_ID);
            String backupId = (String) variables.get(BACKUP_ID);
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, ThreadBasedUserCrnProvider.getUserCrn(), DATALAKE_DATABASE_BACKUP_FINISHED);
            SdxDatabaseBackupStatusResponse backupStatusResponse = sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, operationId);
            if (backupStatusResponse.getStatus().equals(DatalakeDatabaseDrStatus.INPROGRESS)) {
                sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.SUCCEEDED, null);
            }
            sendEvent(context, DatalakeFullBackupWaitRequest.from(context, backupId));
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeBackupFailedEvent.from(payload, ex);
        }
    };
}
Also used : SdxDatabaseBackupStatusResponse(com.sequenceiq.sdx.api.model.SdxDatabaseBackupStatusResponse) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) PollerStoppedException(com.dyngr.exception.PollerStoppedException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 7 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.

the class DatalakeResizeFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(DatalakeResizeFlowChainStartEvent event) {
    Queue<Selectable> chain = new ConcurrentLinkedQueue<>();
    if (event.shouldTakeBackup()) {
        // Take a backup
        chain.add(new DatalakeTriggerBackupEvent(DATALAKE_TRIGGER_BACKUP_EVENT.event(), event.getResourceId(), event.getUserId(), event.getBackupLocation(), "resize" + System.currentTimeMillis(), DatalakeBackupFailureReason.BACKUP_ON_RESIZE, event.accepted()));
        // Stop datalake
        chain.add(new SdxStartStopEvent(SDX_STOP_EVENT.event(), event.getResourceId(), event.getUserId(), STOP_DATAHUBS));
    } else {
        chain.add(new SdxStartStopEvent(SDX_STOP_EVENT.event(), event.getResourceId(), event.getUserId(), STOP_DATAHUBS, event.accepted()));
    }
    // Detach sdx from environment
    chain.add(new SdxStartDetachEvent(SDX_DETACH_EVENT.event(), event.getResourceId(), event.getSdxCluster(), event.getUserId()));
    // Create new
    chain.add(new SdxEvent(SDX_VALIDATION_EVENT.event(), event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId()));
    if (event.shouldPerformRestore()) {
        // restore the new cluster
        chain.add(new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId(), null, event.getBackupLocation(), null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE));
    }
    // Delete the detached Sdx
    chain.add(new SdxDeleteStartEvent(SDX_DELETE_EVENT.event(), event.getResourceId(), event.getUserId(), true));
    chain.add(new DatahubRefreshStartEvent(event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId()));
    return new FlowTriggerEventQueue(getName(), event, chain);
}
Also used : DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) SdxStartStopEvent(com.sequenceiq.datalake.flow.stop.event.SdxStartStopEvent) SdxStartDetachEvent(com.sequenceiq.datalake.flow.detach.event.SdxStartDetachEvent) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) SdxDeleteStartEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeleteStartEvent) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)

Example 8 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.

the class SdxCreateActions method sdxValidation.

@Bean(name = "SDX_CREATION_VALIDATION_STATE")
public Action<?, ?> sdxValidation() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
            setCorrectSdxIdIfNecessary(context, payload);
            eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_PROVISION_STARTED);
            SdxValidationRequest req = new SdxValidationRequest(context);
            sendEvent(context, req.selector(), req);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCreateFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) SdxValidationRequest(com.sequenceiq.datalake.flow.create.event.SdxValidationRequest) StateContext(org.springframework.statemachine.StateContext) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 9 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.

the class CertRenewalActions method certRenewFinishedAction.

@Bean(name = "CERT_RENEWAL_FINISHED_STATE")
public Action<?, ?> certRenewFinishedAction() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Cert renewal is finished");
            certRenewalService.finalizeCertRenewal(payload.getResourceId());
            SdxEvent event = new SdxEvent(SdxCertRenewalEvent.CERT_RENEWAL_FINALIZED_EVENT.event(), context);
            sendEvent(context, event);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRenewalFailedEvent(payload, ex.getMessage());
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) SdxCertRenewalFailedEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 10 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.

the class SdxCertRenewWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<SdxCertRenewalWaitEvent> event) {
    SdxEvent sdxEvent = event.getData();
    Long sdxId = sdxEvent.getResourceId();
    String userId = sdxEvent.getUserId();
    Selectable response;
    try {
        LOGGER.debug("Start polling stack cert renewal process.");
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        certRenewalService.waitForCloudbreakClusterCertRenewal(sdxId, pollingConfig);
        response = new SdxEvent(SdxCertRenewalEvent.CERT_RENEWAL_FINISHED_EVENT.event(), sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Cert renewal polling exited before timeout. Cause: ", userBreakException);
        response = new SdxCertRenewalFailedEvent(sdxId, userId, userBreakException.getMessage());
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Cert renewal poller stopped.");
        response = new SdxCertRenewalFailedEvent(sdxId, userId, "Datalake cert renewal timed out after " + durationInMinutes + " minutes");
    } catch (PollerException exception) {
        LOGGER.error("Cert renewal polling failed. Cause: ", exception);
        response = new SdxCertRenewalFailedEvent(sdxId, userId, exception.getMessage());
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) SdxCertRenewalFailedEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Aggregations

SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)24 SdxContext (com.sequenceiq.datalake.flow.SdxContext)18 Map (java.util.Map)18 Bean (org.springframework.context.annotation.Bean)18 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)16 FlowParameters (com.sequenceiq.flow.core.FlowParameters)16 Optional (java.util.Optional)16 StateContext (org.springframework.statemachine.StateContext)16 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)7 PollerStoppedException (com.dyngr.exception.PollerStoppedException)6 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)5 PollerException (com.dyngr.exception.PollerException)4 UserBreakException (com.dyngr.exception.UserBreakException)4 SdxCertRenewalFailedEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent)4 SdxCertRotationFailedEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent)4 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 SdxCmSyncWaitEvent (com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncWaitEvent)2 DatalakeStatusUpdateException (com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException)2