Search in sources :

Example 6 with OperationException

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

the class StackImageUpdateService method getNewImageIfVersionsMatch.

public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) {
    try {
        restRequestThreadLocalService.setWorkspace(stack.getWorkspace());
        Image currentImage = stackImageService.getCurrentImage(stack);
        StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage);
        if (!isCloudPlatformMatches(stack, newImage)) {
            String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform()));
            LOGGER.debug(message);
            throw new OperationException(message);
        }
        if (!isOsVersionsMatch(currentImage, newImage)) {
            String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType()));
            LOGGER.debug(message);
            throw new OperationException(message);
        }
        if (!isStackMatchIfPrewarmed(newImage)) {
            String message = "Stack versions don't match on prewarmed image with cluster's";
            LOGGER.debug(message);
            throw new OperationException(message);
        }
        return newImage;
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.info("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 7 with OperationException

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

the class LoadBalancerRecreatorService method collectLoadBalancerMetadata.

private List<CloudLoadBalancerMetadata> collectLoadBalancerMetadata(AuthenticatedContext authenticatedContext, Long stackId) {
    List<LoadBalancerType> loadBalancerTypes = loadBalancerPersistenceService.findByStackId(stackId).stream().map(LoadBalancer::getType).collect(Collectors.toList());
    List<CloudResource> cloudResources = resourceService.findByStackIdAndType(stackId, ResourceType.ELASTIC_LOAD_BALANCER).stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
    CollectLoadBalancerMetadataRequest request = new CollectLoadBalancerMetadataRequest(authenticatedContext.getCloudContext(), authenticatedContext.getCloudCredential(), loadBalancerTypes, cloudResources);
    eventBus.notify(request.selector(), Event.wrap(request));
    try {
        CollectLoadBalancerMetadataResult res = request.await();
        LOGGER.debug("Collect load balancer metadata result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            String msg = "Failed to collect the load balancer metadata. " + res.getErrorDetails().getMessage();
            LOGGER.debug(msg);
            throw new CloudbreakServiceException(msg, res.getErrorDetails());
        }
        return res.getResults();
    } catch (InterruptedException e) {
        LOGGER.error("Error while collect load balancer metadata", e);
        throw new OperationException(e);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) Event(reactor.bus.Event) AwsNativeLoadBalancerLaunchService(com.sequenceiq.cloudbreak.cloud.aws.resource.loadbalancer.AwsNativeLoadBalancerLaunchService) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext) MetadataSetupService(com.sequenceiq.cloudbreak.service.stack.flow.MetadataSetupService) ResourceType(com.sequenceiq.common.api.type.ResourceType) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) EventBus(reactor.bus.EventBus) EventStatus(com.sequenceiq.cloudbreak.cloud.event.model.EventStatus) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Component(org.springframework.stereotype.Component) OperationException(com.sequenceiq.cloudbreak.service.OperationException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) OperationException(com.sequenceiq.cloudbreak.service.OperationException) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType)

Example 8 with OperationException

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

the class ServiceProviderConnectorAdapter method getPlatformParameters.

public PlatformParameters getPlatformParameters(Stack stack) {
    LOGGER.debug("Get platform parameters for: {}", stack);
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).build();
    Credential credential = credentialClientService.getByEnvironmentCrn(stack.getEnvironmentCrn());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    PlatformParameterRequest parameterRequest = new PlatformParameterRequest(cloudContext, cloudCredential);
    eventBus.notify(parameterRequest.selector(), eventFactory.createEvent(parameterRequest));
    try {
        PlatformParameterResult res = parameterRequest.await();
        LOGGER.debug("Platform parameter result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to get platform parameters", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return res.getPlatformParameters();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting platform parameters: " + cloudContext, e);
        throw new OperationException(e);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) PlatformParameterRequest(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterRequest) PlatformParameterResult(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterResult) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 9 with OperationException

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

the class ServiceProviderConnectorAdapter method deleteStack.

public void deleteStack(Stack stack) {
    LOGGER.debug("Assembling terminate stack event for stack: {}", stack);
    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(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
    Credential credential = credentialClientService.getByEnvironmentCrn(stack.getEnvironmentCrn());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    List<CloudResource> resources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    TerminateStackRequest<TerminateStackResult> terminateRequest = new TerminateStackRequest<>(cloudContext, cloudStack, cloudCredential, resources);
    LOGGER.debug("Triggering terminate stack event: {}", terminateRequest);
    eventBus.notify(terminateRequest.selector(), eventFactory.createEvent(terminateRequest));
    try {
        TerminateStackResult res = terminateRequest.await();
        LOGGER.debug("Terminate stack result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            if (res.getErrorDetails() != null) {
                LOGGER.info("Failed to terminate the stack", res.getErrorDetails());
                throw new OperationException(res.getErrorDetails());
            }
            throw new OperationException(format("Failed to terminate the stack: %s due to %s", cloudContext, res.getStatusReason()));
        }
    } catch (InterruptedException e) {
        LOGGER.error("Error while terminating the stack", e);
        throw new OperationException(e);
    }
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) PlatformParameterRequest(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterRequest) Resource(com.sequenceiq.cloudbreak.domain.Resource) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) CheckPlatformVariantResult(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantResult) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ErrorHandlerAwareReactorEventFactory(com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) PlatformParameterResult(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterResult) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CredentialClientService(com.sequenceiq.cloudbreak.service.environment.credential.CredentialClientService) TerminateStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackRequest) CheckPlatformVariantRequest(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantRequest) TerminateStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackResult) Set(java.util.Set) EventBus(reactor.bus.EventBus) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) CredentialToCloudCredentialConverter(com.sequenceiq.cloudbreak.converter.spi.CredentialToCloudCredentialConverter) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) EventStatus(com.sequenceiq.cloudbreak.cloud.event.model.EventStatus) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) Component(org.springframework.stereotype.Component) OperationException(com.sequenceiq.cloudbreak.service.OperationException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) TerminateStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackResult) TerminateStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 10 with OperationException

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

the class ResourceDefinitionService method getResourceDefinition.

@Cacheable("resourceDefinitionCache")
public String getResourceDefinition(String cloudPlatform, String resource) {
    LOGGER.debug("Sending request for {} {} resource property definition", cloudPlatform, resource);
    CloudPlatformVariant platformVariant = new CloudPlatformVariant(Platform.platform(cloudPlatform), Variant.EMPTY);
    ResourceDefinitionRequest request = new ResourceDefinitionRequest(platformVariant, resource);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        ResourceDefinitionResult result = request.await();
        LOGGER.debug("Resource property definition: {}", result);
        return result.getDefinition();
    } catch (InterruptedException e) {
        LOGGER.info("Error while sending resource definition request", e);
        throw new OperationException(e);
    }
}
Also used : CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) ResourceDefinitionResult(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult) ResourceDefinitionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Cacheable(org.springframework.cache.annotation.Cacheable)

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