use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class DatabaseService method create.
public DatabaseServerStatusV4Response create(SdxCluster sdxCluster, DetailedEnvironmentResponse env) {
LOGGER.info("Create databaseServer in environment {} for SDX {}", env.getName(), sdxCluster.getClusterName());
String dbResourceCrn;
DatabaseServerStatusV4Response serverStatusV4Response = null;
if (dbHasBeenCreatedPreviously(sdxCluster)) {
dbResourceCrn = sdxCluster.getDatabaseCrn();
} else {
try {
String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
if (sdxStatusService.getActualStatusForSdx(sdxCluster).getStatus().isDeleteInProgressOrCompleted()) {
throw new CloudbreakServiceException("Datalake deletion in progress! Do not provision database, create flow cancelled");
}
serverStatusV4Response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> databaseServerV4Endpoint.createInternal(getDatabaseRequest(sdxCluster, env), initiatorUserCrn));
dbResourceCrn = serverStatusV4Response.getResourceCrn();
sdxCluster.setDatabaseCrn(dbResourceCrn);
sdxClusterRepository.save(sdxCluster);
sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.EXTERNAL_DATABASE_CREATION_IN_PROGRESS, "External database creation in progress", sdxCluster);
} catch (BadRequestException badRequestException) {
LOGGER.error("Redbeams create request failed, bad request", badRequestException);
throw badRequestException;
}
}
if (serverStatusV4Response != null && serverStatusV4Response.getStatus().equals(Status.STOPPED)) {
throw new CloudbreakServiceException(String.format("Database already in %s state. Provisioning new database failed", serverStatusV4Response.getStatus()));
}
return waitAndGetDatabase(sdxCluster, dbResourceCrn, SdxDatabaseOperation.CREATION, true);
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AzureUtils method deleteInstancesAndFillStatuses.
private void deleteInstancesAndFillStatuses(AuthenticatedContext ac, List<CloudVmInstanceStatus> statusesAfterDelete, List<CloudInstance> vmsNotDeleted) {
try {
AzureClient azureClient = ac.getParameter(AzureClient.class);
List<Completable> deleteCompletables = new ArrayList<>();
for (CloudInstance vm : vmsNotDeleted) {
deleteInstance(azureClient, ac.getCloudContext(), statusesAfterDelete, deleteCompletables, vm);
}
Completable.mergeDelayError(deleteCompletables).await();
} catch (CompositeException e) {
String errorMessages = e.getExceptions().stream().map(Throwable::getMessage).collect(Collectors.joining());
LOGGER.error("Error(s) occured while waiting for vm deletion: {}, statuses: {}", errorMessages, statusesAfterDelete);
throw new CloudbreakServiceException("Error(s) occured while waiting for vm deletion: " + errorMessages + ", statuses: " + convertToStatusText(statusesAfterDelete), e);
} catch (RuntimeException e) {
LOGGER.error("Error occured while waiting for vm deletion: {}, statuses: {}", e.getMessage(), statusesAfterDelete, e);
throw new CloudbreakServiceException("Error occured while waiting for vm deletion: " + e.getMessage() + ", statuses: " + convertToStatusText(statusesAfterDelete), e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AzureUtils method deallocateInstancesAndFillStatuses.
private void deallocateInstancesAndFillStatuses(AuthenticatedContext ac, List<CloudVmInstanceStatus> statusesAfterDeallocate, List<CloudInstance> vmsNotStopped) {
try {
AzureClient azureClient = ac.getParameter(AzureClient.class);
List<Completable> deallocateCompletables = new ArrayList<>();
for (CloudInstance vm : vmsNotStopped) {
deallocateInstance(azureClient, ac.getCloudContext(), statusesAfterDeallocate, deallocateCompletables, vm);
}
Completable.mergeDelayError(deallocateCompletables).await();
} catch (CompositeException e) {
String errorMessages = e.getExceptions().stream().map(Throwable::getMessage).collect(Collectors.joining());
LOGGER.error("Error(s) occured while waiting for vm deallocation: {}, statuses: {}", errorMessages, statusesAfterDeallocate);
throw new CloudbreakServiceException("Error(s) occured while waiting for vm deallocation: " + errorMessages + ", statuses: " + convertToStatusText(statusesAfterDeallocate), e);
} catch (RuntimeException e) {
LOGGER.error("Error occured while waiting for vm deallocation: {}, statuses: {}", e.getMessage(), statusesAfterDeallocate, e);
throw new CloudbreakServiceException("Error occured while waiting for vm deallocation: " + e.getMessage() + ", statuses: " + convertToStatusText(statusesAfterDeallocate), e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClusterTemplateV4Controller method getByName.
@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.DESCRIBE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response getByName(Long workspaceId, @ResourceName String name) {
try {
ClusterTemplate clusterTemplate = transactionService.required(() -> clusterTemplateService.getByNameForWorkspaceId(name, threadLocalService.getRequestedWorkspaceId()));
ClusterTemplateV4Response response = transactionService.required(() -> clusterTemplateToClusterTemplateV4ResponseConverter.convert(clusterTemplate));
Optional.ofNullable(response.getEnvironmentCrn()).ifPresent(crn -> environmentServiceDecorator.prepareEnvironment(response));
return response;
} catch (TransactionExecutionException cse) {
LOGGER.warn("Unable to find cluster definition due to " + cse.getMessage(), cse.getCause());
throw new CloudbreakServiceException("Unable to obtain cluster definition!", cse.getCause());
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClusterTemplateV4Controller method getByCrn.
@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response getByCrn(Long workspaceId, @TenantAwareParam @ResourceCrn String crn) {
boolean internalTenant = isInternalTenant();
try {
ClusterTemplate clusterTemplate = transactionService.required(() -> clusterTemplateService.getByCrn(crn, threadLocalService.getRequestedWorkspaceId(), internalTenant));
ClusterTemplateV4Response response = transactionService.required(() -> clusterTemplateToClusterTemplateV4ResponseConverter.convert(clusterTemplate));
if (!StringUtils.isEmpty(response.getEnvironmentCrn())) {
environmentServiceDecorator.prepareEnvironment(response);
} else {
LOGGER.warn("Skipping response decoration with environment name. Environment CRN was empty.");
}
return response;
} catch (TransactionExecutionException cse) {
LOGGER.warn("Unable to find cluster definition due to {}", cse.getMessage());
throw new CloudbreakServiceException("Unable to obtain cluster definition!");
}
}
Aggregations