diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java index a94a18b70a..b2cefa6521 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java @@ -39,6 +39,12 @@ public interface TerremarkEnterpriseCloudAsyncClient { @Delegate LocationAsyncClient getLocationClient(); + /** + * Provides asynchronous access to Network features. + */ + @Delegate + NetworkAsyncClient getNetworkClient(); + /** * Provides asynchronous access to Resource features. */ diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java index 620a6bf925..e34bbd4469 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java @@ -49,6 +49,12 @@ public interface TerremarkEnterpriseCloudClient { @Delegate ResourceClient getResourceClient(); + /** + * Provides synchronous access to Network features. + */ + @Delegate + NetworkClient getNetworkClient(); + /** * Provides synchronous access to Task features. */ diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java index 2aad56db69..7cc37e56cb 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java @@ -48,6 +48,7 @@ public class TerremarkEnterpriseCloudRestClientModule extends public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() .put(LocationClient.class, LocationAsyncClient.class) + .put(NetworkClient.class, NetworkAsyncClient.class) .put(ResourceClient.class, ResourceAsyncClient.class) .put(TaskClient.class, TaskAsyncClient.class) .put(VirtualMachineClient.class, VirtualMachineAsyncClient.class) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/IpAddress.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/IpAddress.java new file mode 100644 index 0000000000..6fdc732ba7 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/IpAddress.java @@ -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; + +/** + * + * @author Jason King + */ +public class IpAddress extends Resource { + + @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 { + 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 in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource 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 links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map 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 links,Set 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; + } + +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/IpAddresses.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/IpAddresses.java new file mode 100644 index 0000000000..c25b512782 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/IpAddresses.java @@ -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; + +/** + * + * @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 addresses = Sets.newLinkedHashSet(); + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.network.IpAddresses#getIpAddresses + */ + public Builder addresses(Set 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 addresses) { + this.addresses = Sets.newLinkedHashSet(addresses); + } + + @XmlElement(name = "IpAddress") + private Set addresses = Sets.newLinkedHashSet(); + + public Set 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()+"]"; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java index 5102392b49..be010907c1 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java @@ -19,26 +19,27 @@ 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.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlRootElement; import java.net.URI; import java.util.Map; -import java.util.Set; import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import static com.google.common.base.Preconditions.checkNotNull; /** * * @author Jason King * */ +@XmlRootElement(name = "Network") public class NetworkReference extends BaseNamedResource { @XmlEnum public static enum NetworkType { @@ -74,8 +75,21 @@ public class NetworkReference extends BaseNamedResource { public static class Builder extends BaseNamedResource.Builder { + private String address; 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 */ @@ -84,9 +98,41 @@ public class NetworkReference extends BaseNamedResource { 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 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) { @@ -142,26 +188,100 @@ public class NetworkReference extends BaseNamedResource { } } - @XmlElement(name = "NetworkType") + @XmlElement(name = "Address", required = false) + private String address; + + @XmlElement(name = "NetworkType", required = true) 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); - 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() { //For JAXB } - @Nullable + public String getAddress() { + return address; + } + public NetworkType getNetworkType() { 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 public String string() { - return super.string()+", networkType="+networkType; + return super.string()+", address="+address+", networkType="+networkType+", broadcastAddress="+broadcastAddress+", gatewayAddress="+gatewayAddress+", rnatAddress="+rnatAddress+", ipAddresses="+ipAddresses; } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/Networks.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/Networks.java new file mode 100644 index 0000000000..c436a1dfe2 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/Networks.java @@ -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 { + + @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 { + private Set networks = Sets.newLinkedHashSet(); + + /** + * @see Networks#getNetworks + */ + public Builder networks(Set 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 in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource 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 links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + + } + + @XmlElement(name = "Network", required = false) + private Set networks = Sets.newLinkedHashSet(); + + private Networks(URI href, String type, String name, Set links, Set actions, Set networks) { + super(href, type, name, links, actions); + this.networks = checkNotNull(networks,"networks"); + } + + private Networks() { + //For JAXB + } + + public Set 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; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/NetworkAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/NetworkAsyncClient.java new file mode 100644 index 0000000000..7de6b01f58 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/NetworkAsyncClient.java @@ -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. + *

+ * + * @see org.jclouds.tmrk.enterprisecloud.features.NetworkClient + * @see + * @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 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 getNetwork(@EndpointParam URI uri); +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/NetworkClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/NetworkClient.java new file mode 100644 index 0000000000..1403874734 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/NetworkClient.java @@ -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. + *

+ * + * @see org.jclouds.tmrk.enterprisecloud.features.NetworkAsyncClient + * @see + * @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); + +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/network/NicsTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/network/NicsTest.java index 23319de659..968e88b82c 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/network/NicsTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/network/NicsTest.java @@ -40,7 +40,7 @@ public class NicsTest { @BeforeMethod() 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(); nics = Nics.builder().addVirtualNic(nic).build(); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/NetworkClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/NetworkClientLiveTest.java new file mode 100644 index 0000000000..321cc1f950 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/NetworkClientLiveTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/NetworksJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/NetworksJAXBParsingTest.java new file mode 100644 index 0000000000..e0831f991b --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/NetworksJAXBParsingTest.java @@ -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 contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo", + "credentialFoo", String.class, Integer.class, + ImmutableSet. of(new MockModule(), new NullLoggingModule(), new AbstractModule() { + + @Override + protected void configure() {} + + @SuppressWarnings("unused") + @Provides + @Named("exception") + Set 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 parser = (Function) 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 parser = (Function) 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()); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/resources/network.xml b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/network.xml new file mode 100644 index 0000000000..3cb69a35d7 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/network.xml @@ -0,0 +1,224 @@ + + + + +

10.146.204.64
+ Internal + 10.146.204.79 + 10.146.204.65 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/resources/networks.xml b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/networks.xml new file mode 100644 index 0000000000..fcd6ea4249 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/networks.xml @@ -0,0 +1,16 @@ + + + + + + Internal + + + Dmz + + \ No newline at end of file