Search in sources :

Example 11 with CloudVmTypes

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<>());
    }
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) MachineType(com.google.api.services.compute.model.MachineType) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) IOException(java.io.IOException) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Compute(com.google.api.services.compute.Compute) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 12 with CloudVmTypes

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));
    }
}
Also used : GetPlatformVmTypesResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformVmTypesResult) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) GetPlatformVmTypesRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformVmTypesRequest)

Example 13 with CloudVmTypes

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);
}
Also used : Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) HashMap(java.util.HashMap) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmRecommendations(com.sequenceiq.cloudbreak.cloud.model.VmRecommendations) DiskTypes(com.sequenceiq.cloudbreak.cloud.model.DiskTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)

Example 14 with CloudVmTypes

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));
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) OSClient(org.openstack4j.api.OSClient) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Test(org.junit.Test)

Aggregations

CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)14 Set (java.util.Set)8 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)7 HashMap (java.util.HashMap)6 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)5 Test (org.junit.Test)5 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)4 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)4 HashSet (java.util.HashSet)4 Cacheable (org.springframework.cache.annotation.Cacheable)4 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)3 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)3 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)3 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)3 Credential (com.sequenceiq.cloudbreak.domain.Credential)3 Template (com.sequenceiq.cloudbreak.domain.Template)3 Map (java.util.Map)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Collections.emptyMap (java.util.Collections.emptyMap)2