Search in sources :

Example 81 with CloudbreakServiceException

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);
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) DatabaseServerStatusV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response) BadRequestException(javax.ws.rs.BadRequestException)

Example 82 with CloudbreakServiceException

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);
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Completable(rx.Completable) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CompositeException(rx.exceptions.CompositeException) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 83 with CloudbreakServiceException

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);
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Completable(rx.Completable) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CompositeException(rx.exceptions.CompositeException) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 84 with CloudbreakServiceException

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());
    }
}
Also used : ClusterTemplateV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response) ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Example 85 with CloudbreakServiceException

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!");
    }
}
Also used : ClusterTemplateV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response) ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)142 Test (org.junit.jupiter.api.Test)25 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 List (java.util.List)20 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 IOException (java.io.IOException)18 Map (java.util.Map)18 ApiException (com.cloudera.api.swagger.client.ApiException)17 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)15 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)14 LoggerFactory (org.slf4j.LoggerFactory)14 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)13 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)12 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)12 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)12 Optional (java.util.Optional)12 Set (java.util.Set)12