Search in sources :

Example 1 with GetPlatformRegionsResultV2

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

the class GetRegionsV2Handler method accept.

@Override
public void accept(Event<GetPlatformRegionsRequestV2> getRegionsRequestEvent) {
    LOGGER.info("Received event: {}", getRegionsRequestEvent);
    GetPlatformRegionsRequestV2 request = getRegionsRequestEvent.getData();
    try {
        CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
        CloudRegions cloudRegions = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().regions(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters());
        GetPlatformRegionsResultV2 getPlatformRegionsResultV2 = new GetPlatformRegionsResultV2(request, cloudRegions);
        request.getResult().onNext(getPlatformRegionsResultV2);
        LOGGER.info("Query platform regions types finished.");
    } catch (Exception e) {
        LOGGER.warn("Could not get regions from the cloud provider due to:", e);
        request.getResult().onNext(new GetPlatformRegionsResultV2(e.getMessage(), e, request));
    }
}
Also used : GetPlatformRegionsResultV2(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformRegionsResultV2) GetPlatformRegionsRequestV2(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformRegionsRequestV2) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)

Example 2 with GetPlatformRegionsResultV2

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

the class CloudParameterService method getRegionsV2.

public CloudRegions getRegionsV2(Credential credential, String region, String variant, Map<String, String> filters) {
    LOGGER.debug("Get platform regions");
    ExtendedCloudCredential cloudCredential = credentialToExtendedCloudCredentialConverter.convert(credential);
    GetPlatformRegionsRequestV2 getPlatformRegionsRequest = new GetPlatformRegionsRequestV2(cloudCredential, cloudCredential, variant, region, filters);
    eventBus.notify(getPlatformRegionsRequest.selector(), Event.wrap(getPlatformRegionsRequest));
    try {
        GetPlatformRegionsResultV2 res = getPlatformRegionsRequest.await();
        LOGGER.info("Platform regions result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            throw new GetCloudParameterException("Failed to get regions from the cloud provider due to network issues or invalid credential", res.getErrorDetails());
        }
        return res.getCloudRegions();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting the platform regions", e);
        throw new OperationException(e);
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) GetPlatformRegionsResultV2(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformRegionsResultV2) GetPlatformRegionsRequestV2(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformRegionsRequestV2) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException)

Aggregations

GetPlatformRegionsRequestV2 (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformRegionsRequestV2)2 GetPlatformRegionsResultV2 (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformRegionsResultV2)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)1