http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java index 1dc8cd7..91c15f4 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java @@ -16,1154 +16,196 @@ */ package org.jclouds.googlecomputeengine.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Optional.fromNullable; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.getLast; +import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf; -import java.beans.ConstructorProperties; import java.net.URI; -import java.util.Date; -import java.util.Set; +import java.util.List; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; -import com.google.common.annotations.Beta; -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; +import com.google.auto.value.AutoValue; -/** - * Represents a virtual machine. - */ -@Beta -public class Instance extends Resource { - - public enum Status { - PROVISIONING, - STAGING, - RUNNING, - STOPPING, - STOPPED, - TERMINATED - } - - protected final Tags tags; - protected final URI machineType; - protected final Status status; - protected final Optional<String> statusMessage; - protected final URI zone; - protected final Set<NetworkInterface> networkInterfaces; - protected final Set<AttachedDisk> disks; - protected final Metadata metadata; - protected final Set<ServiceAccount> serviceAccounts; - - protected Instance(String id, Date creationTimestamp, URI selfLink, String name, String description, - Tags tags, URI machineType, Status status, String statusMessage, - URI zone, Set<NetworkInterface> networkInterfaces, Set<AttachedDisk> disks, - Metadata metadata, Set<ServiceAccount> serviceAccounts) { - super(Kind.INSTANCE, id, creationTimestamp, selfLink, name, description); - this.tags = checkNotNull(tags, "tags"); - this.machineType = checkNotNull(machineType, "machineType of %s", name); - this.status = checkNotNull(status, "status"); - this.statusMessage = fromNullable(statusMessage); - this.zone = checkNotNull(zone, "zone of %s", name); - this.networkInterfaces = networkInterfaces == null ? ImmutableSet.<NetworkInterface>of() : networkInterfaces; - this.disks = disks == null ? ImmutableSet.<AttachedDisk>of() : disks; - this.metadata = checkNotNull(metadata, "metadata"); - this.serviceAccounts = serviceAccounts == null ? ImmutableSet.<ServiceAccount>of() : serviceAccounts; - } - - /** - * Used to identify valid sources or targets for network firewalls. Provided by the client when the instance is - * created. Each tag must be unique, must be 1-63 characters long, and comply with RFC1035. - * - * @return an optional set of items applied to this instance. - */ - public Tags getTags() { - return tags; - } - - /** - * @return URL of the machine type resource describing which machine type to use to host the instance. - */ - public URI getMachineType() { - return machineType; - } - - /** - * @return Instance status - */ - public Status getStatus() { - return status; - } - - /** - * @return an optional, human-readable explanation of the status. - */ - @Nullable - public Optional<String> getStatusMessage() { - return statusMessage; - } - - /** - * @return URL of the zone resource describing where this instance should be hosted; provided by the client when - * the instance is created. - */ - public URI getZone() { - return zone; - } - - /** - * @return set of NetworkInterfaces - * @see NetworkInterface - */ - public Set<NetworkInterface> getNetworkInterfaces() { - return networkInterfaces; - } - - /** - * @return array of disks associated with this instance. Persistent disks must be created before - * you can assign them. - * @see org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk - */ - public Set<AttachedDisk> getDisks() { - return disks; - } - - /** - * @return metadata for this instance - */ - public Metadata getMetadata() { - return metadata; - } - - /** - * @return list of service accounts each with specified scopes. - * @see ServiceAccount - */ - public Set<ServiceAccount> getServiceAccounts() { - return serviceAccounts; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - Instance that = Instance.class.cast(obj); - return equal(this.kind, that.kind) - && equal(this.name, that.name) - && equal(this.zone, that.zone); - } - - /** - * {@inheritDoc} - */ - @Override - protected Objects.ToStringHelper string() { - return super.string() - .omitNullValues() - .add("items", tags) - .add("machineType", machineType) - .add("status", status) - .add("statusMessage", statusMessage.orNull()) - .add("zone", zone) - .add("networkInterfaces", networkInterfaces) - .add("disks", disks) - .add("metadata", metadata) - .add("serviceAccounts", serviceAccounts); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromInstance(this); - } - - public static final class Builder extends Resource.Builder<Builder> { - - private Tags tags; - private URI machineType; - private Status status; - private String statusMessage; - private URI zone; - private Metadata metadata; - private ImmutableSet.Builder<NetworkInterface> networkInterfaces = ImmutableSet.builder(); - private ImmutableSet.Builder<AttachedDisk> disks = ImmutableSet.builder(); - private ImmutableSet.Builder<ServiceAccount> serviceAccounts = ImmutableSet.builder(); - - - /** - * @see Instance#getTags() - */ - public Builder tags(Tags tags) { - this.tags = tags; - return this; - } - - /** - * @see Instance#getMachineType() - */ - public Builder machineType(URI machineType) { - this.machineType = machineType; - return this; - } - - /** - * @see Instance#getStatus() - */ - public Builder status(Status status) { - this.status = status; - return this; - } - - /** - * @see Instance#getStatusMessage() - */ - public Builder statusMessage(String statusMessage) { - this.statusMessage = statusMessage; - return this; - } - - /** - * @see Instance#getZone() - */ - public Builder zone(URI zone) { - this.zone = zone; - return this; - } - - /** - * @see Instance#getNetworkInterfaces() - */ - public Builder addNetworkInterface(NetworkInterface networkInterface) { - this.networkInterfaces.add(networkInterface); - return this; - } - - /** - * @see Instance#getNetworkInterfaces() - */ - public Builder networkInterfaces(Set<NetworkInterface> networkInterfaces) { - this.networkInterfaces.addAll(networkInterfaces); - return this; - } - - /** - * @see Instance#getDisks() - */ - public Builder addDisk(AttachedDisk disk) { - this.disks.add(disk); - return this; - } - - /** - * @see Instance#getDisks() - */ - public Builder disks(Set<AttachedDisk> disks) { - this.disks.addAll(disks); - return this; - } - - /** - * @see Instance#getMetadata() - */ - public Builder metadata(Metadata metadata) { - this.metadata = metadata; - return this; - } - - /** - * @see Instance#getServiceAccounts() - */ - public Builder addServiceAccount(ServiceAccount serviceAccount) { - this.serviceAccounts.add(serviceAccount); - return this; - } - - /** - * @see Instance#getServiceAccounts() - */ - public Builder serviceAccounts(Set<ServiceAccount> serviceAccounts) { - this.serviceAccounts.addAll(serviceAccounts); - return this; - } - - - @Override - protected Builder self() { - return this; - } - - public Instance build() { - return new Instance(super.id, super.creationTimestamp, super.selfLink, super.name, - super.description, tags, machineType, status, statusMessage, zone, - networkInterfaces.build(), disks.build(), metadata, serviceAccounts.build()); - } - - public Builder fromInstance(Instance in) { - return super.fromResource(in) - .tags(in.getTags()) - .machineType(in.getMachineType()) - .status(in.getStatus()) - .statusMessage(in.getStatusMessage().orNull()) - .zone(in.getZone()) - .networkInterfaces(in.getNetworkInterfaces()) - .disks(in.getDisks()) - .metadata(in.getMetadata()) - .serviceAccounts(in.getServiceAccounts()); - } - } - - - - - /** - * Tags for an instance, with their fingerprint. - */ - public static class Tags { - private final String fingerprint; - private final Set<String> items; - - @ConstructorProperties({"fingerprint", "items"}) - public Tags(String fingerprint, @Nullable Set<String> items) { - this.fingerprint = checkNotNull(fingerprint); - this.items = items == null ? ImmutableSet.<String>of() : items; - } - - /** - * Used to identify valid sources or targets for network firewalls. Provided by the client when the instance is - * created. Each tag must be unique, must be 1-63 characters long, and comply with RFC1035. - * - * @return an optional set of items applied to this instance. - */ - public Set<String> getItems() { - return items; - } - - /** - * Gets the fingerprint for the items - needed for updating them. - * - * @return the fingerprint string for the items. - */ - public String getFingerprint() { - return fingerprint; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(fingerprint, items); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - Tags that = Tags.class.cast(obj); - return equal(this.items, that.items) - && equal(this.fingerprint, that.fingerprint); - } - - protected Objects.ToStringHelper string() { - return toStringHelper(this) - .add("items", items) - .add("fingerprint", fingerprint); - } - - public static Builder builder() { - return new Builder(); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static final class Builder { - - private ImmutableSet.Builder<String> items = ImmutableSet.builder(); - private String fingerprint; - - /** - * @see Tags#getItems() - */ - public Builder addItem(String item) { - this.items.add(item); - return this; - } +/** Represents a virtual machine. */ +@AutoValue +public abstract class Instance { - /** - * @see Tags#getItems() - */ - public Builder items(Set<String> items) { - this.items.addAll(items); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.Tags#getFingerprint() - */ - public Builder fingerprint(String fingerprint) { - this.fingerprint = fingerprint; - return this; - } - - public Tags build() { - return new Tags(this.fingerprint, this.items.build()); - } - - public Builder fromTags(Tags in) { - return this.fingerprint(in.getFingerprint()) - .items(in.getItems()); - } - } - } - - /** - * A disk attached to an Instance. - * - * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances"/> - */ - public static class AttachedDisk { - - private final int index; - - public AttachedDisk(Integer index) { - this.index = checkNotNull(index, "index"); - } - - public boolean isPersistent() { - return false; - } - - /** - * @return a zero-based index to assign to this disk, where 0 is reserved for the boot disk. - */ - public int getIndex() { - return index; - } - - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(index); - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - AttachedDisk that = AttachedDisk.class.cast(obj); - return equal(this.index, that.index); - } - - protected Objects.ToStringHelper string() { - return toStringHelper(this).add("index", index); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); + @AutoValue + public abstract static class AttachedDisk { + public enum Type { + PERSISTENT, + SCRATCH; } - public static AttachedDisk ephemeralDiskAtIndex(Integer index) { - return new AttachedDisk(index); - } - } - - public static class PersistentAttachedDisk extends AttachedDisk { public enum Mode { READ_WRITE, READ_ONLY; } - @ConstructorProperties({"mode", "source", "deviceName", "index", "deleteOnTerminate", - "boot"}) - public PersistentAttachedDisk(Mode mode, URI source, String deviceName, Integer index, - boolean deleteOnTerminate, boolean boot) { - super(index); - this.mode = checkNotNull(mode, "mode"); - this.source = checkNotNull(source, "source"); - this.deviceName = fromNullable(deviceName); - this.deleteOnTerminate = deleteOnTerminate; - this.boot = boot; - } + /** A zero-based index to assign to this disk, where 0 is reserved for the boot disk. */ + @Nullable public abstract int index(); - private final Mode mode; - private final URI source; - private final boolean deleteOnTerminate; - private final Optional<String> deviceName; - private final boolean boot; + public abstract Type type(); - @Override - public boolean isPersistent() { - return true; - } + public abstract Mode mode(); - /** - * @return the mode in which to attach this disk, either READ_WRITE or READ_ONLY. - */ - public Mode getMode() { - return mode; - } + /** Corresponds to {@linkplain Disk#selfLink()} when {@linkplain #type()} is {@linkplain Type#PERSISTENT}. */ + @Nullable public abstract URI source(); /** - * @return the URL of the persistent disk resource. + * Must be unique within the instance when specified. This represents a unique + * device name that is reflected into the /dev/ tree of a Linux operating system running within the + * instance. If not specified, a default will be chosen by the system. */ - public URI getSource() { - return source; - } + @Nullable public abstract String deviceName(); - /** - * @return the Name of the persistent disk resource - */ - public String getSourceDiskName() { - return getLast(Splitter.on("/").split(source.toString()), null); - } + public abstract boolean autoDelete(); - /** - * @return Must be unique within the instance when specified. This represents a unique - * device name that is reflected into the /dev/ tree of a Linux operating system running within the - * instance. If not specified, a default will be chosen by the system. - */ - public Optional<String> getDeviceName() { - return deviceName; - } - - - /** - * @return If true, delete the disk and all its data when the associated instance is deleted. - */ - public boolean isDeleteOnTerminate() { - return deleteOnTerminate; - } + public abstract boolean boot(); - /** - * @return If true, this is the boot disk for this instance. - */ - public boolean isBoot() { - return boot; + @SerializedNames({ "index", "type", "mode", "source", "deviceName", "autoDelete", "boot" }) + public static AttachedDisk create(int index, Type type, Mode mode, URI source, String deviceName, + boolean autoDelete, boolean boot) { + return new AutoValue_Instance_AttachedDisk(index, type, mode, source, deviceName, autoDelete, boot); } - public static Builder builder() { - return new Builder(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Objects.ToStringHelper string() { - return toStringHelper(this).add("boot", boot); - } - - - public static final class Builder { - - private Mode mode; - private URI source; - private String deviceName; - private Integer index; - private boolean deleteOnTerminate; - private boolean boot; - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#getMode() - */ - public Builder mode(Mode mode) { - this.mode = mode; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#getSource() - */ - public Builder source(URI source) { - this.source = source; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#getDeviceName() - */ - public Builder deviceName(String deviceName) { - this.deviceName = deviceName; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk#getIndex() - */ - public Builder index(Integer index) { - this.index = index; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#isDeleteOnTerminate() - */ - public Builder deleteOnTerminate(Boolean deleteOnTerminate) { - this.deleteOnTerminate = deleteOnTerminate; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#isBoot() - */ - public Builder boot(Boolean boot) { - this.boot = boot; - return this; - } - - public PersistentAttachedDisk build() { - return new PersistentAttachedDisk(this.mode, this.source, this.deviceName, this.index, - this.deleteOnTerminate, this.boot); - } - - public Builder fromPersistentAttachedDisk(PersistentAttachedDisk in) { - return this.mode(in.getMode()) - .source(in.getSource()) - .deviceName(in.getDeviceName().orNull()) - .index(in.getIndex()) - .deleteOnTerminate(in.isDeleteOnTerminate()) - .boot(in.isBoot()); - } + AttachedDisk() { } } - /** - * A network interface for an Instance. - * - * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances"/> - */ - public static final class NetworkInterface { - - private final String name; - private final URI network; - private final Optional<String> networkIP; - private final Set<AccessConfig> accessConfigs; - - @ConstructorProperties({ - "name", "network", "networkIP", "accessConfigs" - }) - private NetworkInterface(String name, URI network, String networkIP, - Set<AccessConfig> accessConfigs) { - this.name = checkNotNull(name, "name"); - this.network = checkNotNull(network, "network"); - this.networkIP = fromNullable(networkIP); - this.accessConfigs = accessConfigs == null ? ImmutableSet.<AccessConfig>of() : accessConfigs; - } - - /** - * @return the name of the network interface - */ - public String getName() { - return name; - } - + @AutoValue + public abstract static class NetworkInterface { /** - * @return URL of the network resource attached to this interface. - */ - public URI getNetwork() { - return network; - } - - /** - * @return An IPV4 internal network address to assign to this instance. - */ - public Optional<String> getNetworkIP() { - return networkIP; - } - - /** - * @return array of access configurations for this interface. - */ - public Set<AccessConfig> getAccessConfigs() { - return accessConfigs; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(name, network, networkIP, accessConfigs); - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - NetworkInterface that = NetworkInterface.class.cast(obj); - return equal(this.name, that.name) - && equal(this.network, that.network); - } - - protected Objects.ToStringHelper string() { - return toStringHelper(this) - .add("name", name) - .add("network", network).add("networkIP", networkIP).add("accessConfigs", - accessConfigs); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromNetworkInterface(this); - } - - public static class Builder { - - private String name; - private URI network; - private String networkIP; - private ImmutableSet.Builder<AccessConfig> accessConfigs = ImmutableSet.builder(); - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getName() - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getNetwork() - */ - public Builder network(URI network) { - this.network = network; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getNetworkIP() - */ - public Builder networkIP(String networkIP) { - this.networkIP = networkIP; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getAccessConfigs() - */ - public Builder addAccessConfig(AccessConfig accessConfig) { - this.accessConfigs.add(accessConfig); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getAccessConfigs() - */ - public Builder accessConfigs(Set<AccessConfig> accessConfigs) { - this.accessConfigs = ImmutableSet.builder(); - this.accessConfigs.addAll(accessConfigs); - return this; - } - - public NetworkInterface build() { - return new NetworkInterface(this.name, this.network, this.networkIP, this.accessConfigs.build()); - } - - public Builder fromNetworkInterface(NetworkInterface in) { - return this.network(in.getNetwork()) - .networkIP(in.getNetworkIP().orNull()) - .accessConfigs(in.getAccessConfigs()); - } - } - - /** - * Access configuration to an instance's network. - * <p/> * This specifies how this interface is configured to interact with other network services, - * such as connecting to the internet. Currently, ONE_TO_ONE_NAT is the only access config supported. + * such as connecting to the internet. */ - public static final class AccessConfig { + @AutoValue + public abstract static class AccessConfig { public enum Type { ONE_TO_ONE_NAT } - private Optional<String> name; - private Type type; - private Optional<String> natIP; + @Nullable public abstract String name(); - @ConstructorProperties({ - "name", "type", "natIP" - }) - private AccessConfig(String name, Type type, String natIP) { - this.name = fromNullable(name); - this.type = checkNotNull(type, "type"); - this.natIP = fromNullable(natIP); - } + public abstract Type type(); - /** - * @return name of this access configuration. - */ - public Optional<String> getName() { - return name; - } - - /** - * @return type of configuration. Must be set to ONE_TO_ONE_NAT. This configures port-for-port NAT to the - * internet. - */ - public Type getType() { - return type; - } + /** An external IP address associated with this instance, if there is one. */ + @Nullable public abstract String natIP(); - /** - * @return an external IP address associated with this instance, if there is one. - */ - @Nullable - public Optional<String> getNatIP() { - return natIP; + @SerializedNames({ "name", "type", "natIP" }) + public static AccessConfig create(String name, Type type, String natIP) { + return new AutoValue_Instance_NetworkInterface_AccessConfig(name, type, natIP); } - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(name, type, natIP); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - AccessConfig that = AccessConfig.class.cast(obj); - return equal(this.name, that.name) - && equal(this.type, that.type) - && equal(this.natIP, that.natIP); - } - - protected Objects.ToStringHelper string() { - return toStringHelper(this) - .add("name", name).add("type", type).add("natIP", natIP); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromAccessConfig(this); - } - - public static class Builder { - - private String name; - private Type type; - private String natIP; - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig#getName() - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig#getType() - */ - public Builder type(Type type) { - this.type = type; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig#getNatIP() - */ - public Builder natIP(String natIP) { - this.natIP = natIP; - return this; - } - - public AccessConfig build() { - return new AccessConfig(name, type, natIP); - } - - public Builder fromAccessConfig(AccessConfig in) { - return this.name(in.getName().orNull()) - .type(in.getType()) - .natIP(in.getNatIP().orNull()); - } + AccessConfig() { } } - } - /** - * The output of an instance's serial port; - * - * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances/serialPort"/> - */ - public static final class SerialPortOutput { + public abstract String name(); - private final Optional<String> selfLink; - private final String contents; + public abstract URI network(); - @ConstructorProperties({ - "selfLink", "contents" - }) - public SerialPortOutput(String selfLink, String contents) { - this.selfLink = fromNullable(selfLink); - this.contents = checkNotNull(contents, "contents"); - } + /** An IPV4 internal network address to assign to this instance. */ + @Nullable public abstract String networkIP(); - /** - * @return unique identifier for the resource; defined by the server (output only). - */ - public Optional<String> getSelfLink() { - return selfLink; - } + public abstract List<AccessConfig> accessConfigs(); - /** - * @return the contents of the console output. - */ - public String getContents() { - return contents; + @SerializedNames({ "name", "network", "networkIP", "accessConfigs" }) + public static NetworkInterface create(String name, URI network, String networkIP, + List<AccessConfig> accessConfigs) { + return new AutoValue_Instance_NetworkInterface(name, network, networkIP, copyOf(accessConfigs)); } - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(selfLink, contents); + NetworkInterface() { } + } - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - SerialPortOutput that = SerialPortOutput.class.cast(obj); - return equal(this.selfLink, that.selfLink); - } + @AutoValue + public abstract static class SerialPortOutput { - protected Objects.ToStringHelper string() { - return toStringHelper(this).add("selfLink", selfLink).add("contents", contents); - } + @Nullable public abstract URI selfLink(); // TODO: is this really nullable?! - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } + /** The contents of the console output. */ + public abstract String contents(); - public static Builder builder() { - return new Builder(); + @SerializedNames({ "selfLink", "contents" }) + public static SerialPortOutput create(URI selfLink, String contents) { + return new AutoValue_Instance_SerialPortOutput(selfLink, contents); } - public Builder toBuilder() { - return builder().fromInstanceSerialPortOutput(this); + SerialPortOutput() { } - - public static final class Builder { - - private String selfLink; - private String contents; - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput#getSelfLink() - */ - public Builder selfLink(String selfLink) { - this.selfLink = checkNotNull(selfLink); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput#getContents() - */ - public Builder contents(String contents) { - this.contents = contents; - return this; - } - - public SerialPortOutput build() { - return new SerialPortOutput(selfLink, contents); - } - - public Builder fromInstanceSerialPortOutput(SerialPortOutput in) { - return this.selfLink(in.getSelfLink().orNull()) - .contents(in.getContents()); - } - } - } /** * A service account for which access tokens are to be made available to the instance through metadata queries. - * - * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances"/> */ - public static final class ServiceAccount { + @AutoValue + public abstract static class ServiceAccount { - private final String email; - private final Set<String> scopes; + public abstract String email(); - @ConstructorProperties({ - "email", "scopes" - }) - public ServiceAccount(String email, Set<String> scopes) { - this.email = checkNotNull(email, "email"); - this.scopes = checkNotNull(scopes, "scopes"); - } + public abstract List<String> scopes(); - /** - * @return email address of the service account. - */ - public String getEmail() { - return email; + @SerializedNames({ "email", "scopes" }) + public static ServiceAccount create(String email, List<String> scopes) { + return new AutoValue_Instance_ServiceAccount(email, scopes); } - /** - * @return the list of scopes to be made available for this service account. - */ - public Set<String> getScopes() { - return scopes; + ServiceAccount() { } + } - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(email, scopes); - } + public enum Status { + PROVISIONING, + STAGING, + RUNNING, + STOPPING, + STOPPED, + TERMINATED + } - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ServiceAccount that = ServiceAccount.class.cast(obj); - return equal(this.email, that.email) - && equal(this.scopes, that.scopes); - } + public abstract String id(); - protected Objects.ToStringHelper string() { - return toStringHelper(this).add("email", email).add("scopes", scopes); - } + public abstract URI selfLink(); - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } + public abstract String name(); - public static Builder builder() { - return new Builder(); - } + @Nullable public abstract String description(); - public Builder toBuilder() { - return builder().fromInstanceServiceAccount(this); - } + public abstract Tags tags(); - public static final class Builder { + public abstract URI machineType(); - private String email; - private ImmutableSet.Builder<String> scopes = ImmutableSet.builder(); + public abstract Status status(); - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount#getEmail() - */ - public Builder email(String email) { - this.email = checkNotNull(email); - return this; - } + /** Human-readable explanation of the status. */ + @Nullable public abstract String statusMessage(); - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount#getScopes() - */ - public Builder addScopes(String scopes) { - this.scopes.add(scopes); - return this; - } + /** + * URL of the zone resource describing where this instance should be hosted; provided by the client when + * the instance is created. + */ + public abstract URI zone(); - /** - * @see org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount#getScopes() - */ - public Builder scopes(Set<String> scopes) { - this.scopes.addAll(scopes); - return this; - } + public abstract List<NetworkInterface> networkInterfaces(); - public ServiceAccount build() { - return new ServiceAccount(email, scopes.build()); - } + public abstract List<AttachedDisk> disks(); - public Builder fromInstanceServiceAccount(ServiceAccount in) { - return this.email(in.getEmail()).scopes(in.getScopes()); - } - } + public abstract Metadata metadata(); + + public abstract List<ServiceAccount> serviceAccounts(); + + @SerializedNames({ "id", "selfLink", "name", "description", "tags", "machineType", "status", "statusMessage", "zone", + "networkInterfaces", "disks", "metadata", "serviceAccounts" }) + public static Instance create(String id, URI selfLink, String name, String description, Tags tags, URI machineType, + Status status, String statusMessage, URI zone, List<NetworkInterface> networkInterfaces, + List<AttachedDisk> disks, Metadata metadata, List<ServiceAccount> serviceAccounts) { + return new AutoValue_Instance(id, selfLink, name, description, tags, machineType, status, statusMessage, zone, + copyOf(networkInterfaces), copyOf(disks), metadata, copyOf(serviceAccounts)); + } + + Instance() { } }
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java deleted file mode 100644 index 09a3088..0000000 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.googlecomputeengine.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; - -public class InstanceInZone extends SlashEncodedIds { - protected final Instance instance; - - public InstanceInZone(Instance instance, String zoneId) { - super(zoneId, checkNotNull(instance, "instance").getName()); - this.instance = instance; - } - - public Instance getInstance() { - return instance; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - InstanceInZone that = InstanceInZone.class.cast(obj); - return equal(this.instance, that.instance) - && equal(this.firstId, that.firstId) - && equal(this.secondId, that.secondId); - } - - @Override - public String toString() { - return "[instance=" + instance + ", zoneId=" + firstId + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java deleted file mode 100644 index 7b118bc..0000000 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.googlecomputeengine.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type; - -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; - -/** - * Optional information for creating an instance. - */ -public class InstanceTemplate { - - protected String name; - protected String description; - protected URI machineType; - protected URI image; - protected Set<Instance.ServiceAccount> serviceAccounts = Sets.newLinkedHashSet(); - - protected transient List<PersistentDisk> disks = Lists.newArrayList(); - protected transient Set<NetworkInterface> networkInterfaces = Sets.newLinkedHashSet(); - protected transient Map<String, String> metadata = Maps.newLinkedHashMap(); - protected transient String machineTypeName; - - - protected InstanceTemplate(URI machineType) { - this.machineType = checkNotNull(machineType, "machineType"); - } - - protected InstanceTemplate(String machineTypeName) { - this.machineTypeName = checkNotNull(machineTypeName, "machineTypeName"); - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getName() - */ - public InstanceTemplate name(String name) { - this.name = name; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDescription() - */ - public InstanceTemplate description(String description) { - this.description = description; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getImage() - */ - public InstanceTemplate image(URI image) { - this.image = image; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType() - */ - public InstanceTemplate machineType(URI machineType) { - this.machineType = machineType; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType() - */ - public InstanceTemplate machineType(String machineTypeName) { - this.machineTypeName = machineTypeName; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks() - */ - public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source) { - this.disks.add(new PersistentDisk(mode, source, null, false, false)); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks() - */ - public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source, Boolean deleteOnTerminate) { - this.disks.add(new PersistentDisk(mode, source, null, deleteOnTerminate, false)); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks() - */ - public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source, String deviceName, Boolean deleteOnTerminate) { - this.disks.add(new PersistentDisk(mode, source, deviceName, deleteOnTerminate, false)); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks() - */ - public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source, String deviceName, - Boolean deleteOnTerminate, Boolean boot) { - this.disks.add(new PersistentDisk(mode, source, deviceName, deleteOnTerminate, boot)); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks() - */ - public InstanceTemplate disks(List<PersistentDisk> disks) { - this.disks = Lists.newArrayList(); - this.disks.addAll(checkNotNull(disks, "disks")); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces() - */ - public InstanceTemplate addNetworkInterface(URI network) { - this.networkInterfaces.add(new NetworkInterface(checkNotNull(network, "network"), null, null)); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces() - */ - public InstanceTemplate addNetworkInterface(URI network, Type type) { - this.networkInterfaces.add(new NetworkInterface(checkNotNull(network, "network"), null, - ImmutableSet.of(Instance.NetworkInterface.AccessConfig.builder() - .type(type) - .build()))); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces() - */ - public InstanceTemplate addNetworkInterface(NetworkInterface networkInterface) { - this.networkInterfaces.add(networkInterface); - return this; - } - - public InstanceTemplate networkInterfaces(Set<NetworkInterface> networkInterfaces) { - this.networkInterfaces = Sets.newLinkedHashSet(networkInterfaces); - return this; - } - - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getMetadata() - */ - public InstanceTemplate addMetadata(String key, String value) { - this.metadata.put(checkNotNull(key, "key"), checkNotNull(value, "value of %", key)); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getMetadata() - */ - public InstanceTemplate metadata(Map<String, String> metadata) { - this.metadata = Maps.newLinkedHashMap(); - this.metadata.putAll(checkNotNull(metadata, "metadata")); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getServiceAccounts() - */ - public InstanceTemplate addServiceAccount(Instance.ServiceAccount serviceAccount) { - this.serviceAccounts.add(checkNotNull(serviceAccount, "serviceAccount")); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getServiceAccounts() - */ - public InstanceTemplate serviceAccounts(Set<Instance.ServiceAccount> serviceAccounts) { - this.serviceAccounts = Sets.newLinkedHashSet(); - this.serviceAccounts.addAll(checkNotNull(serviceAccounts, "serviceAccounts")); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDescription() - */ - public String getDescription() { - return description; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks() - */ - public List<PersistentDisk> getDisks() { - return disks; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getImage() - */ - public URI getImage() { - return image; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType() - */ - public URI getMachineType() { - return machineType; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType() - */ - public String getMachineTypeName() { - return machineTypeName; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getMetadata() - */ - public Map<String, String> getMetadata() { - return metadata; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces() - */ - public Set<NetworkInterface> getNetworkInterfaces() { - return networkInterfaces; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getServiceAccounts() - */ - public Set<Instance.ServiceAccount> getServiceAccounts() { - return serviceAccounts; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Instance#getName() - */ - public String getName() { - return name; - } - - public static Builder builder() { - return new Builder(); - } - - public static InstanceTemplate fromInstanceTemplate(InstanceTemplate instanceTemplate) { - return Builder.fromInstanceTemplate(instanceTemplate); - } - - public static class Builder { - - public InstanceTemplate forMachineType(URI machineType) { - return new InstanceTemplate(machineType); - } - - public InstanceTemplate forMachineType(String machineTypeName) { - return new InstanceTemplate(machineTypeName); - } - - public static InstanceTemplate fromInstanceTemplate(InstanceTemplate instanceTemplate) { - return InstanceTemplate.builder() - .forMachineType(instanceTemplate.getMachineType()) - .networkInterfaces(instanceTemplate.getNetworkInterfaces()) - .name(instanceTemplate.getName()) - .description(instanceTemplate.getDescription()) - .image(instanceTemplate.getImage()) - .disks(instanceTemplate.getDisks()) - .metadata(instanceTemplate.getMetadata()) - .serviceAccounts(instanceTemplate.getServiceAccounts()); - } - } - - - public static class PersistentDisk { - - public enum Mode { - READ_WRITE, - READ_ONLY - } - - public PersistentDisk(Mode mode, URI source, String deviceName, Boolean deleteOnTerminate, - Boolean boot) { - this.mode = checkNotNull(mode, "mode"); - this.source = checkNotNull(source, "source"); - this.deviceName = deviceName; - this.deleteOnTerminate = checkNotNull(deleteOnTerminate, "deleteOnTerminate"); - this.boot = checkNotNull(boot, "boot"); - } - - private final Mode mode; - private final URI source; - private final Boolean deleteOnTerminate; - private final String deviceName; - private final Boolean boot; - - /** - * @return the mode in which to attach this disk, either READ_WRITE or READ_ONLY. - */ - public Mode getMode() { - return mode; - } - - /** - * @return the URL of the persistent disk resource. - */ - public URI getSource() { - return source; - } - - /** - * @return Must be unique within the instance when specified. This represents a unique - * device name that is reflected into the /dev/ tree of a Linux operating system running within the - * instance. If not specified, a default will be chosen by the system. - */ - public String getDeviceName() { - return deviceName; - } - - - /** - * @return If true, delete the disk and all its data when the associated instance is deleted. - */ - public boolean isDeleteOnTerminate() { - return deleteOnTerminate; - } - - /** - * @return If true, boot from this disk. - */ - public boolean isBoot() { - return boot; - } - } - - public static class NetworkInterface { - - private final URI network; - private final String networkIP; - private final Set<Instance.NetworkInterface.AccessConfig> accessConfigs; - - public NetworkInterface(URI network, String networkIP, Set<Instance.NetworkInterface.AccessConfig> - accessConfigs) { - this.networkIP = networkIP; - this.network = network; - this.accessConfigs = accessConfigs != null ? accessConfigs : ImmutableSet.<Instance.NetworkInterface.AccessConfig>of(); - } - - public Set<Instance.NetworkInterface.AccessConfig> getAccessConfigs() { - return accessConfigs; - } - - public URI getNetwork() { - return network; - } - - public String getNetworkIP() { - return networkIP; - } - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof InstanceTemplate) { - final InstanceTemplate other = InstanceTemplate.class.cast(object); - return equal(description, other.description) - && equal(image, other.image) - && equal(disks, other.disks) - && equal(networkInterfaces, other.networkInterfaces) - && equal(metadata, other.metadata) - && equal(serviceAccounts, other.serviceAccounts); - } else { - return false; - } - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(description, image, disks, networkInterfaces, metadata, serviceAccounts); - } - - protected Objects.ToStringHelper string() { - Objects.ToStringHelper toString = Objects.toStringHelper("") - .omitNullValues(); - toString.add("description", description); - if (disks.size() > 0) - toString.add("disks", disks); - if (metadata.size() > 0) - toString.add("metadata", metadata); - if (serviceAccounts.size() > 0) - toString.add("serviceAccounts", serviceAccounts); - toString.add("image", image); - toString.add("networkInterfaces", networkInterfaces); - return toString; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java index 59ec775..0205df1 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java @@ -16,119 +16,44 @@ */ package org.jclouds.googlecomputeengine.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.googlecomputeengine.domain.Resource.Kind; +import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf; import java.beans.ConstructorProperties; -import java.util.Iterator; +import java.util.List; -import org.jclouds.collect.IterableWithMarker; +import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ForwardingList; /** * The collection returned from any <code>listFirstPage()</code> method. */ -public class ListPage<T> extends IterableWithMarker<T> { +public final class ListPage<T> extends ForwardingList<T> { - private final Kind kind; + private final List<T> items; private final String nextPageToken; - private final Iterable<T> items; + private final List<String> prefixes; - @ConstructorProperties({ "kind", "nextPageToken", "items" }) - protected ListPage(Kind kind, String nextPageToken, Iterable<T> items) { - this.kind = checkNotNull(kind, "kind"); - this.nextPageToken = nextPageToken; - this.items = items != null ? ImmutableList.copyOf(items) : ImmutableList.<T>of(); - } - - public Kind getKind() { - return kind; - } - - @Override - public Optional<Object> nextMarker() { - return Optional.<Object>fromNullable(nextPageToken); - } - - @Override - public Iterator<T> iterator() { - return checkNotNull(items, "items").iterator(); - } - - @Override - public int hashCode() { - return Objects.hashCode(kind, items); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; - ListPage<?> that = ListPage.class.cast(obj); - return equal(this.kind, that.kind) && equal(this.items, that.items); + public static <T> ListPage<T> create(List<T> items, String nextPageToken, List<String> prefixes) { + return new ListPage<T>(items, nextPageToken, prefixes); } - protected Objects.ToStringHelper string() { - return toStringHelper(this).omitNullValues().add("kind", kind).add("nextPageToken", nextPageToken) - .add("items", items); - } - - @Override - public String toString() { - return string().toString(); + @ConstructorProperties({ "items", "nextPageToken", "prefixes" }) + ListPage(List<T> items, String nextPageToken, List<String> prefixes) { + this.items = copyOf(items); + this.nextPageToken = nextPageToken; + this.prefixes = copyOf(prefixes); } - public static <T> Builder<T> builder() { - return new Builder<T>(); + @Nullable public String nextPageToken() { + return nextPageToken; } - public Builder<T> toBuilder() { - return new Builder<T>().fromPagedList(this); + public List<String> prefixes() { + return prefixes; } - public static final class Builder<T> { - - private Kind kind; - private String nextPageToken; - private ImmutableList.Builder<T> items = ImmutableList.builder(); - - public Builder<T> kind(Kind kind) { - this.kind = kind; - return this; - } - - public Builder<T> addItem(T item) { - this.items.add(item); - return this; - } - - public Builder<T> items(Iterable<T> items) { - this.items.addAll(items); - return this; - } - - public Builder<T> nextPageToken(String nextPageToken) { - this.nextPageToken = nextPageToken; - return this; - } - - public ListPage<T> build() { - return new ListPage<T>(kind, nextPageToken, items.build()); - } - - public Builder<T> fromPagedList(ListPage<T> in) { - return this - .kind(in.getKind()) - .nextPageToken((String) in.nextMarker().orNull()) - .items(in); - - } + @Override protected List<T> delegate() { + return items; } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java index 72b1340..3cfd92b 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java @@ -16,330 +16,67 @@ */ package org.jclouds.googlecomputeengine.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Optional.fromNullable; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf; -import java.beans.ConstructorProperties; import java.net.URI; -import java.util.Date; import java.util.List; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; -import com.google.common.annotations.Beta; -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; +import com.google.auto.value.AutoValue; -/** - * Represents a machine type used to host an instance. - */ -@Beta -public final class MachineType extends Resource { - - private final Integer guestCpus; - private final Integer memoryMb; - private final List<ScratchDisk> scratchDisks; - private final Integer maximumPersistentDisks; - private final Long maximumPersistentDisksSizeGb; - private final String zone; - private final Optional<Deprecated> deprecated; - - @ConstructorProperties({ - "id", "creationTimestamp", "selfLink", "name", "description", "guestCpus", "memoryMb", - "scratchDisks", "maximumPersistentDisks", "maximumPersistentDisksSizeGb", "zone", "deprecated" - }) - private MachineType(String id, Date creationTimestamp, URI selfLink, String name, String description, - int guestCpus, int memoryMb, List<ScratchDisk> scratchDisks, - int maximumPersistentDisks, long maximumPersistentDisksSizeGb, String zone, - @Nullable Deprecated deprecated) { - super(Kind.MACHINE_TYPE, id, creationTimestamp, selfLink, name, description); - this.guestCpus = checkNotNull(guestCpus, "guestCpus of %s", name); - this.memoryMb = checkNotNull(memoryMb, "memoryMb of %s", name); - this.scratchDisks = scratchDisks == null ? ImmutableList.<ScratchDisk>of() : scratchDisks; - this.maximumPersistentDisks = checkNotNull(maximumPersistentDisks, "maximumPersistentDisks of %s", name); - this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb; - this.zone = checkNotNull(zone, "zone of %s", name); - this.deprecated = fromNullable(deprecated); - } - - /** - * @return count of CPUs exposed to the instance. - */ - public int getGuestCpus() { - return guestCpus; - } - - /** - * @return physical memory assigned to the instance, defined in MB. - */ - public int getMemoryMb() { - return memoryMb; - } +/** Represents a machine type used to host an instance. */ +@AutoValue +public abstract class MachineType { - /** - * @return extended scratch disks assigned to the instance. - */ - public List<ScratchDisk> getScratchDisks() { - return scratchDisks; - } - - /** - * @return maximum persistent disks allowed. - */ - public int getMaximumPersistentDisks() { - return maximumPersistentDisks; - } - - /** - * @return maximum total persistent disks size (GB) allowed. - */ - public long getMaximumPersistentDisksSizeGb() { - return maximumPersistentDisksSizeGb; - } - - /** - * @return the zones that this machine type can run in. - */ - public String getZone() { - return zone; - } + @AutoValue + public abstract static class ScratchDisk { - /** - * @return the deprecation information for this machine type - */ - public Optional<Deprecated> getDeprecated() { - return deprecated; - } + public abstract int diskGb(); - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - MachineType that = MachineType.class.cast(obj); - return equal(this.kind, that.kind) - && equal(this.name, that.name) - && equal(this.zone, that.zone); - } - - /** - * {@inheritDoc} - */ - @Override - protected Objects.ToStringHelper string() { - return super.string() - .add("guestCpus", guestCpus) - .add("memoryMb", memoryMb) - .add("scratchDisks", scratchDisks) - .add("maximumPersistentDisks", maximumPersistentDisks) - .add("maximumPersistentDisksSizeGb", maximumPersistentDisksSizeGb) - .add("zone", zone) - .add("deprecated", deprecated.orNull()); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromMachineType(this); - } - - public static final class Builder extends Resource.Builder<Builder> { - - private Integer guestCpus; - private Integer memoryMb; - private Integer imageSpaceGb; - private ImmutableList.Builder<ScratchDisk> scratchDisks = ImmutableList.builder(); - private Integer maximumPersistentDisks; - private Long maximumPersistentDisksSizeGb; - private String zone; - private Deprecated deprecated; - - /** - * @see MachineType#getGuestCpus() - */ - public Builder guestCpus(int guesCpus) { - this.guestCpus = guesCpus; - return this; + @SerializedNames({ "diskGb" }) + public static ScratchDisk create(int diskGb) { + return new AutoValue_MachineType_ScratchDisk(diskGb); } - /** - * @see MachineType#getMemoryMb() - */ - public Builder memoryMb(int memoryMb) { - this.memoryMb = memoryMb; - return this; - } - - /** - * @see MachineType#getImageSpaceGb() - */ - public Builder imageSpaceGb(int imageSpaceGb) { - this.imageSpaceGb = imageSpaceGb; - return this; - } - - /** - * @see MachineType#getScratchDisks() - */ - public Builder addScratchDisk(int diskGb) { - this.scratchDisks.add(ScratchDisk.builder().diskGb(diskGb).build()); - return this; - } - - /** - * @see MachineType#getScratchDisks() - */ - public Builder scratchDisks(List<ScratchDisk> scratchDisks) { - this.scratchDisks.addAll(scratchDisks); - return this; - } - - /** - * @see MachineType#getMaximumPersistentDisks() - */ - public Builder maximumPersistentDisks(int maximumPersistentDisks) { - this.maximumPersistentDisks = maximumPersistentDisks; - return this; - } - - /** - * @see MachineType#getMaximumPersistentDisksSizeGb() - */ - public Builder maximumPersistentDisksSizeGb(long maximumPersistentDisksSizeGb) { - this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb; - return this; - } - - /** - * @see MachineType#getZone() - */ - public Builder zone(String zone) { - this.zone = zone; - return this; - } - - /** - * @see MachineType#getDeprecated() - */ - public Builder deprecated(Deprecated deprecated) { - this.deprecated = deprecated; - return this; - } - - @Override - protected Builder self() { - return this; - } - - public MachineType build() { - return new MachineType(id, creationTimestamp, selfLink, name, description, guestCpus, memoryMb, - scratchDisks.build(), maximumPersistentDisks, maximumPersistentDisksSizeGb, zone, deprecated); - } - - - public Builder fromMachineType(MachineType in) { - return super.fromResource(in).memoryMb(in.getMemoryMb()).scratchDisks(in - .getScratchDisks()).maximumPersistentDisks(in.getMaximumPersistentDisks()) - .maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in.getZone()) - .deprecated(in.getDeprecated().orNull()); + ScratchDisk() { } } - /** - * An scratch disk of a MachineType - */ - public static final class ScratchDisk { + public abstract String id(); - private final int diskGb; + public abstract URI selfLink(); - @ConstructorProperties({ - "diskGb" - }) - private ScratchDisk(int diskGb) { - this.diskGb = diskGb; - } + public abstract String name(); - /** - * @return size of the scratch disk, defined in GB. - */ - public int getDiskGb() { - return diskGb; - } + @Nullable public abstract String description(); - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(diskGb); - } + public abstract int guestCpus(); - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ScratchDisk that = ScratchDisk.class.cast(obj); - return equal(this.diskGb, that.diskGb); - } + public abstract int memoryMb(); - protected Objects.ToStringHelper string() { - return toStringHelper(this) - .add("diskGb", diskGb); - } + public abstract List<ScratchDisk> scratchDisks(); - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } + public abstract int maximumPersistentDisks(); - public Builder toBuilder() { - return builder().fromScratchDisk(this); - } + public abstract long maximumPersistentDisksSizeGb(); - public static class Builder { + /** The zones that this machine type can run in. */ + public abstract String zone(); - private int diskGb; + @Nullable public abstract Deprecated deprecated(); - /** - * @see org.jclouds.googlecomputeengine.domain.MachineType.ScratchDisk#getDiskGb() - */ - public Builder diskGb(int diskGb) { - this.diskGb = diskGb; - return this; - } - - public ScratchDisk build() { - return new ScratchDisk(diskGb); - } + @SerializedNames( + { "id", "selfLink", "name", "description", "guestCpus", "memoryMb", "scratchDisks", "maximumPersistentDisks", + "maximumPersistentDisksSizeGb", "zone", "deprecated" }) + public static MachineType create(String id, URI selfLink, String name, String description, int guestCpus, + int memoryMb, List<ScratchDisk> scratchDisks, int maximumPersistentDisks, long maximumPersistentDisksSizeGb, + String zone, Deprecated deprecated) { + return new AutoValue_MachineType(id, selfLink, name, description, guestCpus, memoryMb, copyOf(scratchDisks), + maximumPersistentDisks, maximumPersistentDisksSizeGb, zone, deprecated); + } - public Builder fromScratchDisk(ScratchDisk in) { - return new Builder().diskGb(in.getDiskGb()); - } - } + MachineType() { } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java deleted file mode 100644 index 0a4b5fb..0000000 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.googlecomputeengine.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; - -public class MachineTypeInZone extends SlashEncodedIds { - protected final MachineType machineType; - - public MachineTypeInZone(MachineType machineType, String zoneId) { - super(zoneId, checkNotNull(machineType, "machineType").getName()); - this.machineType = machineType; - } - - public MachineType getMachineType() { - return machineType; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - MachineTypeInZone that = MachineTypeInZone.class.cast(obj); - return equal(this.machineType, that.machineType) - && equal(this.firstId, that.firstId) - && equal(this.secondId, that.secondId); - } - - @Override - public String toString() { - return "[machineType=" + machineType + ", zoneId=" + firstId + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java index da08214..19b55a8 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java @@ -16,121 +16,27 @@ */ package org.jclouds.googlecomputeengine.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; +import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf; -import java.beans.ConstructorProperties; import java.util.Map; import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableMap; +import com.google.auto.value.AutoValue; -/** - * Metadata for an instance or project, with their fingerprint. - */ -public class Metadata { - @Nullable - private final String fingerprint; - private final Map<String, String> items; - - @ConstructorProperties({"fingerprint", "items"}) - public Metadata(@Nullable String fingerprint, @Nullable Map<String, String> items) { - this.fingerprint = fingerprint; - this.items = items == null ? ImmutableMap.<String, String>of() : items; - } - - /** - * @return an optional map of metadata key/value pairs for this instance/project - */ - public Map<String, String> getItems() { - return items; - } - - /** - * Gets the fingerprint for the items - needed for updating them. - * - * @return the fingerprint string for the items. - */ - public String getFingerprint() { - return fingerprint; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(fingerprint, items); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - Metadata that = Metadata.class.cast(obj); - return equal(this.items, that.items) - && equal(this.fingerprint, that.fingerprint); - } +/** Metadata for an instance or project, with their fingerprint. */ +@AutoValue +public abstract class Metadata { + /** The fingerprint for the items - needed for updating them. */ + @Nullable public abstract String fingerprint(); - protected Objects.ToStringHelper string() { - return toStringHelper(this) - .add("items", items) - .add("fingerprint", fingerprint); - } + public abstract Map<String, String> items(); - public static Builder builder() { - return new Builder(); + // No SerializedNames as custom-parsed. + public static Metadata create(String fingerprint, Map<String, String> items) { + return new AutoValue_Metadata(fingerprint, copyOf(items)); } - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static final class Builder { - - private ImmutableMap.Builder<String, String> items = ImmutableMap.builder(); - private String fingerprint; - - /** - * @see Metadata#getItems() - */ - public Builder addItem(String key, String value) { - this.items.put(key, value); - return this; - } - - /** - * @see Metadata#getItems() - */ - public Builder items(Map<String, String> items) { - this.items.putAll(items); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Metadata#getFingerprint() - */ - public Builder fingerprint(String fingerprint) { - this.fingerprint = fingerprint; - return this; - } - - public Metadata build() { - return new Metadata(this.fingerprint, this.items.build()); - } - - public Builder fromMetadata(Metadata in) { - return this.fingerprint(in.getFingerprint()) - .items(in.getItems()); - } + Metadata() { } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java index e306e73..3b7eef9 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java @@ -16,117 +16,45 @@ */ package org.jclouds.googlecomputeengine.domain; - -import static com.google.common.base.Optional.fromNullable; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.beans.ConstructorProperties; import java.net.URI; -import java.util.Date; -import com.google.common.annotations.Beta; -import com.google.common.base.Objects; -import com.google.common.base.Optional; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import com.google.auto.value.AutoValue; /** * Represents a network used to enable instance communication. */ -@Beta -public final class Network extends Resource { +@AutoValue +public abstract class Network { - private final String IPv4Range; - private final Optional<String> gatewayIPv4; + public abstract String id(); - @ConstructorProperties({ - "id", "creationTimestamp", "selfLink", "name", "description", "IPv4Range", - "gatewayIPv4" - }) - protected Network(String id, Date creationTimestamp, URI selfLink, String name, String description, - String IPv4Range, String gatewayIPv4) { - super(Kind.NETWORK, id, creationTimestamp, selfLink, name, description); - this.IPv4Range = checkNotNull(IPv4Range); - this.gatewayIPv4 = fromNullable(gatewayIPv4); - } + public abstract URI selfLink(); - /** - * @return Required; The range of internal addresses that are legal on this network. This range is a CIDR - * specification, for example: 192.168.0.0/16. - */ - public String getIPv4Range() { - return IPv4Range; - } + public abstract String name(); - /** - * This must be within the range specified by IPv4Range, and is typically the first usable address in that range. - * If not specified, the default value is the first usable address in IPv4Range. - * - * @return an optional address that is used for default routing to other networks. - */ - public Optional<String> getGatewayIPv4() { - return gatewayIPv4; - } + @Nullable public abstract String description(); /** - * {@inheritDoc} + * The range of internal addresses that are legal on this network. This range is a CIDR + * specification, for example: {@code 192.168.0.0/16}. */ - @Override - protected Objects.ToStringHelper string() { - return super.string() - .omitNullValues() - .add("IPv4Range", IPv4Range) - .add("gatewayIPv4", gatewayIPv4.orNull()); - } + public abstract String rangeIPv4(); /** - * {@inheritDoc} + * This must be within the range specified by IPv4Range, and is typically the first usable address in that range. + * If not specified, the default value is the first usable address in IPv4Range. */ - @Override - public String toString() { - return string().toString(); - } + @Nullable public abstract String gatewayIPv4(); - public static Builder builder() { - return new Builder(); + @SerializedNames({ "id", "selfLink", "name", "description", "IPv4Range", "gatewayIPv4" }) + public static Network create(String id, URI selfLink, String name, String description, String rangeIPv4, + String gatewayIPv4) { + return new AutoValue_Network(id, selfLink, name, description, rangeIPv4, gatewayIPv4); } - public Builder toBuilder() { - return new Builder().fromNetwork(this); - } - - public static final class Builder extends Resource.Builder<Builder> { - - private String IPv4Range; - private String gatewayIPv4; - - /** - * @see Network#getIPv4Range() - */ - public Builder IPv4Range(String IPv4Range) { - this.IPv4Range = IPv4Range; - return this; - } - - /** - * @see Network#getGatewayIPv4() - */ - public Builder gatewayIPv4(String gatewayIPv4) { - this.gatewayIPv4 = gatewayIPv4; - return this; - } - - @Override - protected Builder self() { - return this; - } - - public Network build() { - return new Network(super.id, super.creationTimestamp, super.selfLink, super.name, - super.description, IPv4Range, gatewayIPv4); - } - - public Builder fromNetwork(Network in) { - return super.fromResource(in); - } + Network() { } - }
