Merge pull request #187 from jsonking/695-1

Issue 695: Added service calls for getTasksByVirtualMachine and getVirtualMachineConfigOptions
This commit is contained in:
Adrian Cole 2011-11-22 13:44:23 -08:00
commit e2372fa4c2
19 changed files with 610 additions and 249 deletions

View File

@ -0,0 +1,140 @@
/**
* 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;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
/**
* <xs:complexType name="ResourceCapacityRange">
* @author Jason King
*/
public class ResourceCapacityRange {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromResourceCapacityRange(this);
}
public static class Builder {
private ResourceCapacity minimumSize;
private ResourceCapacity maximumSize;
private ResourceCapacity stepFactor;
/**
* @see ResourceCapacityRange#getMinimumSize
*/
public Builder minimumSize(ResourceCapacity minimumSize) {
this.minimumSize = minimumSize;
return this;
}
/**
* @see ResourceCapacityRange#getMaximumSize
*/
public Builder maximumSize(ResourceCapacity maximumSize) {
this.maximumSize = maximumSize;
return this;
}
/**
* @see ResourceCapacityRange#getStepFactor
*/
public Builder stepFactor(ResourceCapacity stepFactor) {
this.stepFactor = stepFactor;
return this;
}
public ResourceCapacityRange build() {
return new ResourceCapacityRange(minimumSize,maximumSize,stepFactor);
}
public Builder fromResourceCapacityRange(ResourceCapacityRange in) {
return minimumSize(in.getMinimumSize()).maximumSize(in.getMaximumSize()).stepFactor(in.getStepFactor());
}
}
@XmlElement(name = "MinimumSize", required = false)
private ResourceCapacity minimumSize;
@XmlElement(name = "MaximumSize", required = false)
private ResourceCapacity maximumSize;
@XmlElement(name = "StepFactor", required = false)
private ResourceCapacity stepFactor;
private ResourceCapacityRange(@Nullable ResourceCapacity minimumSize, @Nullable ResourceCapacity maximumSize, @Nullable ResourceCapacity stepFactor) {
this.minimumSize = minimumSize;
this.maximumSize = maximumSize;
this.stepFactor = stepFactor;
}
private ResourceCapacityRange() {
//For JAXB
}
public ResourceCapacity getMinimumSize() {
return minimumSize;
}
public ResourceCapacity getMaximumSize() {
return maximumSize;
}
public ResourceCapacity getStepFactor() {
return stepFactor;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceCapacityRange that = (ResourceCapacityRange) o;
if (maximumSize != null ? !maximumSize.equals(that.maximumSize) : that.maximumSize != null)
return false;
if (minimumSize != null ? !minimumSize.equals(that.minimumSize) : that.minimumSize != null)
return false;
if (stepFactor != null ? !stepFactor.equals(that.stepFactor) : that.stepFactor != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = minimumSize != null ? minimumSize.hashCode() : 0;
result = 31 * result + (maximumSize != null ? maximumSize.hashCode() : 0);
result = 31 * result + (stepFactor != null ? stepFactor.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[minimumSize="+ minimumSize +", maximumSize="+maximumSize+", stepFactor="+stepFactor+"]";
}
}

View File

@ -1,84 +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;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
/**
* @author Jason King
*/
public class Size extends ResourceCapacity<Size> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromSize(this);
}
public static class Builder extends ResourceCapacity.Builder<Size> {
@Override
public Size build() {
return new Size(value,unit);
}
public Builder fromSize(Size in) {
return fromResource(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(ResourceCapacity<Size> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder value(double value) {
return Builder.class.cast(super.value(value));
}
/**
* {@inheritDoc}
*/
@Override
public Builder unit(String unit) {
return Builder.class.cast(super.unit(unit));
}
}
public Size(double value, String unit) {
super(value, unit);
}
protected Size() {
//For JAXB
}
}

View File

@ -24,6 +24,7 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Actions;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.Nics;
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
@ -59,7 +60,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
// TODO Links
private Set<Action> actions = Sets.newLinkedHashSet();
private int processorCount;
private Memory memory;
private ResourceCapacity memory;
private Set<VirtualDisk> virtualDisks = Sets.newLinkedHashSet();
private Set<VirtualNic> virtualNics = Sets.newLinkedHashSet();
@ -82,7 +83,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
/**
* @see HardwareConfiguration#getMemory
*/
public Builder memory(Memory memory) {
public Builder memory(ResourceCapacity memory) {
this.memory = memory;
return this;
}
@ -157,7 +158,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
private int processorCount;
@XmlElement(name = "Memory", required = false)
private Memory memory;
private ResourceCapacity memory;
@XmlElement(name = "Disks", required = false)
private Disks virtualDisks = Disks.builder().build();
@ -165,7 +166,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@XmlElement(name = "Nics", required = false)
private Nics virtualNics = Nics.builder().build();
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable Memory memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable ResourceCapacity memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build();
this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build();
this.virtualNics = Nics.builder().nics(checkNotNull(virtualNics, "virtualNics")).build();
@ -185,7 +186,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return processorCount;
}
public Memory getMemory() {
public ResourceCapacity getMemory() {
return memory;
}

View File

@ -1,84 +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.hardware;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
/**
* @author Jason King
*/
public class Memory extends ResourceCapacity<Memory> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromMemory(this);
}
public static class Builder extends ResourceCapacity.Builder<Memory> {
@Override
public Memory build() {
return new Memory(value,unit);
}
public Builder fromMemory(Memory in) {
return fromResource(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(ResourceCapacity<Memory> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder value(double value) {
return Builder.class.cast(super.value(value));
}
/**
* {@inheritDoc}
*/
@Override
public Builder unit(String unit) {
return Builder.class.cast(super.unit(unit));
}
}
public Memory(double value, String unit) {
super(value, unit);
}
protected Memory() {
//For JAXB
}
}

View File

@ -19,7 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Size;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
@ -44,7 +44,7 @@ public class VirtualDisk {
public static class Builder {
private String name;
private Size size;
private ResourceCapacity size;
private int index;
/**
@ -58,7 +58,7 @@ public class VirtualDisk {
/**
* @see VirtualDisk#getSize
*/
public Builder size(Size size) {
public Builder size(ResourceCapacity size) {
this.size = size;
return this;
}
@ -86,12 +86,12 @@ public class VirtualDisk {
private String name;
@XmlElement(name = "Size", required = false)
private Size size;
private ResourceCapacity size;
@XmlElement(name = "Index", required = false)
private int index;
public VirtualDisk(@Nullable String name, @Nullable Size size, int index) {
public VirtualDisk(@Nullable String name, @Nullable ResourceCapacity size, int index) {
this.name = name;
this.size = size;
this.index = index;
@ -105,7 +105,7 @@ public class VirtualDisk {
return name;
}
public Size getSize() {
public ResourceCapacity getSize() {
return size;
}

View File

@ -25,42 +25,42 @@ import javax.xml.bind.annotation.XmlElement;
/**
* @author Jason King
*/
public class ResourceCapacity<T extends ResourceCapacity<T>> {
public class ResourceCapacity {
public static <T extends ResourceCapacity<T>> Builder<T> builder() {
return new Builder<T>();
public static Builder builder() {
return new Builder();
}
public Builder<T> toBuilder() {
return new Builder<T>().fromResource(this);
public Builder toBuilder() {
return new Builder().fromResource(this);
}
public static class Builder<T extends ResourceCapacity<T>> {
public static class Builder {
protected double value; //mandatory
protected String unit; //optional
/**
* @see ResourceCapacity#getValue
* @see org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity#getValue
*/
public Builder<T> value(double value) {
public Builder value(double value) {
this.value = value;
return this;
}
/**
* @see ResourceCapacity#getUnit
* @see org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity#getUnit
*/
public Builder<T> unit(String unit) {
public Builder unit(String unit) {
this.unit = unit;
return this;
}
public ResourceCapacity<T> build() {
return new ResourceCapacity<T>(value, unit);
public ResourceCapacity build() {
return new ResourceCapacity(value, unit);
}
public Builder<T> fromResource(ResourceCapacity<T> in) {
public Builder fromResource(ResourceCapacity in) {
return value(in.getValue()).unit(in.getUnit());
}
}
@ -91,36 +91,32 @@ public class ResourceCapacity<T extends ResourceCapacity<T>> {
return unit;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceCapacity that = (ResourceCapacity) o;
if (Double.compare(that.value, value) != 0) return false;
if (unit != null ? !unit.equals(that.unit) : that.unit != null)
return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L;
result = (int) (temp ^ (temp >>> 32));
result = 31 * result + (unit != null ? unit.hashCode() : 0);
return result;
}
@Override
public String toString() {
return String.format("[%s]",string());
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceCapacity that = (ResourceCapacity) o;
if (Double.compare(that.value, value) != 0) return false;
if (unit != null ? !unit.equals(that.unit) : that.unit != null)
return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L;
result = (int) (temp ^ (temp >>> 32));
result = 31 * result + (unit != null ? unit.hashCode() : 0);
return result;
}
protected String string() {
return "value="+value+", unit="+unit;
@Override
public String toString() {
return "[value="+value+", unit="+unit+"]";
}
}

View File

@ -0,0 +1,142 @@
/**
* 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.vm;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
/**
* <xs:complexType name="VirtualMachineConfigurationOptions">
* @author Jason King
*
*/
@XmlRootElement(name = "VirtualMachineConfigurationOptions")
public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMachineConfigurationOptions> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromVirtualMachineConfigurationOptions(this);
}
public static class Builder extends BaseResource.Builder<VirtualMachineConfigurationOptions> {
//TODO There are additional fields
protected ResourceCapacityRange memory;
/**
* @see VirtualMachineConfigurationOptions#getMemory
*/
public Builder memory(ResourceCapacityRange memory) {
this.memory = memory;
return this;
}
@Override
public VirtualMachineConfigurationOptions build() {
return new VirtualMachineConfigurationOptions(href, type, memory);
}
public Builder fromVirtualMachineConfigurationOptions(VirtualMachineConfigurationOptions in) {
return fromResource(in).memory(in.getMemory());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(BaseResource<VirtualMachineConfigurationOptions> 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));
}
}
@XmlElement(name = "Memory", required = false)
private ResourceCapacityRange memory;
private VirtualMachineConfigurationOptions(URI href, String type, @Nullable ResourceCapacityRange memory) {
super(href, type);
this.memory = memory;
}
private VirtualMachineConfigurationOptions() {
//For JAXB
}
/**
*
* @return memory capacity range
*/
public ResourceCapacityRange getMemory() {
return memory;
}
@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;
VirtualMachineConfigurationOptions that = (VirtualMachineConfigurationOptions) o;
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (memory != null ? memory.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", memory="+memory;
}
}

View File

@ -62,4 +62,13 @@ public interface TaskAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> getTask(@EndpointParam URI taskId);
/**
* @see TaskClient#getTasksByVirtualMachine
*/
@GET
@Consumes("application/vnd.tmrk.cloud.task; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Tasks> getTasksByVirtualMachine(@EndpointParam URI uri);
}

View File

@ -52,6 +52,14 @@ public interface TaskClient {
*
* @return the task or null if not found
*/
Task getTask(URI taskId);
Task getTask(URI taskUri);
/**
* The Get Tasks by Virtual Machine call returns information regarding tasks
* for a specified virtual machine in an environment.
* @param uri The uri corresponding to the tasks. e.g. /cloudapi/ecloud/tasks/virtualmachines/{id}
* @return Tasks
*/
Tasks getTasksByVirtualMachine(URI uri);
}

View File

@ -24,6 +24,7 @@ import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import javax.ws.rs.Consumes;
@ -71,4 +72,12 @@ public interface VirtualMachineAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AssignedIpAddresses> getAssignedIpAddresses(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#getVirtualMachineConfigurationOptions
*/
@GET
@Consumes("application/vnd.tmrk.cloud.virtualMachineConfigurationOptions")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VirtualMachineConfigurationOptions> getVirtualMachineConfigurationOptions(@EndpointParam URI uri);
}

View File

@ -21,6 +21,7 @@ package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.concurrent.Timeout;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import java.net.URI;
@ -62,4 +63,12 @@ public interface VirtualMachineClient {
*/
AssignedIpAddresses getAssignedIpAddresses(URI uri);
/**
* The Get Virtual Machines Configuration Options call returns information
* regarding the configuration options of a specified virtual machine in a compute pool.
* @param uri the uri for the configuration options. e.g. /cloudapi/ecloud/virtualmachines/{id}/configurationoptions
* @return the configuration options
*/
VirtualMachineConfigurationOptions getVirtualMachineConfigurationOptions(URI uri);
}

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.tmrk.enterprisecloud.domain.Size;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -39,13 +39,13 @@ public class DisksTest {
@BeforeMethod()
public void setUp() throws URISyntaxException {
disk = VirtualDisk.builder().index(0).name("test disk").size(Size.builder().value(1).unit("GB").build()).build();
disk = VirtualDisk.builder().index(0).name("test disk").size(ResourceCapacity.builder().value(1).unit("GB").build()).build();
disks = Disks.builder().addDisk(disk).build();
}
@Test
public void testAddDisk() throws URISyntaxException {
VirtualDisk disk2 = VirtualDisk.builder().index(1).name("test disk 1").size(Size.builder().value(1).unit("GB").build()).build();
VirtualDisk disk2 = VirtualDisk.builder().index(1).name("test disk 1").size(ResourceCapacity.builder().value(1).unit("GB").build()).build();
Disks twoDisks = disks.toBuilder().addDisk(disk2).build();
Set<VirtualDisk> virtualDisks = twoDisks.getVirtualDisks();

View File

@ -52,12 +52,11 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTask", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1"));
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/1"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
@ -67,7 +66,20 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetTasksByVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTasksByVirtualMachine", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/virtualmachines/5504 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task; type=collection\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override

View File

@ -43,18 +43,26 @@ public class TaskClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTe
private TaskClient client;
@Test
public void testGetTasks() throws Exception {
// TODO: don't hard-code id
// TODO: docs say don't parse the href, yet no xml includes "identifier",
// I suspect we may need to change to URI args as opposed to long
Tasks response = client.getTasksInEnvironment(new URI("/cloudapi/ecloud/tasks/environments/77"));
assert null != response;
assertTasks(response);
}
assertTrue(response.getTasks().size() >= 0);
for (Task task : response.getTasks()) {
public void testGetTasksByVirtualMachine() throws Exception {
// TODO: don't hard-code id
Tasks response = client.getTasksByVirtualMachine(URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504"));
assertTasks(response);
}
private void assertTasks(final Tasks tasks) {
assert null != tasks;
assertTrue(tasks.getTasks().size() >= 0);
for (Task task : tasks.getTasks()) {
assertEquals(client.getTask(task.getHref()), task);
assert task.getStatus() != Task.Status.UNRECOGNIZED : response;
assert task.getStatus() != Task.Status.UNRECOGNIZED : tasks;
}
}
}

View File

@ -80,6 +80,20 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
checkFilters(httpRequest);
}
public void testGetVirtualMachineConfigurationOptions() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachineConfigurationOptions", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/configurationoptions HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachineConfigurationOptions\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<VirtualMachineAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {

View File

@ -22,6 +22,7 @@ import com.google.common.collect.Iterables;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -30,11 +31,12 @@ import java.net.URI;
import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
/**
* Tests behavior of {@code VirtualMachineClient}
*
* TODO: don't hard-code uri's it should be possible to determine them but that means chaining the tests potentially.
* @author Jason King
*/
@Test(groups = "live", testName = "VirtualMachineClientLiveTest")
@ -47,31 +49,31 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
private VirtualMachineClient client;
@Test
public void testGetVirtualMachines() throws Exception {
// TODO: don't hard-code uri
VirtualMachines virtualMachines = client.getVirtualMachines(new URI("/cloudapi/ecloud/virtualMachines/computePools/89"));
for( VirtualMachine vm : virtualMachines.getVirtualMachines()) {
VirtualMachine virtualMachine = client.getVirtualMachine(vm.getHref());
assert null != virtualMachine;
assertNotNull(virtualMachine,"virtualMachine should not be null");
assertEquals(virtualMachine.getStatus(),VirtualMachine.VirtualMachineStatus.DEPLOYED);
}
}
@Test
public void testGetVirtualMachine() throws Exception {
// TODO: don't hard-code uri
VirtualMachine virtualMachine = client.getVirtualMachine(new URI("/cloudapi/ecloud/virtualMachines/5504"));
assert null != virtualMachine;
assertNotNull(virtualMachine,"virtualMachine should not be null");
assertEquals(virtualMachine.getStatus(), VirtualMachine.VirtualMachineStatus.DEPLOYED);
}
@Test
public void testGetAssignedIpAddresses() throws Exception {
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(new URI("/cloudapi/ecloud/virtualMachines/5504/assignedips"));
assert null != assignedIpAddresses;
assertNotNull(assignedIpAddresses,"assignedIpAddresses should not be null");
DeviceNetwork network = Iterables.getOnlyElement(assignedIpAddresses.getNetworks().getDeviceNetworks());
Set<String> ipAddresses = network.getIpAddresses().getIpAddresses();
assertTrue(ipAddresses.size()>0, "vm has no assigned ip addresses");
}
}
public void testGetVirtualMachineConfigurationOptions() throws Exception {
VirtualMachineConfigurationOptions virtualMachineConfigurationOptions = client.getVirtualMachineConfigurationOptions(new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
assertNotNull(virtualMachineConfigurationOptions,"options should not be null");
}
}

View File

@ -0,0 +1,106 @@
/**
* 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.ResourceCapacityRange;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
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;
/**
* Tests behavior of JAXB parsing for VirtualMachineConfigurationOptions
*
* @author Jason King
*/
@Test(groups = "unit", testName = "VirtualMachineConfigurationOptionsJAXBParsingTest")
public class VirtualMachineConfigurationOptionsJAXBParsingTest 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 testParseVirtualMachineWithJAXB() throws Exception {
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachineConfigurationOptions", URI.class);
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, VirtualMachineConfigurationOptions> parser = (Function<HttpResponse, VirtualMachineConfigurationOptions>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/virtualMachineConfigurationOptions.xml");
VirtualMachineConfigurationOptions virtualMachineConfigurationOptions = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertMemoryOptions(virtualMachineConfigurationOptions.getMemory());
}
private void assertMemoryOptions(ResourceCapacityRange memory) {
assertEquals(memory.getMinimumSize(), ResourceCapacity.builder().value(256).unit("MB").build());
assertEquals(memory.getMaximumSize(), ResourceCapacity.builder().value(261120).unit("MB").build());
assertEquals(memory.getStepFactor(), ResourceCapacity.builder().value(4).unit("MB").build());
}
}

View File

@ -35,18 +35,18 @@ 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.*;
import org.jclouds.tmrk.enterprisecloud.domain.Layout;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.Memory;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineIpAddresses;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.Assert;
@ -151,7 +151,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) throws Exception {
assertEquals(1,hardwareConfiguration.getActions().size());
assertEquals(1,hardwareConfiguration.getProcessorCount());
Memory memory = Memory.builder().value(384).unit("MB").build();
ResourceCapacity memory = ResourceCapacity.builder().value(384).unit("MB").build();
assertEquals(memory,hardwareConfiguration.getMemory());
assertDisks(hardwareConfiguration.getVirtualDisks());
assertNics(hardwareConfiguration.getVirtualNics());
@ -159,7 +159,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
private void assertDisks(Set<VirtualDisk> disks) {
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
.size(Size.builder().value(10).unit("GB").build())
.size(ResourceCapacity.builder().value(10).unit("GB").build())
.build();
assertEquals(ImmutableSet.of(disk), disks);

View File

@ -0,0 +1,73 @@
<VirtualMachineConfigurationOptions
href="/cloudapi/ecloud/virtualmachines/5504/configurationoptions"
type="application/vnd.tmrk.cloud.virtualMachineConfigurationOptions"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Processor>
<Minimum>1</Minimum>
<Maximum>8</Maximum>
<StepFactor>1</StepFactor>
</Processor>
<Memory>
<MinimumSize>
<Unit>MB</Unit>
<Value>256</Value>
</MinimumSize>
<MaximumSize>
<Unit>MB</Unit>
<Value>261120</Value>
</MaximumSize>
<StepFactor>
<Unit>MB</Unit>
<Value>4</Value>
</StepFactor>
</Memory>
<Disk>
<Minimum>1</Minimum>
<Maximum>15</Maximum>
<SystemDisk>
<ResourceCapacityRange>
<MinimumSize>
<Unit>GB</Unit>
<Value>1</Value>
</MinimumSize>
<MaximumSize>
<Unit>GB</Unit>
<Value>512</Value>
</MaximumSize>
<StepFactor>
<Unit>GB</Unit>
<Value>1</Value>
</StepFactor>
</ResourceCapacityRange>
<MonthlyCost>0</MonthlyCost>
</SystemDisk>
<DataDisk>
<ResourceCapacityRange>
<MinimumSize>
<Unit>GB</Unit>
<Value>1</Value>
</MinimumSize>
<MaximumSize>
<Unit>GB</Unit>
<Value>512</Value>
</MaximumSize>
<StepFactor>
<Unit>GB</Unit>
<Value>1</Value>
</StepFactor>
</ResourceCapacityRange>
<MonthlyCost>0</MonthlyCost>
</DataDisk>
</Disk>
<NetworkAdapter>
<Minimum>1</Minimum>
<Maximum>4</Maximum>
<StepFactor>1</StepFactor>
</NetworkAdapter>
<Customization>
<Type>Linux</Type>
<CanPowerOn>false</CanPowerOn>
<PasswordRequired>false</PasswordRequired>
<SshKeyRequired>true</SshKeyRequired>
</Customization>
</VirtualMachineConfigurationOptions>