Search in sources :

Example 1 with DatabaseBackupFailedEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupFailedEvent in project cloudbreak by hortonworks.

the class DatabaseBackupHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatabaseBackupRequest> event) {
    DatabaseBackupRequest request = event.getData();
    Selectable result;
    Long stackId = request.getResourceId();
    LOGGER.debug("Backing up database on stack {}, backup id {}", stackId, request.getBackupId());
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(stackId);
        Cluster cluster = stack.getCluster();
        InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.hasGateway());
        Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
        ExitCriteriaModel exitModel = ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(stackId, cluster.getId());
        String rangerAdminGroup = rangerVirtualGroupService.getRangerVirtualGroup(stack);
        SaltConfig saltConfig = saltConfigGenerator.createSaltConfig(request.getBackupLocation(), request.getBackupId(), rangerAdminGroup, request.getCloseConnections(), stack);
        hostOrchestrator.backupDatabase(gatewayConfig, gatewayFQDN, stackUtil.collectReachableNodes(stack), saltConfig, exitModel);
        result = new DatabaseBackupSuccess(stackId);
    } catch (Exception e) {
        LOGGER.error("Database backup event failed", e);
        result = new DatabaseBackupFailedEvent(stackId, e, DetailedStackStatus.DATABASE_BACKUP_FAILED);
    }
    return result;
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ClusterDeletionBasedExitCriteriaModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) DatabaseBackupRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupRequest) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) DatabaseBackupFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupFailedEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) DatabaseBackupSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupSuccess) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with DatabaseBackupFailedEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupFailedEvent in project cloudbreak by hortonworks.

the class DatabaseBackupActions method databaseBackupFailedAction.

@Bean(name = "DATABASE_BACKUP_FAILED_STATE")
public Action<?, ?> databaseBackupFailedAction() {
    return new AbstractBackupRestoreActions<>(DatabaseBackupFailedEvent.class) {

        @Override
        protected BackupRestoreContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatabaseBackupFailedEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return BackupRestoreContext.from(flowParameters, payload, null, null, true);
        }

        @Override
        protected void doExecute(BackupRestoreContext context, DatabaseBackupFailedEvent payload, Map<Object, Object> variables) {
            backupRestoreStatusService.handleDatabaseBackupFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
            sendEvent(context, DATABASE_BACKUP_FAIL_HANDLED_EVENT.event(), payload);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) StateContext(org.springframework.statemachine.StateContext) AbstractBackupRestoreActions(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.AbstractBackupRestoreActions) DatabaseBackupFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupFailedEvent) Map(java.util.Map) BackupRestoreContext(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.BackupRestoreContext) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Aggregations

DatabaseBackupFailedEvent (com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupFailedEvent)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 ClusterDeletionBasedExitCriteriaModel (com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel)1 AbstractBackupRestoreActions (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.AbstractBackupRestoreActions)1 BackupRestoreContext (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.dr.BackupRestoreContext)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)1 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)1 DatabaseBackupRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupRequest)1 DatabaseBackupSuccess (com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupSuccess)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1