mirror of https://github.com/apache/jclouds.git
Issue 695: Added rest of NetworkReference object graph+services+tests. Also Networks wrapper. NetworkReference data needed when creating a VM from a template.
This commit is contained in:
parent
40df188c10
commit
a756462bc9
|
@ -39,6 +39,12 @@ public interface TerremarkEnterpriseCloudAsyncClient {
|
||||||
@Delegate
|
@Delegate
|
||||||
LocationAsyncClient getLocationClient();
|
LocationAsyncClient getLocationClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to Network features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
NetworkAsyncClient getNetworkClient();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides asynchronous access to Resource features.
|
* Provides asynchronous access to Resource features.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -49,6 +49,12 @@ public interface TerremarkEnterpriseCloudClient {
|
||||||
@Delegate
|
@Delegate
|
||||||
ResourceClient getResourceClient();
|
ResourceClient getResourceClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to Network features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
NetworkClient getNetworkClient();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides synchronous access to Task features.
|
* Provides synchronous access to Task features.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class TerremarkEnterpriseCloudRestClientModule extends
|
||||||
|
|
||||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
||||||
.put(LocationClient.class, LocationAsyncClient.class)
|
.put(LocationClient.class, LocationAsyncClient.class)
|
||||||
|
.put(NetworkClient.class, NetworkAsyncClient.class)
|
||||||
.put(ResourceClient.class, ResourceAsyncClient.class)
|
.put(ResourceClient.class, ResourceAsyncClient.class)
|
||||||
.put(TaskClient.class, TaskAsyncClient.class)
|
.put(TaskClient.class, TaskAsyncClient.class)
|
||||||
.put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)
|
.put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)
|
||||||
|
|
|
@ -0,0 +1,221 @@
|
||||||
|
/**
|
||||||
|
* 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.tmrk.enterprisecloud.domain.network;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xs:complexType name="IpAddressType">
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class IpAddress extends Resource<IpAddress> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromIpAddress(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends Resource.Builder<IpAddress> {
|
||||||
|
private NamedResource host;
|
||||||
|
private NamedResource detectedOn;
|
||||||
|
private NamedResource rnatAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see IpAddress#getHost
|
||||||
|
*/
|
||||||
|
public Builder host(NamedResource host) {
|
||||||
|
this.host = host;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see IpAddress#getDetectedOn
|
||||||
|
*/
|
||||||
|
public Builder detectedOn(NamedResource detectedOn) {
|
||||||
|
this.detectedOn = detectedOn;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see IpAddress#getRnatAddress
|
||||||
|
*/
|
||||||
|
public Builder rnatAddress(NamedResource rnatAddress) {
|
||||||
|
this.rnatAddress = rnatAddress;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IpAddress build() {
|
||||||
|
return new IpAddress(href, type, name, links, actions, host, detectedOn, rnatAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromIpAddress(IpAddress in) {
|
||||||
|
return fromResource(in).host(in.getHost()).detectedOn(in.getDetectedOn()).rnatAddress(in.getRnatAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromBaseResource(BaseResource<IpAddress> in) {
|
||||||
|
return Builder.class.cast(super.fromBaseResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromResource(Resource<IpAddress> in) {
|
||||||
|
return Builder.class.cast(super.fromResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder type(String type) {
|
||||||
|
return Builder.class.cast(super.type(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder href(URI href) {
|
||||||
|
return Builder.class.cast(super.href(href));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.name(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder links(Set<Link> links) {
|
||||||
|
return Builder.class.cast(super.links(links));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder actions(Set<Action> actions) {
|
||||||
|
return Builder.class.cast(super.actions(actions));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromAttributes(Map<String, String> attributes) {
|
||||||
|
return Builder.class.cast(super.fromAttributes(attributes));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Host", required = false)
|
||||||
|
private NamedResource host;
|
||||||
|
|
||||||
|
@XmlElement(name = "DetectedOn", required = false)
|
||||||
|
private NamedResource detectedOn;
|
||||||
|
|
||||||
|
@XmlElement(name = "RnatAddress", required = false)
|
||||||
|
private NamedResource rnatAddress;
|
||||||
|
|
||||||
|
private IpAddress(URI href, String type, String name, Set<Link> links,Set<Action> actions,
|
||||||
|
@Nullable NamedResource host,@Nullable NamedResource detectedOn,@Nullable NamedResource rnatAddress) {
|
||||||
|
super(href, type, name, links, actions);
|
||||||
|
this.host = host;
|
||||||
|
this.detectedOn = detectedOn;
|
||||||
|
this.rnatAddress = rnatAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IpAddress() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamedResource getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamedResource getDetectedOn() {
|
||||||
|
return detectedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamedResource getRnatAddress() {
|
||||||
|
return rnatAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
|
IpAddress ipAddress = (IpAddress) o;
|
||||||
|
|
||||||
|
if (detectedOn != null ? !detectedOn.equals(ipAddress.detectedOn) : ipAddress.detectedOn != null)
|
||||||
|
return false;
|
||||||
|
if (host != null ? !host.equals(ipAddress.host) : ipAddress.host != null)
|
||||||
|
return false;
|
||||||
|
if (rnatAddress != null ? !rnatAddress.equals(ipAddress.rnatAddress) : ipAddress.rnatAddress != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (host != null ? host.hashCode() : 0);
|
||||||
|
result = 31 * result + (detectedOn != null ? detectedOn.hashCode() : 0);
|
||||||
|
result = 31 * result + (rnatAddress != null ? rnatAddress.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String string() {
|
||||||
|
return super.string()+", host="+host+", detectedOn="+detectedOn+", rnatAddress="+rnatAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
/**
|
||||||
|
* 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.tmrk.enterprisecloud.domain.network;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xs:complexType name="IpAddressesType">
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class IpAddresses {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromIpAddresses(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private Set<IpAddress> addresses = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.network.IpAddresses#getIpAddresses
|
||||||
|
*/
|
||||||
|
public Builder addresses(Set<IpAddress> addresses) {
|
||||||
|
this.addresses = Sets.newLinkedHashSet(checkNotNull(addresses, "addresses"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addIpAddress(IpAddress address) {
|
||||||
|
addresses.add(checkNotNull(address, "address"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IpAddresses build() {
|
||||||
|
return new IpAddresses(addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromIpAddresses(IpAddresses in) {
|
||||||
|
return addresses(in.getIpAddresses());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IpAddresses() {
|
||||||
|
//For JAXB and builder use
|
||||||
|
}
|
||||||
|
|
||||||
|
private IpAddresses(Set<IpAddress> addresses) {
|
||||||
|
this.addresses = Sets.newLinkedHashSet(addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "IpAddress")
|
||||||
|
private Set<IpAddress> addresses = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
public Set<IpAddress> getIpAddresses() {
|
||||||
|
return Collections.unmodifiableSet(addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
IpAddresses that = (IpAddresses) o;
|
||||||
|
|
||||||
|
if (!addresses.equals(that.addresses)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return addresses.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "["+ addresses.toString()+"]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,26 +19,27 @@
|
||||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlEnum;
|
import javax.xml.bind.annotation.XmlEnum;
|
||||||
import javax.xml.bind.annotation.XmlEnumValue;
|
import javax.xml.bind.annotation.XmlEnumValue;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
|
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
|
||||||
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
|
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <xs:complexType name="NetworkReference">
|
* <xs:complexType name="NetworkReference">
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@XmlRootElement(name = "Network")
|
||||||
public class NetworkReference extends BaseNamedResource<NetworkReference> {
|
public class NetworkReference extends BaseNamedResource<NetworkReference> {
|
||||||
@XmlEnum
|
@XmlEnum
|
||||||
public static enum NetworkType {
|
public static enum NetworkType {
|
||||||
|
@ -74,7 +75,20 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
|
||||||
|
|
||||||
public static class Builder extends BaseNamedResource.Builder<NetworkReference> {
|
public static class Builder extends BaseNamedResource.Builder<NetworkReference> {
|
||||||
|
|
||||||
|
private String address;
|
||||||
private NetworkType networkType;
|
private NetworkType networkType;
|
||||||
|
private String broadcastAddress;
|
||||||
|
private String gatewayAddress;
|
||||||
|
private NamedResource rnatAddress;
|
||||||
|
private IpAddresses ipAddresses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NetworkReference#getAddress
|
||||||
|
*/
|
||||||
|
public Builder address(String address) {
|
||||||
|
this.address = address;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NetworkReference#getNetworkType
|
* @see NetworkReference#getNetworkType
|
||||||
|
@ -84,9 +98,41 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NetworkReference#getBroadcastAddress
|
||||||
|
*/
|
||||||
|
public Builder broadcastAddress(String broadcastAddress) {
|
||||||
|
this.broadcastAddress = broadcastAddress;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NetworkReference#getGatewayAddress
|
||||||
|
*/
|
||||||
|
public Builder gatewayAddress(String gatewayAddress) {
|
||||||
|
this.gatewayAddress = gatewayAddress;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NetworkReference#getRnatAddress
|
||||||
|
*/
|
||||||
|
public Builder rnatAddress(NamedResource rnatAddress) {
|
||||||
|
this.rnatAddress = rnatAddress;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NetworkReference#getIpAddresses
|
||||||
|
*/
|
||||||
|
public Builder gatewayAddress(IpAddresses ipAddresses) {
|
||||||
|
this.ipAddresses = ipAddresses;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkReference build() {
|
public NetworkReference build() {
|
||||||
return new NetworkReference(href, type, name, networkType);
|
return new NetworkReference(href, type, name, address, networkType, broadcastAddress, gatewayAddress, rnatAddress, ipAddresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fromNetworkReference(NetworkReference in) {
|
public Builder fromNetworkReference(NetworkReference in) {
|
||||||
|
@ -142,26 +188,100 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "NetworkType")
|
@XmlElement(name = "Address", required = false)
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@XmlElement(name = "NetworkType", required = true)
|
||||||
private NetworkType networkType;
|
private NetworkType networkType;
|
||||||
|
|
||||||
private NetworkReference(URI href, String type, String name,@Nullable NetworkType networkType) {
|
@XmlElement(name = "BroadcastAddress", required = false)
|
||||||
|
private String broadcastAddress;
|
||||||
|
|
||||||
|
@XmlElement(name = "GatewayAddress", required = false)
|
||||||
|
private String gatewayAddress;
|
||||||
|
|
||||||
|
@XmlElement(name = "RnatAddress", required = false)
|
||||||
|
private NamedResource rnatAddress;
|
||||||
|
|
||||||
|
@XmlElement(name = "IpAddresses", required = false)
|
||||||
|
private IpAddresses ipAddresses;
|
||||||
|
|
||||||
|
private NetworkReference(URI href, String type, String name,@Nullable String address, NetworkType networkType,
|
||||||
|
@Nullable String broadcastAddress, @Nullable String gatewayAddress, @Nullable NamedResource rnatAddress, @Nullable IpAddresses ipAddresses) {
|
||||||
super(href, type, name);
|
super(href, type, name);
|
||||||
this.networkType = networkType;
|
this.address = address;
|
||||||
|
this.networkType = checkNotNull(networkType,"networkType");
|
||||||
|
this.broadcastAddress = broadcastAddress;
|
||||||
|
this.gatewayAddress = gatewayAddress;
|
||||||
|
this.rnatAddress = rnatAddress;
|
||||||
|
this.ipAddresses = ipAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkReference() {
|
private NetworkReference() {
|
||||||
//For JAXB
|
//For JAXB
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
public NetworkType getNetworkType() {
|
public NetworkType getNetworkType() {
|
||||||
return networkType;
|
return networkType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getBroadcastAddress() {
|
||||||
|
return broadcastAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGatewayAddress() {
|
||||||
|
return gatewayAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamedResource getRnatAddress() {
|
||||||
|
return rnatAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IpAddresses getIpAddresses() {
|
||||||
|
return ipAddresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
|
NetworkReference that = (NetworkReference) o;
|
||||||
|
|
||||||
|
if (address != null ? !address.equals(that.address) : that.address != null)
|
||||||
|
return false;
|
||||||
|
if (broadcastAddress != null ? !broadcastAddress.equals(that.broadcastAddress) : that.broadcastAddress != null)
|
||||||
|
return false;
|
||||||
|
if (gatewayAddress != null ? !gatewayAddress.equals(that.gatewayAddress) : that.gatewayAddress != null)
|
||||||
|
return false;
|
||||||
|
if (ipAddresses != null ? !ipAddresses.equals(that.ipAddresses) : that.ipAddresses != null)
|
||||||
|
return false;
|
||||||
|
if (networkType != that.networkType) return false;
|
||||||
|
if (rnatAddress != null ? !rnatAddress.equals(that.rnatAddress) : that.rnatAddress != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (address != null ? address.hashCode() : 0);
|
||||||
|
result = 31 * result + networkType.hashCode();
|
||||||
|
result = 31 * result + (broadcastAddress != null ? broadcastAddress.hashCode() : 0);
|
||||||
|
result = 31 * result + (gatewayAddress != null ? gatewayAddress.hashCode() : 0);
|
||||||
|
result = 31 * result + (rnatAddress != null ? rnatAddress.hashCode() : 0);
|
||||||
|
result = 31 * result + (ipAddresses != null ? ipAddresses.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String string() {
|
public String string() {
|
||||||
return super.string()+", networkType="+networkType;
|
return super.string()+", address="+address+", networkType="+networkType+", broadcastAddress="+broadcastAddress+", gatewayAddress="+gatewayAddress+", rnatAddress="+rnatAddress+", ipAddresses="+ipAddresses;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,182 @@
|
||||||
|
/**
|
||||||
|
* 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.tmrk.enterprisecloud.domain.network;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Networks is more than a simple wrapper as it extends BaseResource.
|
||||||
|
* @author Jason King
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "Networks")
|
||||||
|
public class Networks extends Resource<Networks> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromTemplates(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends Resource.Builder<Networks> {
|
||||||
|
private Set<NetworkReference> networks = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Networks#getNetworks
|
||||||
|
*/
|
||||||
|
public Builder networks(Set<NetworkReference> networks) {
|
||||||
|
this.networks =(checkNotNull(networks,"networks"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Networks build() {
|
||||||
|
return new Networks(href, type, name, links, actions, networks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromTemplates(Networks in) {
|
||||||
|
return fromResource(in).networks(in.getNetworks());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromBaseResource(BaseResource<Networks> in) {
|
||||||
|
return Builder.class.cast(super.fromBaseResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromResource(Resource<Networks> in) {
|
||||||
|
return Builder.class.cast(super.fromResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder type(String type) {
|
||||||
|
return Builder.class.cast(super.type(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder href(URI href) {
|
||||||
|
return Builder.class.cast(super.href(href));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.name(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder links(Set<Link> links) {
|
||||||
|
return Builder.class.cast(super.links(links));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder actions(Set<Action> actions) {
|
||||||
|
return Builder.class.cast(super.actions(actions));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromAttributes(Map<String, String> attributes) {
|
||||||
|
return Builder.class.cast(super.fromAttributes(attributes));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Network", required = false)
|
||||||
|
private Set<NetworkReference> networks = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
private Networks(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<NetworkReference> networks) {
|
||||||
|
super(href, type, name, links, actions);
|
||||||
|
this.networks = checkNotNull(networks,"networks");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Networks() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<NetworkReference> getNetworks() {
|
||||||
|
return networks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
|
Networks networks1 = (Networks) o;
|
||||||
|
|
||||||
|
if (!networks.equals(networks1.networks)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + networks.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String string() {
|
||||||
|
return super.string()+", networks="+networks;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
* 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.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.rest.annotations.*;
|
||||||
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to various Networks via their REST API.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkClient
|
||||||
|
* @see <a href=
|
||||||
|
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
|
||||||
|
* />
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@RequestFilters(BasicAuthentication.class)
|
||||||
|
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
|
||||||
|
public interface NetworkAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkClient#getNetworks
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.network; type=collection")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
public ListenableFuture<Networks> getNetworks(@EndpointParam URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkClient#getNetwork
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.network")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
public ListenableFuture<NetworkReference> getNetwork(@EndpointParam URI uri);
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* 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.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to various Resources.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkAsyncClient
|
||||||
|
* @see <a href=
|
||||||
|
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
|
||||||
|
* />
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface NetworkClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Get Networks call returns information regarding networks in an environment.
|
||||||
|
|
||||||
|
* @param uri the uri of the call based upon the environment
|
||||||
|
* e.g. /cloudapi/ecloud/networks/environments/{id}
|
||||||
|
* @return the Networks
|
||||||
|
*/
|
||||||
|
public Networks getNetworks(URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Get Networks by ID call returns information regarding the usage of all
|
||||||
|
* IP addresses on a specified network defined in an environment.
|
||||||
|
|
||||||
|
* @param uri the uri of the call based upon the network
|
||||||
|
* e.g. /cloudapi/ecloud/networks/{id}
|
||||||
|
* @return the NetworkReference
|
||||||
|
*/
|
||||||
|
public NetworkReference getNetwork(URI uri);
|
||||||
|
|
||||||
|
}
|
|
@ -40,7 +40,7 @@ public class NicsTest {
|
||||||
|
|
||||||
@BeforeMethod()
|
@BeforeMethod()
|
||||||
public void setUp() throws URISyntaxException {
|
public void setUp() throws URISyntaxException {
|
||||||
networkReference = NetworkReference.builder().href(new URI("/netref")).type("a network ref").name("my network ref").build();
|
networkReference = NetworkReference.builder().href(new URI("/netref")).type("a network ref").name("my network ref").networkType(NetworkReference.NetworkType.INTERNAL).build();
|
||||||
nic = VirtualNic.builder().macAddress("aa:bb").name("my nic").network(networkReference).unitNumber(1).build();
|
nic = VirtualNic.builder().macAddress("aa:bb").name("my nic").network(networkReference).unitNumber(1).build();
|
||||||
nics = Nics.builder().addVirtualNic(nic).build();
|
nics = Nics.builder().addVirtualNic(nic).build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
* 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.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
|
||||||
|
import org.testng.annotations.BeforeGroups;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code NetworkClient}
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", testName = "NetworkClientLiveTest")
|
||||||
|
public class NetworkClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
|
||||||
|
@BeforeGroups(groups = { "live" })
|
||||||
|
public void setupClient() {
|
||||||
|
super.setupClient();
|
||||||
|
client = context.getApi().getNetworkClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
private NetworkClient client;
|
||||||
|
|
||||||
|
public void testGetNetworks() throws Exception {
|
||||||
|
Networks networks = client.getNetworks(URI.create("/cloudapi/ecloud/networks/environments/77"));
|
||||||
|
assertNotNull(networks);
|
||||||
|
for(NetworkReference network: networks.getNetworks()) {
|
||||||
|
testGetNetwork(network.getHref());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testGetNetwork(URI uri) throws Exception {
|
||||||
|
NetworkReference network = client.getNetwork(uri);
|
||||||
|
assertNotNull(network);
|
||||||
|
assertNotNull(network.getAddress());
|
||||||
|
assertNotNull(network.getNetworkType());
|
||||||
|
assertNotNull(network.getBroadcastAddress());
|
||||||
|
assertNotNull(network.getGatewayAddress());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,156 @@
|
||||||
|
/**
|
||||||
|
* 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.tmrk.enterprisecloud.xml;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import org.jclouds.crypto.Crypto;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||||
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
import org.jclouds.rest.BaseRestClientTest;
|
||||||
|
import org.jclouds.rest.RestContextSpec;
|
||||||
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.IpAddress;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.features.LocationAsyncClient;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.features.NetworkAsyncClient;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.jclouds.io.Payloads.newInputStreamPayload;
|
||||||
|
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||||
|
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of JAXB parsing for Network(s)
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "NetworksJAXBParsingTest")
|
||||||
|
public class NetworksJAXBParsingTest extends BaseRestClientTest {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
void setupFactory() {
|
||||||
|
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||||
|
"credentialFoo", String.class, Integer.class,
|
||||||
|
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Provides
|
||||||
|
@Named("exception")
|
||||||
|
Set<String> exception() {
|
||||||
|
throw new AuthorizationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
injector = createContextBuilder(contextSpec).buildInjector();
|
||||||
|
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||||
|
crypto = injector.getInstance(Crypto.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseNetworksWithJAXB() throws Exception {
|
||||||
|
Method method = NetworkAsyncClient.class.getMethod("getNetworks",URI.class);
|
||||||
|
HttpRequest request = factory(LocationAsyncClient.class).createRequest(method, new URI("/1"));
|
||||||
|
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||||
|
|
||||||
|
Function<HttpResponse, Networks> parser = (Function<HttpResponse, Networks>) RestAnnotationProcessor
|
||||||
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
|
InputStream is = getClass().getResourceAsStream("/networks.xml");
|
||||||
|
Networks networks = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||||
|
assertNotNull(networks);
|
||||||
|
for(NetworkReference network: networks.getNetworks()) {
|
||||||
|
assertNetworkFromNetworks(network);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseNetworkWithJAXB() throws Exception {
|
||||||
|
Method method = NetworkAsyncClient.class.getMethod("getNetwork",URI.class);
|
||||||
|
HttpRequest request = factory(LocationAsyncClient.class).createRequest(method, new URI("/1"));
|
||||||
|
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||||
|
|
||||||
|
Function<HttpResponse, NetworkReference> parser = (Function<HttpResponse, NetworkReference>) RestAnnotationProcessor
|
||||||
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
|
InputStream is = getClass().getResourceAsStream("/network.xml");
|
||||||
|
NetworkReference network = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||||
|
assertNotNull(network.getAddress());
|
||||||
|
assertNotNull(network.getNetworkType());
|
||||||
|
assertNotNull(network.getBroadcastAddress());
|
||||||
|
assertNotNull(network.getGatewayAddress());
|
||||||
|
assertRnatAddress(network.getRnatAddress());
|
||||||
|
for(IpAddress address:network.getIpAddresses().getIpAddresses()) {
|
||||||
|
assertIpAddress(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertRnatAddress(NamedResource rnatAddress) {
|
||||||
|
assertNotNull(rnatAddress);
|
||||||
|
assertNotNull(rnatAddress.getHref());
|
||||||
|
assertNotNull(rnatAddress.getName());
|
||||||
|
assertNotNull(rnatAddress.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertIpAddress(IpAddress address) {
|
||||||
|
assertNotNull(address);
|
||||||
|
assertNotNull(address.getName());
|
||||||
|
if( address.getHost() != null) {
|
||||||
|
assertNamedResource(address.getHost());
|
||||||
|
}
|
||||||
|
if( address.getDetectedOn() != null) {
|
||||||
|
assertNamedResource(address.getDetectedOn());
|
||||||
|
}
|
||||||
|
if( address.getRnatAddress() != null) {
|
||||||
|
assertNamedResource(address.getRnatAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertNamedResource(NamedResource resource) {
|
||||||
|
assertNotNull(resource.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertNetworkFromNetworks(NetworkReference network) {
|
||||||
|
assertNotNull(network.getHref());
|
||||||
|
assertNotNull(network.getType());
|
||||||
|
assertNotNull(network.getName());
|
||||||
|
assertNotNull(network.getNetworkType());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,224 @@
|
||||||
|
<Network href="/cloudapi/ecloud/networks/3936" name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network"
|
||||||
|
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/environments/77" name="Beta Environment 01"
|
||||||
|
type="application/vnd.tmrk.cloud.environment" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Address>10.146.204.64</Address>
|
||||||
|
<NetworkType>Internal</NetworkType>
|
||||||
|
<BroadcastAddress>10.146.204.79</BroadcastAddress>
|
||||||
|
<GatewayAddress>10.146.204.65</GatewayAddress>
|
||||||
|
<RnatAddress href="/cloudapi/ecloud/rnats/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.networkRnat"/>
|
||||||
|
<IpAddresses>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.65"
|
||||||
|
name="10.146.204.65"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.65/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
<Host href="/cloudapi/ecloud/networkhosts/3930"
|
||||||
|
name="DAC90012VFW001"
|
||||||
|
type="application/vnd.tmrk.cloud.networkHost"/>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.66"
|
||||||
|
name="10.146.204.66"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.66/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
<Host href="/cloudapi/ecloud/networkhosts/3930"
|
||||||
|
name="DAC90012VFW001"
|
||||||
|
type="application/vnd.tmrk.cloud.networkHost"/>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.67"
|
||||||
|
name="10.146.204.67"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.67/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
<Host href="/cloudapi/ecloud/networkhosts/5504" name="helloworld"
|
||||||
|
type="application/vnd.tmrk.cloud.networkHost"/>
|
||||||
|
<DetectedOn href="/cloudapi/ecloud/networkhosts/5504"
|
||||||
|
name="helloworld"
|
||||||
|
type="application/vnd.tmrk.cloud.networkHost"/>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.68"
|
||||||
|
name="10.146.204.68"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.68/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.69"
|
||||||
|
name="10.146.204.69"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.69/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.70"
|
||||||
|
name="10.146.204.70"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.70/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.71"
|
||||||
|
name="10.146.204.71"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.71/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.72"
|
||||||
|
name="10.146.204.72"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.72/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.73"
|
||||||
|
name="10.146.204.73"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.73/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.74"
|
||||||
|
name="10.146.204.74"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.74/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.75"
|
||||||
|
name="10.146.204.75"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.75/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.76"
|
||||||
|
name="10.146.204.76"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.76/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.77"
|
||||||
|
name="10.146.204.77"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.77/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
<IpAddress
|
||||||
|
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.78"
|
||||||
|
name="10.146.204.78"
|
||||||
|
type="application/vnd.tmrk.cloud.ipAddress">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.78/action/sync"
|
||||||
|
name="sync" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
</IpAddress>
|
||||||
|
</IpAddresses>
|
||||||
|
</Network>
|
|
@ -0,0 +1,16 @@
|
||||||
|
<Networks href="/cloudapi/ecloud/networks/environments/77"
|
||||||
|
type="application/vnd.tmrk.cloud.network; type=collection"
|
||||||
|
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/environments/77" name="Beta Environment 01"
|
||||||
|
type="application/vnd.tmrk.cloud.environment" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Network href="/cloudapi/ecloud/networks/3936" name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network">
|
||||||
|
<NetworkType>Internal</NetworkType>
|
||||||
|
</Network>
|
||||||
|
<Network href="/cloudapi/ecloud/networks/3933" name="10.146.205.128/27"
|
||||||
|
type="application/vnd.tmrk.cloud.network">
|
||||||
|
<NetworkType>Dmz</NetworkType>
|
||||||
|
</Network>
|
||||||
|
</Networks>
|
Loading…
Reference in New Issue