Search in sources :

Example 1 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class FileSystemValidator method validate.

public void validate(String platform, CloudCredential cloudCredential, CloudStorageBase cloudStorageRequest, Long workspaceId) {
    if (cloudStorageRequest == null) {
        return;
    }
    LOGGER.info("Sending fileSystemRequest to {} to validate the file system", platform);
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(platform).withWorkspaceId(workspaceId).build();
    SpiFileSystem spiFileSystem = cloudStorageConverter.requestToSpiFileSystem(cloudStorageRequest);
    FileSystemValidationRequest request = new FileSystemValidationRequest(spiFileSystem, cloudCredential, cloudContext);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        FileSystemValidationResult result = request.await();
        LOGGER.info("File system validation result: {}", result);
        Exception exception = result.getErrorDetails();
        if (exception != null) {
            throw new BadRequestException(result.getStatusReason(), exception);
        }
    } catch (InterruptedException e) {
        LOGGER.error("Error while sending the file system validation request", e);
        throw new OperationException(e);
    }
}
Also used : FileSystemValidationResult(com.sequenceiq.cloudbreak.cloud.event.validation.FileSystemValidationResult) FileSystemValidationRequest(com.sequenceiq.cloudbreak.cloud.event.validation.FileSystemValidationRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 2 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class StackParameterService method getStackParams.

public List<StackParamValidation> getStackParams(String name, Stack stack) {
    LOGGER.debug("Get stack params");
    Credential credential = credentialClientService.getByEnvironmentCrn(stack.getEnvironmentCrn());
    if (credential != null) {
        CloudContext cloudContext = CloudContext.Builder.builder().withName(name).withCrn(credential.getCrn()).withPlatform(credential.cloudPlatform()).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(stack.getTenant().getId()).build();
        GetStackParamValidationRequest getStackParamValidationRequest = new GetStackParamValidationRequest(cloudContext);
        eventBus.notify(getStackParamValidationRequest.selector(), eventFactory.createEvent(getStackParamValidationRequest));
        try {
            GetStackParamValidationResult res = getStackParamValidationRequest.await();
            LOGGER.debug("Get stack params result: {}", res);
            if (res.getStatus().equals(EventStatus.FAILED)) {
                LOGGER.info("Failed to get stack params", res.getErrorDetails());
                throw new OperationException(res.getErrorDetails());
            }
            return res.getStackParamValidations();
        } catch (InterruptedException e) {
            LOGGER.info("Error while getting the stack params", e);
            throw new OperationException(e);
        }
    } else {
        return Collections.emptyList();
    }
}
Also used : Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) GetStackParamValidationResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetStackParamValidationResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) GetStackParamValidationRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetStackParamValidationRequest) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 3 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class ServiceProviderSetupAdapter method checkImage.

public ImageStatusResult checkImage(Stack stack) throws Exception {
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(stack.getTenant().getId()).build();
    CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
    Image image = imageService.getImage(stack.getId());
    CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(cloudContext, cloudCredential, cloudStackConverter.convert(stack), image);
    LOGGER.debug("Triggering event: {}", checkImageRequest);
    eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
    try {
        CheckImageResult res = checkImageRequest.await();
        LOGGER.debug("Result: {}", res);
        if (res.getErrorDetails() != null) {
            LOGGER.info("Failed to check image state", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return new ImageStatusResult(res.getImageStatus(), res.getStatusProgressValue());
    } catch (InterruptedException e) {
        LOGGER.info("Error while executing check image", e);
        throw new OperationException(e);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ImageStatusResult(com.sequenceiq.common.api.type.ImageStatusResult)

Example 4 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class CredentialPrerequisiteService method getCloudbreakPrerequisites.

public CredentialPrerequisitesResponse getCloudbreakPrerequisites(String cloudPlatform, String deploymentAddress, CredentialType type) {
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(cloudPlatform).withWorkspaceId(TEMP_WORKSPACE_ID).build();
    CredentialPrerequisitesRequest request = new CredentialPrerequisitesRequest(cloudContext, userPreferencesService.getExternalIdForCurrentUser(), userPreferencesService.getAuditExternalIdForCurrentUser(), deploymentAddress, type);
    LOGGER.debug("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    String message = String.format("Failed to get prerequisites for platform '%s': ", cloudPlatform);
    try {
        CredentialPrerequisitesResult res = request.await();
        LOGGER.debug("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.info(message, res.getErrorDetails());
            throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        return res.getCredentialPrerequisitesResponse();
    } catch (InterruptedException e) {
        LOGGER.error(message, e);
        throw new OperationException(e);
    }
}
Also used : CredentialPrerequisitesRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(javax.ws.rs.BadRequestException) CredentialPrerequisitesResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult) CredentialOperationException(com.sequenceiq.environment.credential.exception.CredentialOperationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 5 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class StackImageUpdateActions method checkImageVersion.

@Bean(name = "CHECK_IMAGE_VERSIONS_STATE")
public AbstractStackImageUpdateAction<?> checkImageVersion() {
    return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) {
            getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED);
            if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) {
                throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']');
            }
            StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(), payload.getImageCatalogName(), payload.getImageCatalogUrl());
            sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), context.getStack().getId(), newImage));
        }
    };
}
Also used : StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Map(java.util.Map) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) OperationException(com.sequenceiq.cloudbreak.service.OperationException) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Bean(org.springframework.context.annotation.Bean)

Aggregations

OperationException (com.sequenceiq.cloudbreak.service.OperationException)47 Retryable (org.springframework.retry.annotation.Retryable)19 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)16 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)11 Location (com.sequenceiq.cloudbreak.cloud.model.Location)6 GetPlatformTemplateResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult)5 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)5 BadRequestException (javax.ws.rs.BadRequestException)5 PlatformParameterRequest (com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterRequest)4 PlatformParameterResult (com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterResult)4 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)3 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)3 EventStatus (com.sequenceiq.cloudbreak.cloud.event.model.EventStatus)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3