mirror of https://github.com/apache/jclouds.git
Issue 695: Service call for HardwareConfiguration+parsing+tests
This commit is contained in:
parent
39be81a337
commit
835ea8bb57
|
@ -29,6 +29,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.network.Nics;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -40,6 +41,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
* <xs:complexType name="HardwareConfiguration">
|
* <xs:complexType name="HardwareConfiguration">
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
*/
|
*/
|
||||||
|
@XmlRootElement(name = "HardwareConfiguration")
|
||||||
public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.*;
|
import org.jclouds.rest.annotations.*;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
||||||
|
@ -81,4 +82,13 @@ public interface VirtualMachineAsyncClient {
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<VirtualMachineConfigurationOptions> getConfigurationOptions(@EndpointParam URI uri);
|
ListenableFuture<VirtualMachineConfigurationOptions> getConfigurationOptions(@EndpointParam URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualMachineClient#getHardwareConfiguration
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.virtualMachineHardware")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<HardwareConfiguration> getHardwareConfiguration(@EndpointParam URI uri);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.tmrk.enterprisecloud.features;
|
package org.jclouds.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
||||||
|
@ -71,4 +72,12 @@ public interface VirtualMachineClient {
|
||||||
*/
|
*/
|
||||||
VirtualMachineConfigurationOptions getConfigurationOptions(URI uri);
|
VirtualMachineConfigurationOptions getConfigurationOptions(URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Get Virtual Machines Hardware Configuration call returns information
|
||||||
|
* regarding the hardware configuration of a specified virtual machine in a compute pool.
|
||||||
|
* @param uri the uri for the hardware configuration e.g. /cloudapi/ecloud/virtualmachines/{id}/hardwareconfiguration
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HardwareConfiguration getHardwareConfiguration(URI uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetVirtualMachineConfigurationOptions() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
public void testGetConfigurationOptions() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
Method method = VirtualMachineAsyncClient.class.getMethod("getConfigurationOptions", URI.class);
|
Method method = VirtualMachineAsyncClient.class.getMethod("getConfigurationOptions", URI.class);
|
||||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
|
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
|
||||||
|
|
||||||
|
@ -95,6 +95,20 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetHardwareConfiguration() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
|
Method method = VirtualMachineAsyncClient.class.getMethod("getHardwareConfiguration", URI.class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachineHardware\nx-tmrk-version: 2011-07-01\n");
|
||||||
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||||
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>> createTypeLiteral() {
|
protected TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>> createTypeLiteral() {
|
||||||
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {
|
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.tmrk.enterprisecloud.features;
|
package org.jclouds.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||||
|
@ -85,8 +86,19 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
|
||||||
assertNull(assignedIpAddresses);
|
assertNull(assignedIpAddresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetVirtualMachineConfigurationOptions() throws Exception {
|
public void testGetConfigurationOptions() throws Exception {
|
||||||
VirtualMachineConfigurationOptions virtualMachineConfigurationOptions = client.getConfigurationOptions(new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
|
VirtualMachineConfigurationOptions configurationOptions = client.getConfigurationOptions(new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
|
||||||
assertNotNull(virtualMachineConfigurationOptions);
|
assertNotNull(configurationOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetHardwareConfiguration() throws Exception {
|
||||||
|
HardwareConfiguration hardwareConfiguration = client.getHardwareConfiguration(new URI("/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"));
|
||||||
|
assertNotNull(hardwareConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetHardwareConfigurationWhenMissing() throws Exception {
|
||||||
|
HardwareConfiguration result = client.getHardwareConfiguration(new URI("/cloudapi/ecloud/virtualmachines/-1/hardwareconfiguration"));
|
||||||
|
assertNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.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.hardware.HardwareConfiguration;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
|
||||||
|
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.assertFalse;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import static org.testng.AssertJUnit.assertEquals;
|
||||||
|
import static org.testng.AssertJUnit.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of JAXB parsing for VirtualMachines
|
||||||
|
* @author Jason King
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class HardwareConfigurationJAXBParsingTest 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(groups = "unit", testName = "HardwareConfigurationJAXBParsingTest")
|
||||||
|
public void testParse() throws Exception {
|
||||||
|
|
||||||
|
Method method = VirtualMachineAsyncClient.class.getMethod("getHardwareConfiguration", URI.class);
|
||||||
|
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
|
||||||
|
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||||
|
|
||||||
|
Function<HttpResponse, HardwareConfiguration> parser = (Function<HttpResponse, HardwareConfiguration>) RestAnnotationProcessor
|
||||||
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
|
InputStream is = getClass().getResourceAsStream("/hardwareConfiguration.xml");
|
||||||
|
HardwareConfiguration hardwareConfiguration = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||||
|
|
||||||
|
assertHardwareConfiguration(hardwareConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) throws Exception {
|
||||||
|
assertEquals(1,hardwareConfiguration.getActions().size());
|
||||||
|
assertEquals(1,hardwareConfiguration.getProcessorCount());
|
||||||
|
ResourceCapacity memory = ResourceCapacity.builder().value(384).unit("MB").build();
|
||||||
|
assertEquals(memory,hardwareConfiguration.getMemory());
|
||||||
|
assertDisks(hardwareConfiguration.getVirtualDisks());
|
||||||
|
assertNics(hardwareConfiguration.getVirtualNics());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertDisks(Set<VirtualDisk> disks) {
|
||||||
|
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
|
||||||
|
.size(ResourceCapacity.builder().value(10).unit("GB").build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(ImmutableSet.of(disk), disks);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void assertNics(Set<VirtualNic> nics) throws Exception {
|
||||||
|
|
||||||
|
assertEquals(1, nics.size());
|
||||||
|
|
||||||
|
NetworkReference network = NetworkReference.builder()
|
||||||
|
.href(new URI("/cloudapi/ecloud/networks/3936"))
|
||||||
|
.name("10.146.204.64/28")
|
||||||
|
.type("application/vnd.tmrk.cloud.network")
|
||||||
|
.networkType(NetworkReference.NetworkType.INTERNAL)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
VirtualNic nic = VirtualNic.builder()
|
||||||
|
.macAddress("00:50:56:b8:00:58")
|
||||||
|
.name("Network adapter 1")
|
||||||
|
.network(network)
|
||||||
|
.unitNumber(7)
|
||||||
|
.build();
|
||||||
|
assertEquals(nic,nics.iterator().next());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
<HardwareConfiguration
|
||||||
|
href="/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"
|
||||||
|
type="application/vnd.tmrk.cloud.virtualMachineHardware"
|
||||||
|
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"
|
||||||
|
name="edit"
|
||||||
|
type="application/vnd.tmrk.cloud.virtualMachineHardware"/>
|
||||||
|
</Actions>
|
||||||
|
<ProcessorCount>1</ProcessorCount>
|
||||||
|
<Memory>
|
||||||
|
<Unit>MB</Unit>
|
||||||
|
<Value>384</Value>
|
||||||
|
</Memory>
|
||||||
|
<Disks>
|
||||||
|
<Disk>
|
||||||
|
<Index>0</Index>
|
||||||
|
<Size>
|
||||||
|
<Unit>GB</Unit>
|
||||||
|
<Value>10</Value>
|
||||||
|
</Size>
|
||||||
|
<Name>Hard Disk 1</Name>
|
||||||
|
</Disk>
|
||||||
|
</Disks>
|
||||||
|
<Nics>
|
||||||
|
<Nic>
|
||||||
|
<UnitNumber>7</UnitNumber>
|
||||||
|
<Name>Network adapter 1</Name>
|
||||||
|
<MacAddress>00:50:56:b8:00:58</MacAddress>
|
||||||
|
<Network href="/cloudapi/ecloud/networks/3936"
|
||||||
|
name="10.146.204.64/28"
|
||||||
|
type="application/vnd.tmrk.cloud.network">
|
||||||
|
<NetworkType>Internal</NetworkType>
|
||||||
|
</Network>
|
||||||
|
</Nic>
|
||||||
|
</Nics>
|
||||||
|
</HardwareConfiguration>
|
Loading…
Reference in New Issue