mirror of https://github.com/apache/jclouds.git
Merge pull request #166 from vijaykiran/networkclient-fixes
Sync the output of network json with the domain model
This commit is contained in:
commit
3b4bc8d1d2
|
@ -18,19 +18,18 @@
|
|||
*/
|
||||
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.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -42,13 +41,11 @@ public class Network implements Comparable<Network> {
|
|||
|
||||
public static class Builder {
|
||||
private long id;
|
||||
private String account;
|
||||
private String broadcastDomainType;
|
||||
private URI broadcastURI;
|
||||
private String displayText;
|
||||
private List<String> DNS = ImmutableList.of();
|
||||
private String domain;
|
||||
private long domainId;
|
||||
private String endIP;
|
||||
private String gateway;
|
||||
private boolean isDefault;
|
||||
|
@ -68,18 +65,13 @@ public class Network implements Comparable<Network> {
|
|||
private String VLAN;
|
||||
private TrafficType trafficType;
|
||||
private long zoneId;
|
||||
private Set<? extends NetworkService> services = ImmutableSet.<NetworkService> of();
|
||||
private Set<? extends NetworkService> services = ImmutableSet.<NetworkService>of();
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder account(String account) {
|
||||
this.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder broadcastDomainType(String broadcastDomainType) {
|
||||
this.broadcastDomainType = broadcastDomainType;
|
||||
return this;
|
||||
|
@ -105,11 +97,6 @@ public class Network implements Comparable<Network> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder domainId(long domainId) {
|
||||
this.domainId = domainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder endIP(String endIP) {
|
||||
this.endIP = endIP;
|
||||
return this;
|
||||
|
@ -206,12 +193,12 @@ public class Network implements Comparable<Network> {
|
|||
}
|
||||
|
||||
public Builder services(Set<? extends NetworkService> services) {
|
||||
this.services = ImmutableSet.<NetworkService> copyOf(checkNotNull(services, "services"));
|
||||
this.services = ImmutableSet.<NetworkService>copyOf(checkNotNull(services, "services"));
|
||||
return this;
|
||||
}
|
||||
|
||||
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,
|
||||
networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state,
|
||||
guestIPType, VLAN, trafficType, zoneId, services);
|
||||
|
@ -219,7 +206,6 @@ public class Network implements Comparable<Network> {
|
|||
}
|
||||
|
||||
private long id;
|
||||
private String account;
|
||||
@SerializedName("broadcastdomaintype")
|
||||
private String broadcastDomainType;
|
||||
@SerializedName("broadcasturi")
|
||||
|
@ -230,10 +216,8 @@ public class Network implements Comparable<Network> {
|
|||
private String DNS1;
|
||||
@SerializedName("dns2")
|
||||
private String DNS2;
|
||||
@SerializedName("networkdomain")
|
||||
private String domain;
|
||||
@Nullable
|
||||
@SerializedName("domainid")
|
||||
private long domainId;
|
||||
@SerializedName("endip")
|
||||
private String endIP;
|
||||
private String gateway;
|
||||
|
@ -270,7 +254,7 @@ public class Network implements Comparable<Network> {
|
|||
private long zoneId;
|
||||
@SerializedName("service")
|
||||
// so tests and serialization comes out expected
|
||||
private SortedSet<? extends NetworkService> services = ImmutableSortedSet.<NetworkService> of();
|
||||
private SortedSet<? extends NetworkService> services = ImmutableSortedSet.<NetworkService>of();
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
|
@ -279,21 +263,19 @@ public class Network implements Comparable<Network> {
|
|||
|
||||
}
|
||||
|
||||
public Network(long id, String account, String broadcastDomainType, URI broadcastURI, String displayText,
|
||||
List<String> DNS, String domain, long domainId, String endIP, String gateway, boolean isDefault,
|
||||
boolean isShared, boolean isSystem, String netmask, String networkDomain, String networkOfferingAvailability,
|
||||
String networkOfferingDisplayText, long networkOfferingId, String networkOfferingName, long related,
|
||||
String startIP, String name, String state, GuestIPType type, String vLAN, TrafficType trafficType,
|
||||
long zoneId, Set<? extends NetworkService> services) {
|
||||
public Network(long id, String broadcastDomainType, URI broadcastURI, String displayText,
|
||||
List<String> DNS, String domain, String endIP, String gateway, boolean isDefault,
|
||||
boolean isShared, boolean isSystem, String netmask, String networkDomain, String networkOfferingAvailability,
|
||||
String networkOfferingDisplayText, long networkOfferingId, String networkOfferingName, long related,
|
||||
String startIP, String name, String state, GuestIPType type, String vLAN, TrafficType trafficType,
|
||||
long zoneId, Set<? extends NetworkService> services) {
|
||||
this.id = id;
|
||||
this.account = account;
|
||||
this.broadcastDomainType = broadcastDomainType;
|
||||
this.broadcastURI = broadcastURI;
|
||||
this.displayText = displayText;
|
||||
this.DNS1 = checkNotNull(DNS, "DNS").size() > 0 ? DNS.get(0) : null;
|
||||
this.DNS2 = DNS.size() > 1 ? DNS.get(1) : null;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.endIP = endIP;
|
||||
this.gateway = gateway;
|
||||
this.isDefault = isDefault;
|
||||
|
@ -323,13 +305,6 @@ public class Network implements Comparable<Network> {
|
|||
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
|
||||
*/
|
||||
|
@ -370,14 +345,6 @@ public class Network implements Comparable<Network> {
|
|||
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
|
||||
*/
|
||||
|
@ -525,12 +492,10 @@ public class Network implements Comparable<Network> {
|
|||
result = prime * result + ((DNS1 == null) ? 0 : DNS1.hashCode());
|
||||
result = prime * result + ((DNS2 == null) ? 0 : DNS2.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 + ((broadcastURI == null) ? 0 : broadcastURI.hashCode());
|
||||
result = prime * result + ((displayText == null) ? 0 : displayText.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 + ((gateway == null) ? 0 : gateway.hashCode());
|
||||
result = prime * result + ((guestIPType == null) ? 0 : guestIPType.hashCode());
|
||||
|
@ -578,11 +543,6 @@ public class Network implements Comparable<Network> {
|
|||
return false;
|
||||
} else if (!VLAN.equals(other.VLAN))
|
||||
return false;
|
||||
if (account == null) {
|
||||
if (other.account != null)
|
||||
return false;
|
||||
} else if (!account.equals(other.account))
|
||||
return false;
|
||||
if (broadcastDomainType == null) {
|
||||
if (other.broadcastDomainType != null)
|
||||
return false;
|
||||
|
@ -603,8 +563,6 @@ public class Network implements Comparable<Network> {
|
|||
return false;
|
||||
} else if (!domain.equals(other.domain))
|
||||
return false;
|
||||
if (domainId != other.domainId)
|
||||
return false;
|
||||
if (endIP == null) {
|
||||
if (other.endIP != null)
|
||||
return false;
|
||||
|
@ -684,10 +642,10 @@ public class Network implements Comparable<Network> {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", state=" + state + ", name=" + name + ", displayText=" + displayText + ", guestIPType="
|
||||
+ guestIPType + ", trafficType=" + trafficType + ", DNS=" + getDNS() + ", VLAN=" + VLAN + ", account="
|
||||
+ account + ", startIP=" + startIP + ", endIP=" + endIP + ", netmask=" + netmask + ", gateway=" + gateway
|
||||
+ guestIPType + ", trafficType=" + trafficType + ", DNS=" + getDNS() + ", VLAN=" + VLAN
|
||||
+ ", startIP=" + startIP + ", endIP=" + endIP + ", netmask=" + netmask + ", gateway=" + gateway
|
||||
+ ", 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="
|
||||
+ networkDomain + ", networkOfferingAvailability=" + networkOfferingAvailability
|
||||
+ ", networkOfferingDisplayText=" + networkOfferingDisplayText + ", networkOfferingId=" + networkOfferingId
|
||||
|
|
|
@ -18,22 +18,6 @@
|
|||
*/
|
||||
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.Network;
|
||||
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.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}
|
||||
*
|
||||
|
@ -151,7 +149,6 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assert network.getName() != null : network;
|
||||
assert network.getDNS().size() != 0 : network;
|
||||
assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network;
|
||||
assert network.getAccount() != null : network;
|
||||
assert network.getBroadcastDomainType() != null : network;
|
||||
assert network.getDisplayText() != null : network;
|
||||
// Network domain can be null sometimes
|
||||
|
@ -166,7 +163,6 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assert network.getTrafficType() != null : network;
|
||||
assert network.getZoneId() > 0 : network;
|
||||
assert network.getDomain() != null : network;
|
||||
assert network.getDomainId() > 0 : network;
|
||||
switch (network.getGuestIPType()) {
|
||||
case VIRTUAL:
|
||||
assert network.getNetmask() == null : network;
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.parse;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import org.jclouds.cloudstack.domain.GuestIPType;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.domain.NetworkService;
|
||||
|
@ -29,11 +27,8 @@ import org.jclouds.json.BaseSetParserTest;
|
|||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -71,8 +66,6 @@ public class ListNetworksResponseTest extends BaseSetParserTest<Network> {
|
|||
.broadcastURI(URI.create("vlan://240"))
|
||||
.DNS(ImmutableList.of("8.8.8.8"))
|
||||
.guestIPType(GuestIPType.VIRTUAL)
|
||||
.account("adrian")
|
||||
.domainId(1)
|
||||
.domain("ROOT")
|
||||
.isDefault(true)
|
||||
.services(
|
||||
|
|
Loading…
Reference in New Issue