Search in sources :

Example 1 with MachineType

use of com.google.api.services.compute.model.MachineType in project platformlayer by platformlayer.

the class GoogleComputeClient method findCheapest.

private MachineType findCheapest(List<MachineType> candidates) {
    MachineType bestFlavor = null;
    float bestPrice = Float.MAX_VALUE;
    for (MachineType candidate : candidates) {
        float price = computePrice(candidate);
        if (price < bestPrice) {
            bestFlavor = candidate;
            bestPrice = price;
        }
    }
    return bestFlavor;
}
Also used : MachineType(com.google.api.services.compute.model.MachineType)

Example 2 with MachineType

use of com.google.api.services.compute.model.MachineType in project platformlayer by platformlayer.

the class GoogleComputeClient method getClosestInstanceType.

private MachineType getClosestInstanceType(MachineCreationRequest request) throws OpsException {
    log.info("Listing machine types to find best size");
    Iterable<MachineType> flavors = listMachineTypes(projectId);
    List<MachineType> candidates = Lists.newArrayList();
    for (MachineType flavor : flavors) {
        // TODO: Is this right?
        if (flavor.getEphemeralDisks() == null || flavor.getEphemeralDisks().isEmpty()) {
            continue;
        }
        int instanceMemoryMB = flavor.getMemoryMb();
        if (request.minimumMemoryMB > instanceMemoryMB) {
            continue;
        }
        candidates.add(flavor);
    }
    MachineType bestFlavor = findCheapest(candidates);
    if (bestFlavor == null) {
        return null;
    }
    return bestFlavor;
}
Also used : MachineType(com.google.api.services.compute.model.MachineType)

Example 3 with MachineType

use of com.google.api.services.compute.model.MachineType in project platformlayer by platformlayer.

the class GoogleComputeClient method listMachineTypes.

private Iterable<MachineType> listMachineTypes(String projectId) throws OpsException {
    List<MachineType> ret = Lists.newArrayList();
    MachineTypeList machineTypeList;
    try {
        log.debug("Listing machine types in project " + projectId);
        machineTypeList = compute.machineTypes().list(projectId).execute();
    } catch (IOException e) {
        throw new OpsException("Error listing machine types", e);
    }
    if (machineTypeList.getItems() != null) {
        ret.addAll(machineTypeList.getItems());
    }
    return ret;
}
Also used : OpsException(org.platformlayer.ops.OpsException) MachineType(com.google.api.services.compute.model.MachineType) IOException(java.io.IOException) MachineTypeList(com.google.api.services.compute.model.MachineTypeList)

Example 4 with MachineType

use of com.google.api.services.compute.model.MachineType in project google-cloud-java by GoogleCloudPlatform.

the class HttpComputeRpc method listMachineTypes.

@Override
public Tuple<String, Iterable<MachineType>> listMachineTypes(String zone, Map<Option, ?> options) {
    try {
        MachineTypeList machineTypesList = compute.machineTypes().list(this.options.getProjectId(), zone).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).setFields(Option.FIELDS.getString(options)).execute();
        Iterable<MachineType> machineTypes = machineTypesList.getItems();
        return Tuple.of(machineTypesList.getNextPageToken(), machineTypes);
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : MachineType(com.google.api.services.compute.model.MachineType) IOException(java.io.IOException) MachineTypeList(com.google.api.services.compute.model.MachineTypeList)

Example 5 with MachineType

use of com.google.api.services.compute.model.MachineType in project google-cloud-java by GoogleCloudPlatform.

the class HttpComputeRpc method listMachineTypes.

@Override
public Tuple<String, Iterable<MachineType>> listMachineTypes(Map<Option, ?> options) {
    try {
        MachineTypeAggregatedList aggregatedList = compute.machineTypes().aggregatedList(this.options.getProjectId()).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).execute();
        ImmutableList.Builder<MachineType> builder = ImmutableList.builder();
        Map<String, MachineTypesScopedList> scopedList = aggregatedList.getItems();
        if (scopedList != null) {
            for (MachineTypesScopedList machineTypesScopedList : scopedList.values()) {
                if (machineTypesScopedList.getMachineTypes() != null) {
                    builder.addAll(machineTypesScopedList.getMachineTypes());
                }
            }
        }
        return Tuple.<String, Iterable<MachineType>>of(aggregatedList.getNextPageToken(), builder.build());
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : MachineTypesScopedList(com.google.api.services.compute.model.MachineTypesScopedList) ImmutableList(com.google.common.collect.ImmutableList) MachineType(com.google.api.services.compute.model.MachineType) IOException(java.io.IOException) MachineTypeAggregatedList(com.google.api.services.compute.model.MachineTypeAggregatedList)

Aggregations

MachineType (com.google.api.services.compute.model.MachineType)7 IOException (java.io.IOException)5 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)3 Set (java.util.Set)2 OpsException (org.platformlayer.ops.OpsException)2 Compute (com.google.api.services.compute.Compute)1 AccessConfig (com.google.api.services.compute.model.AccessConfig)1 Image (com.google.api.services.compute.model.Image)1 Instance (com.google.api.services.compute.model.Instance)1 MachineTypeAggregatedList (com.google.api.services.compute.model.MachineTypeAggregatedList)1 MachineTypesScopedList (com.google.api.services.compute.model.MachineTypesScopedList)1 Metadata (com.google.api.services.compute.model.Metadata)1 Items (com.google.api.services.compute.model.Metadata.Items)1 NetworkInterface (com.google.api.services.compute.model.NetworkInterface)1 Operation (com.google.api.services.compute.model.Operation)1 ImmutableList (com.google.common.collect.ImmutableList)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)1 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)1