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);
}
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;
}
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;
}
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;
}
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));
}
}
Aggregations