Search in sources :

Example 6 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class DatalakeFullBackupWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatalakeFullBackupWaitRequest> event) {
    DatalakeFullBackupWaitRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    Selectable response;
    try {
        LOGGER.info("Start polling datalake full backup status for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        sdxBackupRestoreService.waitForDatalakeDrBackupToComplete(sdxId, request.getOperationId(), request.getUserId(), pollingConfig, "Full backup");
        response = new DatalakeBackupSuccessEvent(sdxId, userId, request.getOperationId());
    } catch (UserBreakException userBreakException) {
        LOGGER.info("Full backup polling exited before timeout. Cause: ", userBreakException);
        response = new DatalakeBackupFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.info("Full backup poller stopped for cluster: {}", sdxId);
        response = new DatalakeBackupFailedEvent(sdxId, userId, new PollerStoppedException("Datalake backup timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.info("Full backup polling failed for cluster: {}", sdxId);
        response = new DatalakeBackupFailedEvent(sdxId, userId, exception);
    } catch (CloudbreakApiException exception) {
        LOGGER.info("Datalake backup failed. Reason: " + exception.getMessage());
        response = new DatalakeBackupFailedEvent(sdxId, userId, exception);
    }
    return response;
}
Also used : DatalakeBackupFailedEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeBackupFailedEvent) DatalakeFullBackupWaitRequest(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeFullBackupWaitRequest) UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) DatalakeBackupSuccessEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeBackupSuccessEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 7 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxRecoveryService method recoverCluster.

public void recoverCluster(Long clusterId) {
    SdxCluster sdxCluster = sdxService.getById(clusterId);
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RECOVERY_IN_PROGRESS, DATALAKE_RECOVERY_REQUESTED, "Recovering datalake stack", sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.recoverClusterByNameInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn)).getFlowIdentifier();
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack recovery failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 8 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxUpgradeService method changeImage.

public void changeImage(Long id, UpgradeOptionV4Response upgradeOption) {
    SdxCluster cluster = sdxService.getById(id);
    String targetImageId = upgradeOption.getUpgrade().getImageId();
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    stackImageChangeRequest.setImageId(targetImageId);
    stackImageChangeRequest.setImageCatalogName(upgradeOption.getUpgrade().getImageCatalogName());
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.CHANGE_IMAGE_IN_PROGRESS, "Changing image", cluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.changeImageInternal(0L, cluster.getClusterName(), stackImageChangeRequest, initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack change image failed on cluster: [%s]. Message: [%s]", cluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 9 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxUpgradeService method upgradeRuntime.

public void upgradeRuntime(Long id, String imageId) {
    SdxCluster sdxCluster = sdxService.getById(id);
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DATALAKE_UPGRADE_IN_PROGRESS, "Upgrading datalake stack", sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.upgradeClusterByNameInternal(0L, sdxCluster.getClusterName(), imageId, initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack upgrade failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 10 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.

the class SdxUpgradeRecoveryService method validateRecovery.

@Override
public SdxRecoverableResponse validateRecovery(SdxCluster sdxCluster, SdxRecoveryRequest request) {
    MDCBuilder.buildMdcContext(sdxCluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        if (Objects.nonNull(request) && request.getType() == SdxRecoveryType.RECOVER_WITH_DATA) {
            String clusterRuntime = sdxCluster.getRuntime();
            datalakeDRProto.DatalakeBackupInfo lastSuccessfulBackup = datalakeDrClient.getLastSuccessfulBackup(sdxCluster.getClusterName(), initiatorUserCrn, Optional.of(clusterRuntime));
            if (Objects.isNull(lastSuccessfulBackup)) {
                return new SdxRecoverableResponse("There is no successful backup taken yet for data lake cluster with runtime " + clusterRuntime + ".", RecoveryStatus.NON_RECOVERABLE);
            }
        }
        RecoveryValidationV4Response response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.getClusterRecoverableByNameInternal(0L, sdxCluster.getClusterName(), initiatorUserCrn));
        return new SdxRecoverableResponse(response.getReason(), response.getStatus());
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack recovery validation failed on cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) WebApplicationException(javax.ws.rs.WebApplicationException) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) com.cloudera.thunderhead.service.datalakedr.datalakeDRProto(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto)

Aggregations

CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)20 WebApplicationException (javax.ws.rs.WebApplicationException)10 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)7 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)5 PollerException (com.dyngr.exception.PollerException)2 PollerStoppedException (com.dyngr.exception.PollerStoppedException)2 UserBreakException (com.dyngr.exception.UserBreakException)2 RecoveryValidationV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 FlowNotAcceptedException (com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)2 FlowsAlreadyRunningException (com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException)2 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)2 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)2 SdxRecoverableResponse (com.sequenceiq.sdx.api.model.SdxRecoverableResponse)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 com.cloudera.thunderhead.service.datalakedr.datalakeDRProto (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto)1