use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class SdxBackupRestoreServiceTest method testgetDatabaseBackupStatus.
@Test
public void testgetDatabaseBackupStatus() {
when(sdxOperationRepository.findSdxOperationByOperationId(Mockito.anyString())).thenReturn(null);
try {
sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, BACKUP_ID);
fail("Exception should have been thrown");
} catch (NotFoundException notFoundException) {
String exceptedMessage = String.format("Status with id: [%s] not found", BACKUP_ID);
assertEquals(exceptedMessage, notFoundException.getLocalizedMessage());
}
reset(sdxOperationRepository);
SdxOperation sdxOperation = new SdxOperation();
sdxOperation.setOperationType(SdxOperationType.RESTORE);
sdxOperation.setSdxClusterId(sdxCluster.getId());
sdxOperation.setOperationId(BACKUP_ID);
when(sdxOperationRepository.findSdxOperationByOperationId(Mockito.anyString())).thenReturn(sdxOperation);
try {
sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, BACKUP_ID);
fail("Exception should have been thrown");
} catch (CloudbreakApiException cloudbreakApiException) {
String exceptedMessage = String.format("Invalid operation-id: [%s]. provided", BACKUP_ID);
assertEquals(exceptedMessage, cloudbreakApiException.getLocalizedMessage());
}
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class SdxUpgradeService method upgradeOs.
public void upgradeOs(Long id) {
SdxCluster cluster = sdxService.getById(id);
sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DATALAKE_UPGRADE_IN_PROGRESS, "OS upgrade started", cluster);
try {
String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.upgradeOsInternal(0L, cluster.getClusterName(), initiatorUserCrn));
cloudbreakFlowService.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
} catch (WebApplicationException e) {
String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
String message = String.format("Stack upgrade failed on cluster: [%s]. Message: [%s]", cluster.getClusterName(), exceptionMessage);
throw new CloudbreakApiException(message, e);
}
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class ClusterToClusterV4ResponseConverter method convertContainerConfig.
private void convertContainerConfig(Cluster source, ClusterV4Response clusterResponse) {
Json customContainerDefinition = source.getCustomContainerDefinition();
if (customContainerDefinition != null && StringUtils.isNotEmpty(customContainerDefinition.getValue())) {
try {
Map<String, String> map = customContainerDefinition.get(Map.class);
Map<String, String> result = new HashMap<>();
for (Entry<String, String> stringStringEntry : map.entrySet()) {
result.put(stringStringEntry.getKey(), stringStringEntry.getValue());
}
CustomContainerV4Response customContainers = new CustomContainerV4Response();
customContainers.setDefinitions(result);
clusterResponse.setCustomContainers(customContainers);
} catch (IOException e) {
LOGGER.info("Failed to add customContainerDefinition to response", e);
throw new CloudbreakApiException("Failed to add customContainerDefinition to response", e);
}
}
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class SdxImageCatalogService method changeImageCatalog.
public void changeImageCatalog(SdxCluster sdxCluster, String imageCatalog) {
if (flowLogService.isOtherFlowRunning(sdxCluster.getId())) {
throw new CloudbreakApiException(String.format("Operation is running for cluster '%s'. Please try again later.", sdxCluster.getName()));
}
try {
ChangeImageCatalogV4Request changeImageCatalogRequest = new ChangeImageCatalogV4Request();
changeImageCatalogRequest.setImageCatalog(imageCatalog);
String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.changeImageCatalogInternal(WORKSPACE_ID_DEFAULT, sdxCluster.getClusterName(), initiatorUserCrn, changeImageCatalogRequest));
} catch (CloudbreakServiceException e) {
throw new CloudbreakApiException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class SdxUpgradeRecoveryService method validateRecovery.
public SdxRecoverableResponse validateRecovery(SdxCluster sdxCluster) {
MDCBuilder.buildMdcContext(sdxCluster);
try {
String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
RecoveryValidationV4Response response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> 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);
}
}
Aggregations