Search in sources :

Example 1 with PollerException

use of com.dyngr.exception.PollerException in project cloudbreak by hortonworks.

the class StartExternalDatabaseHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StartExternalDatabaseRequest> event) {
    LOGGER.debug("In StartExternalDatabaseHandler.doAccept");
    StartExternalDatabaseRequest request = event.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Selectable result;
    try {
        if (StackType.WORKLOAD != stack.getType()) {
            LOGGER.debug("External database start in Cloudbreak service is required for WORKLOAD stacks only.");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Start is not possible.", stack.getName());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
            LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_COMMANCED, "External database start in progress");
            startService.startDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FINISHED, "External database start finished");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.error("Database 'start' polling exited before timeout. Cause: ", e);
        result = startFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.error(String.format("Database 'start' poller stopped for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.error(String.format("Database 'start' polling failed for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    }
    return result;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StartExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StartExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 2 with PollerException

use of com.dyngr.exception.PollerException in project cloudbreak by hortonworks.

the class RdsDeletionHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RdsDeletionWaitRequest> event) {
    RdsDeletionWaitRequest rdsWaitRequest = event.getData();
    Long sdxId = rdsWaitRequest.getResourceId();
    String userId = rdsWaitRequest.getUserId();
    Selectable response;
    try {
        sdxClusterRepository.findById(sdxId).ifPresent(sdxCluster -> {
            if (sdxCluster.hasExternalDatabase() && StringUtils.isNotEmpty(sdxCluster.getDatabaseCrn())) {
                LOGGER.debug("start polling database termination for sdx: {}", sdxId);
                databaseService.terminate(sdxCluster, rdsWaitRequest.isForced());
            } else {
                LOGGER.debug("skipping deletion of database for sdx: {}", sdxId);
            }
            setDeletedStatus(sdxCluster);
        });
        response = new RdsDeletionSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
        response = new SdxDeletionFailedEvent(sdxId, userId, userBreakException, rdsWaitRequest.isForced());
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
        response = new SdxDeletionFailedEvent(sdxId, userId, new PollerStoppedException("Database deletion timed out after " + durationInMinutes + " minutes"), rdsWaitRequest.isForced());
    } catch (PollerException exception) {
        LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
        response = new SdxDeletionFailedEvent(sdxId, userId, exception, rdsWaitRequest.isForced());
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx database deletion wait phase", anotherException);
        response = new SdxDeletionFailedEvent(sdxId, userId, anotherException, rdsWaitRequest.isForced());
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) RdsDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent) RdsDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.RdsDeletionWaitRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 3 with PollerException

use of com.dyngr.exception.PollerException in project cloudbreak by hortonworks.

the class StackDeletionHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StackDeletionWaitRequest> event) {
    StackDeletionWaitRequest stackDeletionWaitRequest = event.getData();
    Long sdxId = stackDeletionWaitRequest.getResourceId();
    String userId = stackDeletionWaitRequest.getUserId();
    Selectable response;
    try {
        LOGGER.debug("Start polling stack deletion process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        provisionerService.waitCloudbreakClusterDeletion(sdxId, pollingConfig);
        response = new StackDeletionSuccessEvent(sdxId, userId, stackDeletionWaitRequest.isForced());
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Deletion polling exited before timeout. Cause: ", userBreakException);
        response = new SdxDeletionFailedEvent(sdxId, userId, userBreakException, stackDeletionWaitRequest.isForced());
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Deletion poller stopped for stack: {}", sdxId);
        response = new SdxDeletionFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stack deletion timed out after " + durationInMinutes + " minutes"), stackDeletionWaitRequest.isForced());
    } catch (PollerException exception) {
        LOGGER.error("Deletion polling failed for stack: {}", sdxId);
        response = new SdxDeletionFailedEvent(sdxId, userId, exception, stackDeletionWaitRequest.isForced());
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) StackDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.StackDeletionWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException) StackDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.StackDeletionSuccessEvent)

Example 4 with PollerException

use of com.dyngr.exception.PollerException in project cloudbreak by hortonworks.

the class RdsWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RdsWaitRequest> event) {
    RdsWaitRequest rdsWaitRequest = event.getData();
    Long sdxId = rdsWaitRequest.getResourceId();
    String userId = rdsWaitRequest.getUserId();
    try {
        DetailedEnvironmentResponse env = environmentService.waitNetworkAndGetEnvironment(sdxId);
        Optional<SdxCluster> sdxCluster = sdxClusterRepository.findById(sdxId);
        if (sdxCluster.isPresent()) {
            if (sdxCluster.get().hasExternalDatabase()) {
                validForDatabaseCreation(sdxId, env);
                LOGGER.debug("start polling database for sdx: {}", sdxId);
                databaseService.create(sdxCluster.get(), env);
                setRdsCreatedStatus(sdxCluster.get());
                return new RdsWaitSuccessEvent(sdxId, userId);
            } else {
                LOGGER.debug("skipping creation of database for sdx: {}", sdxId);
                return new RdsWaitSuccessEvent(sdxId, userId);
            }
        } else {
            throw notFound("SDX cluster", sdxId).get();
        }
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
        return new SdxCreateFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
        return new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Database creation timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
        return new SdxCreateFailedEvent(sdxId, userId, exception);
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx database creation wait phase", anotherException);
        return new SdxCreateFailedEvent(sdxId, userId, anotherException);
    }
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) RdsWaitSuccessEvent(com.sequenceiq.datalake.flow.create.event.RdsWaitSuccessEvent) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) RdsWaitRequest(com.sequenceiq.datalake.flow.create.event.RdsWaitRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 5 with PollerException

use of com.dyngr.exception.PollerException in project cloudbreak by hortonworks.

the class DatalakeVmReplaceWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatalakeVmReplaceWaitRequest> event) {
    DatalakeVmReplaceWaitRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    Selectable response;
    try {
        LOGGER.info("Start polling cluster VM replacement process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        upgradeService.waitCloudbreakFlow(sdxId, pollingConfig, "VM replace");
        response = new DatalakeUpgradeSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("VM replace polling exited before timeout. Cause: ", userBreakException);
        response = new DatalakeUpgradeFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("VM replace poller stopped for cluster: {}", sdxId);
        response = new DatalakeUpgradeFailedEvent(sdxId, userId, new PollerStoppedException("VM replace timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("VM replace polling failed for cluster: {}", sdxId);
        response = new DatalakeUpgradeFailedEvent(sdxId, userId, exception);
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened during VM replacement wait phase", anotherException);
        response = new DatalakeUpgradeFailedEvent(sdxId, userId, anotherException);
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) DatalakeUpgradeFailedEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFailedEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) DatalakeVmReplaceWaitRequest(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeVmReplaceWaitRequest) DatalakeUpgradeSuccessEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeSuccessEvent)

Aggregations

PollerException (com.dyngr.exception.PollerException)37 PollerStoppedException (com.dyngr.exception.PollerStoppedException)31 UserBreakException (com.dyngr.exception.UserBreakException)30 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)28 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)22 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)7 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)5 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)5 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)4 SdxStopFailedEvent (com.sequenceiq.datalake.flow.stop.event.SdxStopFailedEvent)4 Test (org.junit.jupiter.api.Test)4 DatalakeUpgradeFailedEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFailedEvent)3 SdxDiagnosticsSuccessEvent (com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsSuccessEvent)3 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)2 StackCreationSuccessEvent (com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent)2 StackCreationWaitRequest (com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest)2 SdxDeletionFailedEvent (com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent)2 SdxDiagnosticsFailedEvent (com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsFailedEvent)2