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);
}
}
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);
}
}
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);
}
}
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);
}
}
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());
}
}
Aggregations