Merge pull request #166 from vijaykiran/networkclient-fixes

Sync the output of network json with the domain model
This commit is contained in:
Adrian Cole 2011-11-17 05:03:08 -08:00
commit 3b4bc8d1d2
3 changed files with 37 additions and 90 deletions

View File

@ -18,19 +18,18 @@
*/ */
package org.jclouds.cloudstack.domain; package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.gson.annotations.SerializedName;
import javax.annotation.Nullable;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.gson.annotations.SerializedName;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -42,13 +41,11 @@ public class Network implements Comparable<Network> {
public static class Builder { public static class Builder {
private long id; private long id;
private String account;
private String broadcastDomainType; private String broadcastDomainType;
private URI broadcastURI; private URI broadcastURI;
private String displayText; private String displayText;
private List<String> DNS = ImmutableList.of(); private List<String> DNS = ImmutableList.of();
private String domain; private String domain;
private long domainId;
private String endIP; private String endIP;
private String gateway; private String gateway;
private boolean isDefault; private boolean isDefault;
@ -75,11 +72,6 @@ public class Network implements Comparable<Network> {
return this; return this;
} }
public Builder account(String account) {
this.account = account;
return this;
}
public Builder broadcastDomainType(String broadcastDomainType) { public Builder broadcastDomainType(String broadcastDomainType) {
this.broadcastDomainType = broadcastDomainType; this.broadcastDomainType = broadcastDomainType;
return this; return this;
@ -105,11 +97,6 @@ public class Network implements Comparable<Network> {
return this; return this;
} }
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder endIP(String endIP) { public Builder endIP(String endIP) {
this.endIP = endIP; this.endIP = endIP;
return this; return this;
@ -211,7 +198,7 @@ public class Network implements Comparable<Network> {
} }
public Network build() { public Network build() {
return new Network(id, account, broadcastDomainType, broadcastURI, displayText, DNS, domain, domainId, endIP, return new Network(id, broadcastDomainType, broadcastURI, displayText, DNS, domain, endIP,
gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability, gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability,
networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state, networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state,
guestIPType, VLAN, trafficType, zoneId, services); guestIPType, VLAN, trafficType, zoneId, services);
@ -219,7 +206,6 @@ public class Network implements Comparable<Network> {
} }
private long id; private long id;
private String account;
@SerializedName("broadcastdomaintype") @SerializedName("broadcastdomaintype")
private String broadcastDomainType; private String broadcastDomainType;
@SerializedName("broadcasturi") @SerializedName("broadcasturi")
@ -230,10 +216,8 @@ public class Network implements Comparable<Network> {
private String DNS1; private String DNS1;
@SerializedName("dns2") @SerializedName("dns2")
private String DNS2; private String DNS2;
@SerializedName("networkdomain")
private String domain; private String domain;
@Nullable
@SerializedName("domainid")
private long domainId;
@SerializedName("endip") @SerializedName("endip")
private String endIP; private String endIP;
private String gateway; private String gateway;
@ -279,21 +263,19 @@ public class Network implements Comparable<Network> {
} }
public Network(long id, String account, String broadcastDomainType, URI broadcastURI, String displayText, public Network(long id, String broadcastDomainType, URI broadcastURI, String displayText,
List<String> DNS, String domain, long domainId, String endIP, String gateway, boolean isDefault, List<String> DNS, String domain, String endIP, String gateway, boolean isDefault,
boolean isShared, boolean isSystem, String netmask, String networkDomain, String networkOfferingAvailability, boolean isShared, boolean isSystem, String netmask, String networkDomain, String networkOfferingAvailability,
String networkOfferingDisplayText, long networkOfferingId, String networkOfferingName, long related, String networkOfferingDisplayText, long networkOfferingId, String networkOfferingName, long related,
String startIP, String name, String state, GuestIPType type, String vLAN, TrafficType trafficType, String startIP, String name, String state, GuestIPType type, String vLAN, TrafficType trafficType,
long zoneId, Set<? extends NetworkService> services) { long zoneId, Set<? extends NetworkService> services) {
this.id = id; this.id = id;
this.account = account;
this.broadcastDomainType = broadcastDomainType; this.broadcastDomainType = broadcastDomainType;
this.broadcastURI = broadcastURI; this.broadcastURI = broadcastURI;
this.displayText = displayText; this.displayText = displayText;
this.DNS1 = checkNotNull(DNS, "DNS").size() > 0 ? DNS.get(0) : null; this.DNS1 = checkNotNull(DNS, "DNS").size() > 0 ? DNS.get(0) : null;
this.DNS2 = DNS.size() > 1 ? DNS.get(1) : null; this.DNS2 = DNS.size() > 1 ? DNS.get(1) : null;
this.domain = domain; this.domain = domain;
this.domainId = domainId;
this.endIP = endIP; this.endIP = endIP;
this.gateway = gateway; this.gateway = gateway;
this.isDefault = isDefault; this.isDefault = isDefault;
@ -323,13 +305,6 @@ public class Network implements Comparable<Network> {
return id; return id;
} }
/**
* @return the name of the account to which the template beLongs
*/
public String getAccount() {
return account;
}
/** /**
* @return Broadcast domain type of the network * @return Broadcast domain type of the network
*/ */
@ -370,14 +345,6 @@ public class Network implements Comparable<Network> {
return domain; return domain;
} }
/**
* @return the ID of the containing domain, null for public zones
*/
@Nullable
public long getDomainId() {
return domainId;
}
/** /**
* @return the end ip of the network * @return the end ip of the network
*/ */
@ -525,12 +492,10 @@ public class Network implements Comparable<Network> {
result = prime * result + ((DNS1 == null) ? 0 : DNS1.hashCode()); result = prime * result + ((DNS1 == null) ? 0 : DNS1.hashCode());
result = prime * result + ((DNS2 == null) ? 0 : DNS2.hashCode()); result = prime * result + ((DNS2 == null) ? 0 : DNS2.hashCode());
result = prime * result + ((VLAN == null) ? 0 : VLAN.hashCode()); result = prime * result + ((VLAN == null) ? 0 : VLAN.hashCode());
result = prime * result + ((account == null) ? 0 : account.hashCode());
result = prime * result + ((broadcastDomainType == null) ? 0 : broadcastDomainType.hashCode()); result = prime * result + ((broadcastDomainType == null) ? 0 : broadcastDomainType.hashCode());
result = prime * result + ((broadcastURI == null) ? 0 : broadcastURI.hashCode()); result = prime * result + ((broadcastURI == null) ? 0 : broadcastURI.hashCode());
result = prime * result + ((displayText == null) ? 0 : displayText.hashCode()); result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
result = prime * result + ((domain == null) ? 0 : domain.hashCode()); result = prime * result + ((domain == null) ? 0 : domain.hashCode());
result = prime * result + (int) (domainId ^ (domainId >>> 32));
result = prime * result + ((endIP == null) ? 0 : endIP.hashCode()); result = prime * result + ((endIP == null) ? 0 : endIP.hashCode());
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode()); result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
result = prime * result + ((guestIPType == null) ? 0 : guestIPType.hashCode()); result = prime * result + ((guestIPType == null) ? 0 : guestIPType.hashCode());
@ -578,11 +543,6 @@ public class Network implements Comparable<Network> {
return false; return false;
} else if (!VLAN.equals(other.VLAN)) } else if (!VLAN.equals(other.VLAN))
return false; return false;
if (account == null) {
if (other.account != null)
return false;
} else if (!account.equals(other.account))
return false;
if (broadcastDomainType == null) { if (broadcastDomainType == null) {
if (other.broadcastDomainType != null) if (other.broadcastDomainType != null)
return false; return false;
@ -603,8 +563,6 @@ public class Network implements Comparable<Network> {
return false; return false;
} else if (!domain.equals(other.domain)) } else if (!domain.equals(other.domain))
return false; return false;
if (domainId != other.domainId)
return false;
if (endIP == null) { if (endIP == null) {
if (other.endIP != null) if (other.endIP != null)
return false; return false;
@ -684,10 +642,10 @@ public class Network implements Comparable<Network> {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", state=" + state + ", name=" + name + ", displayText=" + displayText + ", guestIPType=" return "[id=" + id + ", state=" + state + ", name=" + name + ", displayText=" + displayText + ", guestIPType="
+ guestIPType + ", trafficType=" + trafficType + ", DNS=" + getDNS() + ", VLAN=" + VLAN + ", account=" + guestIPType + ", trafficType=" + trafficType + ", DNS=" + getDNS() + ", VLAN=" + VLAN
+ account + ", startIP=" + startIP + ", endIP=" + endIP + ", netmask=" + netmask + ", gateway=" + gateway + ", startIP=" + startIP + ", endIP=" + endIP + ", netmask=" + netmask + ", gateway=" + gateway
+ ", broadcastDomainType=" + broadcastDomainType + ", broadcastURI=" + broadcastURI + ", services=" + ", broadcastDomainType=" + broadcastDomainType + ", broadcastURI=" + broadcastURI + ", services="
+ services + ", domain=" + domain + ", domainId=" + domainId + ", isDefault=" + isDefault + ", isShared=" + services + ", domain=" + domain + ", isDefault=" + isDefault + ", isShared="
+ isShared + ", isSystem=" + isSystem + ", related=" + related + ", zoneId=" + zoneId + ", domain=" + isShared + ", isSystem=" + isSystem + ", related=" + related + ", zoneId=" + zoneId + ", domain="
+ networkDomain + ", networkOfferingAvailability=" + networkOfferingAvailability + networkDomain + ", networkOfferingAvailability=" + networkOfferingAvailability
+ ", networkOfferingDisplayText=" + networkOfferingDisplayText + ", networkOfferingId=" + networkOfferingId + ", networkOfferingDisplayText=" + networkOfferingDisplayText + ", networkOfferingId=" + networkOfferingId

View File

@ -18,22 +18,6 @@
*/ */
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.vlan;
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.specifyVLAN;
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.accountInDomain;
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jclouds.cloudstack.domain.GuestIPType; import org.jclouds.cloudstack.domain.GuestIPType;
import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkOffering; import org.jclouds.cloudstack.domain.NetworkOffering;
@ -43,6 +27,20 @@ import org.jclouds.cloudstack.predicates.ZonePredicates;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.collect.Iterables.*;
import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.vlan;
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.specifyVLAN;
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.accountInDomain;
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
/** /**
* Tests behavior of {@code NetworkClientLiveTest} * Tests behavior of {@code NetworkClientLiveTest}
* *
@ -151,7 +149,6 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
assert network.getName() != null : network; assert network.getName() != null : network;
assert network.getDNS().size() != 0 : network; assert network.getDNS().size() != 0 : network;
assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network; assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network;
assert network.getAccount() != null : network;
assert network.getBroadcastDomainType() != null : network; assert network.getBroadcastDomainType() != null : network;
assert network.getDisplayText() != null : network; assert network.getDisplayText() != null : network;
// Network domain can be null sometimes // Network domain can be null sometimes
@ -166,7 +163,6 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
assert network.getTrafficType() != null : network; assert network.getTrafficType() != null : network;
assert network.getZoneId() > 0 : network; assert network.getZoneId() > 0 : network;
assert network.getDomain() != null : network; assert network.getDomain() != null : network;
assert network.getDomainId() > 0 : network;
switch (network.getGuestIPType()) { switch (network.getGuestIPType()) {
case VIRTUAL: case VIRTUAL:
assert network.getNetmask() == null : network; assert network.getNetmask() == null : network;

View File

@ -18,9 +18,7 @@
*/ */
package org.jclouds.cloudstack.parse; package org.jclouds.cloudstack.parse;
import java.net.URI; import com.google.common.collect.*;
import java.util.Set;
import org.jclouds.cloudstack.domain.GuestIPType; import org.jclouds.cloudstack.domain.GuestIPType;
import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkService; import org.jclouds.cloudstack.domain.NetworkService;
@ -29,11 +27,8 @@ import org.jclouds.json.BaseSetParserTest;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import java.net.URI;
import com.google.common.collect.ImmutableMap; import java.util.Set;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
/** /**
* *
@ -71,8 +66,6 @@ public class ListNetworksResponseTest extends BaseSetParserTest<Network> {
.broadcastURI(URI.create("vlan://240")) .broadcastURI(URI.create("vlan://240"))
.DNS(ImmutableList.of("8.8.8.8")) .DNS(ImmutableList.of("8.8.8.8"))
.guestIPType(GuestIPType.VIRTUAL) .guestIPType(GuestIPType.VIRTUAL)
.account("adrian")
.domainId(1)
.domain("ROOT") .domain("ROOT")
.isDefault(true) .isDefault(true)
.services( .services(