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;
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations