Search in sources :

Example 1 with GetPlatformResourceGroupsResult

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

the class CloudParameterService method getResourceGroups.

@Retryable(value = GetCloudParameterException.class, maxAttempts = 5, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000))
public CloudResourceGroups getResourceGroups(ExtendedCloudCredential cloudCredential, String region, String platformVariant, Map<String, String> filters) {
    LOGGER.debug("Get platform resource groups for credential: [{}]", cloudCredential.getName());
    GetPlatformResourceGroupsRequest request = new GetPlatformResourceGroupsRequest(cloudCredential, cloudCredential, platformVariant, region, null);
    eventBus.notify(request.selector(), Event.wrap(request));
    try {
        GetPlatformResourceGroupsResult result = request.await();
        LOGGER.debug("Platform ResourceGroupsResult result: {}", result);
        if (result.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.debug("Failed to get platform ResourceGroupsResult", result.getErrorDetails());
            throw new GetCloudParameterException(String.format("Failed to get resource groups tables for the cloud provider: %s. %s", result.getStatusReason(), getCauseMessages(result.getErrorDetails())), result.getErrorDetails());
        }
        return result.getResourceGroups();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting the platform ResourceGroupsResult", e);
        throw new OperationException(e);
    }
}
Also used : GetPlatformResourceGroupsRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformResourceGroupsRequest) GetPlatformResourceGroupsResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformResourceGroupsResult) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Retryable(org.springframework.retry.annotation.Retryable)

Example 2 with GetPlatformResourceGroupsResult

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

the class GetPlatformResourceGroupsHandler method accept.

@Override
public void accept(Event<GetPlatformResourceGroupsRequest> event) {
    LOGGER.debug("Received event: {}", event);
    GetPlatformResourceGroupsRequest request = event.getData();
    try {
        CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
        CloudResourceGroups resourceGroups = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().resourceGroups(request.getExtendedCloudCredential(), Region.region(request.getRegion()), request.getFilters());
        GetPlatformResourceGroupsResult result = new GetPlatformResourceGroupsResult(request.getResourceId(), resourceGroups);
        request.getResult().onNext(result);
        LOGGER.debug("Query platform Resource groups finished.");
    } catch (RuntimeException e) {
        request.getResult().onNext(new GetPlatformResourceGroupsResult(e.getMessage(), e, request.getResourceId()));
    }
}
Also used : CloudResourceGroups(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups) GetPlatformResourceGroupsRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformResourceGroupsRequest) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) GetPlatformResourceGroupsResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformResourceGroupsResult)

Aggregations

GetPlatformResourceGroupsRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformResourceGroupsRequest)2 GetPlatformResourceGroupsResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformResourceGroupsResult)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 CloudResourceGroups (com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 Retryable (org.springframework.retry.annotation.Retryable)1