use of com.sequenceiq.cloudbreak.cloud.model.Region 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.Region 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.Region in project cloudbreak by hortonworks.
the class PlatformRegionsToRegionResponseConverter method convert.
@Override
public RegionResponse convert(CloudRegions source) {
RegionResponse json = new RegionResponse();
Set<String> regions = new HashSet<>();
for (Region region : source.getCloudRegions().keySet()) {
regions.add(region.value());
}
Map<String, Collection<String>> availabilityZones = new HashMap<>();
for (Entry<Region, List<AvailabilityZone>> regionListEntry : source.getCloudRegions().entrySet()) {
Collection<String> azs = new ArrayList<>();
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
azs.add(availabilityZone.value());
}
availabilityZones.put(regionListEntry.getKey().value(), azs);
}
Map<String, String> displayNames = new HashMap<>();
for (Entry<Region, String> regionStringEntry : source.getDisplayNames().entrySet()) {
displayNames.put(regionStringEntry.getKey().value(), regionStringEntry.getValue());
}
json.setRegions(regions);
json.setAvailabilityZones(availabilityZones);
json.setDefaultRegion(source.getDefaultRegion());
json.setDisplayNames(displayNames);
return json;
}
use of com.sequenceiq.cloudbreak.cloud.model.Region in project cloudbreak by hortonworks.
the class AwsPlatformResources method gateways.
@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
CloudRegions regions = regions(cloudCredential, region, filters);
for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || regionListEntry.getKey().value().equals(region.value())) {
ec2Client.setRegion(RegionUtils.getRegion(regionListEntry.getKey().value()));
DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest();
DescribeInternetGatewaysResult describeInternetGatewaysResult = ec2Client.describeInternetGateways(describeInternetGatewaysRequest);
Set<CloudGateWay> gateWays = new HashSet<>();
for (InternetGateway internetGateway : describeInternetGatewaysResult.getInternetGateways()) {
CloudGateWay cloudGateWay = new CloudGateWay();
cloudGateWay.setId(internetGateway.getInternetGatewayId());
cloudGateWay.setName(internetGateway.getInternetGatewayId());
Collection<String> vpcs = new ArrayList<>();
for (InternetGatewayAttachment internetGatewayAttachment : internetGateway.getAttachments()) {
vpcs.add(internetGatewayAttachment.getVpcId());
}
Map<String, Object> properties = new HashMap<>();
properties.put("attachment", vpcs);
cloudGateWay.setProperties(properties);
gateWays.add(cloudGateWay);
}
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
resultCloudGateWayMap.put(availabilityZone.value(), gateWays);
}
}
}
return new CloudGateWays(resultCloudGateWayMap);
}
use of com.sequenceiq.cloudbreak.cloud.model.Region in project cloudbreak by hortonworks.
the class AwsPlatformResources method sshKeys.
@Override
public CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudSshKey>> result = new HashMap<>();
for (Region actualRegion : regions(cloudCredential, region, new HashMap<>()).getCloudRegions().keySet()) {
// If region is provided then should filter for those region
if (regionMatch(actualRegion, region)) {
Set<CloudSshKey> cloudSshKeys = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), actualRegion.value());
// create sshkey filter view
PlatformResourceSshKeyFilterView filter = new PlatformResourceSshKeyFilterView(filters);
DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
// If the filtervalue is provided then we should filter only for those securitygroups
if (!Strings.isNullOrEmpty(filter.getKeyName())) {
describeKeyPairsRequest.withKeyNames(filter.getKeyName());
}
for (KeyPairInfo keyPairInfo : ec2Client.describeKeyPairs(describeKeyPairsRequest).getKeyPairs()) {
Map<String, Object> properties = new HashMap<>();
properties.put("fingerPrint", keyPairInfo.getKeyFingerprint());
cloudSshKeys.add(new CloudSshKey(keyPairInfo.getKeyName(), properties));
}
result.put(actualRegion.value(), cloudSshKeys);
}
}
return new CloudSshKeys(result);
}
Aggregations