Search in sources :

Example 1 with PollerStoppedException

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

the class SdxDeleteService method waitSdxClustersDeletion.

private void waitSdxClustersDeletion(PollingConfig pollingConfig, EnvironmentView environment, Set<String> sdxCrnsOrDatalakeName, boolean legacySdxEndpoint, boolean force) {
    LOGGER.debug("Calling sdxEndpoint.deleteByCrn for all data lakes [{}]", String.join(", ", sdxCrnsOrDatalakeName));
    if (legacySdxEndpoint) {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        sdxCrnsOrDatalakeName.forEach(name -> ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.deleteInternal(0L, name, force, initiatorUserCrn)));
    } else {
        sdxCrnsOrDatalakeName.forEach(crn -> sdxEndpoint.deleteByCrn(crn, force));
    }
    LOGGER.debug("Starting poller to check all Data Lake stacks for environment {} is deleted", environment.getName());
    try {
        Polling.stopAfterDelay(pollingConfig.getTimeout(), pollingConfig.getTimeoutTimeUnit()).stopIfException(pollingConfig.getStopPollingIfExceptionOccured()).waitPeriodly(pollingConfig.getSleepTime(), pollingConfig.getSleepTimeUnit()).run(() -> periodicCheckForDeletion(environment));
    } catch (PollerStoppedException e) {
        LOGGER.info("Datalake deletion timed out");
        throw new SdxOperationFailedException("Datalake deletion timed out");
    }
}
Also used : SdxOperationFailedException(com.sequenceiq.environment.exception.SdxOperationFailedException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 2 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException 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 3 with PollerStoppedException

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

the class LoadBalancerPollerService method updateStackWithLoadBalancer.

public void updateStackWithLoadBalancer(Long environmentId, String environmentCrn, String environmentName, PublicEndpointAccessGateway endpointAccessGateway) {
    Set<String> stackNames;
    if (PublicEndpointAccessGateway.ENABLED.equals(endpointAccessGateway)) {
        LOGGER.debug("Updating load balancers for endpoint gateway on Data Lake and Data Hubs.");
        stackNames = getDataLakeAndDataHubNames(environmentCrn, environmentName);
        LOGGER.debug("Found {} Data Lake and Data Hub clusters to update for environment {}.", stackNames.size(), environmentName);
    } else {
        LOGGER.debug("Updating load balancer for Data Lake cluster.");
        stackNames = getAttachedDatalakeClusters(environmentName);
    }
    if (stackNames.isEmpty()) {
        LOGGER.debug("No Data Lake or Data Hub clusters found for environment.");
    } else {
        try {
            List<FlowIdentifier> failedFlows = waitStackLoadBalancerUpdate(getPollingConfig(), stackNames, environmentName);
            LOGGER.debug("Data Lake and Data Hub load balancer update finished.");
            if (!failedFlows.isEmpty()) {
                LOGGER.error("Found failed flows for Data Lake or Data Hub load balancer updates: " + failedFlows);
                throw new UpdateFailedException("Data Lake or Data Hub update flows failed: " + failedFlows);
            }
        } catch (PollerStoppedException e) {
            throw new UpdateFailedException("Stack update poller reached timeout.", e);
        }
    }
}
Also used : FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) UpdateFailedException(com.sequenceiq.environment.exception.UpdateFailedException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 4 with PollerStoppedException

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

the class DatahubDeletionService method waitDatahubClustersDeletion.

private void waitDatahubClustersDeletion(PollingConfig pollingConfig, Environment environment, Collection<StackViewV4Response> list, boolean force) {
    DistroXMultiDeleteV1Request multiDeleteRequest = new DistroXMultiDeleteV1Request();
    multiDeleteRequest.setCrns(list.stream().map(StackViewV4Response::getCrn).collect(Collectors.toSet()));
    LOGGER.debug("Calling distroXV1Endpoint.deleteMultiple with crn [{}]", multiDeleteRequest.getCrns());
    datahubService.deleteMultiple(environment.getResourceCrn(), multiDeleteRequest, force);
    LOGGER.debug("Starting poller to check all Datahub stacks for environment {} are deleted", environment.getName());
    try {
        Polling.stopAfterDelay(pollingConfig.getTimeout(), pollingConfig.getTimeoutTimeUnit()).stopIfException(pollingConfig.getStopPollingIfExceptionOccured()).waitPeriodly(pollingConfig.getSleepTime(), pollingConfig.getSleepTimeUnit()).run(() -> periodicCheckForDeletion(environment));
    } catch (PollerStoppedException e) {
        LOGGER.info("Datahub cluster deletion timed out");
        throw new DatahubOperationFailedException("Datahub cluster deletion timed out", e);
    }
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) DistroXMultiDeleteV1Request(com.sequenceiq.distrox.api.v1.distrox.model.cluster.DistroXMultiDeleteV1Request) DatahubOperationFailedException(com.sequenceiq.environment.exception.DatahubOperationFailedException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 5 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException 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)

Aggregations

PollerStoppedException (com.dyngr.exception.PollerStoppedException)43 PollerException (com.dyngr.exception.PollerException)31 UserBreakException (com.dyngr.exception.UserBreakException)30 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)28 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)7 Test (org.junit.jupiter.api.Test)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 DatalakeUpgradeFailedEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFailedEvent)3 SdxDiagnosticsSuccessEvent (com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsSuccessEvent)3 Event (reactor.bus.Event)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)2