mirror of https://github.com/apache/jclouds.git
Issue 830: Use MetadataClient in VAppTemplateClient and tests
This commit is contained in:
parent
3e114c7b2e
commit
d2dc81a1a9
|
@ -380,12 +380,6 @@ public interface VAppAsyncClient {
|
|||
ListenableFuture<Task> insertMedia(@EndpointParam URI vmURI,
|
||||
@BinderParam(BindToXMLPayload.class) MediaInsertOrEjectParams mediaParams);
|
||||
|
||||
/**
|
||||
* @return asynchronous access to {@link Metadata} features
|
||||
*/
|
||||
@Delegate
|
||||
MetadataAsyncClient.Writable getMetadataClient();
|
||||
|
||||
/**
|
||||
* @see VAppClient#getNetworkConfigSection(URI)
|
||||
*/
|
||||
|
@ -722,4 +716,10 @@ public interface VAppAsyncClient {
|
|||
ListenableFuture<Task> modifyVirtualHardwareSectionSerialPorts(@EndpointParam URI vAppURI,
|
||||
@BinderParam(BindToXMLPayload.class) RasdItemsList rasdItemsList);
|
||||
|
||||
/**
|
||||
* @return asynchronous access to {@link Metadata} features
|
||||
*/
|
||||
@Delegate
|
||||
MetadataAsyncClient.Writable getMetadataClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -433,12 +433,6 @@ public interface VAppClient {
|
|||
*/
|
||||
Task insertMedia(URI vmURI, MediaInsertOrEjectParams mediaParams);
|
||||
|
||||
/**
|
||||
* @return synchronous access to {@link Metadata} features
|
||||
*/
|
||||
@Delegate
|
||||
MetadataClient.Writeable getMetadataClient();
|
||||
|
||||
/**
|
||||
* Retrieves the network config section of a vApp or vApp template.
|
||||
*
|
||||
|
@ -791,4 +785,10 @@ public interface VAppClient {
|
|||
* @since 1.5
|
||||
*/
|
||||
Task modifyVirtualHardwareSectionSerialPorts(URI vAppURI, RasdItemsList rasdItemsList);
|
||||
|
||||
/**
|
||||
* @return synchronous access to {@link Metadata} features
|
||||
*/
|
||||
@Delegate
|
||||
MetadataClient.Writeable getMetadataClient();
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import javax.ws.rs.PathParam;
|
|||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
|
@ -362,5 +363,11 @@ public interface VAppTemplateAsyncClient {
|
|||
ListenableFuture<Task> editProductSectionsForVAppTemplate(@EndpointParam URI templateURI,
|
||||
@BinderParam(BindToXMLPayload.class) ProductSectionList sections);
|
||||
|
||||
// TODO shadowVms ?
|
||||
// TODO shadowVms
|
||||
|
||||
/**
|
||||
* @return asynchronous access to {@link Metadata} features
|
||||
*/
|
||||
@Delegate
|
||||
MetadataAsyncClient.Writable getMetadataClient();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.net.URI;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.CustomizationSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.LeaseSettingsSection;
|
||||
|
@ -155,46 +156,6 @@ public interface VAppTemplateClient {
|
|||
*/
|
||||
Task editVappTemplateLeaseSettingsSection(URI templateUri, LeaseSettingsSection section);
|
||||
|
||||
/**
|
||||
* Retrieves the metadata associated with a vApp Template.
|
||||
*
|
||||
* @param templateUri the URI of the template
|
||||
* @return the requested metadata
|
||||
*/
|
||||
Metadata getVAppTemplateMetadata(URI templateUri);
|
||||
|
||||
/**
|
||||
* Merges the metadata for a vApp Template with the information provided.
|
||||
*
|
||||
* @param templateUri the URI of the template
|
||||
* @return the task performing the action
|
||||
*/
|
||||
Task editVAppTemplateMetadata(URI templateUri, Metadata metadata);
|
||||
|
||||
/**
|
||||
* Consolidates a VM
|
||||
*
|
||||
* @param templateUri the URI of the template
|
||||
* @return the task performing the action
|
||||
*/
|
||||
MetadataValue getVAppTemplateMetadataValue(URI templateUri, String key);
|
||||
|
||||
/**
|
||||
* Consolidates a VM
|
||||
*
|
||||
* @param templateUri the URI of the template
|
||||
* @return the task performing the action
|
||||
*/
|
||||
Task editVAppTemplateMetadataValue(URI templateUri, String key, MetadataValue value);
|
||||
|
||||
/**
|
||||
* Consolidates a VM
|
||||
*
|
||||
* @param templateUri the URI of the template
|
||||
* @return the task performing the action
|
||||
*/
|
||||
Task deleteVAppTemplateMetadataValue(URI templateUri, String key);
|
||||
|
||||
/**
|
||||
* Retrieves the network config section of a vApp or vApp template.
|
||||
*
|
||||
|
@ -269,5 +230,11 @@ public interface VAppTemplateClient {
|
|||
*/
|
||||
Task editProductSectionsForVAppTemplate(URI templateUri, ProductSectionList sections);
|
||||
|
||||
// TODO ShadowVms???
|
||||
// TODO ShadowVms
|
||||
|
||||
/**
|
||||
* @return synchronous access to {@link Metadata} features
|
||||
*/
|
||||
@Delegate
|
||||
MetadataClient.Writeable getMetadataClient();
|
||||
}
|
||||
|
|
|
@ -398,11 +398,11 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
|||
).getVAppTemplateClient();
|
||||
|
||||
assertNotNull(client);
|
||||
Metadata metadata = client.getVAppTemplateMetadata(uri);
|
||||
Metadata metadata = client.getMetadataClient().getMetadata(uri);
|
||||
|
||||
assertEquals(metadata, exampleMetadata());
|
||||
|
||||
Task task = client.editVAppTemplateMetadata(uri, exampleMetadata());
|
||||
Task task = client.getMetadataClient().mergeMetadata(uri, exampleMetadata());
|
||||
assertNotNull(task);
|
||||
}
|
||||
|
||||
|
@ -415,7 +415,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
|||
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata").acceptMedia(ANY).httpRequestBuilder().build(),
|
||||
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateClient();
|
||||
|
||||
client.getVAppTemplateMetadata(uri);
|
||||
client.getMetadataClient().getMetadata(uri);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
||||
|
@ -427,7 +427,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
|||
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/metadata").xmlFilePayload("/vapptemplate/metadata.xml", METADATA).acceptMedia(TASK).httpRequestBuilder().build(),
|
||||
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateClient();
|
||||
|
||||
client.editVAppTemplateMetadata(uri, exampleMetadata());
|
||||
client.getMetadataClient().mergeMetadata(uri, exampleMetadata());
|
||||
}
|
||||
|
||||
public void testVappTemplateMetadataValue() {
|
||||
|
@ -444,14 +444,14 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
|||
).getVAppTemplateClient();
|
||||
|
||||
assertNotNull(client);
|
||||
MetadataValue metadata = client.getVAppTemplateMetadataValue(uri, "12345");
|
||||
MetadataValue metadata = client.getMetadataClient().getMetadataValue(uri, "12345");
|
||||
|
||||
assertEquals(metadata, exampleMetadataValue());
|
||||
|
||||
Task task = client.editVAppTemplateMetadataValue(uri, "12345", exampleMetadataValue());
|
||||
Task task = client.getMetadataClient().setMetadata(uri, "12345", exampleMetadataValue());
|
||||
assertNotNull(task);
|
||||
|
||||
task = client.deleteVAppTemplateMetadataValue(uri, "12345");
|
||||
task = client.getMetadataClient().deleteMetadataEntry(uri, "12345");
|
||||
assertNotNull(task);
|
||||
}
|
||||
|
||||
|
@ -464,7 +464,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
|||
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata/12345").acceptMedia(METADATA_ENTRY).httpRequestBuilder().build(),
|
||||
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateClient();
|
||||
|
||||
client.getVAppTemplateMetadataValue(uri, "12345");
|
||||
client.getMetadataClient().getMetadataValue(uri, "12345");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
||||
|
@ -476,7 +476,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
|||
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/metadata/12345").xmlFilePayload("/vapptemplate/metadataValue.xml", METADATA_ENTRY).acceptMedia(TASK).httpRequestBuilder().build(),
|
||||
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateClient();
|
||||
|
||||
client.editVAppTemplateMetadataValue(uri, "12345", exampleMetadataValue());
|
||||
client.getMetadataClient().setMetadata(uri, "12345", exampleMetadataValue());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
||||
|
@ -488,7 +488,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
|||
new VcloudHttpRequestPrimer().apiCommand("DELETE", templateId + "/metadata/12345").acceptMedia(TASK).httpRequestBuilder().build(),
|
||||
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateClient();
|
||||
|
||||
client.deleteVAppTemplateMetadataValue(uri, "12345");
|
||||
client.getMetadataClient().deleteMetadataEntry(uri, "12345");
|
||||
}
|
||||
|
||||
public void testNetworkConfigSection() throws ParseException {
|
||||
|
|
|
@ -149,17 +149,17 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetVAppTemplateMetadata() {
|
||||
Metadata metadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Metadata metadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI);
|
||||
|
||||
checkMetadata(metadata);
|
||||
}
|
||||
|
||||
@Test // implicitly tested by testEditVAppTemplateMetadataValue, which first creates the metadata entry; otherwise no entry may exist
|
||||
public void testGetMetadataValue() {
|
||||
Metadata metadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Metadata metadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI);
|
||||
MetadataEntry entry = Iterables.get(metadata.getMetadataEntries(), 0);
|
||||
|
||||
MetadataValue val = vAppTemplateClient.getVAppTemplateMetadataValue(vAppTemplateURI, entry.getKey());
|
||||
MetadataValue val = vAppTemplateClient.getMetadataClient().getMetadataValue(vAppTemplateURI, entry.getKey());
|
||||
|
||||
checkMetadataValue(val);
|
||||
assertEquals(val.getValue(), entry.getValue());
|
||||
|
@ -218,7 +218,7 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
public void testEditMetadata() {
|
||||
// TODO Cleanup after ourselves..
|
||||
|
||||
Metadata oldMetadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Metadata oldMetadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI);
|
||||
Map<String,String> oldMetadataMap = metadataToMap(oldMetadata);
|
||||
|
||||
String uid = ""+random.nextInt();
|
||||
|
@ -227,10 +227,10 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).build();
|
||||
Metadata metadata = Metadata.builder().fromMetadata(oldMetadata).entry(metadataEntry).build();
|
||||
|
||||
final Task task = vAppTemplateClient.editVAppTemplateMetadata(vAppTemplateURI, metadata);
|
||||
final Task task = vAppTemplateClient.getMetadataClient().mergeMetadata(vAppTemplateURI, metadata);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
Metadata newMetadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Metadata newMetadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI);
|
||||
Map<String,String> expectedMetadataMap = ImmutableMap.<String,String>builder()
|
||||
.putAll(oldMetadataMap)
|
||||
.put(key, val)
|
||||
|
@ -247,10 +247,10 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
String val = "myval-"+uid;
|
||||
MetadataValue metadataValue = MetadataValue.builder().value(val).build();
|
||||
|
||||
final Task task = vAppTemplateClient.editVAppTemplateMetadataValue(vAppTemplateURI, key, metadataValue);
|
||||
final Task task = vAppTemplateClient.getMetadataClient().setMetadata(vAppTemplateURI, key, metadataValue);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
MetadataValue newMetadataValue = vAppTemplateClient.getVAppTemplateMetadataValue(vAppTemplateURI, key);
|
||||
MetadataValue newMetadataValue = vAppTemplateClient.getMetadataClient().getMetadataValue(vAppTemplateURI, key);
|
||||
assertEquals(newMetadataValue.getValue(), metadataValue.getValue());
|
||||
}
|
||||
|
||||
|
@ -259,15 +259,15 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
// First store a value
|
||||
String key = "mykey-"+random.nextInt();
|
||||
MetadataValue metadataValue = MetadataValue.builder().value("myval").build();
|
||||
final Task task = vAppTemplateClient.editVAppTemplateMetadataValue(vAppTemplateURI, key, metadataValue);
|
||||
final Task task = vAppTemplateClient.getMetadataClient().setMetadata(vAppTemplateURI, key, metadataValue);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
// Then delete the entry
|
||||
final Task deletionTask = vAppTemplateClient.deleteVAppTemplateMetadataValue(vAppTemplateURI, key);
|
||||
final Task deletionTask = vAppTemplateClient.getMetadataClient().deleteMetadataEntry(vAppTemplateURI, key);
|
||||
retryTaskSuccess.apply(deletionTask);
|
||||
|
||||
// Then confirm the entry is not there
|
||||
Metadata newMetadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Metadata newMetadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI);
|
||||
checkMetadataKeyAbsentFor("vAppTemplate", newMetadata, key);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue