Search in sources :

Example 46 with OperationException

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

the class ServiceProviderConnectorAdapter method waitGetTemplate.

public String waitGetTemplate(Stack stack, GetPlatformTemplateRequest getPlatformTemplateRequest) {
    try {
        GetPlatformTemplateResult res = getPlatformTemplateRequest.await();
        LOGGER.debug("Get template result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to get template", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return res.getTemplate();
    } catch (InterruptedException e) {
        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();
        LOGGER.error("Error while getting template: " + cloudContext, e);
        throw new OperationException(e);
    }
}
Also used : GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 47 with OperationException

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

the class ServiceProviderMetadataAdapter method getState.

public InstanceSyncState getState(Stack stack, InstanceGroup instanceGroup, String instanceId, DetailedEnvironmentResponse environment) {
    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);
    InstanceGroup ig = stack.getInstanceGroupByInstanceGroupName(instanceGroup.getGroupName());
    CloudInstance instance = null;
    for (InstanceMetaData metaData : ig.getAllInstanceMetaData()) {
        if (instanceId.equalsIgnoreCase(metaData.getInstanceId())) {
            instance = metadataConverter.convert(metaData, environment, stack.getStackAuthentication());
            break;
        }
    }
    if (instance != null) {
        GetInstancesStateRequest<GetInstancesStateResult> stateRequest = new GetInstancesStateRequest<>(cloudContext, cloudCredential, Collections.singletonList(instance));
        LOGGER.debug("Triggering event: {}", stateRequest);
        eventBus.notify(stateRequest.selector(), eventFactory.createEvent(stateRequest));
        try {
            GetInstancesStateResult res = stateRequest.await();
            LOGGER.debug("Result: {}", res);
            if (res.isFailed()) {
                LOGGER.info("Failed to retrieve instance state", res.getErrorDetails());
                throw new OperationException(res.getErrorDetails());
            }
            return InstanceSyncState.getInstanceSyncState(res.getStatuses().get(0).getStatus());
        } catch (InterruptedException e) {
            LOGGER.info(format("Error while retrieving instance state of: %s", cloudContext), e);
            throw new OperationException(e);
        }
    } else {
        return InstanceSyncState.DELETED;
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) GetInstancesStateRequest(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) GetInstancesStateResult(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateResult) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

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