Search in sources :

Example 1 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class AwsPlatformResources method virtualMachines.

@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    CloudRegions regions = regions(cloudCredential, region, filters);
    Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
    Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
    for (AvailabilityZone availabilityZone : regions.getCloudRegions().get(region)) {
        cloudVmResponses.put(availabilityZone.value(), vmTypes.get(region));
        defaultCloudVmResponses.put(availabilityZone.value(), defaultVmTypes.get(region));
    }
    return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) HashMap(java.util.HashMap) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method virtualMachines.

@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
    Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters);
    regions.getCloudRegions().forEach((cloudRegion, availabilityZones) -> {
        Set<VmType> types = collectVmTypes(osClient);
        convertVmSizeToGB(types);
        availabilityZones.forEach(availabilityZone -> cloudVmResponses.put(availabilityZone.value(), types));
        defaultCloudVmResponses.put(cloudRegion.value(), types.isEmpty() ? null : (VmType) types.toArray()[0]);
    });
    CloudVmTypes cloudVmTypes = new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
    LOGGER.info("openstack virtual machine types: {}", cloudVmTypes);
    return cloudVmTypes;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) HashMap(java.util.HashMap) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 3 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    Set<String> regionsFromOpenStack = openStackClient.getRegion(cloudCredential);
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<Region, List<AvailabilityZone>> cloudRegions = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    for (String regionFromOpenStack : regionsFromOpenStack) {
        List<AvailabilityZone> availabilityZones = openStackClient.getZones(osClient, regionFromOpenStack);
        cloudRegions.put(region(regionFromOpenStack), availabilityZones);
        displayNames.put(region(regionFromOpenStack), regionFromOpenStack);
    }
    String defaultRegion = null;
    if (!cloudRegions.keySet().isEmpty()) {
        defaultRegion = ((StringType) cloudRegions.keySet().toArray()[0]).value();
    }
    CloudRegions regions = new CloudRegions(cloudRegions, displayNames, defaultRegion);
    LOGGER.info("openstack regions result: {}", regions);
    return regions;
}
Also used : HashMap(java.util.HashMap) Region(com.sequenceiq.cloudbreak.cloud.model.Region) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) List(java.util.List) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 4 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method gateways.

@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters);
    for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
        Set<CloudGateWay> cloudGateWays = new HashSet<>();
        List<? extends Router> routerList = osClient.networking().router().list();
        LOGGER.info("routers from openstack: {}", routerList);
        for (Router router : routerList) {
            CloudGateWay cloudGateWay = new CloudGateWay();
            cloudGateWay.setId(router.getId());
            cloudGateWay.setName(router.getName());
            Map<String, Object> properties = new HashMap<>();
            properties.put("tenantId", router.getTenantId());
            cloudGateWay.setProperties(properties);
            cloudGateWays.add(cloudGateWay);
        }
        for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
            resultCloudGateWayMap.put(availabilityZone.value(), cloudGateWays);
        }
    }
    CloudGateWays cloudGateWays = new CloudGateWays(resultCloudGateWayMap);
    LOGGER.info("openstack cloudgateway result: {}", cloudGateWays);
    return cloudGateWays;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Router(org.openstack4j.model.network.Router) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudGateWay(com.sequenceiq.cloudbreak.cloud.model.CloudGateWay) Region(com.sequenceiq.cloudbreak.cloud.model.Region) List(java.util.List) HashSet(java.util.HashSet)

Example 5 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions 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)

Aggregations

CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)14 HashMap (java.util.HashMap)10 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)8 Region (com.sequenceiq.cloudbreak.cloud.model.Region)7 List (java.util.List)7 Cacheable (org.springframework.cache.annotation.Cacheable)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 ArrayList (java.util.ArrayList)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 Compute (com.google.api.services.compute.Compute)2 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudGateWay (com.sequenceiq.cloudbreak.cloud.model.CloudGateWay)2 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)2 Collections.singletonList (java.util.Collections.singletonList)2 Test (org.junit.Test)2 DescribeAvailabilityZonesRequest (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)1