Search in sources :

Example 1 with InstanceAggregatedList

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

the class HttpComputeRpc method listInstances.

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

Aggregations

Instance (com.google.api.services.compute.model.Instance)1 InstanceAggregatedList (com.google.api.services.compute.model.InstanceAggregatedList)1 InstancesScopedList (com.google.api.services.compute.model.InstancesScopedList)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1