Search in sources :

Example 11 with CloudbreakApiException

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

the class SdxBackupRestoreService method databaseRestore.

public void databaseRestore(SdxOperation drStatus, Long clusterId, String backupId, String backupLocation) {
    try {
        sdxOperationRepository.save(drStatus);
        sdxClusterRepository.findById(clusterId).ifPresentOrElse(sdxCluster -> {
            String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
            RestoreV4Response restoreV4Response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.restoreDatabaseByNameInternal(0L, sdxCluster.getClusterName(), backupLocation, backupId, initiatorUserCrn));
            updateSuccessStatus(drStatus.getOperationId(), sdxCluster, restoreV4Response.getFlowIdentifier(), SdxOperationStatus.TRIGGERRED);
        }, () -> {
            updateFailureStatus(drStatus.getOperationId(), clusterId, String.format("SDX cluster with Id [%d] not found", clusterId));
        });
    } catch (WebApplicationException e) {
        String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Database restore failed for datalake-id: [%d]. Message: [%s]", clusterId, errorMessage);
        throw new CloudbreakApiException(message);
    }
}
Also used : RestoreV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.dr.RestoreV4Response) WebApplicationException(javax.ws.rs.WebApplicationException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 12 with CloudbreakApiException

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

the class SdxBackupRestoreService method databaseBackup.

public void databaseBackup(SdxOperation drStatus, Long clusterId, SdxDatabaseBackupRequest backupRequest) {
    try {
        sdxOperationRepository.save(drStatus);
        sdxClusterRepository.findById(clusterId).ifPresentOrElse(sdxCluster -> {
            String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
            BackupV4Response backupV4Response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.backupDatabaseByNameInternal(0L, sdxCluster.getClusterName(), backupRequest.getBackupId(), backupRequest.getBackupLocation(), backupRequest.getCloseConnections(), initiatorUserCrn));
            updateSuccessStatus(drStatus.getOperationId(), sdxCluster, backupV4Response.getFlowIdentifier(), SdxOperationStatus.TRIGGERRED);
        }, () -> {
            updateFailureStatus(drStatus.getOperationId(), clusterId, String.format("SDX cluster with Id [%d] not found", clusterId));
        });
    } catch (WebApplicationException e) {
        String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Database backup failed for datalake-id: [%d]. Message: [%s]", clusterId, errorMessage);
        throw new CloudbreakApiException(message);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BackupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.dr.BackupV4Response) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 13 with CloudbreakApiException

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

the class SdxCmSyncService method callCmSync.

public void callCmSync(Long sdxId) {
    SdxCluster sdxCluster = sdxService.getById(sdxId);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        ClouderaManagerSyncV4Request clouderaManagerSyncV4Request = new ClouderaManagerSyncV4Request().withCandidateImageUuids(Set.of());
        LOGGER.debug("Calling core: sync CM and parcel versions from CM server for {}", sdxCluster.getClusterName());
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.syncCm(0L, sdxCluster.getClusterName(), initiatorUserCrn, clouderaManagerSyncV4Request));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Couldn't call cm sync for cluster: [%s]. Message: [%s]", sdxCluster.getClusterName(), exceptionMessage);
        LOGGER.info(message);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) ClouderaManagerSyncV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerSyncV4Request) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 14 with CloudbreakApiException

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

the class ReactorNotifier method checkFlowStatus.

private FlowIdentifier checkFlowStatus(Event<? extends Acceptable> event, String identifier) {
    try {
        FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        if (accepted == null) {
            LOGGER.error("Event not accepted: {}", event);
            reactorReporter.logErrorReport();
            throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for stack %s.", identifier));
        }
        switch(accepted.getResultType()) {
            case ALREADY_EXISTING_FLOW:
                reactorReporter.logErrorReport();
                throw new FlowsAlreadyRunningException(String.format("Request not allowed, cluster '%s' already has a running operation. " + "Running operation(s): [%s]", identifier, flowNameFormatService.formatFlows(accepted.getAlreadyRunningFlows())));
            case RUNNING_IN_FLOW:
                return new FlowIdentifier(FlowType.FLOW, accepted.getAsFlowId());
            case RUNNING_IN_FLOW_CHAIN:
                return new FlowIdentifier(FlowType.FLOW_CHAIN, accepted.getAsFlowChainId());
            default:
                throw new IllegalStateException("Unsupported accept result type: " + accepted.getClass());
        }
    } catch (InterruptedException e) {
        throw new CloudbreakApiException(e.getMessage(), e);
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 15 with CloudbreakApiException

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

the class SdxReactorFlowManager method notify.

private FlowIdentifier notify(String selector, SdxEvent acceptable, String identifier) {
    Map<String, Object> flowTriggerUserCrnHeader = Map.of(FlowConstants.FLOW_TRIGGER_USERCRN, acceptable.getUserId());
    Event<Acceptable> event = eventFactory.createEventWithErrHandler(flowTriggerUserCrnHeader, acceptable);
    reactor.notify(selector, event);
    try {
        FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        if (accepted == null) {
            throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for sdx cluster %s.", event.getData().getResourceId()));
        } else {
            switch(accepted.getResultType()) {
                case ALREADY_EXISTING_FLOW:
                    throw new FlowsAlreadyRunningException(String.format("Request not allowed, datalake cluster '%s' already has a running operation. " + "Running operation(s): [%s]", identifier, flowNameFormatService.formatFlows(accepted.getAlreadyRunningFlows())));
                case RUNNING_IN_FLOW:
                    return new FlowIdentifier(FlowType.FLOW, accepted.getAsFlowId());
                case RUNNING_IN_FLOW_CHAIN:
                    return new FlowIdentifier(FlowType.FLOW_CHAIN, accepted.getAsFlowChainId());
                default:
                    throw new IllegalStateException("Unsupported accept result type: " + accepted.getClass());
            }
        }
    } catch (InterruptedException e) {
        throw new CloudbreakApiException(e.getMessage());
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

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