Search in sources :

Example 1 with Address

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;
}
Also used : Address(com.google.api.services.compute.model.Address) BigInteger(java.math.BigInteger)

Example 2 with Address

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);
    }
}
Also used : Address(com.google.api.services.compute.model.Address) IOException(java.io.IOException) AddressList(com.google.api.services.compute.model.AddressList)

Example 3 with Address

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);
    }
}
Also used : AddressesScopedList(com.google.api.services.compute.model.AddressesScopedList) Address(com.google.api.services.compute.model.Address) ImmutableList(com.google.common.collect.ImmutableList) AddressAggregatedList(com.google.api.services.compute.model.AddressAggregatedList) IOException(java.io.IOException)

Example 4 with Address

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;
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Address(com.google.api.services.compute.model.Address) HashMap(java.util.HashMap) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Operation(com.google.api.services.compute.model.Operation) Insert(com.google.api.services.compute.Compute.Addresses.Insert)

Example 5 with Address

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);
    }
}
Also used : Address(com.google.api.services.compute.model.Address) IOException(java.io.IOException) AddressList(com.google.api.services.compute.model.AddressList)

Aggregations

Address (com.google.api.services.compute.model.Address)5 IOException (java.io.IOException)3 AddressList (com.google.api.services.compute.model.AddressList)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Insert (com.google.api.services.compute.Compute.Addresses.Insert)1 AddressAggregatedList (com.google.api.services.compute.model.AddressAggregatedList)1 AddressesScopedList (com.google.api.services.compute.model.AddressesScopedList)1 Operation (com.google.api.services.compute.model.Operation)1 ImmutableList (com.google.common.collect.ImmutableList)1 GcpResourceException (com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1