Search in sources :

Example 1 with ResourceDefinitionResult

use of com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult in project cloudbreak by hortonworks.

the class ResourceDefinitionHandler method accept.

@Override
public void accept(Event<ResourceDefinitionRequest> getRegionsRequestEvent) {
    LOGGER.info("Received event: {}", getRegionsRequestEvent);
    ResourceDefinitionRequest request = getRegionsRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getPlatform());
        String resource = request.getResource();
        String definition = connector.parameters().resourceDefinition(request.getResource());
        if (definition == null) {
            Exception exception = new Exception("Failed to find resource definition for " + resource);
            request.getResult().onNext(new ResourceDefinitionResult(exception.getMessage(), exception, request));
        } else {
            request.getResult().onNext(new ResourceDefinitionResult(request, definition));
        }
    } catch (RuntimeException e) {
        request.getResult().onNext(new ResourceDefinitionResult(e.getMessage(), e, request));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) ResourceDefinitionResult(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult) ResourceDefinitionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest)

Example 2 with ResourceDefinitionResult

use of com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult 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.info("Resource property definition: {}", result);
        return result.getDefinition();
    } catch (InterruptedException e) {
        LOGGER.error("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.stack.connector.OperationException) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ResourceDefinitionRequest (com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest)2 ResourceDefinitionResult (com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)1 Cacheable (org.springframework.cache.annotation.Cacheable)1