From 397231284de78b0827a7ac592f74859d3a64367a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 12 Jul 2012 18:09:14 -0700 Subject: [PATCH] vcloud tidies --- .../vcloud/config/VCloudRestClientModule.java | 16 +-- .../domain/internal/ReferenceTypeImpl.java | 51 +++----- .../vcloud/domain/internal/TaskImpl.java | 6 +- .../vcloud/domain/network/DhcpService.java | 53 +++----- .../vcloud/domain/network/Features.java | 49 +++---- .../domain/network/FirewallService.java | 40 +++--- .../vcloud/domain/network/IpRange.java | 41 +++--- .../vcloud/domain/network/IpScope.java | 82 +++--------- .../vcloud/domain/network/NatService.java | 54 +++----- .../vcloud/domain/network/OrgNetwork.java | 4 +- .../network/firewall/FirewallProtocols.java | 34 ++--- .../domain/network/firewall/FirewallRule.java | 62 +++------ .../network/internal/OrgNetworkImpl.java | 121 ++++-------------- .../network/nat/rules/OneToOneVmRule.java | 25 ++++ .../network/nat/rules/PortForwardingRule.java | 57 +++------ .../domain/network/nat/rules/VmRule.java | 61 +++------ ...atalog.java => CatalogItemsInCatalog.java} | 4 +- ...ItemsInOrg.java => CatalogItemsInOrg.java} | 4 +- ...lCatalogsInOrg.java => CatalogsInOrg.java} | 4 +- .../vcloud/functions/NetworksInOrg.java | 72 +++++++++++ .../{AllVDCsInOrg.java => VDCsInOrg.java} | 4 +- 21 files changed, 329 insertions(+), 515 deletions(-) rename apis/vcloud/src/main/java/org/jclouds/vcloud/functions/{AllCatalogItemsInCatalog.java => CatalogItemsInCatalog.java} (92%) rename apis/vcloud/src/main/java/org/jclouds/vcloud/functions/{AllCatalogItemsInOrg.java => CatalogItemsInOrg.java} (92%) rename apis/vcloud/src/main/java/org/jclouds/vcloud/functions/{AllCatalogsInOrg.java => CatalogsInOrg.java} (92%) create mode 100644 apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java rename apis/vcloud/src/main/java/org/jclouds/vcloud/functions/{AllVDCsInOrg.java => VDCsInOrg.java} (92%) diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index 1040931bfe..3651bc274c 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -92,10 +92,10 @@ import org.jclouds.vcloud.features.VDCAsyncClient; import org.jclouds.vcloud.features.VDCClient; import org.jclouds.vcloud.features.VmAsyncClient; import org.jclouds.vcloud.features.VmClient; -import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog; -import org.jclouds.vcloud.functions.AllCatalogItemsInOrg; -import org.jclouds.vcloud.functions.AllCatalogsInOrg; -import org.jclouds.vcloud.functions.AllVDCsInOrg; +import org.jclouds.vcloud.functions.CatalogItemsInCatalog; +import org.jclouds.vcloud.functions.CatalogItemsInOrg; +import org.jclouds.vcloud.functions.CatalogsInOrg; +import org.jclouds.vcloud.functions.VDCsInOrg; import org.jclouds.vcloud.functions.DefaultNetworkNameInTemplate; import org.jclouds.vcloud.functions.OrgsForLocations; import org.jclouds.vcloud.functions.OrgsForNames; @@ -179,10 +179,10 @@ public class VCloudRestClientModule extends RestClientModule() { }); bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { + }).to(new TypeLiteral() { }); bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { + }).to(new TypeLiteral() { }); bind(new TypeLiteral, Iterable>>() { }).to(new TypeLiteral() { @@ -191,10 +191,10 @@ public class VCloudRestClientModule extends RestClientModule() { }); bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { + }).to(new TypeLiteral() { }); bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { + }).to(new TypeLiteral() { }); bindCacheLoaders(); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/ReferenceTypeImpl.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/ReferenceTypeImpl.java index 95008bbeed..27c3efbb44 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/ReferenceTypeImpl.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/ReferenceTypeImpl.java @@ -18,10 +18,15 @@ */ package org.jclouds.vcloud.domain.internal; +import static com.google.common.base.Objects.equal; + import java.net.URI; import org.jclouds.vcloud.domain.ReferenceType; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + /** * Location of a Rest resource * @@ -60,44 +65,26 @@ public class ReferenceTypeImpl implements ReferenceType { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((href == null) ? 0 : href.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ReferenceTypeImpl that = ReferenceTypeImpl.class.cast(o); + return equal(this.href, that.href); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ReferenceTypeImpl other = (ReferenceTypeImpl) obj; - if (href == null) { - if (other.href != null) - return false; - } else if (!href.equals(other.href)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(href); } @Override public String toString() { - return "[href=" + href + ", name=" + name + ", type=" + type + "]"; + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").omitNullValues().add("href", href).add("name", name).add("type", type); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java index 1671d6d16b..9d117d81df 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java @@ -89,9 +89,9 @@ public class TaskImpl extends ReferenceTypeImpl implements Task { @Override public String toString() { - return Objects.toStringHelper("").add("href", getHref()).add("name", getName()).add("owner", owner).add( - "operation", operation).add("startTime", startTime).add("endTime", endTime) - .add("expiryTime", expiryTime).add("error", error).toString(); + return Objects.toStringHelper("").omitNullValues().add("href", getHref()).add("name", getName()) + .add("owner", owner).add("operation", operation).add("startTime", startTime).add("endTime", endTime) + .add("expiryTime", expiryTime).add("error", error).toString(); } public Date getExpiryTime() { diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/DhcpService.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/DhcpService.java index 3279039c18..0363be0b22 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/DhcpService.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/DhcpService.java @@ -18,8 +18,12 @@ */ package org.jclouds.vcloud.domain.network; +import static com.google.common.base.Objects.equal; + import org.jclouds.javax.annotation.Nullable; +import com.google.common.base.Objects; + /** * specifies the properties of the network’s DHCP service */ @@ -80,48 +84,25 @@ public class DhcpService { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((defaultLeaseTime == null) ? 0 : defaultLeaseTime.hashCode()); - result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + ((ipRange == null) ? 0 : ipRange.hashCode()); - result = prime * result + ((maxLeaseTime == null) ? 0 : maxLeaseTime.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + DhcpService that = DhcpService.class.cast(o); + return equal(this.enabled, that.enabled) && equal(this.defaultLeaseTime, that.defaultLeaseTime) + && equal(this.maxLeaseTime, that.maxLeaseTime) && equal(this.ipRange, that.ipRange); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - DhcpService other = (DhcpService) obj; - if (defaultLeaseTime == null) { - if (other.defaultLeaseTime != null) - return false; - } else if (!defaultLeaseTime.equals(other.defaultLeaseTime)) - return false; - if (enabled != other.enabled) - return false; - if (ipRange == null) { - if (other.ipRange != null) - return false; - } else if (!ipRange.equals(other.ipRange)) - return false; - if (maxLeaseTime == null) { - if (other.maxLeaseTime != null) - return false; - } else if (!maxLeaseTime.equals(other.maxLeaseTime)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(enabled, defaultLeaseTime, maxLeaseTime, ipRange); } @Override public String toString() { - return "[defaultLeaseTime=" + defaultLeaseTime + ", enabled=" + enabled + ", ipRange=" + ipRange - + ", maxLeaseTime=" + maxLeaseTime + "]"; + return Objects.toStringHelper("").omitNullValues().add("enabled", enabled) + .add("defaultLeaseTime", defaultLeaseTime).add("maxLeaseTime", maxLeaseTime).add("ipRange", ipRange) + .toString(); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/Features.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/Features.java index cee229f1c0..b547b0f200 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/Features.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/Features.java @@ -18,8 +18,12 @@ */ package org.jclouds.vcloud.domain.network; +import static com.google.common.base.Objects.equal; + import org.jclouds.javax.annotation.Nullable; +import com.google.common.base.Objects; + /** * The Features element defines the DHCP and firewall features of a network. */ @@ -69,46 +73,25 @@ public class Features { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((dhcpService == null) ? 0 : dhcpService.hashCode()); - result = prime * result + ((firewallService == null) ? 0 : firewallService.hashCode()); - result = prime * result + ((natService == null) ? 0 : natService.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Features that = Features.class.cast(o); + return equal(this.dhcpService, that.dhcpService) && equal(this.firewallService, that.firewallService) + && equal(this.natService, that.natService); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Features other = (Features) obj; - if (dhcpService == null) { - if (other.dhcpService != null) - return false; - } else if (!dhcpService.equals(other.dhcpService)) - return false; - if (firewallService == null) { - if (other.firewallService != null) - return false; - } else if (!firewallService.equals(other.firewallService)) - return false; - if (natService == null) { - if (other.natService != null) - return false; - } else if (!natService.equals(other.natService)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(dhcpService, firewallService, natService); } @Override public String toString() { - return "[dhcpService=" + dhcpService + ", firewallService=" + firewallService + ", natService=" + natService - + "]"; + return Objects.toStringHelper("").omitNullValues().add("dhcpService", dhcpService) + .add("firewallService", firewallService).add("natService", natService).toString(); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/FirewallService.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/FirewallService.java index 4d72df7a9f..f4afe7d58d 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/FirewallService.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/FirewallService.java @@ -18,6 +18,7 @@ */ package org.jclouds.vcloud.domain.network; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import java.util.List; @@ -25,6 +26,8 @@ import java.util.List; import org.jclouds.javax.annotation.Nullable; import org.jclouds.vcloud.domain.network.firewall.FirewallRule; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -61,36 +64,25 @@ public class FirewallService { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + ((firewallRules == null) ? 0 : firewallRules.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + FirewallService that = FirewallService.class.cast(o); + return equal(this.enabled, that.enabled) && equal(this.firewallRules, that.firewallRules); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FirewallService other = (FirewallService) obj; - if (enabled != other.enabled) - return false; - if (firewallRules == null) { - if (other.firewallRules != null) - return false; - } else if (!firewallRules.equals(other.firewallRules)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(enabled, firewallRules); } @Override public String toString() { - return "[enabled=" + enabled + ", firewallRules=" + firewallRules + "]"; + ToStringHelper helper = Objects.toStringHelper("").omitNullValues().add("enabled", enabled); + if (firewallRules.size() > 0) + helper.add("firewallRules", firewallRules); + return helper.toString(); } - } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpRange.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpRange.java index c46d13dafb..2a4d63237d 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpRange.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpRange.java @@ -18,8 +18,11 @@ */ package org.jclouds.vcloud.domain.network; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Objects; + /** * The IpRange element defines a range of IP addresses available on a network. * @@ -52,38 +55,24 @@ public class IpRange { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((endAddress == null) ? 0 : endAddress.hashCode()); - result = prime * result + ((startAddress == null) ? 0 : startAddress.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + IpRange that = IpRange.class.cast(o); + return equal(this.startAddress, that.startAddress) && equal(this.endAddress, that.endAddress); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IpRange other = (IpRange) obj; - if (endAddress == null) { - if (other.endAddress != null) - return false; - } else if (!endAddress.equals(other.endAddress)) - return false; - if (startAddress == null) { - if (other.startAddress != null) - return false; - } else if (!startAddress.equals(other.startAddress)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(startAddress, endAddress); } @Override public String toString() { - return "[startAddress=" + startAddress + ", endAddress=" + endAddress + "]"; + return Objects.toStringHelper("").omitNullValues().add("startAddress", startAddress) + .add("endAddress", endAddress).toString(); } + } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpScope.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpScope.java index ef627f4a2d..7f830f6218 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpScope.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/IpScope.java @@ -18,12 +18,15 @@ */ package org.jclouds.vcloud.domain.network; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Set; import org.jclouds.javax.annotation.Nullable; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -138,73 +141,30 @@ public class IpScope { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((allocatedIpAddresses == null) ? 0 : allocatedIpAddresses.hashCode()); - result = prime * result + ((dns1 == null) ? 0 : dns1.hashCode()); - result = prime * result + ((dns2 == null) ? 0 : dns2.hashCode()); - result = prime * result + ((dnsSuffix == null) ? 0 : dnsSuffix.hashCode()); - result = prime * result + ((gateway == null) ? 0 : gateway.hashCode()); - result = prime * result + (inherited ? 1231 : 1237); - result = prime * result + ((ipRanges == null) ? 0 : ipRanges.hashCode()); - result = prime * result + ((netmask == null) ? 0 : netmask.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + IpScope that = IpScope.class.cast(o); + return equal(this.inherited, that.inherited) && equal(this.gateway, that.gateway) + && equal(this.netmask, that.netmask) && equal(this.dns1, that.dns1) && equal(this.dns2, that.dns2) + && equal(this.dnsSuffix, that.dnsSuffix) && equal(this.ipRanges, ipRanges) && equal(this.allocatedIpAddresses, allocatedIpAddresses); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IpScope other = (IpScope) obj; - if (allocatedIpAddresses == null) { - if (other.allocatedIpAddresses != null) - return false; - } else if (!allocatedIpAddresses.equals(other.allocatedIpAddresses)) - return false; - if (dns1 == null) { - if (other.dns1 != null) - return false; - } else if (!dns1.equals(other.dns1)) - return false; - if (dns2 == null) { - if (other.dns2 != null) - return false; - } else if (!dns2.equals(other.dns2)) - return false; - if (dnsSuffix == null) { - if (other.dnsSuffix != null) - return false; - } else if (!dnsSuffix.equals(other.dnsSuffix)) - return false; - if (gateway == null) { - if (other.gateway != null) - return false; - } else if (!gateway.equals(other.gateway)) - return false; - if (inherited != other.inherited) - return false; - if (ipRanges == null) { - if (other.ipRanges != null) - return false; - } else if (!ipRanges.equals(other.ipRanges)) - return false; - if (netmask == null) { - if (other.netmask != null) - return false; - } else if (!netmask.equals(other.netmask)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(inherited, gateway, netmask, dns1, dns2, dnsSuffix, ipRanges, allocatedIpAddresses); } @Override public String toString() { - return "[allocatedIpAddresses=" + allocatedIpAddresses + ", dns1=" + dns1 + ", dns2=" + dns2 + ", dnsSuffix=" - + dnsSuffix + ", gateway=" + gateway + ", inherited=" + inherited + ", ipRanges=" + ipRanges - + ", netmask=" + netmask + "]"; + ToStringHelper helper = Objects.toStringHelper("").omitNullValues().add("inherited", inherited).add("gateway", gateway) + .add("netmask", netmask).add("dns1", dns1).add("dns2", dns2).add("dnsSuffix", dnsSuffix); + if (ipRanges.size() >0) + helper.add("ipRanges", ipRanges); + if (allocatedIpAddresses.size() >0) + helper.add("allocatedIpAddresses", allocatedIpAddresses); + return helper.toString(); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/NatService.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/NatService.java index 4dd82a38cd..d7c066315a 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/NatService.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/NatService.java @@ -18,6 +18,7 @@ */ package org.jclouds.vcloud.domain.network; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import java.util.List; @@ -27,6 +28,8 @@ import org.jclouds.vcloud.domain.network.nat.NatPolicy; import org.jclouds.vcloud.domain.network.nat.NatRule; import org.jclouds.vcloud.domain.network.nat.NatType; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -88,48 +91,27 @@ public class NatService { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + ((natRules == null) ? 0 : natRules.hashCode()); - result = prime * result + ((policy == null) ? 0 : policy.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + NatService that = NatService.class.cast(o); + return equal(this.enabled, that.enabled) && equal(this.type, that.type) + && equal(this.policy, that.policy) && equal(this.natRules, that.natRules); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - NatService other = (NatService) obj; - if (enabled != other.enabled) - return false; - if (natRules == null) { - if (other.natRules != null) - return false; - } else if (!natRules.equals(other.natRules)) - return false; - if (policy == null) { - if (other.policy != null) - return false; - } else if (!policy.equals(other.policy)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(enabled, type, policy, natRules); } @Override public String toString() { - return "[enabled=" + enabled + ", natRules=" + natRules + ", policy=" + policy + ", type=" + type + "]"; + ToStringHelper helper = Objects.toStringHelper("").omitNullValues().add("enabled", enabled) + .add("type", type).add("policy", policy); + if (natRules.size() >0) + helper.add("natRules", natRules); + return helper.toString(); } - } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/OrgNetwork.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/OrgNetwork.java index 93e30a8914..4c07f77c0f 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/OrgNetwork.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/OrgNetwork.java @@ -24,7 +24,7 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.internal.VDCImpl; +import org.jclouds.vcloud.domain.network.internal.OrgNetworkImpl; import com.google.inject.ImplementedBy; @@ -34,7 +34,7 @@ import com.google.inject.ImplementedBy; * @author Adrian Cole */ @org.jclouds.vcloud.endpoints.Network -@ImplementedBy(VDCImpl.class) +@ImplementedBy(OrgNetworkImpl.class) public interface OrgNetwork extends ReferenceType { /** * The org this network belongs to. diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallProtocols.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallProtocols.java index 935aec8092..0fb8e2c1bd 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallProtocols.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallProtocols.java @@ -18,6 +18,10 @@ */ package org.jclouds.vcloud.domain.network.firewall; +import static com.google.common.base.Objects.equal; + +import com.google.common.base.Objects; + /** * The Protocols element specifies the protocols to which firewall rules apply. * @@ -49,33 +53,23 @@ public class FirewallProtocols { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (tcp ? 1231 : 1237); - result = prime * result + (udp ? 1231 : 1237); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + FirewallProtocols that = FirewallProtocols.class.cast(o); + return equal(this.tcp, that.tcp) && equal(this.udp, that.udp); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FirewallProtocols other = (FirewallProtocols) obj; - if (tcp != other.tcp) - return false; - if (udp != other.udp) - return false; - return true; + public int hashCode() { + return Objects.hashCode(tcp, udp); } @Override public String toString() { - return "Protocols [tcp=" + tcp + ", udp=" + udp + "]"; + return Objects.toStringHelper("").omitNullValues().add("tcp", tcp).add("udp", udp).toString(); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallRule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallRule.java index 0eacfe6252..af96596707 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallRule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/firewall/FirewallRule.java @@ -18,10 +18,13 @@ */ package org.jclouds.vcloud.domain.network.firewall; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.javax.annotation.Nullable; +import com.google.common.base.Objects; + /** * The FirewallRule element defines a single firewall rule. * @@ -98,58 +101,27 @@ public class FirewallRule { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((destinationIp == null) ? 0 : destinationIp.hashCode()); - result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + ((policy == null) ? 0 : policy.hashCode()); - result = prime * result + port; - result = prime * result + ((protocols == null) ? 0 : protocols.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + FirewallRule that = FirewallRule.class.cast(o); + return equal(this.enabled, that.enabled) && equal(this.description, that.description) + && equal(this.policy, that.policy) && equal(this.protocols, that.protocols) && equal(this.port, that.port) + && equal(this.destinationIp, that.destinationIp); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FirewallRule other = (FirewallRule) obj; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (destinationIp == null) { - if (other.destinationIp != null) - return false; - } else if (!destinationIp.equals(other.destinationIp)) - return false; - if (enabled != other.enabled) - return false; - if (policy == null) { - if (other.policy != null) - return false; - } else if (!policy.equals(other.policy)) - return false; - if (port != other.port) - return false; - if (protocols == null) { - if (other.protocols != null) - return false; - } else if (!protocols.equals(other.protocols)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(enabled, description, policy, protocols, port, destinationIp); } @Override public String toString() { - return "[description=" + description + ", destinationIp=" + destinationIp + ", enabled=" + enabled + ", policy=" - + policy + ", port=" + port + ", protocols=" + protocols + "]"; + return Objects.toStringHelper("").omitNullValues().add("enabled", enabled).add("description", description) + .add("policy", policy).add("protocols", protocols).add("port", port).add("destinationIp", destinationIp) + .toString(); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/internal/OrgNetworkImpl.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/internal/OrgNetworkImpl.java index 7af8acc259..bc5ffa633b 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/internal/OrgNetworkImpl.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/internal/OrgNetworkImpl.java @@ -18,6 +18,7 @@ */ package org.jclouds.vcloud.domain.network.internal; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; @@ -33,6 +34,8 @@ import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.IpScope; import org.jclouds.vcloud.domain.network.OrgNetwork; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -116,52 +119,25 @@ public class OrgNetworkImpl extends ReferenceTypeImpl implements OrgNetwork { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((features == null) ? 0 : features.hashCode()); - result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode()); - result = prime * result + ((ipScope == null) ? 0 : ipScope.hashCode()); - result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ConfigurationImpl that = ConfigurationImpl.class.cast(o); + return equal(this.ipScope, that.ipScope) && equal(this.parentNetwork, that.parentNetwork) + && equal(this.fenceMode, that.fenceMode) && equal(this.features, that.features); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ConfigurationImpl other = (ConfigurationImpl) obj; - if (features == null) { - if (other.features != null) - return false; - } else if (!features.equals(other.features)) - return false; - if (fenceMode == null) { - if (other.fenceMode != null) - return false; - } else if (!fenceMode.equals(other.fenceMode)) - return false; - if (ipScope == null) { - if (other.ipScope != null) - return false; - } else if (!ipScope.equals(other.ipScope)) - return false; - if (parentNetwork == null) { - if (other.parentNetwork != null) - return false; - } else if (!parentNetwork.equals(other.parentNetwork)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(ipScope, parentNetwork, fenceMode, features); } @Override public String toString() { - return "[features=" + features + ", fenceMode=" + fenceMode + ", ipScope=" + ipScope + ", parentNetwork=" - + parentNetwork + "]"; + return Objects.toStringHelper("").omitNullValues().add("ipScope", ipScope).add("parentNetwork", parentNetwork) + .add("fenceMode", fenceMode).add("features", features).toString(); } } @@ -215,65 +191,14 @@ public class OrgNetworkImpl extends ReferenceTypeImpl implements OrgNetwork { } @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((allowedExternalIpAddresses == null) ? 0 : allowedExternalIpAddresses.hashCode()); - result = prime * result + ((configuration == null) ? 0 : configuration.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((networkPool == null) ? 0 : networkPool.hashCode()); - result = prime * result + ((org == null) ? 0 : org.hashCode()); - result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - OrgNetworkImpl other = (OrgNetworkImpl) obj; - if (allowedExternalIpAddresses == null) { - if (other.allowedExternalIpAddresses != null) - return false; - } else if (!allowedExternalIpAddresses.equals(other.allowedExternalIpAddresses)) - return false; - if (configuration == null) { - if (other.configuration != null) - return false; - } else if (!configuration.equals(other.configuration)) - return false; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (networkPool == null) { - if (other.networkPool != null) - return false; - } else if (!networkPool.equals(other.networkPool)) - return false; - if (org == null) { - if (other.org != null) - return false; - } else if (!org.equals(other.org)) - return false; - if (tasks == null) { - if (other.tasks != null) - return false; - } else if (!tasks.equals(other.tasks)) - return false; - return true; - } - - @Override - public String toString() { - return "[allowedExternalIpAddresses=" + allowedExternalIpAddresses + ", configuration=" + configuration - + ", description=" + description + ", networkPool=" + networkPool + ", org=" + org + ", tasks=" + tasks - + "]"; + public ToStringHelper string() { + ToStringHelper helper = super.string().add("org", org).add("description", description) + .add("configuration", configuration).add("networkPool", networkPool); + if (allowedExternalIpAddresses.size() > 0) + helper.add("allowedExternalIpAddresses", allowedExternalIpAddresses); + if (tasks.size() > 0) + helper.add("tasks", tasks); + return helper; } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/OneToOneVmRule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/OneToOneVmRule.java index adb2cb9314..c062f10066 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/OneToOneVmRule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/OneToOneVmRule.java @@ -18,11 +18,14 @@ */ package org.jclouds.vcloud.domain.network.nat.rules; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.javax.annotation.Nullable; import org.jclouds.vcloud.domain.network.nat.NatRule; +import com.google.common.base.Objects; + /** * The OneToOneVmRule element describes a NAT rule that specifies network address translation * details for a single virtual machine. The external IP address can be specified manually or @@ -48,6 +51,28 @@ public class OneToOneVmRule implements NatRule { this.vmNicId = vmNicId; } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + OneToOneVmRule that = OneToOneVmRule.class.cast(o); + return equal(this.mappingMode, that.mappingMode) && equal(this.externalIP, that.externalIP) + && equal(this.vAppScopedVmId, that.vAppScopedVmId) && equal(this.vmNicId, that.vmNicId); + } + + @Override + public int hashCode() { + return Objects.hashCode(mappingMode, externalIP, vAppScopedVmId, vmNicId); + } + + @Override + public String toString() { + return Objects.toStringHelper("").omitNullValues().add("mappingMode", mappingMode).add("externalIP", externalIP) + .add("vAppScopedVmId", vAppScopedVmId).add("vmNicId", vmNicId).toString(); + } + /** * @return how IP address mapping is implemented by the NAT service * @since vcloud 0.9 diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/PortForwardingRule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/PortForwardingRule.java index 18ec78ca02..488467a0a5 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/PortForwardingRule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/PortForwardingRule.java @@ -18,11 +18,14 @@ */ package org.jclouds.vcloud.domain.network.nat.rules; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.vcloud.domain.network.nat.NatProtocol; import org.jclouds.vcloud.domain.network.nat.NatRule; +import com.google.common.base.Objects; + /** * The PortForwardingRule element describes a NAT rule that maps an IP address and port in an * organization network to an external IP address and port. @@ -44,7 +47,6 @@ public class PortForwardingRule implements NatRule { this.internalIP = checkNotNull(internalIP, "internalIP"); this.internalPort = internalPort; this.protocol = checkNotNull(protocol, "protocol"); - } /** @@ -85,52 +87,27 @@ public class PortForwardingRule implements NatRule { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode()); - result = prime * result + externalPort; - result = prime * result + ((internalIP == null) ? 0 : internalIP.hashCode()); - result = prime * result + internalPort; - result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + PortForwardingRule that = PortForwardingRule.class.cast(o); + return equal(this.externalIP, that.externalIP) && equal(this.externalPort, that.externalPort) + && equal(this.internalIP, that.internalIP) && equal(this.internalPort, that.internalPort) + && equal(this.protocol, that.protocol); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - PortForwardingRule other = (PortForwardingRule) obj; - if (externalIP == null) { - if (other.externalIP != null) - return false; - } else if (!externalIP.equals(other.externalIP)) - return false; - if (externalPort != other.externalPort) - return false; - if (internalIP == null) { - if (other.internalIP != null) - return false; - } else if (!internalIP.equals(other.internalIP)) - return false; - if (internalPort != other.internalPort) - return false; - if (protocol == null) { - if (other.protocol != null) - return false; - } else if (!protocol.equals(other.protocol)) - return false; - return true; + public int hashCode() { + return Objects.hashCode(externalIP, externalPort, internalIP, internalPort, protocol); } @Override public String toString() { - return "[externalIP=" + externalIP + ", externalPort=" + externalPort + ", internalIP=" + internalIP - + ", internalPort=" + internalPort + ", protocol=" + protocol + "]"; + return Objects.toStringHelper("").omitNullValues().add("externalIP", externalIP) + .add("externalPort", externalPort).add("internalIP", internalIP).add("internalPort", internalPort) + .add("protocol", protocol).toString(); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/VmRule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/VmRule.java index 69bc3f9f50..86311a5455 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/VmRule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/domain/network/nat/rules/VmRule.java @@ -18,12 +18,15 @@ */ package org.jclouds.vcloud.domain.network.nat.rules; +import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.javax.annotation.Nullable; import org.jclouds.vcloud.domain.network.nat.NatProtocol; import org.jclouds.vcloud.domain.network.nat.NatRule; +import com.google.common.base.Objects; + /** * The VmRule element describes a NAT rule that maps an IP address and port in a vApp network to an * external IP address and port. The external IP address, external port, and internal port are @@ -54,7 +57,7 @@ public class VmRule implements NatRule { } /** - * IP address to which this NAT rule maps the IP address specified in the InternalIp element. + * IP address to which this NAT rule maps the IP address specified in the vAppScopedLocalId element. */ @Nullable public String getExternalIP() { @@ -101,55 +104,27 @@ public class VmRule implements NatRule { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode()); - result = prime * result + externalPort; - result = prime * result + internalPort; - result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); - result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode()); - result = prime * result + vmNicId; - return result; + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + VmRule that = VmRule.class.cast(o); + return equal(this.externalIP, that.externalIP) && equal(this.externalPort, that.externalPort) + && equal(this.vAppScopedLocalId, that.vAppScopedLocalId) && equal(this.vmNicId, that.vmNicId) + && equal(this.internalPort, that.internalPort) && equal(this.protocol, that.protocol); } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VmRule other = (VmRule) obj; - if (externalIP == null) { - if (other.externalIP != null) - return false; - } else if (!externalIP.equals(other.externalIP)) - return false; - if (externalPort != other.externalPort) - return false; - if (internalPort != other.internalPort) - return false; - if (protocol == null) { - if (other.protocol != null) - return false; - } else if (!protocol.equals(other.protocol)) - return false; - if (vAppScopedLocalId == null) { - if (other.vAppScopedLocalId != null) - return false; - } else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId)) - return false; - if (vmNicId != other.vmNicId) - return false; - return true; + public int hashCode() { + return Objects.hashCode(externalIP, externalPort, vAppScopedLocalId, vmNicId, internalPort, protocol); } @Override public String toString() { - return "[externalIP=" + externalIP + ", externalPort=" + externalPort + ", internalPort=" + internalPort - + ", protocol=" + protocol + ", vAppScopedLocalId=" + vAppScopedLocalId + ", vmNicId=" + vmNicId + "]"; + return Objects.toStringHelper("").omitNullValues().add("externalIP", externalIP) + .add("externalPort", externalPort).add("vAppScopedLocalId", vAppScopedLocalId).add("vmNicId", vmNicId) + .add("internalPort", internalPort).add("protocol", protocol).toString(); } } \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogItemsInCatalog.java similarity index 92% rename from apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java rename to apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogItemsInCatalog.java index 0393f3b96b..71959fcf2f 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogItemsInCatalog.java @@ -45,7 +45,7 @@ import com.google.common.base.Predicate; * @author Adrian Cole */ @Singleton -public class AllCatalogItemsInCatalog implements Function> { +public class CatalogItemsInCatalog implements Function> { @Resource public Logger logger = Logger.NULL; @@ -53,7 +53,7 @@ public class AllCatalogItemsInCatalog implements Function> { +public class CatalogItemsInOrg implements Function> { private final Function> allCatalogsInOrg; private final Function> allCatalogItemsInCatalog; @Inject - AllCatalogItemsInOrg(Function> allCatalogsInOrg, + CatalogItemsInOrg(Function> allCatalogsInOrg, Function> allCatalogItemsInCatalog) { this.allCatalogsInOrg = allCatalogsInOrg; this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrg.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogsInOrg.java similarity index 92% rename from apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrg.java rename to apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogsInOrg.java index 683209f396..22172c7418 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrg.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogsInOrg.java @@ -42,7 +42,7 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class AllCatalogsInOrg implements Function> { +public class CatalogsInOrg implements Function> { @Resource public Logger logger = Logger.NULL; @@ -50,7 +50,7 @@ public class AllCatalogsInOrg implements Function> { private final ExecutorService executor; @Inject - AllCatalogsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + CatalogsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java new file mode 100644 index 0000000000..fcd86b917f --- /dev/null +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.vcloud.functions; + +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.logging.Logger; +import org.jclouds.util.Iterables2; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.network.OrgNetwork; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class NetworksInOrg implements Function> { + @Resource + public Logger logger = Logger.NULL; + + private final VCloudAsyncClient aclient; + private final ExecutorService executor; + + @Inject + NetworksInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(final Org org) { + + Iterable networkItems = transformParallel(org.getNetworks().values(), + new Function>() { + @Override + public Future apply(ReferenceType from) { + return aclient.getNetworkClient().getNetwork(from.getHref()); + } + + }, executor, null, logger, "OrgNetworks in org " + org.getName()); + return Iterables2.concreteCopy(networkItems); + } + +} \ No newline at end of file diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrg.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VDCsInOrg.java similarity index 92% rename from apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrg.java rename to apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VDCsInOrg.java index a65d6d409a..57c26a67a3 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrg.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VDCsInOrg.java @@ -42,7 +42,7 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class AllVDCsInOrg implements Function> { +public class VDCsInOrg implements Function> { @Resource public Logger logger = Logger.NULL; @@ -50,7 +50,7 @@ public class AllVDCsInOrg implements Function> { private final ExecutorService executor; @Inject - AllVDCsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + VDCsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; }