use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes 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.CloudVmTypes in project cloudbreak by hortonworks.
the class GetPlatformVmTypesHandler method accept.
@Override
public void accept(Event<GetPlatformVmTypesRequest> getPlatformVmTypesRequest) {
LOGGER.info("Received event: {}", getPlatformVmTypesRequest);
GetPlatformVmTypesRequest request = getPlatformVmTypesRequest.getData();
try {
CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
CloudVmTypes platformVirtualMachinesJson = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().virtualMachines(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters());
GetPlatformVmTypesResult getPlatformSecurityGroupsResult = new GetPlatformVmTypesResult(request, platformVirtualMachinesJson);
request.getResult().onNext(getPlatformSecurityGroupsResult);
LOGGER.info("Query platform vmtypes types finished.");
} catch (Exception e) {
request.getResult().onNext(new GetPlatformVmTypesResult(e.getMessage(), e, request));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes in project cloudbreak by hortonworks.
the class CloudResourceAdvisor method createForBlueprint.
public PlatformRecommendation createForBlueprint(String blueprintName, Long blueprintId, PlatformResourceRequest resourceRequest, IdentityUser cbUser) {
String cloudPlatform = resourceRequest.getCloudPlatform();
String region = resourceRequest.getRegion();
String availabilityZone = resourceRequest.getAvailabilityZone();
Map<String, VmType> vmTypesByHostGroup = new HashMap<>();
Map<String, Boolean> hostGroupContainsMasterComp = new HashMap<>();
LOGGER.info("Advising resources for blueprintId: {}, blueprintName: {}, provider: {} and region: {}.", blueprintId, blueprintName, cloudPlatform, region);
String blueprintText = getBlueprint(blueprintName, blueprintId, cbUser).getBlueprintText();
Map<String, Set<String>> componentsByHostGroup = blueprintProcessorFactory.get(blueprintText).getComponentsByHostGroup();
componentsByHostGroup.forEach((hGName, components) -> hostGroupContainsMasterComp.put(hGName, isThereMasterComponents(components)));
CloudVmTypes vmTypes = cloudParameterService.getVmTypesV2(resourceRequest.getCredential(), resourceRequest.getRegion(), resourceRequest.getPlatformVariant(), resourceRequest.getFilters());
VmType defaultVmType = getDefaultVmType(availabilityZone, vmTypes);
if (defaultVmType != null) {
componentsByHostGroup.keySet().forEach(comp -> vmTypesByHostGroup.put(comp, defaultVmType));
}
VmRecommendations recommendations = cloudParameterService.getRecommendation(cloudPlatform);
Set<VmType> availableVmTypes = vmTypes.getCloudVmResponses().get(availabilityZone);
if (availableVmTypes == null) {
availableVmTypes = Collections.emptySet();
}
if (recommendations != null) {
Map<String, VmType> masterVmTypes = getVmTypesForComponentType(true, recommendations.getMaster(), hostGroupContainsMasterComp, availableVmTypes);
vmTypesByHostGroup.putAll(masterVmTypes);
Map<String, VmType> workerVmTypes = getVmTypesForComponentType(false, recommendations.getWorker(), hostGroupContainsMasterComp, availableVmTypes);
vmTypesByHostGroup.putAll(workerVmTypes);
}
PlatformDisks platformDisks = cloudParameterService.getDiskTypes();
Platform platform = platform(cloudPlatform);
DiskTypes diskTypes = new DiskTypes(platformDisks.getDiskTypes().get(platform), platformDisks.getDefaultDisks().get(platform), platformDisks.getDiskMappings().get(platform), platformDisks.getDiskDisplayNames().get(platform));
return new PlatformRecommendation(vmTypesByHostGroup, availableVmTypes, diskTypes);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes 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));
}
Aggregations