Merge pull request #270 from jsonking/695-Terremark

Issue 695: GET and EDIT on InternetService plus various tidies
This commit is contained in:
Jason King 2011-12-20 12:42:14 -08:00
commit 8bd4fb483a
31 changed files with 2190 additions and 144 deletions

View File

@ -33,6 +33,12 @@ import org.jclouds.tmrk.enterprisecloud.features.*;
*/
public interface TerremarkEnterpriseCloudAsyncClient {
/**
* Provides asynchronous access to Internet Service features.
*/
@Delegate
InternetServiceAsyncClient getInternetServiceClient();
/**
* Provides asynchronous access to Layout features.
*/

View File

@ -37,6 +37,12 @@ import org.jclouds.tmrk.enterprisecloud.features.*;
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface TerremarkEnterpriseCloudClient {
/**
* Provides synchronous access to Internet Service features.
*/
@Delegate
InternetServiceClient getInternetServiceClient();
/**
* Provides synchronous access to Layout features.
*/

View File

@ -22,7 +22,7 @@ import com.jamesmurty.utils.XMLBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting;
@ -76,7 +76,7 @@ public class BindCreateVirtualMachineKeyToXmlPayload implements Binder {
final String description = vmData.getDescription();
final LayoutRequest layout = vmData.getLayout();
final String poweredOn = Boolean.toString(vmData.isPoweredOn());
final AnonymousResource template = vmData.getTemplate();
final NamedResource template = vmData.getTemplate();
XMLBuilder builder = XMLBuilder.create("CreateVirtualMachine").a("name",name)
.e("ProcessorCount").t(processorCount).up()

View File

@ -0,0 +1,122 @@
/**
* 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.binders;
import com.jamesmurty.utils.XMLBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.util.Properties;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* For use with {@see VirtualMachineClient#createVirtualMachineFromTemplate}
* @author Jason King
*/
@Singleton
public class BindInternetServiceToXmlPayload implements Binder {
private final BindToStringPayload stringBinder;
@Inject
BindInternetServiceToXmlPayload(BindToStringPayload stringBinder) {
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object key) {
checkArgument(checkNotNull(key, "key") instanceof InternetService, "this binder is only valid for InternetService instances");
checkNotNull(request, "request");
InternetService data = InternetService.class.cast(key);
String payload = createXMLPayload(data);
return stringBinder.bindToRequest(request, payload);
}
private String createXMLPayload(InternetService data) {
try {
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
final String name = checkNotNull(data.getName(), "name");
final String enabled = Boolean.toString(data.isEnabled());
final String description = data.getDescription();
final InternetServicePersistenceType persistence = data.getPersistence();
final String redirectUrl = data.getRedirectUrl();
final NamedResource trustedNetworkGroup = data.getTrustedNetworkGroup();
final NamedResource backupInternetService = data.getBackupInternetService();
XMLBuilder builder = XMLBuilder.create("InternetService").a("name", name)
.e("Enabled").t(enabled).up();
if(description!=null) {
builder = builder.e("Description").t(description).up();
}
builder = persistence(builder,persistence);
if(redirectUrl!=null) {
builder = builder.e("RedirectUrl").t(redirectUrl);
}
if(trustedNetworkGroup!=null) {
final String href = trustedNetworkGroup.getHref().toString();
String groupName = trustedNetworkGroup.getName();
String type = trustedNetworkGroup.getType();
builder = builder.e("TrustedNetworkGroup").a("href",href).a("name",groupName).a("type", type).up();
}
if(backupInternetService!=null) {
final String href = backupInternetService.getHref().toString();
String groupName = backupInternetService.getName();
String type = backupInternetService.getType();
builder = builder.e("BackupInternetService").a("href",href).a("name",groupName).a("type",type).up();
}
return builder.asString(outputProperties);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (TransformerException t) {
throw new RuntimeException(t);
}
}
private XMLBuilder persistence(XMLBuilder in, InternetServicePersistenceType persistenceType) {
checkNotNull(persistenceType,"persistenceType");
final InternetServicePersistenceType.PersistenceType type = persistenceType.getPersistenceType();
final int timeout = persistenceType.getTimeout();
in = in.e("Persistence").e("Type").t(type.value()).up();
if(!type.equals(InternetServicePersistenceType.PersistenceType.NONE) && timeout > -1 ) {
in = in.e("Timeout").t(Integer.toString(timeout)).up();
}
return in.up();
}
}

View File

@ -46,6 +46,7 @@ public class TerremarkEnterpriseCloudRestClientModule extends
RestClientModule<TerremarkEnterpriseCloudClient, TerremarkEnterpriseCloudAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(InternetServiceClient.class, InternetServiceAsyncClient.class)
.put(LayoutClient.class, LayoutAsyncClient.class)
.put(LocationClient.class, LocationAsyncClient.class)
.put(NetworkClient.class, NetworkAsyncClient.class)

View File

@ -1,95 +0,0 @@
/**
* 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.internal;
import java.net.URI;
import java.util.Map;
/**
* A Resource with no name.
* @author Jason King
*
*/
public class AnonymousResource extends BaseResource<AnonymousResource> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromBaseResource(this);
}
public static class Builder extends BaseResource.Builder<AnonymousResource> {
/**
* {@inheritDoc}
*/
@Override
public AnonymousResource build() {
return new AnonymousResource(href, type);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<AnonymousResource> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> in) {
return Builder.class.cast(super.fromAttributes(in));
}
}
private AnonymousResource(URI href, String type) {
super(href, type);
}
protected AnonymousResource() {
//For JAXB
}
}

View File

@ -83,7 +83,7 @@ public class BaseNamedResource<T extends BaseNamedResource<T>> extends BaseResou
protected BaseNamedResource(URI href, String type, String name) {
super(href, type);
this.name = checkNotNull(name, "name");
this.name = name;
}
protected BaseNamedResource() {

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.tmrk.enterprisecloud.domain.internal;
import org.jclouds.tmrk.enterprisecloud.functions.URISource;
import javax.xml.bind.annotation.XmlAttribute;
import java.net.URI;
import java.util.Map;
@ -30,7 +32,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* @author Adrian Cole
*
*/
public class BaseResource<T extends BaseResource<T>> {
public class BaseResource<T extends BaseResource<T>> implements URISource {
public static <T extends BaseResource<T>> Builder<T> builder() {
return new Builder<T>();
@ -82,7 +84,7 @@ public class BaseResource<T extends BaseResource<T>> {
protected URI href;
protected BaseResource(URI href, String type) {
this.type = checkNotNull(type, "type");
this.type = type;
this.href = checkNotNull(href, "href");
}
@ -106,6 +108,13 @@ public class BaseResource<T extends BaseResource<T>> {
return href;
}
/**
* @see #getHref
*/
public URI getURI() {
return getHref();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -19,7 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.layout;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import javax.xml.bind.annotation.XmlElement;
@ -61,15 +61,15 @@ public class LayoutRequest {
}
public static class Builder {
private AnonymousResource row;
private AnonymousResource group;
private NamedResource row;
private NamedResource group;
private String newRow;
private String newGroup;
/**
* @see LayoutRequest#getRow
*/
public Builder row(AnonymousResource row) {
public Builder row(NamedResource row) {
this.row = row;
return this;
}
@ -77,7 +77,7 @@ public class LayoutRequest {
/**
* @see LayoutRequest#getGroup
*/
public Builder group(AnonymousResource group) {
public Builder group(NamedResource group) {
this.group = group;
return this;
}
@ -108,10 +108,10 @@ public class LayoutRequest {
}
@XmlElement(name = "Row", required = false)
private AnonymousResource row;
private NamedResource row;
@XmlElement(name = "Group", required = false)
private AnonymousResource group;
private NamedResource group;
@XmlElement(name = "NewRow", required = false)
private String newRow;
@ -120,7 +120,7 @@ public class LayoutRequest {
private String newGroup;
private LayoutRequest(@Nullable AnonymousResource row, @Nullable AnonymousResource group, @Nullable String newRow, @Nullable String newGroup) {
private LayoutRequest(@Nullable NamedResource row, @Nullable NamedResource group, @Nullable String newRow, @Nullable String newGroup) {
this.row = row;
this.group = group;
this.newRow = newRow;
@ -131,11 +131,11 @@ public class LayoutRequest {
//For JAXB
}
public AnonymousResource getRow() {
public NamedResource getRow() {
return row;
}
public AnonymousResource getGroup() {
public NamedResource getGroup() {
return group;
}

View File

@ -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 org.jclouds.javax.annotation.Nullable;
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 java.net.URI;
import java.util.Map;
/**
* <xs:complexType name="IpAddressReferenceType">
* @author Jason King
*
*/
public class IpAddressReference extends BaseNamedResource<IpAddressReference> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromNetworkReference(this);
}
public static class Builder extends BaseNamedResource.Builder<IpAddressReference> {
private NamedResource network;
private NamedResource host;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.network.IpAddressReference#getNetwork
*/
public Builder network(NamedResource network) {
this.network = network;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.network.IpAddressReference#getHost
*/
public Builder host(NamedResource host) {
this.host = host;
return this;
}
@Override
public IpAddressReference build() {
return new IpAddressReference(href, type, name, network, host);
}
public Builder fromNetworkReference(IpAddressReference in) {
return fromNamedResource(in).network(in.getNetwork()).host(in.getHost());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<IpAddressReference> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromNamedResource(BaseNamedResource<IpAddressReference> in) {
return Builder.class.cast(super.fromNamedResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Network", required = false)
private NamedResource network;
@XmlElement(name = "Host", required = false)
private NamedResource host;
private IpAddressReference(URI href, String type, String name,
@Nullable NamedResource network, @Nullable NamedResource host) {
super(href, type, name);
this.network = network;
this.host = host;
}
private IpAddressReference() {
//For JAXB
}
public NamedResource getNetwork() {
return network;
}
public NamedResource getHost() {
return host;
}
@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;
IpAddressReference that = (IpAddressReference) o;
if (host != null ? !host.equals(that.host) : that.host != null)
return false;
if (network != null ? !network.equals(that.network) : that.network != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (network != null ? network.hashCode() : 0);
result = 31 * result + (host != null ? host.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", network="+network+", host="+host;
}
}

View File

@ -19,7 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.network;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import javax.xml.bind.annotation.XmlElement;
@ -41,7 +41,7 @@ public class LinuxCustomization {
public static class Builder {
private NetworkSettings networkSettings = NetworkSettings.builder().build();
private AnonymousResource sshKey;
private NamedResource sshKey;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization#getNetworkSettings
@ -54,7 +54,7 @@ public class LinuxCustomization {
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization#getSshKey
*/
public Builder sshKey(AnonymousResource sshKey) {
public Builder sshKey(NamedResource sshKey) {
this.sshKey = sshKey;
return this;
}
@ -72,9 +72,9 @@ public class LinuxCustomization {
private NetworkSettings networkSettings;
@XmlElement(name = "SshKey", required = false)
private AnonymousResource sshKey;
private NamedResource sshKey;
public LinuxCustomization(@Nullable NetworkSettings networkSettings, @Nullable AnonymousResource sshKey) {
public LinuxCustomization(@Nullable NetworkSettings networkSettings, @Nullable NamedResource sshKey) {
this.networkSettings = networkSettings;
this.sshKey = sshKey;
}
@ -87,7 +87,7 @@ public class LinuxCustomization {
return networkSettings;
}
public AnonymousResource getSshKey() {
public NamedResource getSshKey() {
return sshKey;
}

View File

@ -19,7 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.resource;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import javax.xml.bind.annotation.XmlElement;
@ -40,13 +40,13 @@ public class ComputePoolPerformanceStatistic {
}
public static class Builder {
private AnonymousResource cpu;
private AnonymousResource memory;
private NamedResource cpu;
private NamedResource memory;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistic#getCpu
*/
public Builder cpu(AnonymousResource cpu) {
public Builder cpu(NamedResource cpu) {
this.cpu = cpu;
return this;
}
@ -54,7 +54,7 @@ public class ComputePoolPerformanceStatistic {
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistic#getMemory
*/
public Builder memory(AnonymousResource memory) {
public Builder memory(NamedResource memory) {
this.memory = memory;
return this;
}
@ -69,12 +69,12 @@ public class ComputePoolPerformanceStatistic {
}
@XmlElement(name = "Cpu", required = false)
private AnonymousResource cpu;
private NamedResource cpu;
@XmlElement(name = "Memory", required = false)
private AnonymousResource memory;
private NamedResource memory;
private ComputePoolPerformanceStatistic(@Nullable AnonymousResource cpu, @Nullable AnonymousResource memory) {
private ComputePoolPerformanceStatistic(@Nullable NamedResource cpu, @Nullable NamedResource memory) {
this.cpu = cpu;
this.memory = memory;
}
@ -83,11 +83,11 @@ public class ComputePoolPerformanceStatistic {
//For JAXB
}
public AnonymousResource getCpu() {
public NamedResource getCpu() {
return cpu;
}
public AnonymousResource getMemory() {
public NamedResource getMemory() {
return memory;
}

View File

@ -0,0 +1,34 @@
package org.jclouds.tmrk.enterprisecloud.domain.service;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
@XmlEnum
public enum Protocol {
@XmlEnumValue("HTTP")
HTTP,
@XmlEnumValue("HTTPS")
HTTPS,
@XmlEnumValue("TCP")
TCP,
@XmlEnumValue("UDP")
UDP,
@XmlEnumValue("IPSEC")
IPSEC,
@XmlEnumValue("FTP")
FTP,
@XmlEnumValue("Any")
Any;
@Override
public String toString() {
return name();
}
}

View File

@ -0,0 +1,419 @@
/**
* 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.service.internet;
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.Task;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Entity;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
import org.jclouds.tmrk.enterprisecloud.domain.service.node.NodeServices;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
/**
* <xs:complexType name="InternetServiceType">
* @author Jason King
*/
@XmlRootElement(name="InternetService")
public class InternetService extends Entity<InternetService> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromSshKey(this);
}
public static class Builder extends Entity.Builder<InternetService> {
private Protocol protocol;
private int port;
private boolean enabled;
private String description;
private NamedResource publicIp;
private InternetServicePersistenceType persistence;
private String redirectUrl;
private NamedResource monitor;
private NamedResource trustedNetworkGroup;
private NamedResource backupInternetService;
private NodeServices nodeServices;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getProtocol
*/
public Builder protocol(Protocol protocol) {
this.protocol = protocol;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getPort
*/
public Builder port(int port) {
this.port = port;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#isEnabled
*/
public Builder enabled(boolean enabled) {
this.enabled = enabled;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getDescription
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getPersistence
*/
public Builder persistence(InternetServicePersistenceType persistence) {
this.persistence = persistence;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getPublicIp
*/
public Builder publicIp(NamedResource publicIp) {
this.publicIp = publicIp;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getRedirectUrl
*/
public Builder redirectUrl(String redirectUrl) {
this.redirectUrl = redirectUrl;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getMonitor
*/
public Builder monitor(NamedResource monitor) {
this.monitor = monitor;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getTrustedNetworkGroup
*/
public Builder trustedNetworkGroup(NamedResource trustedNetworkGroup) {
this.trustedNetworkGroup = trustedNetworkGroup;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getBackupInternetService
*/
public Builder backupInternetService(NamedResource backupInternetService) {
this.backupInternetService = backupInternetService;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService#getNodeServices
*/
public Builder nodeServices(NodeServices nodeServices) {
this.nodeServices = nodeServices;
return this;
}
@Override
public InternetService build() {
return new InternetService(href, type, name, links, actions, tasks,
protocol, port, enabled, description,publicIp,persistence,
redirectUrl, monitor, trustedNetworkGroup, backupInternetService, nodeServices);
}
public Builder fromSshKey(InternetService in) {
return fromEntity(in).protocol(in.getProtocol())
.port(in.getPort())
.enabled(in.isEnabled())
.description(in.getDescription())
.publicIp(in.getPublicIp())
.persistence(in.getPersistence())
.redirectUrl(in.getRedirectUrl())
.monitor(in.getMonitor())
.trustedNetworkGroup(in.getTrustedNetworkGroup())
.backupInternetService(in.getBackupInternetService())
.nodeServices(in.getNodeServices());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<InternetService> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<InternetService> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromEntity(Entity<InternetService> in) {
return Builder.class.cast(super.fromEntity(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 tasks(Set<Task> tasks) {
return Builder.class.cast(super.tasks(tasks));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Protocol", required = false)
private Protocol protocol;
@XmlElement(name = "Port", required = false)
private int port;
@XmlElement(name = "Enabled", required = true)
private boolean enabled;
@XmlElement(name = "PrivateKey", required = false)
private String description;
@XmlElement(name = "PublicIp", required = false)
private NamedResource publicIp;
@XmlElement(name = "Persistence", required = false)
private InternetServicePersistenceType persistence;
@XmlElement(name = "RedirectUrl", required = false)
private String redirectUrl;
@XmlElement(name = "Monitor", required = false)
private NamedResource monitor;
@XmlElement(name = "TrustedNetworkGroup", required = false)
private NamedResource trustedNetworkGroup;
@XmlElement(name = "BackupInternetService", required = false)
private NamedResource backupInternetService;
@XmlElement(name = "NodeServices", required = false)
private NodeServices nodeServices;
private InternetService(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<Task> tasks,
@Nullable Protocol protocol, int port, boolean enabled, @Nullable String description,
@Nullable NamedResource publicIp, @Nullable InternetServicePersistenceType persistence, @Nullable String redirectUrl, @Nullable NamedResource monitor,
@Nullable NamedResource trustedNetworkGroup, @Nullable NamedResource backupInternetService, @Nullable NodeServices nodeServices) {
super(href, type, name, links, actions, tasks);
this.protocol = protocol;
this.port = port;
this.enabled = enabled;
this.description = description;
this.publicIp = publicIp;
this.persistence = persistence;
this.redirectUrl = redirectUrl;
this.monitor = monitor;
this.trustedNetworkGroup = trustedNetworkGroup;
this.backupInternetService = backupInternetService;
this.nodeServices = nodeServices;
}
private InternetService() {
//For JAXB
}
public Protocol getProtocol() {
return protocol;
}
public int getPort() {
return port;
}
public boolean isEnabled() {
return enabled;
}
public String getDescription() {
return description;
}
public NamedResource getPublicIp() {
return publicIp;
}
public InternetServicePersistenceType getPersistence() {
return persistence;
}
public String getRedirectUrl() {
return redirectUrl;
}
public NamedResource getMonitor() {
return monitor;
}
public NamedResource getTrustedNetworkGroup() {
return trustedNetworkGroup;
}
public NamedResource getBackupInternetService() {
return backupInternetService;
}
public NodeServices getNodeServices() {
return nodeServices;
}
@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;
InternetService that = (InternetService) o;
if (enabled != that.enabled) return false;
if (port != that.port) return false;
if (backupInternetService != null ? !backupInternetService.equals(that.backupInternetService) : that.backupInternetService != null)
return false;
if (description != null ? !description.equals(that.description) : that.description != null)
return false;
if (monitor != null ? !monitor.equals(that.monitor) : that.monitor != null)
return false;
if (nodeServices != null ? !nodeServices.equals(that.nodeServices) : that.nodeServices != null)
return false;
if (persistence != null ? !persistence.equals(that.persistence) : that.persistence != null)
return false;
if (protocol != that.protocol) return false;
if (publicIp != null ? !publicIp.equals(that.publicIp) : that.publicIp != null)
return false;
if (redirectUrl != null ? !redirectUrl.equals(that.redirectUrl) : that.redirectUrl != null)
return false;
if (trustedNetworkGroup != null ? !trustedNetworkGroup.equals(that.trustedNetworkGroup) : that.trustedNetworkGroup != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (protocol != null ? protocol.hashCode() : 0);
result = 31 * result + port;
result = 31 * result + (enabled ? 1 : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (publicIp != null ? publicIp.hashCode() : 0);
result = 31 * result + (persistence != null ? persistence.hashCode() : 0);
result = 31 * result + (redirectUrl != null ? redirectUrl.hashCode() : 0);
result = 31 * result + (monitor != null ? monitor.hashCode() : 0);
result = 31 * result + (trustedNetworkGroup != null ? trustedNetworkGroup.hashCode() : 0);
result = 31 * result + (backupInternetService != null ? backupInternetService.hashCode() : 0);
result = 31 * result + (nodeServices != null ? nodeServices.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+
", protocol="+protocol+", port="+port+", enabled="+enabled+", description="+description+
", publicIp="+publicIp+" persistence="+persistence+", redirectUrl="+redirectUrl+
", monitor="+monitor+", trustedNetworkGroup="+trustedNetworkGroup+
", backupInternetService="+backupInternetService+", nodeServices="+nodeServices;
}
}

View File

@ -0,0 +1,135 @@
/**
* 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.service.internet;
import org.jclouds.javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import static com.google.common.base.CaseFormat.*;
/**
* <xs:complexType name="InternetServiceType">
* @author Jason King
*/
public class InternetServicePersistenceType {
@XmlEnum
public static enum PersistenceType {
@XmlEnumValue("None")
NONE,
@XmlEnumValue("SourceIp")
SOURCE_IP;
public String value() {
String lower = UPPER_UNDERSCORE.to(LOWER_CAMEL,name());
return LOWER_CAMEL.to(UPPER_CAMEL,lower);
}
}
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromNodeServices(this);
}
public static class Builder {
private PersistenceType persistenceType;
private int timeout = -1;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType#getPersistenceType
*/
public Builder persistenceType(PersistenceType persistenceType) {
this.persistenceType = persistenceType;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType#getTimeout
*/
public Builder timeout(int timeout) {
this.timeout = timeout;
return this;
}
public InternetServicePersistenceType build() {
return new InternetServicePersistenceType(persistenceType,timeout);
}
public Builder fromNodeServices(InternetServicePersistenceType in) {
return persistenceType(in.getPersistenceType()).timeout(in.getTimeout());
}
}
private InternetServicePersistenceType() {
//For JAXB and builder use
}
private InternetServicePersistenceType(@Nullable PersistenceType persistenceType, int timeout ) {
this.persistenceType = persistenceType;
this.timeout = timeout;
}
@XmlElement(name = "Type")
private PersistenceType persistenceType;
@XmlElement(name = "Timeout")
private int timeout = -1;
public PersistenceType getPersistenceType() {
return persistenceType;
}
public int getTimeout() {
return timeout;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InternetServicePersistenceType that = (InternetServicePersistenceType) o;
if (timeout != that.timeout) return false;
if (persistenceType != that.persistenceType) return false;
return true;
}
@Override
public int hashCode() {
int result = persistenceType != null ? persistenceType.hashCode() : 0;
result = 31 * result + timeout;
return result;
}
public String toString() {
return "[persistenceType="+persistenceType+", timeout="+timeout+"]";
}
}

View File

@ -0,0 +1,281 @@
/**
* 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.service.node;
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.Task;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Entity;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
import org.jclouds.tmrk.enterprisecloud.domain.network.IpAddressReference;
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
import javax.xml.bind.annotation.XmlElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
/**
* <xs:complexType name="NodeServiceType">
* @author Jason King
*/
public class NodeService extends Entity<NodeService> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromSshKey(this);
}
public static class Builder extends Entity.Builder<NodeService> {
private IpAddressReference ipAddress;
private Protocol protocol;
private int port;
private boolean enabled;
private String description;
/**
* @see NodeService#getIpAddress
*/
public Builder ipAddress(IpAddressReference ipAddress) {
this.ipAddress = ipAddress;
return this;
}
/**
* @see NodeService#getProtocol
*/
public Builder protocol(Protocol protocol) {
this.protocol = protocol;
return this;
}
/**
* @see NodeService#getPort
*/
public Builder port(int port) {
this.port = port;
return this;
}
/**
* @see NodeService#isEnabled
*/
public Builder enabled(boolean enabled) {
this.enabled = enabled;
return this;
}
/**
* @see NodeService#getDescription
*/
public Builder description(String description) {
this.description = description;
return this;
}
@Override
public NodeService build() {
return new NodeService(href, type, name, links, actions, tasks, ipAddress, protocol, port, enabled, description);
}
public Builder fromSshKey(NodeService in) {
return fromEntity(in).ipAddress(in.getIpAddress())
.protocol(in.getProtocol())
.port(in.getPort())
.enabled(in.isEnabled())
.description(in.getDescription());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<NodeService> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<NodeService> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromEntity(Entity<NodeService> in) {
return Builder.class.cast(super.fromEntity(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 tasks(Set<Task> tasks) {
return Builder.class.cast(super.tasks(tasks));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "IpAddress", required = false)
private IpAddressReference ipAddress;
@XmlElement(name = "Protocol", required = false)
private Protocol protocol;
@XmlElement(name = "Port", required = false)
private int port;
@XmlElement(name = "Enabled", required = false)
private boolean enabled;
@XmlElement(name = "PrivateKey", required = false)
private String description;
private NodeService(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<Task> tasks,
@Nullable IpAddressReference ipAddress, @Nullable Protocol protocol, int port, boolean enabled, @Nullable String description) {
super(href, type, name, links, actions, tasks);
this.ipAddress = ipAddress;
this.protocol = protocol;
this.port = port;
this.enabled = enabled;
this.description = description;
}
private NodeService() {
//For JAXB
}
public IpAddressReference getIpAddress() {
return ipAddress;
}
public Protocol getProtocol() {
return protocol;
}
public int getPort() {
return port;
}
public boolean isEnabled() {
return enabled;
}
public String getDescription() {
return description;
}
@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;
NodeService that = (NodeService) o;
if (enabled != that.enabled) return false;
if (port != that.port) return false;
if (description != null ? !description.equals(that.description) : that.description != null)
return false;
if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null)
return false;
if (protocol != that.protocol) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0);
result = 31 * result + (protocol != null ? protocol.hashCode() : 0);
result = 31 * result + port;
result = 31 * result + (enabled ? 1 : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", ipAddress="+ipAddress+", protocol="+protocol+", port="+port+", enabled="+enabled+", description="+description;
}
}

View File

@ -0,0 +1,104 @@
/**
* 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.service.node;
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 NodeServices {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromNodeServices(this);
}
public static class Builder {
private Set<NodeService> services = Sets.newLinkedHashSet();
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.service.node.NodeServices#getNodeServices()
*/
public Builder services(Set<NodeService> services) {
this.services = Sets.newLinkedHashSet(checkNotNull(services, "services"));
return this;
}
public Builder addNodeService(NodeService service) {
services.add(checkNotNull(service, "service"));
return this;
}
public NodeServices build() {
return new NodeServices(services);
}
public Builder fromNodeServices(NodeServices in) {
return services(in.getNodeServices());
}
}
private NodeServices() {
//For JAXB and builder use
}
private NodeServices(Set<NodeService> services) {
this.services = Sets.newLinkedHashSet(services);
}
@XmlElement(name = "NodeService")
private Set<NodeService> services = Sets.newLinkedHashSet();
public Set<NodeService> getNodeServices() {
return Collections.unmodifiableSet(services);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeServices that = (NodeServices) o;
if (!services.equals(that.services)) return false;
return true;
}
@Override
public int hashCode() {
return services.hashCode();
}
public String toString() {
return "["+ services.toString()+"]";
}
}

View File

@ -19,9 +19,9 @@
package org.jclouds.tmrk.enterprisecloud.domain.vm;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
import org.jclouds.tmrk.enterprisecloud.domain.network.WindowsCustomization;
@ -57,7 +57,7 @@ public class CreateVirtualMachine extends CreateVirtualMachineRequest {
private LinuxCustomization linuxCustomization;
private WindowsCustomization windowsCustomization;
private boolean poweredOn;
private AnonymousResource template;
private NamedResource template;
/**
* @see CreateVirtualMachine#getLinuxCustomization
@ -87,7 +87,7 @@ public class CreateVirtualMachine extends CreateVirtualMachineRequest {
/**
* @see CreateVirtualMachine#getTemplate
*/
public Builder template(AnonymousResource template) {
public Builder template(NamedResource template) {
this.template = template;
return this;
}
@ -164,13 +164,13 @@ public class CreateVirtualMachine extends CreateVirtualMachineRequest {
private boolean poweredOn;
@XmlElement(name = "Template", required = false)
private AnonymousResource template;
private NamedResource template;
private CreateVirtualMachine(String name, int processorCount, ResourceCapacity memory,
@Nullable String description, @Nullable LayoutRequest layout, @Nullable Set<String> tags,
@Nullable LinuxCustomization linuxCustomization, @Nullable WindowsCustomization windowsCustomization,
boolean poweredOn, @Nullable AnonymousResource template) {
boolean poweredOn, @Nullable NamedResource template) {
super(name,processorCount,memory,description,layout,tags);
this.linuxCustomization = linuxCustomization;
this.windowsCustomization = windowsCustomization;
@ -194,7 +194,7 @@ public class CreateVirtualMachine extends CreateVirtualMachineRequest {
return poweredOn;
}
public AnonymousResource getTemplate() {
public NamedResource getTemplate() {
return template;
}

View File

@ -0,0 +1,65 @@
/**
* 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.Task;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
import org.jclouds.tmrk.enterprisecloud.functions.URISource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import java.net.URI;
/**
* Provides asynchronous access to Layouts via their REST API.
* <p/>
*
* @see org.jclouds.tmrk.enterprisecloud.features.LayoutClient
* @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 InternetServiceAsyncClient {
/**
* @see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#getInternetService
*/
@GET
@Consumes("application/vnd.tmrk.cloud.internetService")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<InternetService> getInternetService(@EndpointParam URI uri);
/**
* @see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#editInternetService
*/
@PUT
@Consumes("application/vnd.tmrk.cloud.internetService")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> editInternetService(@EndpointParam(parser = URISource.GetURI.class) InternetService internetService);
}

View File

@ -0,0 +1,78 @@
/**
* 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.Task;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
import java.net.URI;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to Internet Service.
* <p/>
*
* @see org.jclouds.tmrk.enterprisecloud.features.LayoutAsyncClient
* @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 InternetServiceClient {
/**
* getInternetService call returns information regarding a specified Internet service defined in an environment.
* @param uri the uri of the internet service
* e.g. /cloudapi/ecloud/internetservices/{internet service id}
* @return the internet service
*/
InternetService getInternetService(URI uri);
/**
* The editInternetService call edits the name, enablement, description, persistence,
* redirect URL, trusted network group, or backup Internet service
* on a specified Internet service in an environment.
* If successful, the call returns the task that modified the Internet service.
*
* The name property on InternetService is required and may be changed.
* Note: The name may not be changed to that of another Internet service.
* Port is optional and ignored if present.
* Enabled is required.
* Persistence Type refers to the method for persisting a connection session.
* e.g. SourceIp use the IP address of the source device for persistence.
* If Timeout is absent with Type=SourceIp, then Timeout defaults to 2 minutes.
* Omit Timeout if Type=none.
* Note: The minimum value for Timeout is 2 (for two minutes) and the maximum is 5.
* Both TrustedNetworkGroup and BackupInternetService are optional.
* Including a TrustedNetworkGroup or BackupInternetService not currently on the Internet service
* adds that trusted network group or backup Internet service to the Internet service.
* Note: If any TrustedNetworkGroup is valued on the Internet service and not present in the call,
* that trusted network group is removed from the Internet service.
* Similarly, if any BackupInternetService is valued on the Internet service and not present in the call,
* that backup Internet service is removed from the Internet service.
*
* @param service the internet service to edit
* @return the Task representing the create action
*/
Task editInternetService(InternetService service);
}

View File

@ -0,0 +1,37 @@
package org.jclouds.tmrk.enterprisecloud.functions;
import com.google.common.base.Function;
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
import java.net.URI;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Defines the URI Source interface and a function that uses it to obtain the URI
* @author Jason King
*/
public interface URISource {
URI getURI();
/**
* Converts a URI Source to a URI
*/
public class GetURI implements Function<Object, URI> {
/**
* Expects to be called with an object implementing the URISource interface
* Calls the getURI method to obtain the URI.
* @param source a URISource
* @return the URI
*/
@Override
public URI apply(Object source) {
checkArgument(checkNotNull(source, "source") instanceof URISource, "this function is only valid for URISource instances");
URISource uriSource = URISource.class.cast(source);
return uriSource.getURI();
}
}
}

View File

@ -24,7 +24,6 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.http.HttpRequest;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
@ -84,11 +83,11 @@ public class BindCreateVirtualMachineKeyToXmlPayloadTest {
.processorCount(2)
.memory(ResourceCapacity.builder().value(1024).unit("MB").build());
AnonymousResource group = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/layoutgroups/308")).type("application/vnd.tmrk.cloud.layoutGroup").build();
NamedResource group = NamedResource.builder().href(URI.create("/cloudapi/ecloud/layoutgroups/308")).type("application/vnd.tmrk.cloud.layoutGroup").build();
builder.layout(LayoutRequest.builder().group(group).build());
builder.description("This is my first VM");
builder.tags(ImmutableSet.of("Web"));
AnonymousResource sshKey = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/admin/sshkeys/77")).type("application/vnd.tmrk.cloud.admin.sshKey").build();
NamedResource sshKey = NamedResource.builder().href(URI.create("/cloudapi/ecloud/admin/sshkeys/77")).type("application/vnd.tmrk.cloud.admin.sshKey").build();
NamedResource network = NamedResource.builder()
.href(URI.create("/cloudapi/ecloud/networks/3936"))
@ -111,7 +110,7 @@ public class BindCreateVirtualMachineKeyToXmlPayloadTest {
.build();
builder.linuxCustomization(linuxCustomization);
AnonymousResource template = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/templates/6/computepools/89")).type("application/vnd.tmrk.cloud.template").build();
NamedResource template = NamedResource.builder().href(URI.create("/cloudapi/ecloud/templates/6/computepools/89")).type("application/vnd.tmrk.cloud.template").build();
builder.template(template);
binder.bindToRequest(request, builder.build());
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));

View File

@ -0,0 +1,169 @@
/**
* 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.binders;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.http.HttpRequest;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.URI;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code BindInternetServiceToXmlPayload}
* @author Jason King
*/
@Test(groups = "unit", testName = "BindInternetServiceToXmlPayloadTest")
public class BindInternetServiceToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
}
});
public void testPayloadMinimalXmlContent() throws IOException {
String expected =
"<InternetService name='testName'>" +
"<Enabled>true</Enabled>" +
"<Persistence>" +
"<Type>None</Type>" +
"</Persistence>" +
"</InternetService>";
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindInternetServiceToXmlPayload binder = injector
.getInstance(BindInternetServiceToXmlPayload.class);
InternetService.Builder builder = InternetService.builder();
builder.href(URI.create("/cloudapi/ecloud/internetservices/797"));
builder.name("testName");
builder.enabled(true);
builder.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.NONE).build());
binder.bindToRequest(request, builder.build());
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));
}
public void testPayloadWithSourceIPXmlContent() throws IOException {
String expected =
"<InternetService name='testName'>" +
"<Enabled>true</Enabled>" +
"<Persistence>" +
"<Type>SourceIp</Type>" +
"</Persistence>" +
"</InternetService>";
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindInternetServiceToXmlPayload binder = injector
.getInstance(BindInternetServiceToXmlPayload.class);
InternetService.Builder builder = InternetService.builder();
builder.href(URI.create("/cloudapi/ecloud/internetservices/797"));
builder.name("testName");
builder.enabled(true);
builder.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.SOURCE_IP).build());
binder.bindToRequest(request, builder.build());
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));
}
public void testPayloadWithSourceIPAndTimeoutXmlContent() throws IOException {
String expected =
"<InternetService name='testName'>" +
"<Enabled>true</Enabled>" +
"<Persistence>" +
"<Type>SourceIp</Type>" +
"<Timeout>5</Timeout>" +
"</Persistence>" +
"</InternetService>";
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindInternetServiceToXmlPayload binder = injector
.getInstance(BindInternetServiceToXmlPayload.class);
InternetService.Builder builder = InternetService.builder();
builder.href(URI.create("/cloudapi/ecloud/internetservices/797"));
builder.name("testName");
builder.enabled(true);
builder.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.SOURCE_IP).timeout(5).build());
binder.bindToRequest(request, builder.build());
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));
}
public void testPayloadRedirectURLContent() throws IOException {
String expected =
"<InternetService name='testName'>" +
"<Enabled>true</Enabled>" +
"<Persistence>" +
"<Type>None</Type>" +
"</Persistence>" +
"<RedirectUrl>/dev/null</RedirectUrl>" +
"</InternetService>";
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindInternetServiceToXmlPayload binder = injector
.getInstance(BindInternetServiceToXmlPayload.class);
InternetService.Builder builder = InternetService.builder();
builder.href(URI.create("/cloudapi/ecloud/internetservices/797"));
builder.name("testName");
builder.enabled(true);
builder.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.NONE).build());
builder.redirectUrl("/dev/null");
binder.bindToRequest(request, builder.build());
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));
}
public void testPayloadTrustedNetworkGroupAndBackupServiceXmlContent() throws IOException {
String expected =
"<InternetService name='testName'>" +
"<Enabled>true</Enabled>" +
"<Persistence>" +
"<Type>None</Type>" +
"</Persistence>" +
"<TrustedNetworkGroup href='/dev/null' name='groupName' type='groupType'/>"+
"<BackupInternetService href='/foo/bar' name='backupName' type='backupType'/>"+
"</InternetService>";
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindInternetServiceToXmlPayload binder = injector
.getInstance(BindInternetServiceToXmlPayload.class);
InternetService.Builder builder = InternetService.builder();
builder.href(URI.create("/cloudapi/ecloud/internetservices/797"));
builder.name("testName");
builder.enabled(true);
builder.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.NONE).build());
builder.trustedNetworkGroup(NamedResource.builder().href(URI.create("/dev/null")).name("groupName").type("groupType").build());
builder.backupInternetService(NamedResource.builder().href(URI.create("/foo/bar")).name("backupName").type("backupType").build());
binder.bindToRequest(request, builder.build());
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));
}
}

View File

@ -0,0 +1,44 @@
/**
* 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.internal;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.functions.URISource;
import org.testng.annotations.Test;
import java.net.URI;
import java.net.URISyntaxException;
import static org.testng.Assert.assertEquals;
/**
* @author Jason King
*/
@Test(groups = "unit", testName = "BaseResourceTest")
public class NamedResourceTest {
/**
* Tests getURI on BaseResource via NamedResource subclass
*/
public void testGetURI() throws URISyntaxException {
URI uri = URI.create("/dev/null");
URISource source = NamedResource.builder().href(uri).build();
assertEquals(uri,source.getURI());
}
}

View File

@ -0,0 +1,83 @@
/**
* 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.inject.TypeLiteral;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Tests annotation parsing of {@code InternetServiceAsyncClient}
*
* @author Jason King
*/
@Test(groups = "unit", testName = "LayoutAsyncClientTest")
public class InternetServiceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<InternetServiceAsyncClient> {
public void testGetInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = InternetServiceAsyncClient.class.getMethod("getInternetService", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/internetservices/797"));
String requestLine = "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/internetservices/797 HTTP/1.1";
assertRequestLineEquals(httpRequest, requestLine);
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.internetService\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testEditInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = InternetServiceAsyncClient.class.getMethod("editInternetService", InternetService.class);
URI uri = URI.create("/cloudapi/ecloud/internetservices/797");
InternetService service = InternetService.builder().href(uri).build();
HttpRequest httpRequest = processor.createRequest(method, service);
String requestLine = "PUT https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/internetservices/797 HTTP/1.1";
assertRequestLineEquals(httpRequest, requestLine);
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.internetService\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<InternetServiceAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<InternetServiceAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,81 @@
/**
* 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.Task;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.net.URI;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
/**
* Tests behavior of {@code InternetServiceClient}
*
* @author Jason King
*/
@Test(groups = "live", testName = "InternetServiceClientLiveTest")
public class InternetServiceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
@BeforeGroups(groups = { "live" })
public void setupClient() {
super.setupClient();
client = context.getApi().getInternetServiceClient();
}
private InternetServiceClient client;
public void testGetInternetService() throws Exception {
//TODO: The URI should come from the environment
//TODO: Should create a new service edit it then delete it.
//TODO: Need a retryable predicate to wait until the task is done.
URI uri = URI.create("/cloudapi/ecloud/internetservices/797");
InternetService internetService = client.getInternetService(uri);
assertNotNull(internetService);
/*
final String originalName = internetService.getName();
final String newName = originalName+"edited";
boolean enable = !internetService.isEnabled();
// Change the name and enabled flag
testEditInternetService(internetService.getHref(),newName,enable);
internetService = client.getInternetService(uri);
assertEquals(internetService.getName(),newName);
assertEquals(internetService.isEnabled(),enable);
// Change it back again
enable = !internetService.isEnabled();
testEditInternetService(internetService.getHref(),originalName,enable);
assertEquals(internetService.getName(),originalName);
assertEquals(internetService.isEnabled(),enable);
*/
}
public void testGetMissingInternetService() {
assertNull(client.getInternetService(URI.create("/cloudapi/ecloud/internetservices/-1")));
}
private void testEditInternetService(URI uri, String name, boolean enable) {
InternetService service = InternetService.builder().href(uri).name(name).enabled(enable).build();
Task task = client.editInternetService(service);
//TODO: Wait for task to complete.
}
}

View File

@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
import org.jclouds.tmrk.enterprisecloud.domain.network.*;
@ -112,11 +111,11 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
.processorCount(2)
.memory(ResourceCapacity.builder().value(1024).unit("MB").build());
AnonymousResource group = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/layoutgroups/308")).type("application/vnd.tmrk.cloud.layoutGroup").build();
NamedResource group = NamedResource.builder().href(URI.create("/cloudapi/ecloud/layoutgroups/308")).type("application/vnd.tmrk.cloud.layoutGroup").build();
builder.layout(LayoutRequest.builder().group(group).build());
builder.description("This is my first VM");
builder.tags(ImmutableSet.of("Web"));
AnonymousResource sshKey = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/admin/sshkeys/77")).type("application/vnd.tmrk.cloud.admin.sshKey").build();
NamedResource sshKey = NamedResource.builder().href(URI.create("/cloudapi/ecloud/admin/sshkeys/77")).type("application/vnd.tmrk.cloud.admin.sshKey").build();
NamedResource network = NamedResource.builder()
.href(URI.create("/cloudapi/ecloud/networks/3933"))
@ -142,7 +141,7 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
.build();
builder.linuxCustomization(linuxCustomization);
AnonymousResource template = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/templates/6/computepools/89")).type("application/vnd.tmrk.cloud.template").build();
NamedResource template = NamedResource.builder().href(URI.create("/cloudapi/ecloud/templates/6/computepools/89")).type("application/vnd.tmrk.cloud.template").build();
builder.template(template);
VirtualMachine vm = client.createVirtualMachineFromTemplate(URI.create("/cloudapi/ecloud/virtualMachines/computePools/89/action/createVirtualMachine"), builder.build());

View File

@ -0,0 +1,62 @@
/**
* 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.functions;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.net.URI;
import static org.testng.Assert.assertEquals;
/**
*
* @author Jason King
*/
@Test(groups = "unit", testName = "GetURITest")
public class GetURITest {
private URISource.GetURI function;
@BeforeMethod
public void setUp() {
function = new URISource.GetURI();
}
public void testApply() {
URI expected = URI.create("/dev/null");
URISource source = new TestURISource(expected);
URI result = function.apply(source);
assertEquals(result,expected);
}
private static class TestURISource implements URISource {
private URI expected;
public TestURISource(URI expected) {
this.expected = expected;
}
@Override
public URI getURI() {
return expected;
}
}
}

View File

@ -35,7 +35,7 @@ import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistics;
import org.jclouds.tmrk.enterprisecloud.features.ResourceAsyncClient;
import org.testng.annotations.BeforeClass;
@ -102,8 +102,8 @@ public class ComputePoolPerformanceStatisticsJAXBParsingTest extends BaseRestCli
assertEquals(stats.getDaily().getMemory(), createResource("memory", "daily"));
}
private AnonymousResource createResource(String type, String period) {
return AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/computepools/89/usage/"+type+"/performancestatistics/"+period))
private NamedResource createResource(String type, String period) {
return NamedResource.builder().href(URI.create("/cloudapi/ecloud/computepools/89/usage/"+type+"/performancestatistics/"+period))
.type("application/vnd.tmrk.cloud.performanceStatistics")
.build();
}

View File

@ -0,0 +1,128 @@
/**
* 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.common.collect.Iterables;
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.IpAddressReference;
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
import org.jclouds.tmrk.enterprisecloud.domain.service.node.NodeService;
import org.jclouds.tmrk.enterprisecloud.domain.service.node.NodeServices;
import org.jclouds.tmrk.enterprisecloud.features.InternetServiceAsyncClient;
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.assertEquals;
import static org.testng.Assert.assertTrue;
/**
* Tests behavior of JAXB parsing for Location
*
* @author Jason King
*/
@Test(groups = "unit", testName = "InternetServiceJAXBParsingTest")
public class InternetServiceJAXBParsingTest 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 testParseInternetServiceWithJAXB() throws Exception {
Method method = InternetServiceAsyncClient.class.getMethod("getInternetService",URI.class);
HttpRequest request = factory(InternetServiceAsyncClient.class).createRequest(method, new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, InternetService> parser = (Function<HttpResponse, InternetService>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/internetService.xml");
InternetService internetService = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertEquals(internetService.getProtocol(), Protocol.TCP);
assertEquals(internetService.getPort(),22);
assertTrue(internetService.isEnabled());
assertEquals(internetService.getPublicIp(), NamedResource.builder().href(URI.create("/cloudapi/ecloud/publicips/3929")).type("application/vnd.tmrk.cloud.publicIp").name("208.39.65.40").build());
assertEquals(internetService.getPersistence().getPersistenceType(), InternetServicePersistenceType.PersistenceType.NONE);
assertEquals(internetService.getPersistence().getTimeout(), -1); //Default value
assertEquals(internetService.getMonitor(),NamedResource.builder().href(URI.create("/cloudapi/ecloud/internetservices/797/monitor")).type("application/vnd.tmrk.cloud.defaultMonitor").build());
assertNodeServices(internetService.getNodeServices());
System.out.println(internetService);
}
private void assertNodeServices(NodeServices nodeServices) {
assertEquals(nodeServices.getNodeServices().size(),1);
NodeService nodeService = Iterables.getOnlyElement(nodeServices.getNodeServices());
assertEquals(nodeService.getName(),"ssh");
IpAddressReference ipAddress = nodeService.getIpAddress();
assertEquals(ipAddress.getName(),"10.146.205.131");
assertEquals(ipAddress.getNetwork(),NamedResource.builder().href(URI.create("/cloudapi/ecloud/networks/3933")).type("application/vnd.tmrk.cloud.network").name("10.146.205.128/27").build());
assertEquals(ipAddress.getHost(),NamedResource.builder().href(URI.create("/cloudapi/ecloud/networkhosts/7144")).type("application/vnd.tmrk.cloud.networkHost").name("vmDMZ1").build());
assertEquals(nodeService.getProtocol(), Protocol.TCP);
assertEquals(nodeService.getPort(),22);
assertTrue(nodeService.isEnabled());
}
}

View File

@ -0,0 +1,97 @@
<InternetService href="/cloudapi/ecloud/internetservices/797" name="ssh"
type="application/vnd.tmrk.cloud.internetService"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/publicips/3929" name="208.39.65.40"
type="application/vnd.tmrk.cloud.publicIp" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/internetservices/797" name="edit"
type="application/vnd.tmrk.cloud.internetService"/>
<Action href="/cloudapi/ecloud/nodeservices/internetservices/797/action/createnodeservice"
name="createNodeService"
type="application/vnd.tmrk.cloud.createNodeService"/>
<Action href="/cloudapi/ecloud/internetservices/797" name="remove"
actionDisabled="disabled"/>
<Action href="/cloudapi/ecloud/internetservices/797/action/createecvmonitor"
name="createEcvMonitor"
type="application/vnd.tmrk.cloud.createEcvMonitor"
actionDisabled="disabled"/>
<Action href="/cloudapi/ecloud/internetservices/797/action/createhttpmonitor"
name="createHttpMonitor"
type="application/vnd.tmrk.cloud.createHttpMonitor"
actionDisabled="disabled"/>
<Action href="/cloudapi/ecloud/internetservices/797/action/createpingmonitor"
name="createPingMonitor"
type="application/vnd.tmrk.cloud.createPingMonitor"/>
<Action href="/cloudapi/ecloud/internetservices/797/action/createdefaultmonitor"
name="createDefaultMonitor" actionDisabled="disabled"/>
<Action href="/cloudapi/ecloud/internetservices/797/action/createloopbackmonitor"
name="createLoopbackMonitor"/>
</Actions>
<Tasks>
<Task href="/cloudapi/ecloud/tasks/30926"
type="application/vnd.tmrk.cloud.task">
<Operation>Add Internet Service</Operation>
<Status>Complete</Status>
<ImpactedItem href="/cloudapi/ecloud/internetservices/797"
name="208.39.65.40"
type="application/vnd.tmrk.cloud.internetService"/>
<StartTime>2011-12-19T19:34:33.57Z</StartTime>
<CompletedTime>2011-12-19T19:34:36.03Z</CompletedTime>
<Notes>Name: ssh
Public IP: 208.39.65.40
Protocol: TCP
Port: 22
Persistence: N/A
Persistence Type: NONE
Redirect URL:
State: Enabled
Trusted Network Group: ANY
</Notes>
<InitiatedBy href="/cloudapi/ecloud/admin/users/1804"
name="Jason King"
type="application/vnd.tmrk.cloud.admin.user"/>
</Task>
<TotalCount>1</TotalCount>
</Tasks>
<Protocol>TCP</Protocol>
<Port>22</Port>
<Enabled>true</Enabled>
<Description>this is ssh</Description>
<PublicIp href="/cloudapi/ecloud/publicips/3929" name="208.39.65.40"
type="application/vnd.tmrk.cloud.publicIp"/>
<Persistence>
<Type>None</Type>
</Persistence>
<Monitor href="/cloudapi/ecloud/internetservices/797/monitor"
type="application/vnd.tmrk.cloud.defaultMonitor"/>
<NodeServices>
<NodeService href="/cloudapi/ecloud/nodeservices/606" name="ssh"
type="application/vnd.tmrk.cloud.nodeService">
<Links>
<Link href="/cloudapi/ecloud/internetservices/797" name="ssh"
type="application/vnd.tmrk.cloud.internetService"
rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/nodeservices/606" name="edit"
type="application/vnd.tmrk.cloud.nodeService"/>
<Action href="/cloudapi/ecloud/nodeservices/606" name="remove"/>
</Actions>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3933/10.146.205.131"
name="10.146.205.131">
<Network href="/cloudapi/ecloud/networks/3933"
name="10.146.205.128/27"
type="application/vnd.tmrk.cloud.network"/>
<Host href="/cloudapi/ecloud/networkhosts/7144" name="vmDMZ1"
type="application/vnd.tmrk.cloud.networkHost"/>
</IpAddress>
<Protocol>TCP</Protocol>
<Port>22</Port>
<Enabled>true</Enabled>
<Description/>
</NodeService>
</NodeServices>
</InternetService>