use of com.google.api.services.compute.model.Address in project google-cloud-java by GoogleCloudPlatform.
the class AddressInfo method toPb.
Address toPb() {
Address addressPb = usage != null ? usage.toPb() : new Address();
addressPb.setAddress(address);
if (creationTimestamp != null) {
addressPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
}
addressPb.setDescription(description);
if (generatedId != null) {
addressPb.setId(new BigInteger(generatedId));
}
addressPb.setName(addressId.getAddress());
if (addressId.getType() == AddressId.Type.REGION) {
addressPb.setRegion(this.<RegionAddressId>getAddressId().getRegionId().getSelfLink());
}
if (status != null) {
addressPb.setStatus(status.name());
}
addressPb.setSelfLink(addressId.getSelfLink());
return addressPb;
}
use of com.google.api.services.compute.model.Address in project google-cloud-java by GoogleCloudPlatform.
the class HttpComputeRpc method listGlobalAddresses.
@Override
public Tuple<String, Iterable<Address>> listGlobalAddresses(Map<Option, ?> options) {
try {
AddressList addressList = compute.globalAddresses().list(this.options.getProjectId()).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).setFields(Option.FIELDS.getString(options)).execute();
Iterable<Address> operations = addressList.getItems();
return Tuple.of(addressList.getNextPageToken(), operations);
} catch (IOException ex) {
throw translate(ex);
}
}
use of com.google.api.services.compute.model.Address in project google-cloud-java by GoogleCloudPlatform.
the class HttpComputeRpc method listAddresses.
@Override
public Tuple<String, Iterable<Address>> listAddresses(Map<Option, ?> options) {
try {
AddressAggregatedList aggregatedList = compute.addresses().aggregatedList(this.options.getProjectId()).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).execute();
ImmutableList.Builder<Address> builder = ImmutableList.builder();
Map<String, AddressesScopedList> scopedList = aggregatedList.getItems();
if (scopedList != null) {
for (AddressesScopedList addressesScopedList : scopedList.values()) {
if (addressesScopedList.getAddresses() != null) {
builder.addAll(addressesScopedList.getAddresses());
}
}
}
return Tuple.<String, Iterable<Address>>of(aggregatedList.getNextPageToken(), builder.build());
} catch (IOException ex) {
throw translate(ex);
}
}
use of com.google.api.services.compute.model.Address in project cloudbreak by hortonworks.
the class GcpReservedIpResourceBuilder method build.
@Override
public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
List<CloudResource> result = buildableResource;
if (!buildableResource.isEmpty()) {
CloudResource resource = buildableResource.get(0);
String projectId = context.getProjectId();
String region = context.getLocation().getRegion().value();
Address address = new Address();
address.setName(resource.getName());
Map<String, String> customTags = new HashMap<>();
customTags.putAll(tags);
customTags.putAll(defaultCostTaggingService.prepareIpTagging());
address.setLabels(customTags);
Insert networkInsert = context.getCompute().addresses().insert(projectId, region, address);
try {
Operation operation = networkInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
}
result = Collections.singletonList(createOperationAwareCloudResource(resource, operation));
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
}
}
return result;
}
use of com.google.api.services.compute.model.Address in project google-cloud-java by GoogleCloudPlatform.
the class HttpComputeRpc method listRegionAddresses.
@Override
public Tuple<String, Iterable<Address>> listRegionAddresses(String region, Map<Option, ?> options) {
try {
AddressList addressList = compute.addresses().list(this.options.getProjectId(), region).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).setFields(Option.FIELDS.getString(options)).execute();
Iterable<Address> operations = addressList.getItems();
return Tuple.of(addressList.getNextPageToken(), operations);
} catch (IOException ex) {
throw translate(ex);
}
}
Aggregations