use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone in project cloudbreak by hortonworks.
the class GcpPlatformResources method virtualMachines.
@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
try {
Set<VmType> types = new HashSet<>();
VmType defaultVmType = null;
CloudRegions regions = regions(cloudCredential, region, filters);
for (AvailabilityZone availabilityZone : regions.getCloudRegions().get(region)) {
MachineTypeList machineTypeList = compute.machineTypes().list(projectId, availabilityZone.value()).execute();
for (MachineType machineType : machineTypeList.getItems()) {
VmTypeMeta vmTypeMeta = VmTypeMetaBuilder.builder().withCpuAndMemory(machineType.getGuestCpus(), machineType.getMemoryMb().floatValue() / THOUSAND).withMagneticConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisksSizeGb().intValue()).withSsdConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisks()).withMaximumPersistentDisksSizeGb(machineType.getMaximumPersistentDisksSizeGb().toString()).create();
VmType vmType = VmType.vmTypeWithMeta(machineType.getName(), vmTypeMeta, true);
types.add(vmType);
if (machineType.getName().equals(gcpVmDefault)) {
defaultVmType = vmType;
}
}
cloudVmResponses.put(availabilityZone.value(), types);
defaultCloudVmResponses.put(availabilityZone.value(), defaultVmType);
}
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
} catch (Exception e) {
return new CloudVmTypes(new HashMap<>(), new HashMap<>());
}
}
use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone in project cloudbreak by hortonworks.
the class GcpPlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
String defaultRegion = gcpZoneParameterDefault;
RegionList regionList = compute.regions().list(projectId).execute();
for (com.google.api.services.compute.model.Region gcpRegion : regionList.getItems()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || gcpRegion.getName().equals(region.value())) {
List<AvailabilityZone> availabilityZones = new ArrayList<>();
for (String s : gcpRegion.getZones()) {
String[] split = s.split("/");
if (split.length > 0) {
availabilityZones.add(AvailabilityZone.availabilityZone(split[split.length - 1]));
}
}
regionListMap.put(region(gcpRegion.getName()), availabilityZones);
displayNames.put(region(gcpRegion.getName()), displayName(gcpRegion.getName()));
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone in project cloudbreak by hortonworks.
the class HeatTemplateBuilder method build.
public String build(ModelContext modelContext) {
try {
List<NovaInstanceView> novaInstances = new OpenStackGroupView(modelContext.stackName, modelContext.groups, modelContext.tags).getFlatNovaView();
Map<String, Object> model = new HashMap<>();
model.put("cb_stack_name", openStackUtil.adjustStackNameLength(modelContext.stackName));
model.put("agents", novaInstances);
model.put("core_user_data", formatUserData(modelContext.instanceUserData.getUserDataByType(InstanceGroupType.CORE)));
model.put("gateway_user_data", formatUserData(modelContext.instanceUserData.getUserDataByType(InstanceGroupType.GATEWAY)));
model.put("groups", modelContext.groups);
model.put("existingNetwork", modelContext.existingNetwork);
model.put("existingSubnet", modelContext.existingSubnet);
model.put("network", modelContext.neutronNetworkView);
model.putAll(defaultCostTaggingService.prepareAllTagsForTemplate());
AvailabilityZone az = modelContext.location.getAvailabilityZone();
if (az != null && az.value() != null) {
model.put("availability_zone", az.value());
}
Template template = new Template(openStackHeatTemplatePath, modelContext.templateString, freemarkerConfiguration);
String generatedTemplate = processTemplateIntoString(template, model);
LOGGER.debug("Generated Heat template: {}", generatedTemplate);
return generatedTemplate;
} catch (IOException | TemplateException e) {
throw new CloudConnectorException("Failed to process the OpenStack HeatTemplateBuilder", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone in project cloudbreak by hortonworks.
the class OpenStackPlatformResourcesTest method testVirtualMachinesWhenTypesEmpty.
@Test
public void testVirtualMachinesWhenTypesEmpty() {
CloudCredential cloudCredential = new CloudCredential(0L, "name");
OSClient osClient = mock(OSClient.class);
String regionName = "region1";
Set<String> regionsFromOpenStack = Sets.newHashSet(regionName);
List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1"));
when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient);
when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack);
when(openStackClient.getZones(osClient, regionName)).thenReturn(availabilityZones);
when(openStackClient.getFlavors(osClient)).thenReturn(emptyList());
CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null);
verify(openStackClient, times(1)).getFlavors(osClient);
Assert.assertEquals(0, actual.getCloudVmResponses().get("zone1").size());
Assert.assertNull(actual.getDefaultCloudVmResponses().get(regionName));
}
use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method publicIpPool.
@Override
public CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
Map<String, Set<CloudIpPool>> cloudIpPools = new HashMap<>();
CloudRegions regions = regions(cloudCredential, region, filters);
for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
Set<CloudIpPool> cloudGateWays = new HashSet<>();
List<? extends Network> networks = getNetworks(osClient);
List<? extends Network> networksWithExternalRouter = networks.stream().filter(Network::isRouterExternal).collect(Collectors.toList());
for (Network network : networksWithExternalRouter) {
CloudIpPool cloudIpPool = new CloudIpPool();
cloudIpPool.setId(network.getId());
cloudIpPool.setName(network.getName());
cloudGateWays.add(cloudIpPool);
}
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
cloudIpPools.put(availabilityZone.value(), cloudGateWays);
}
}
LOGGER.info("openstack public ip pool result: {}", cloudIpPools);
return new CloudIpPools(cloudIpPools);
}
Aggregations