Merge commit '7d0248c5dd972287e51ad1971d61a6ddc8bdcdf5'

This commit is contained in:
Dmitri Babaev 2011-06-01 20:36:55 +04:00
commit 0fedf6e467
397 changed files with 10944 additions and 1990 deletions

0
antcontrib/samples/javaoverssh/README.txt Executable file → Normal file
View File

0
apis/atmos/src/test/resources/log4j.xml Executable file → Normal file
View File

0
apis/byon/src/test/resources/log4j.xml Executable file → Normal file
View File

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.cloudfiles.blobstore.integration;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobIntegrationLiveTest;
import org.testng.annotations.Test;
@ -27,6 +28,12 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class CloudFilesBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest {
@Override
protected void checkContentDisposition(Blob blob, String contentDisposition) {
assert blob.getPayload().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob
.getPayload().getContentMetadata().getContentDisposition();
assert blob.getMetadata().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob
.getMetadata().getContentMetadata().getContentDisposition();
}
}

0
apis/cloudservers/src/test/resources/log4j.xml Executable file → Normal file
View File

View File

@ -30,6 +30,7 @@ import org.jclouds.compute.domain.Template;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
/**
@ -45,24 +46,26 @@ public class DeltacloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTe
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) {
case UBUNTU:
return input.version.equals("11.04") || input.version.equals("8.04") || !input.is64Bit;
return !(input.version.equals("11.04") || input.version.equals("8.04")) && input.is64Bit;
case DEBIAN:
return !(input.version.equals("6.0")) && input.is64Bit;
case CENTOS:
return input.version.matches("5.[023]") || !input.is64Bit;
return !(input.version.matches("5.[023]") || input.version.equals("8.04")) && input.is64Bit;
case WINDOWS:
return input.version.equals("2008") || input.version.indexOf("2003") != -1
|| (input.version.equals("2008 R2") && !input.is64Bit);
return input.version.equals("2008 SP2") || input.version.equals("")
|| (input.version.equals("2008 R2") && input.is64Bit);
default:
return true;
return false;
}
}
};
});
}
@Test

View File

@ -28,15 +28,15 @@ import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.utils.ModifyRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.binders.BindAsHostPrefix;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.util.Strings2;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
/**
*
@ -52,8 +52,8 @@ public class BindAsHostPrefixIfConfigured implements Binder {
@Inject
public BindAsHostPrefixIfConfigured(BindAsHostPrefix bindAsHostPrefix,
@Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
@Named(PROPERTY_S3_SERVICE_PATH) String servicePath, Provider<UriBuilder> uriBuilderProvider) {
@Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
@Named(PROPERTY_S3_SERVICE_PATH) String servicePath, Provider<UriBuilder> uriBuilderProvider) {
this.bindAsHostPrefix = bindAsHostPrefix;
this.isVhostStyle = isVhostStyle;
this.servicePath = servicePath;
@ -69,14 +69,17 @@ public class BindAsHostPrefixIfConfigured implements Binder {
} else {
UriBuilder builder = uriBuilderProvider.get().uri(request.getEndpoint());
StringBuilder path = new StringBuilder(Strings2.urlEncode(request.getEndpoint().getPath(), S3AsyncClient.class
.getAnnotation(SkipEncoding.class).value()));
int indexToInsert = path.indexOf(servicePath);
indexToInsert = indexToInsert == -1 ? 0 : indexToInsert;
indexToInsert += servicePath.length();
.getAnnotation(SkipEncoding.class).value()));
int indexToInsert = 0;
if (!servicePath.equals("/")) {
indexToInsert = path.indexOf(servicePath);
indexToInsert = indexToInsert == -1 ? 0 : indexToInsert;
indexToInsert += servicePath.length();
}
path.insert(indexToInsert, "/" + payload.toString());
builder.replacePath(path.toString());
return (R) request.toBuilder().endpoint(builder.buildFromEncodedMap(Maps.<String, Object> newLinkedHashMap()))
.build();
return (R) request.toBuilder().endpoint(builder.buildFromEncodedMap(ImmutableMap.<String, Object> of()))
.build();
}
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.s3.binders;
import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.s3.BaseS3AsyncClientTest;
import org.jclouds.s3.S3AsyncClient;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code BindAsHostPrefixIfConfigured}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "BindAsHostPrefixIfConfiguredNoPathTest")
public class BindAsHostPrefixIfConfiguredNoPathTest extends BaseS3AsyncClientTest<S3AsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<S3AsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<S3AsyncClient>>() {
};
}
public void testBucketWithHostnameStyle() throws IOException, SecurityException, NoSuchMethodException {
Method method = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class);
GeneratedHttpRequest<S3AsyncClient> request = processor.createRequest(method, "testbucket.example.com", "test.jpg");
assertRequestLineEquals(request, "DELETE https://s3.amazonaws.com/testbucket.example.com/test.jpg HTTP/1.1");
}
@Override
protected Properties getProperties() {
Properties properties = super.getProperties();
properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
return properties;
}
}

View File

@ -23,6 +23,7 @@ import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCK
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
@ -60,6 +61,20 @@ public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest<S3As
}
public void testBucketWithHostnameStyle() throws IOException, SecurityException, NoSuchMethodException {
HttpRequest request = new HttpRequest("GET", URI.create("http://euc/services/Walrus"));
BindAsHostPrefixIfConfigured binder = injector.getInstance(BindAsHostPrefixIfConfigured.class);
request = binder.bindToRequest(request, "testbucket.example.com");
assertEquals(request.getRequestLine(), "GET http://euc/services/Walrus/testbucket.example.com HTTP/1.1");
Method method = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class);
request = processor.createRequest(method, "testbucket.example.com", "test.jpg");
assertRequestLineEquals(request, "DELETE http://euc/services/Walrus/testbucket.example.com/test.jpg HTTP/1.1");
}
@Test(dataProvider = "objects")
public void testObject(String key) throws InterruptedException {
@ -80,6 +95,7 @@ public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest<S3As
@Override
protected Properties getProperties() {
Properties properties = super.getProperties();
properties.setProperty("s3.endpoint", "http://euc/services/Walrus");
properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/services/Walrus");
properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
return properties;

View File

0
apis/swift/src/test/resources/log4j.xml Executable file → Normal file
View File

View File

@ -18,11 +18,9 @@
*/
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORKCONNECTIONSECTION_XML;
import static org.jclouds.vcloud.VCloudMediaType.RASDITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
@ -47,6 +45,7 @@ import org.jclouds.ovf.Envelope;
import org.jclouds.ovf.xml.EnvelopeHandler;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
@ -58,17 +57,13 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCPUCountToXmlPayload;
import org.jclouds.vcloud.binders.BindCaptureVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindCatalogItemToXmlPayload;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindGuestCustomizationSectionToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindMemoryToXmlPayload;
import org.jclouds.vcloud.binders.BindNetworkConnectionSectionToXmlPayload;
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.ReferenceType;
@ -77,13 +72,21 @@ import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.endpoints.OrgList;
import org.jclouds.vcloud.features.CatalogAsyncClient;
import org.jclouds.vcloud.features.NetworkAsyncClient;
import org.jclouds.vcloud.features.OrgAsyncClient;
import org.jclouds.vcloud.features.TaskAsyncClient;
import org.jclouds.vcloud.features.VAppAsyncClient;
import org.jclouds.vcloud.features.VAppTemplateAsyncClient;
import org.jclouds.vcloud.features.VAppTemplateClient;
import org.jclouds.vcloud.features.VDCAsyncClient;
import org.jclouds.vcloud.features.VmAsyncClient;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.options.CaptureVAppOptions;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.OrgListHandler;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VAppHandler;
@ -96,8 +99,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href=
* "https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx"
* @see <a href= "https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx"
* />
* @author Adrian Cole
*/
@ -105,9 +107,82 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
/**
* Provides asynchronous access to VApp Template features.
*
* @see VCloudClient#getVAppTemplateClient
*
* @see VCloudClient#getThumbnailOfVm
*/
@Delegate
VAppTemplateAsyncClient getVAppTemplateClient();
/**
* Provides asynchronous access to VApp features.
*
* @see VCloudClient#getVAppClient
*
*/
@Delegate
VAppAsyncClient getVAppClient();
/**
* Provides asynchronous access to Vm features.
*
* @see VCloudClient#getVmClient
*
*/
@Delegate
VmAsyncClient getVmClient();
/**
* Provides asynchronous access to Catalog features.
*
* @see VCloudClient#getCatalogClient
*
*/
@Delegate
CatalogAsyncClient getCatalogClient();
/**
* Provides asynchronous access to Task features.
*
* @see VCloudClient#getTaskClient
*
*/
@Delegate
TaskAsyncClient getTaskClient();
/**
* Provides asynchronous access to VDC features.
*
* @see VCloudClient#getVDCClient
*
*/
@Delegate
VDCAsyncClient getVDCClient();
/**
* Provides asynchronous access to Network features.
*
* @see VCloudClient#getNetworkClient
*
*/
@Delegate
NetworkAsyncClient getNetworkClient();
/**
* Provides asynchronous access to Org features.
*
* @see VCloudClient#getOrgClient
*
*/
@Delegate
OrgAsyncClient getOrgClient();
/**
*
* @see VmAsyncClient#getScreenThumbnailForVm
*/
@Deprecated
@GET
@Path("/screen")
@Consumes("image/png")
@ -116,8 +191,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
/**
*
* @see VCloudClient#listOrgs
* @see OrgAsyncClient#listOrgs
*/
@Deprecated
@GET
@Endpoint(OrgList.class)
@XMLResponseParser(OrgListHandler.class)
@ -125,8 +201,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<Map<String, ReferenceType>> listOrgs();
/**
* @see VCloudClient#getVAppTemplate
* @see VAppTemplateAsyncClient#getVAppTemplate
*/
@Deprecated
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ -134,8 +211,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#getOvfEnvelopeForVAppTemplate
* @see VAppTemplateClient#getOvfEnvelopeForVAppTemplate
*/
@Deprecated
@GET
@Consumes(MediaType.TEXT_XML)
@Path("/ovf")
@ -144,20 +222,22 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Envelope> getOvfEnvelopeForVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNamed
* @see VAppTemplateAsyncClient#findVAppTemplateInOrgCatalogNamed
*/
@Deprecated
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#instantiateVAppTemplateInVDC
* @see VAppTemplateAsyncClient#createVAppInVDCByInstantiatingTemplate
*/
@Deprecated
@POST
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@ -165,52 +245,27 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@PayloadParam("template") URI template,
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
@PayloadParam("template") URI template,
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
/**
* @see VCloudClient#cloneVAppInVDC
* @see VAppAsyncClient#copyVAppToVDCAndName
*/
@Deprecated
@POST
@Path("/action/cloneVApp")
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("vApp") URI toClone,
@PayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, CloneVAppOptions... options);
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("Source") URI toClone,
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String newName, CloneVAppOptions... options);
/**
* @see VCloudClient#addResourceEntitytoCatalog(URI, String, String, URI)
*/
@POST
@Path("/catalogItems")
@Consumes(CATALOGITEM_XML)
@Produces(CATALOGITEM_XML)
@MapBinder(BindCatalogItemToXmlPayload.class)
@XMLResponseParser(CatalogItemHandler.class)
ListenableFuture<? extends CatalogItem> addResourceEntitytoCatalog(@EndpointParam URI catalog,
@PayloadParam("name") String name, @PayloadParam("description") String description,
@PayloadParam("entity") URI entity);
/**
* @see VCloudClient#addResourceEntitytoCatalog(URI, String, String, URI,
* Map)
*/
@POST
@Path("/catalogItems")
@Consumes(CATALOGITEM_XML)
@Produces(CATALOGITEM_XML)
@MapBinder(BindCatalogItemToXmlPayload.class)
@XMLResponseParser(CatalogItemHandler.class)
ListenableFuture<? extends CatalogItem> addResourceEntitytoCatalog(@EndpointParam URI catalog,
@PayloadParam("name") String name, @PayloadParam("description") String description,
@PayloadParam("entity") URI entity, Map<String, String> properties);
/**
* @see VCloudClient#captureVAppInVDC
* @see VAppTemplateAsyncClient#captureVAppInVDC
*/
@Deprecated
@POST
@Path("/action/captureVApp")
@Produces("application/vnd.vmware.vcloud.captureVAppParams+xml")
@ -218,25 +273,27 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@XMLResponseParser(VAppTemplateHandler.class)
@MapBinder(BindCaptureVAppParamsToXmlPayload.class)
ListenableFuture<? extends VAppTemplate> captureVAppInVDC(@EndpointParam URI vdc,
@PayloadParam("vApp") URI toCapture,
@PayloadParam("templateName") @ParamValidators(DnsNameValidator.class) String templateName,
CaptureVAppOptions... options);
@PayloadParam("vApp") URI toCapture,
@PayloadParam("templateName") @ParamValidators(DnsNameValidator.class) String templateName,
CaptureVAppOptions... options);
/**
* @see VCloudClient#findVAppInOrgVDCNamed
* @see VAppAsyncClient#findVAppInOrgVDCNamed
*/
@Deprecated
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudClient#getVApp
* @see VAppAsyncClient#getVApp
*/
@Deprecated
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ -244,8 +301,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
/**
* @see VCloudClient#getVm
* @see VmAsyncClient#getVm
*/
@Deprecated
@GET
@Consumes(VM_XML)
@XMLResponseParser(VmHandler.class)
@ -253,53 +311,36 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Vm> getVm(@EndpointParam URI vm);
/**
* @see VCloudClient#updateCPUCountOfVm
*/
@PUT
@Consumes(TASK_XML)
@Produces(RASDITEM_XML)
@Path("/virtualHardwareSection/cpu")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateCPUCountOfVm(@EndpointParam URI vm,
@BinderParam(BindCPUCountToXmlPayload.class) int cpuCount);
/**
* @see VCloudClient#updateMemoryMBOfVm
*/
@PUT
@Consumes(TASK_XML)
@Produces(RASDITEM_XML)
@Path("/virtualHardwareSection/memory")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateMemoryMBOfVm(@EndpointParam URI vm,
@BinderParam(BindMemoryToXmlPayload.class) int memoryInMB);
/**
* @see VCloudClient#updateGuestCustomizationOfVm
* @see VmAsyncClient#updateGuestCustomizationOfVm
*/
@Deprecated
@PUT
@Consumes(TASK_XML)
@Produces(GUESTCUSTOMIZATIONSECTION_XML)
@Path("/guestCustomizationSection")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateGuestCustomizationOfVm(
@EndpointParam URI vm,
@BinderParam(BindGuestCustomizationSectionToXmlPayload.class) GuestCustomizationSection guestCustomizationSection);
@EndpointParam URI vm,
@BinderParam(BindGuestCustomizationSectionToXmlPayload.class) GuestCustomizationSection guestCustomizationSection);
/**
* @see VCloudClient#updateNetworkConnectionOfVm
* @see VmAsyncClient#updateNetworkConnectionOfVm
*/
@Deprecated
@PUT
@Consumes(TASK_XML)
@Produces(NETWORKCONNECTIONSECTION_XML)
@Path("/networkConnectionSection")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateNetworkConnectionOfVm(@EndpointParam URI vm,
@BinderParam(BindNetworkConnectionSectionToXmlPayload.class) NetworkConnectionSection networkConnectionSection);
ListenableFuture<? extends Task> updateNetworkConnectionOfVm(
@EndpointParam URI vm,
@BinderParam(BindNetworkConnectionSectionToXmlPayload.class) NetworkConnectionSection networkConnectionSection);
/**
* @see VCloudClient#deployVAppOrVm
* @see VAppAsyncClient#deployVApp
* @see VmAsyncClient#deployVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Produces(DEPLOYVAPPPARAMS_XML)
@ -309,8 +350,10 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> deployVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#deployAndPowerOnVAppOrVm
* @see VAppAsyncClient#deployAndPowerOnVApp
* @see VmAsyncClient#deployAndPowerOnVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Produces(DEPLOYVAPPPARAMS_XML)
@ -321,8 +364,10 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> deployAndPowerOnVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#undeployVAppOrVm
* @see VAppAsyncClient#undeployVApp
* @see VmAsyncClient#undeployVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Produces(UNDEPLOYVAPPPARAMS_XML)
@ -332,8 +377,10 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> undeployVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#undeployAndSaveStateOfVAppOrVm
* @see VAppAsyncClient#undeployAndSaveStateOfVApp
* @see VmAsyncClient#undeployAndSaveStateOfVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Produces(UNDEPLOYVAPPPARAMS_XML)
@ -344,8 +391,10 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> undeployAndSaveStateOfVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#powerOnVAppOrVm
* @see VAppAsyncClient#powerOnVApp
* @see VmAsyncClient#powerOnVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@ -353,8 +402,10 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> powerOnVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#powerOffVAppOrVm
* @see VAppAsyncClient#powerOffVApp
* @see VmAsyncClient#powerOffVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@ -362,15 +413,19 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> powerOffVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#shutdownVAppOrVm
* @see VAppAsyncClient#shutdownVApp
* @see VmAsyncClient#shutdownVm
*/
@Deprecated
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#resetVAppOrVm
* @see VAppAsyncClient#resetVApp
* @see VmAsyncClient#resetVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@ -378,15 +433,19 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> resetVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#rebootVAppOrVm
* @see VAppAsyncClient#rebootVApp
* @see VmAsyncClient#rebootVm
*/
@Deprecated
@POST
@Path("/power/action/reboot")
ListenableFuture<Void> rebootVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see VCloudClient#suspendVAppOrVm
* @see VAppAsyncClient#suspendVApp
* @see VmAsyncClient#suspendVm
*/
@Deprecated
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@ -394,15 +453,7 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> suspendVAppOrVm(@EndpointParam URI vAppOrVmId);
/**
* @see CommonVCloudClient#deleteVAppTemplateVAppOrMediaImage
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deleteVAppTemplateVAppOrMediaImage(@EndpointParam URI id);
/**
* @see CommonVCloudClient#deleteVApp
* @see VAppAsyncClient#deleteVApp
*/
@Deprecated
@DELETE

View File

@ -21,21 +21,34 @@ package org.jclouds.vcloud;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.ovf.Envelope;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.features.CatalogClient;
import org.jclouds.vcloud.features.NetworkClient;
import org.jclouds.vcloud.features.OrgClient;
import org.jclouds.vcloud.features.TaskClient;
import org.jclouds.vcloud.features.VAppClient;
import org.jclouds.vcloud.features.VAppTemplateClient;
import org.jclouds.vcloud.features.VDCClient;
import org.jclouds.vcloud.features.VmClient;
import org.jclouds.vcloud.options.CaptureVAppOptions;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -44,269 +57,336 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a
* href="http://communities.vmware.com/community/developer/forums/vcloudapi"
* />
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudClient extends CommonVCloudClient {
/**
* Provides asynchronous access to VApp Template features.
*
*/
@Delegate
VAppTemplateClient getVAppTemplateClient();
/**
* Get a Screen Thumbnail for a Virtual Machine
*
* @param vm
* to snapshot
* Provides synchronous access to VApp features.
*/
@Delegate
VAppClient getVAppClient();
/**
* Provides synchronous access to Vm features.
*/
@Delegate
VmClient getVmClient();
/**
* Provides synchronous access to Catalog features.
*/
@Delegate
CatalogClient getCatalogClient();
/**
* Provides synchronous access to Task features.
*/
@Delegate
TaskClient getTaskClient();
/**
* Provides synchronous access to VDC features.
*/
@Delegate
VDCClient getVDCClient();
/**
* Provides synchronous access to Network features.
*/
@Delegate
NetworkClient getNetworkClient();
/**
* Provides synchronous access to Org features.
*/
@Delegate
OrgClient getOrgClient();
/**
* @see VmClient#getThumbnail
*/
@Deprecated
InputStream getThumbnailOfVm(URI vm);
/**
* The response to a login request includes a list of the organizations to
* which the authenticated user has access.
*
* @return organizations indexed by name
* @see OrgClient#listOrgs
*/
@Deprecated
Map<String, ReferenceType> listOrgs();
/**
* @see VAppTemplateClient#createVAppInVDCByInstantiatingTemplate
*/
@Deprecated
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);
/**
* @see VAppClient#copyVAppToVDCAndName
*/
@Deprecated
Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options);
/**
* The captureVApp request creates a vApp template from an instantiated vApp.
* <h4>Note</h4> Before it can be captured, a vApp must be undeployed
*
* @param vDC
* @param toClone
* @param templateName
* @param options
* @return template in progress
* @see VAppClient#captureAsTemplateInVDC
*/
@Deprecated
VAppTemplate captureVAppInVDC(URI vDC, URI toClone, String templateName, CaptureVAppOptions... options);
/**
* @see VAppTemplateClient#get
*/
@Deprecated
VAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* @see VAppTemplateClient#getOvfEnvelope
*/
@Deprecated
Envelope getOvfEnvelopeForVAppTemplate(URI vAppTemplate);
/**
* Modify the Guest Customization Section of a Virtual Machine
*
* @param vm
* uri to modify
* @param updated
* guestCustomizationSection
* @return task in progress
* @see VmClient#updateGuestCustomization
*/
@Deprecated
Task updateGuestCustomizationOfVm(URI vm, GuestCustomizationSection guestCustomizationSection);
/**
* Modify the Network Connection Section of a Virtual Machine
*
* @param vm
* uri to modify
* @param updated
* networkConnectionSection
* @return task in progress
* @see VmClient#updateNetworkConnection
*/
@Deprecated
Task updateNetworkConnectionOfVm(URI vm, NetworkConnectionSection guestCustomizationSection);
/**
* returns the vapp template corresponding to a catalog item in the catalog
* associated with the specified name. Note that the org and catalog
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that
* isn't present
* @see VAppTemplateClient#findInOrgCatalogNamed
*/
@Deprecated
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
String itemName);
/**
* @see VAppClient#findInOrgVDCNamed
*/
@Deprecated
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
/**
* @see VAppClient#get
*/
@Deprecated
VApp getVApp(URI vApp);
/**
* @see VmClient#get
*/
@Deprecated
Vm getVm(URI vm);
/**
* update the cpuCount of an existing VM
*
* @param vm
* to update
* @param cpuCount
* count to change the primary cpu to
*/
Task updateCPUCountOfVm(URI vm, int cpuCount);
/**
* update the memoryInMB of an existing VM
*
* @param vm
* to update
* @param memoryInMB
* memory in MB to assign to the VM
*/
Task updateMemoryMBOfVm(URI vm, int memoryInMB);
/**
* To deploy a vApp, the client makes a request to its action/deploy URL.
* Deploying a vApp automatically deploys all of the virtual machines it
* contains. To deploy a virtual machine, the client makes a request to its
* action/deploy URL.
* <p/>
* Deploying a Vm implicitly deploys the parent vApp if that vApp is not
* already deployed.
* @see VAppClient#deploy
* @see VmClient#deploy
*/
@Deprecated
Task deployVAppOrVm(URI vAppOrVmId);
/**
* like {@link #deployVAppOrVm(URI)}, except deploy transistions to power on
* state
*
* @see VAppClient#deployAndPowerOn
* @see VmClient#deployAndPowerOn
*/
@Deprecated
Task deployAndPowerOnVAppOrVm(URI vAppOrVmId);
/**
* Undeploying a vApp powers off or suspends any running virtual machines it
* contains, then frees the resources reserved for the vApp and sets the
* vApps deploy attribute to a value of false to indicate that it is not
* deployed.
* <p/>
* Undeploying a virtual machine powers off or suspends the virtual machine,
* then frees the resources reserved for it and sets the its deploy attribute
* to a value of false to indicate that it is not deployed. This operation
* has no effect on the containing vApp.
* <h4>NOTE</h4>
* Using this method will simply power off the vms. In order to save their
* state, use {@link #undeployAndSaveStateOfVAppOrVm}
*
* @see VAppClient#undeploy
* @see VmClient#undeploy
*/
@Deprecated
Task undeployVAppOrVm(URI vAppOrVmId);
/**
* like {@link #undeployVAppOrVm(URI)}, where the undeployed virtual machines
* are suspended and their suspend state saved
*
* @see VAppClient#undeployAndSaveState
* @see VmClient#undeployAndSaveState
*/
@Deprecated
Task undeployAndSaveStateOfVAppOrVm(URI vAppOrVmId);
/**
* A powerOn request to a vApp URL powers on all of the virtual machines in
* the vApp, as specified in the vApps StartupSection field.
* <p/>
* A powerOn request to a virtual machine URL powers on the specified virtual
* machine and forces deployment of the parent vApp.
* <p/>
* <h4>NOTE</h4> A powerOn request to a vApp or virtual machine that is
* undeployed forces deployment.
*
* @see VAppClient#powerOn
* @see VmClient#powerOn
*/
@Deprecated
Task powerOnVAppOrVm(URI vAppOrVmId);
/**
* A powerOff request to a vApp URL powers off all of the virtual machines in
* the vApp, as specified in its StartupSection field.
* <p/>
* A powerOff request to a virtual machine URL powers off the specified
* virtual machine.
*
* @see VAppClient#powerOff
* @see VmClient#powerOff
*/
@Deprecated
Task powerOffVAppOrVm(URI vAppOrVmId);
/**
* A shutdown request to a vApp URL shuts down all of the virtual machines in
* the vApp, as specified in its StartupSection field.
* <p/>
* A shutdown request to a virtual machine URL shuts down the specified
* virtual machine.
* <p/>
* <h4>NOTE</h4Because this request sends a signal to the guest OS, the
* vCloud API cannot track the progress or verify the result of the requested
* operation. Hence, void is returned
*
* @see VAppClient#shutdown
* @see VmClient#shutdown
*/
@Deprecated
void shutdownVAppOrVm(URI vAppOrVmId);
/**
* A reset request to a vApp URL resets all of the virtual machines in the
* vApp, as specified in its StartupSection field.
* <p/>
* A reset request to a virtual machine URL resets the specified virtual
* machine.
*
* @see VAppClient#reset
* @see VmClient#reset
*/
@Deprecated
Task resetVAppOrVm(URI vAppOrVmId);
/**
* A reboot request to a vApp URL reboots all of the virtual machines in the
* vApp, as specified in its StartupSection field.
* <p/>
* A reboot request to a virtual machine URL reboots the specified virtual
* machine.
* <p/>
* <h4>NOTE</h4> Because this request sends a signal to the guest OS, the
* vCloud API cannot track the progress or verify the result of the requested
* operation. Hence, void is returned
*
* @see VAppClient#reboot
* @see VmClient#reboot
*/
@Deprecated
void rebootVAppOrVm(URI vAppOrVmId);
/**
* A suspend request to a vApp URL suspends all of the virtual machines in
* the vApp, as specified in its StartupSection field.
* <p/>
* A suspend request to a virtual machine URL suspends the specified virtual
* machine.
*
* @see VAppClient#suspend
* @see VmClient#suspend
*/
@Deprecated
Task suspendVAppOrVm(URI vAppOrVmId);
/**
* delete a vAppTemplate, vApp, or media image. You cannot delete an object
* if it is in use. Any object that is being copied or moved is in use. Other
* criteria that determine whether an object is in use depend on the object
* type.
* <ul>
* <li>A vApptemplate is in use if it is being instantiated. After
* instantiation is complete, the template is no longer in use.</li>
* <li>A vApp is in use if it is deployed.</li>
* <li>A media image is in use if it is inserted in a Vm.</li>
* </ul>
*
* @param id
* href of the vAppTemplate, vApp, or media image
* @return task of the operation in progress
*/
Task deleteVAppTemplateVAppOrMediaImage(URI id);
/**
*
* @see deleteVAppTemplateVAppOrMediaImage
* @see VAppClient#delete
*/
@Deprecated
Task deleteVApp(URI vAppId);
/**
* A catalog can contain references to vApp templates and media images that
* have been uploaded to any vDC in an organization. A vApp template or media
* image can be listed in at most one catalog.
*
* @param catalog
* URI of the catalog to add the resourceEntity from
* @param name
* name of the entry in the catalog
* @param description
* description of the entry in the catalog
* @param entity
* the reference to the item from the VDC
* @param properties
* metadata to associate with this item
* @return the new catalog item
* @see CatalogClient#getCatalog
*/
CatalogItem addResourceEntitytoCatalog(URI catalog, String name, String description, URI entity,
Map<String, String> properties);
@Override
@Deprecated
Catalog getCatalog(URI catalogId);
CatalogItem addResourceEntitytoCatalog(URI catalog, String name, String description, URI entity);
/**
*
* @see CatalogClient#getCatalogItem
*/
@Override
@Deprecated
Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName);
/**
*
* @see CatalogClient#getCatalogItem
*/
@Override
@Deprecated
CatalogItem getCatalogItem(URI catalogItem);
/**
*
* @see CatalogClient#findCatalogItemInOrgCatalogNamed
*/
@Override
@Deprecated
CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName);
/**
*
* @see TaskClient#getTasksList
*/
@Override
@Deprecated
TasksList getTasksList(URI tasksListId);
/**
*
* @see TaskClient#findTasksListInOrgNamed
*/
@Override
@Deprecated
TasksList findTasksListInOrgNamed(String orgName);
/**
*
* @see TaskClient#getTask
*/
@Override
@Deprecated
Task getTask(URI taskId);
/**
*
* @see TaskClient#cancelTask
*/
@Override
@Deprecated
void cancelTask(URI taskId);
/**
*
* @see VDCClient#getVDC
*/
@Override
@Deprecated
VDC getVDC(URI vdc);
/**
*
* @see VDCClient#findVDCInOrgNamed
*/
@Override
@Deprecated
VDC findVDCInOrgNamed(String orgName, String vdcName);
/**
*
* @see NetworkClient#findNetworkInOrgVDCNamed
*/
@Override
@Deprecated
OrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
/**
*
* @see NetworkClient#getNetwork
*/
@Override
@Deprecated
OrgNetwork getNetwork(URI network);
/**
*
* @see OrgClient#getOrg
*/
@Override
@Deprecated
Org getOrg(URI orgId);
/**
*
* @see OrgClient#findOrgNamed
*/
@Override
@Deprecated
Org findOrgNamed(@Nullable String name);
}

View File

@ -26,8 +26,8 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_S
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Map.Entry;
import javax.inject.Named;
import javax.inject.Singleton;
@ -39,8 +39,8 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.options.CatalogItemOptions;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@ -58,7 +58,7 @@ public class BindCatalogItemToXmlPayload implements MapBinder {
@Inject
public BindCatalogItemToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
@ -67,19 +67,15 @@ public class BindCatalogItemToXmlPayload implements MapBinder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.get("name"), "name");
String description = checkNotNull(postParams.get("description"), "description");
URI entity = URI.create(checkNotNull(postParams.get("entity"), "entity"));
URI entity = URI.create(checkNotNull(postParams.get("Entity"), "Entity"));
Map<String, String> properties = findMapInArgsOrNull(gRequest);
if (properties == null) {
properties = ImmutableMap.of();
}
CatalogItemOptions options = findOptionsInArgsOrNew(gRequest);
try {
return stringBinder.bindToRequest(request, generateXml(name, description, entity, properties));
return stringBinder.bindToRequest(request, generateXml(name, entity, options));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
@ -90,12 +86,13 @@ public class BindCatalogItemToXmlPayload implements MapBinder {
}
protected String generateXml(String templateName, String description, URI entity, Map<String, String> properties)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
protected String generateXml(String templateName, URI entity, CatalogItemOptions options)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(templateName);
rootBuilder.e("Description").t(description);
if (options.getDescription() != null)
rootBuilder.e("Description").t(options.getDescription());
rootBuilder.e("Entity").a("href", entity.toASCIIString());
for (Entry<String, String> entry : properties.entrySet()) {
for (Entry<String, String> entry : options.getProperties().entrySet()) {
rootBuilder.e("Property").a("key", entry.getKey()).t(entry.getValue());
}
Properties outputProperties = new Properties();
@ -104,19 +101,22 @@ public class BindCatalogItemToXmlPayload implements MapBinder {
}
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("CatalogItem").a("name", name).a("xmlns", ns)
.a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
XMLBuilder rootBuilder = XMLBuilder.create("CatalogItem").a("name", name).a("xmlns", ns).a("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
return rootBuilder;
}
@SuppressWarnings("unchecked")
protected Map<String, String> findMapInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
protected CatalogItemOptions findOptionsInArgsOrNew(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof Map) {
return (Map<String, String>) arg;
if (arg instanceof CatalogItemOptions) {
return CatalogItemOptions.class.cast(arg);
} else if (arg.getClass().isArray()) {
Object[] array = (Object[]) arg;
if (array.length > 0 && array[0] instanceof CatalogItemOptions)
return CatalogItemOptions.class.cast(array[0]);
}
}
return null;
return new CatalogItemOptions();
}
@Override

View File

@ -0,0 +1,139 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Map;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.options.CloneOptions;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public abstract class BindCloneParamsToXmlPayload<O extends CloneOptions> implements MapBinder {
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
protected abstract String getRootElement();
protected abstract String getSourceMediaType();
protected abstract Class<O> getOptionClass();
@Inject
public BindCloneParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.get("name"), "name");
String source = checkNotNull(postParams.get("Source"), "Source");
boolean isSourceDelete = Boolean.parseBoolean(postParams.get("IsSourceDelete"));
O options = findOptionsInArgsOrNew(gRequest);
return stringBinder.bindToRequest(request, generateXml(name, source, isSourceDelete, options));
}
protected String generateXml(String name, String source, boolean isSourceDelete, O options) {
XMLBuilder rootBuilder = buildRoot(name, options);
addElementsUnderRoot(rootBuilder, source, options, isSourceDelete);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
try {
return rootBuilder.asString(outputProperties);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
protected void addElementsUnderRoot(XMLBuilder rootBuilder, String source, O options, boolean isSourceDelete) {
if (options.getDescription() != null)
rootBuilder.e("Description").text(options.getDescription());
rootBuilder.e("Source").a("href", source).a("type", getSourceMediaType());
if (isSourceDelete)
rootBuilder.e("IsSourceDelete").t("true");
}
protected XMLBuilder buildRoot(String name, O options) {
try {
return XMLBuilder.create(getRootElement()).a("xmlns", ns).a("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema).a("name",
name);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
@SuppressWarnings("unchecked")
protected O findOptionsInArgsOrNew(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (getOptionClass().isInstance(arg)) {
return (O) arg;
} else if (arg.getClass().isArray()) {
Object[] array = (Object[]) arg;
if (array.length > 0 && getOptionClass().isInstance(array[0]))
return (O) array[0];
}
}
try {
return getOptionClass().newInstance();
} catch (Exception e) {
Throwables.propagate(e);
assert false : "unreachable code";
return null;
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException("CloneParams is needs parameters");
}
protected String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -0,0 +1,67 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.options.CloneVAppOptions;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindCloneVAppParamsToXmlPayload extends BindCloneParamsToXmlPayload<CloneVAppOptions> {
@Inject
public BindCloneVAppParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
super(stringBinder, schema, schema);
}
@Override
protected Class<CloneVAppOptions> getOptionClass() {
return CloneVAppOptions.class;
}
@Override
protected String getRootElement() {
return "CloneVAppParams";
}
@Override
protected String getSourceMediaType() {
return VCloudMediaType.VAPP_XML;
}
protected XMLBuilder buildRoot(String name, CloneVAppOptions options) {
return super.buildRoot(name, options).a("deploy", options.isDeploy() + "").a("powerOn", options.isPowerOn() + "");
}
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
import com.google.inject.Inject;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindCloneVAppTemplateParamsToXmlPayload extends BindCloneParamsToXmlPayload<CloneVAppTemplateOptions> {
@Inject
public BindCloneVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
super(stringBinder, schema, schema);
}
@Override
protected Class<CloneVAppTemplateOptions> getOptionClass() {
return CloneVAppTemplateOptions.class;
}
@Override
protected String getRootElement() {
return "CloneVAppTemplateParams";
}
@Override
protected String getSourceMediaType() {
return VCloudMediaType.VAPPTEMPLATE_XML;
}
}

View File

@ -140,7 +140,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
Set<? extends Vm> ifCustomizationScriptIsSetGetVmsInTemplate(String customizationScript, final URI template) {
Set<? extends Vm> vms = Sets.newLinkedHashSet();
if (customizationScript != null) {
VAppTemplate vAppTemplate = client.getVAppTemplate(template);
VAppTemplate vAppTemplate = client.getVAppTemplateClient().getVAppTemplate(template);
checkArgument(vAppTemplate != null, "vAppTemplate %s not found!", template);
vms = vAppTemplate.getChildren();
checkArgument(vms.size() > 0, "no vms found in vAppTemplate %s", vAppTemplate);
@ -189,7 +189,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
@Override
public String apply(URI template) {
String networkName;
VAppTemplate vAppTemplate = client.getVAppTemplate(template);
VAppTemplate vAppTemplate = client.getVAppTemplateClient().getVAppTemplate(template);
checkArgument(vAppTemplate != null, "vAppTemplate %s not found!", template);
Set<org.jclouds.ovf.Network> networks = vAppTemplate.getNetworkSection().getNetworks();
checkArgument(networks.size() > 0, "no networks found in vAppTemplate %s", vAppTemplate);

View File

@ -26,8 +26,10 @@ import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.VirtualHardwareSection;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
@ -42,11 +44,11 @@ public class HardwareForVApp implements Function<VApp, Hardware> {
@Resource
protected Logger logger = Logger.NULL;
private final FindLocationForResource findLocationForResource;
private final Function<ReferenceType, Location> findLocationForResource;
private final VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
@Inject
protected HardwareForVApp(FindLocationForResource findLocationForResource,
protected HardwareForVApp(Function<ReferenceType, Location> findLocationForResource,
VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");

View File

@ -72,7 +72,7 @@ public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware>
return null;
}
Envelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref());
Envelope ovf = client.getVAppTemplateClient().getOvfEnvelopeForVAppTemplate(from.getHref());
if (ovf == null) {
logger.warn("cannot parse hardware as no ovf envelope found for %s", from);
return null;

View File

@ -38,7 +38,7 @@ import com.google.common.collect.Iterables;
@Singleton
public class HardwareInOrg implements Function<Org, Iterable<? extends Hardware>> {
private final AllCatalogItemsInOrg allCatalogItemsInOrg;
private final Function<Org, Iterable<? extends CatalogItem>> allCatalogItemsInOrg;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<HardwareForVAppTemplate> sizeForVAppTemplateProvider;

View File

@ -63,7 +63,7 @@ public class ImageForVAppTemplate implements Function<VAppTemplate, Image> {
builder.name(from.getName());
builder.location(findLocationForResource.apply(checkNotNull(parent, "parent")));
builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
Envelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref());
Envelope ovf = client.getVAppTemplateClient().getOvfEnvelopeForVAppTemplate(from.getHref());
builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf));
builder.defaultCredentials(credentialsProvider.execute(from));
return builder.build();

View File

@ -38,10 +38,10 @@ import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection.Builder;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.NetworkConnectionSection.Builder;
import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -54,7 +54,7 @@ import com.google.common.collect.Iterables;
*/
@Singleton
public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn implements
CreateNodeWithGroupEncodedIntoName {
CreateNodeWithGroupEncodedIntoName {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@ -65,7 +65,7 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
@Inject
protected InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn(Predicate<URI> successTester,
VCloudClient client, GetNodeMetadataStrategy getNode) {
VCloudClient client, GetNodeMetadataStrategy getNode) {
this.client = client;
this.successTester = successTester;
this.getNode = getNode;
@ -81,7 +81,7 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
String customizationScript = VCloudTemplateOptions.class.cast(template.getOptions()).getCustomizationScript();
IpAddressAllocationMode ipAddressAllocationMode = VCloudTemplateOptions.class.cast(template.getOptions())
.getIpAddressAllocationMode();
.getIpAddressAllocationMode();
options.description(VCloudTemplateOptions.class.cast(template.getOptions()).getDescription());
options.customizeOnInstantiate(false);
@ -96,12 +96,13 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VApp vAppResponse = client.instantiateVAppTemplateInVDC(VDC, templateId, name, options);
VApp vAppResponse = client.getVAppTemplateClient().createVAppInVDCByInstantiatingTemplate(name, VDC, templateId,
options);
waitForTask(vAppResponse.getTasks().get(0), vAppResponse);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
// note customization is a serial concern at the moment
Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0);
Vm vm = Iterables.get(client.getVAppClient().getVApp(vAppResponse.getHref()).getChildren(), 0);
if (customizationScript != null) {
logger.trace(">> updating customization vm(%s) ", vm.getName());
waitForTask(updateVmWithCustomizationScript(vm, customizationScript), vAppResponse);
@ -121,8 +122,8 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
waitForTask(updateMemoryMBOfVm(vm, memoryMB), vAppResponse);
logger.trace("<< updated memoryMB vm(%s) ", vm.getName());
logger.trace(">> deploying and powering on vApp(%s) ", vAppResponse.getName());
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse,
client.deployAndPowerOnVAppOrVm(vAppResponse.getHref()));
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, client.getVAppClient().deployAndPowerOnVApp(
vAppResponse.getHref()));
}
@ -140,34 +141,34 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
// returns a script that
// loses newlines.
guestConfiguration.setCustomizationScript(customizationScript);
return client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration);
return client.getVmClient().updateGuestCustomizationOfVm(guestConfiguration, vm.getHref());
}
public Task updateVmWithIpAddressAllocationMode(Vm vm, final IpAddressAllocationMode ipAddressAllocationMode) {
NetworkConnectionSection net = vm.getNetworkConnectionSection();
Builder builder = net.toBuilder();
builder.connections(Iterables.transform(net.getConnections(),
new Function<NetworkConnection, NetworkConnection>() {
new Function<NetworkConnection, NetworkConnection>() {
@Override
public NetworkConnection apply(NetworkConnection arg0) {
return arg0.toBuilder().connected(true).ipAddressAllocationMode(ipAddressAllocationMode).build();
}
@Override
public NetworkConnection apply(NetworkConnection arg0) {
return arg0.toBuilder().connected(true).ipAddressAllocationMode(ipAddressAllocationMode).build();
}
}));
return client.updateNetworkConnectionOfVm(vm.getHref(), builder.build());
}));
return client.getVmClient().updateNetworkConnectionOfVm(builder.build(), vm.getHref());
}
public Task updateCPUCountOfVm(Vm vm, int cpuCount) {
return client.updateCPUCountOfVm(vm.getHref(), cpuCount);
return client.getVmClient().updateCPUCountOfVm(cpuCount, vm.getHref());
}
public Task updateMemoryMBOfVm(Vm vm, int memoryInMB) {
return client.updateMemoryMBOfVm(vm.getHref(), memoryInMB);
return client.getVmClient().updateMemoryMBOfVm(memoryInMB, vm.getHref());
}
private NodeMetadata blockOnDeployAndPowerOnIfConfigured(InstantiateVAppTemplateOptions options, VApp vAppResponse,
Task task) {
Task task) {
if (options.shouldBlock()) {
waitForTask(task, vAppResponse);
logger.debug("<< ready vApp(%s)", vAppResponse.getName());

View File

@ -64,7 +64,7 @@ public class VCloudDestroyNodeStrategy implements DestroyNodeStrategy {
@Override
public NodeMetadata destroyNode(String id) {
URI vappId = URI.create(checkNotNull(id, "node.id"));
VApp vApp = client.getVApp(vappId);
VApp vApp = client.getVAppClient().getVApp(vappId);
if (vApp == null)
return null;
vApp = powerOffVAppIfDeployed(vApp);
@ -80,7 +80,7 @@ public class VCloudDestroyNodeStrategy implements DestroyNodeStrategy {
void deleteVApp(URI vappId) {
logger.debug(">> deleting vApp(%s)", vappId);
Task task = client.deleteVAppTemplateVAppOrMediaImage(vappId);
Task task = client.getVAppClient().deleteVApp(vappId);
if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "delete", vappId, task));
}
@ -90,12 +90,12 @@ public class VCloudDestroyNodeStrategy implements DestroyNodeStrategy {
VApp undeployVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(Status.RESOLVED) > 0) {
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
Task task = client.undeployVAppOrVm(vApp.getHref());
Task task = client.getVAppClient().undeployVApp(vApp.getHref());
if (!successTester.apply(task.getHref())) {
// TODO timeout
throw new RuntimeException(String.format("failed to %s %s: %s", "undeploy", vApp.getName(), task));
}
vApp = client.getVApp(vApp.getHref());
vApp = client.getVAppClient().getVApp(vApp.getHref());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
return vApp;
@ -104,12 +104,12 @@ public class VCloudDestroyNodeStrategy implements DestroyNodeStrategy {
VApp powerOffVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(Status.OFF) > 0) {
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
Task task = client.powerOffVAppOrVm(vApp.getHref());
Task task = client.getVAppClient().powerOffVApp(vApp.getHref());
if (!successTester.apply(task.getHref())) {
// TODO timeout
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
}
vApp = client.getVApp(vApp.getHref());
vApp = client.getVAppClient().getVApp(vApp.getHref());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
return vApp;

View File

@ -49,7 +49,7 @@ public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
public NodeMetadata getNode(String in) {
URI id = URI.create(in);
VApp from = client.getVApp(id);
VApp from = client.getVAppClient().getVApp(id);
if (from == null)
return null;
return vAppToNodeMetadata.apply(from);

View File

@ -57,7 +57,7 @@ public class VCloudLifeCycleStrategy implements RebootNodeStrategy, ResumeNodeSt
@Override
public NodeMetadata rebootNode(String in) {
URI id = URI.create(checkNotNull(in, "node.id"));
Task task = client.resetVAppOrVm(id);
Task task = client.getVAppClient().resetVApp(id);
return returnWhenTaskCompletes(in, task);
}
@ -68,13 +68,13 @@ public class VCloudLifeCycleStrategy implements RebootNodeStrategy, ResumeNodeSt
@Override
public NodeMetadata resumeNode(String in) {
Task task = client.powerOnVAppOrVm(URI.create(checkNotNull(in, "node.id")));
Task task = client.getVAppClient().powerOnVApp(URI.create(checkNotNull(in, "node.id")));
return returnWhenTaskCompletes(in, task);
}
@Override
public NodeMetadata suspendNode(String in) {
Task task = client.powerOffVAppOrVm(URI.create(checkNotNull(in, "node.id")));
Task task = client.getVAppClient().powerOffVApp(URI.create(checkNotNull(in, "node.id")));
return returnWhenTaskCompletes(in, task);
}
}

View File

@ -21,8 +21,10 @@ package org.jclouds.vcloud.config;
import static com.google.common.base.Throwables.propagate;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
@ -35,6 +37,7 @@ import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudLoginAsyncClient;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
@ -59,12 +62,34 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
super(syncClientType, asyncClientType);
}
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap);
}
@Singleton
public static class VCloudWritableCatalog extends WriteableCatalog {
private final VCloudClient client;
@Inject
public VCloudWritableCatalog(VCloudClient client) {
super(client);
this.client = client;
}
@Override
public boolean apply(ReferenceType arg0) {
return !client.getCatalogClient().getCatalog(arg0.getHref()).isReadOnly();
}
}
@Override
protected void configure() {
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
});
bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class);
bind(WriteableCatalog.class).to(VCloudWritableCatalog.class);
super.configure();
}

View File

@ -18,10 +18,30 @@
*/
package org.jclouds.vcloud.config;
import java.util.Map;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.features.CatalogAsyncClient;
import org.jclouds.vcloud.features.CatalogClient;
import org.jclouds.vcloud.features.NetworkAsyncClient;
import org.jclouds.vcloud.features.NetworkClient;
import org.jclouds.vcloud.features.OrgAsyncClient;
import org.jclouds.vcloud.features.OrgClient;
import org.jclouds.vcloud.features.TaskAsyncClient;
import org.jclouds.vcloud.features.TaskClient;
import org.jclouds.vcloud.features.VAppAsyncClient;
import org.jclouds.vcloud.features.VAppClient;
import org.jclouds.vcloud.features.VAppTemplateAsyncClient;
import org.jclouds.vcloud.features.VAppTemplateClient;
import org.jclouds.vcloud.features.VDCAsyncClient;
import org.jclouds.vcloud.features.VDCClient;
import org.jclouds.vcloud.features.VmAsyncClient;
import org.jclouds.vcloud.features.VmClient;
import com.google.common.collect.ImmutableMap;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
@ -32,8 +52,19 @@ import org.jclouds.vcloud.VCloudClient;
@ConfiguresRestClient
public class VCloudRestClientModule extends BaseVCloudRestClientModule<VCloudClient, VCloudAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(VAppTemplateClient.class, VAppTemplateAsyncClient.class)//
.put(VAppClient.class, VAppAsyncClient.class)//
.put(VmClient.class, VmAsyncClient.class)//
.put(CatalogClient.class, CatalogAsyncClient.class)//
.put(TaskClient.class, TaskAsyncClient.class)//
.put(VDCClient.class, VDCAsyncClient.class)//
.put(NetworkClient.class, NetworkAsyncClient.class)//
.put(OrgClient.class, OrgAsyncClient.class)//
.build();
public VCloudRestClientModule() {
super(VCloudClient.class, VCloudAsyncClient.class);
super(VCloudClient.class, VCloudAsyncClient.class, DELEGATE_MAP);
}
}

View File

@ -0,0 +1,124 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCatalogItemToXmlPayload;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.options.CatalogItemOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to Catalog functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface CatalogAsyncClient {
/**
* @see CatalogClient#getCatalog
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see CatalogClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see CatalogClient#getCatalogItem
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see CatalogClient#getCatalogItemInOrg
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
/**
* @see CatalogClient#addVAppTemplateOrMediaImageToCatalog
*/
@POST
@Path("/catalogItems")
@Consumes(CATALOGITEM_XML)
@Produces(CATALOGITEM_XML)
@MapBinder(BindCatalogItemToXmlPayload.class)
@XMLResponseParser(CatalogItemHandler.class)
ListenableFuture<? extends CatalogItem> addVAppTemplateOrMediaImageToCatalogAndNameItem(@PayloadParam("Entity") URI entity,
@EndpointParam URI catalog, @PayloadParam("name") String name, CatalogItemOptions... options);
/**
* @see CatalogClient#deleteCatalogItem
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteCatalogItem(@EndpointParam URI href);
}

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.options.CatalogItemOptions;
/**
* Provides access to Catalog functionality in vCloud
* <p/>
*
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface CatalogClient {
Catalog getCatalog(URI catalogId);
/**
* returns the catalog in the organization associated with the specified name. Note that both
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or catalog name that isn't present
*/
Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName);
CatalogItem getCatalogItem(URI catalogItem);
/**
* returns the catalog item in the catalog associated with the specified name. Note that the org
* and catalog parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that isn't present
*/
CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName);
/**
* A catalog can contain references to vApp templates and media images that have been uploaded to
* any vDC in an organization. A vApp template or media image can be listed in at most one
* catalog.
*
* @param entity
* the reference to the vApp templates and media image
* @param catalog
* URI of the catalog to add the resourceEntity from
* @param name
* name of the entry in the catalog
*
* @param options
* options such as description or properties
* @return the new catalog item
*/
CatalogItem addVAppTemplateOrMediaImageToCatalogAndNameItem(URI entity, URI catalog, String name, CatalogItemOptions... options);
void deleteCatalogItem(URI href);
}

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.xml.OrgNetworkHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to Network functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface NetworkAsyncClient {
/**
* @see NetworkClient#findNetworkInOrgVDCNamed
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see NetworkClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
}

View File

@ -0,0 +1,40 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.network.OrgNetwork;
/**
* Provides access to Network functionality in vCloud
* <p/>
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface NetworkClient {
OrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
OrgNetwork getNetwork(URI network);
}

View File

@ -0,0 +1,84 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.OrgList;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.OrgListHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to Org functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface OrgAsyncClient {
/**
*
* @see OrgClient#listOrgs
*/
@GET
@Endpoint(OrgList.class)
@XMLResponseParser(OrgListHandler.class)
@Consumes(VCloudMediaType.ORGLIST_XML)
ListenableFuture<Map<String, ReferenceType>> listOrgs();
/**
* @see OrgClient#getOrg
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Org> getOrg(@EndpointParam URI orgId);
/**
* @see OrgClient#getOrgNamed
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Org> findOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
/**
* Provides access to Org functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface OrgClient {
/**
* The response to a login request includes a list of the organizations to which the
* authenticated user has access.
*
* @return organizations indexed by name
*/
Map<String, ReferenceType> listOrgs();
Org getOrg(URI orgId);
/**
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within
* the organization.
*
* @param name
* organization name, or null for the default
* @throws NoSuchElementException
* if you specified an org name that isn't present
*/
Org findOrgNamed(@Nullable String name);
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to Task functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface TaskAsyncClient {
/**
* @see TaskClient#getTasksList
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
/**
* @see TaskClient#findTasksListInOrgNamed
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName);
/**
* @see TaskClient#getTask
*/
@GET
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
/**
* @see TaskClient#cancelTask
*/
@POST
@Path("/action/cancel")
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
}

View File

@ -0,0 +1,54 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
/**
* Provides access to Task functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface TaskClient {
TasksList getTasksList(URI tasksListId);
TasksList findTasksListInOrgNamed(String orgName);
/**
* Whenever the result of a request cannot be returned immediately, the server creates a Task
* object and includes it in the response, as a member of the Tasks container in the response
* body. Each Task has an href value, which is a URL that the client can use to retrieve the Task
* element alone, without the rest of the response in which it was contained. All information
* about the task is included in the Task element when it is returned in the responses Tasks
* container, so a client does not need to make an additional request to the Task URL unless it
* wants to follow the progress of a task that was incomplete.
*/
Task getTask(URI taskId);
void cancelTask(URI taskId);
}

View File

@ -0,0 +1,221 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.PayloadParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to VApp functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VAppAsyncClient {
/**
* @see VAppClient#copyVAppToVDCAndName
*/
@POST
@Path("/action/cloneVApp")
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> copyVAppToVDCAndName(@PayloadParam("Source") URI sourceVApp,
@EndpointParam URI vdc, @PayloadParam("name") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);
/**
* @see VAppClient#moveVAppToVDCAndRename
*/
@POST
@Path("/action/cloneVApp")
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@PayloadParams(keys = "IsSourceDelete", values = "true")
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> moveVAppToVDCAndRename(@PayloadParam("Source") URI sourceVApp,
@EndpointParam URI vdc, @PayloadParam("name") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);
/**
* @see VAppClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VAppClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI href);
/**
* @see VAppClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Produces(DEPLOYVAPPPARAMS_XML)
@Path("/action/deploy")
@MapBinder(BindDeployVAppParamsToXmlPayload.class)
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI href);
/**
* @see VAppClient#deployAndPowerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Produces(DEPLOYVAPPPARAMS_XML)
@Path("/action/deploy")
@MapBinder(BindDeployVAppParamsToXmlPayload.class)
@PayloadParams(keys = "powerOn", values = "true")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployAndPowerOnVApp(@EndpointParam URI href);
/**
* @see VAppClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Produces(UNDEPLOYVAPPPARAMS_XML)
@Path("/action/undeploy")
@MapBinder(BindUndeployVAppParamsToXmlPayload.class)
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI href);
/**
* @see VAppClient#undeployAndSaveStateOfVApp
*/
@POST
@Consumes(TASK_XML)
@Produces(UNDEPLOYVAPPPARAMS_XML)
@Path("/action/undeploy")
@MapBinder(BindUndeployVAppParamsToXmlPayload.class)
@PayloadParams(keys = "saveState", values = "true")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployAndSaveStateOfVApp(@EndpointParam URI href);
/**
* @see VAppClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI href);
/**
* @see VAppClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI href);
/**
* @see VAppClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI href);
/**
* @see VAppClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI href);
/**
* @see VAppClient#rebootVApp
*/
@POST
@Path("/power/action/reboot")
ListenableFuture<Void> rebootVApp(@EndpointParam URI href);
/**
* @see VAppClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI href);
/**
* @see VAppClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deleteVApp(@EndpointParam URI href);
}

View File

@ -0,0 +1,159 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.options.CloneVAppOptions;
/**
* Provides access to VApp functionality in vCloud
* <p/>
*
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VAppClient {
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
Task copyVAppToVDCAndName(URI sourceVApp, URI vDC, String newName, CloneVAppOptions... options);
Task moveVAppToVDCAndRename(URI sourceVApp, URI vDC, String newName, CloneVAppOptions... options);
VApp getVApp(URI vApp);
/**
* To deploy a vApp, the client makes a request to its action/deploy URL. Deploying a vApp
* automatically deploys all of the virtual machines it contains. To deploy a virtual machine,
* the client makes a request to its action/deploy URL.
* <p/>
* Deploying a Vm implicitly deploys the parent vApp if that vApp is not already deployed.
*/
Task deployVApp(URI href);
/**
* like {@link #deployVApp(URI)}, except deploy transistions to power on state
*
*/
Task deployAndPowerOnVApp(URI href);
/**
* Undeploying a vApp powers off or suspends any running virtual machines it contains, then frees
* the resources reserved for the vApp and sets the vApps deploy attribute to a value of false
* to indicate that it is not deployed.
* <p/>
* Undeploying a virtual machine powers off or suspends the virtual machine, then frees the
* resources reserved for it and sets the its deploy attribute to a value of false to indicate
* that it is not deployed. This operation has no effect on the containing vApp.
* <h4>NOTE</h4>
* Using this method will simply power off the vms. In order to save their state, use
* {@link #undeployAndSaveStateOf}
*
*/
Task undeployVApp(URI href);
/**
* like {@link #undeployVApp(URI)}, where the undeployed virtual machines are suspended and their
* suspend state saved
*
*/
Task undeployAndSaveStateOfVApp(URI href);
/**
* A powerOn request to a vApp URL powers on all of the virtual machines in the vApp, as
* specified in the vApps StartupSection field.
* <p/>
* A powerOn request to a virtual machine URL powers on the specified virtual machine and forces
* deployment of the parent vApp.
* <p/>
* <h4>NOTE</h4> A powerOn request to a vApp or virtual machine that is undeployed forces
* deployment.
*/
Task powerOnVApp(URI href);
/**
* A powerOff request to a vApp URL powers off all of the virtual machines in the vApp, as
* specified in its StartupSection field.
* <p/>
* A powerOff request to a virtual machine URL powers off the specified virtual machine.
*/
Task powerOffVApp(URI href);
/**
* A shutdown request to a vApp URL shuts down all of the virtual machines in the vApp, as
* specified in its StartupSection field.
* <p/>
* A shutdown request to a virtual machine URL shuts down the specified virtual machine.
* <p/>
* <h4>NOTE</h4Because this request sends a signal to the guest OS, the vCloud API cannot track
* the progress or verify the result of the requested operation. Hence, void is returned
*/
void shutdownVApp(URI href);
/**
* A reset request to a vApp URL resets all of the virtual machines in the vApp, as specified in
* its StartupSection field.
* <p/>
* A reset request to a virtual machine URL resets the specified virtual machine.
*/
Task resetVApp(URI href);
/**
* A reboot request to a vApp URL reboots all of the virtual machines in the vApp, as specified
* in its StartupSection field.
* <p/>
* A reboot request to a virtual machine URL reboots the specified virtual machine.
* <p/>
* <h4>NOTE</h4> Because this request sends a signal to the guest OS, the vCloud API cannot track
* the progress or verify the result of the requested operation. Hence, void is returned
*/
void rebootVApp(URI href);
/**
* A suspend request to a vApp URL suspends all of the virtual machines in the vApp, as specified
* in its StartupSection field.
* <p/>
* A suspend request to a virtual machine URL suspends the specified virtual machine.
*/
Task suspendVApp(URI href);
/**
* delete a vAppTemplate, vApp, or media image. You cannot delete an object if it is in use. Any
* object that is being copied or moved is in use. Other criteria that determine whether an
* object is in use depend on the object type.
* <ul>
* <li>A vApptemplate is in use if it is being instantiated. After instantiation is complete, the
* template is no longer in use.</li>
* <li>A vApp is in use if it is deployed.</li>
* <li>A media image is in use if it is inserted in a Vm.</li>
* </ul>
*
* @param href
* href of the vApp
* @return task of the operation in progress
*/
Task deleteVApp(URI href);
}

View File

@ -0,0 +1,167 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.ovf.Envelope;
import org.jclouds.ovf.xml.EnvelopeHandler;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.PayloadParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCaptureVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindCloneVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.options.CaptureVAppOptions;
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VAppTemplateHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to VAppTemplate functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VAppTemplateAsyncClient {
/**
* @see VAppTemplateClient#createVAppInVDCByInstantiatingTemplate
*/
@POST
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> createVAppInVDCByInstantiatingTemplate(
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, @EndpointParam URI vdc,
@PayloadParam("template") URI template, InstantiateVAppTemplateOptions... options);
/**
* @see VAppTemplateClient#getOvfEnvelopeForVAppTemplate
*/
@GET
@Consumes(MediaType.TEXT_XML)
@Path("/ovf")
@XMLResponseParser(EnvelopeHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Envelope> getOvfEnvelopeForVAppTemplate(@EndpointParam URI href);
/**
* @see VAppTemplateClient#captureVAppAsTemplateInVDC
*/
@POST
@Path("/action/captureVApp")
@Produces("application/vnd.vmware.vcloud.captureVAppParams+xml")
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@MapBinder(BindCaptureVAppParamsToXmlPayload.class)
ListenableFuture<? extends VAppTemplate> captureVAppAsTemplateInVDC(@PayloadParam("vApp") URI toCapture,
@PayloadParam("templateName") @ParamValidators(DnsNameValidator.class) String templateName,
@EndpointParam URI vdc, CaptureVAppOptions... options);
/**
* @see VAppTemplateClient#copyVAppTemplateToVDCAndName
*/
@POST
@Path("/action/cloneVAppTemplate")
@Produces("application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends Task> copyVAppTemplateToVDCAndName(@PayloadParam("Source") URI sourceVAppTemplate,
@EndpointParam URI vdc, @PayloadParam("name") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppTemplateOptions... options);
/**
* @see VAppTemplateClient#moveVAppTemplateToVDCAndRename
*/
@POST
@Path("/action/cloneVAppTemplate")
@Produces("application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@PayloadParams(keys = "IsSourceDelete", values = "true")
@MapBinder(BindCloneVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends Task> moveVAppTemplateToVDCAndRename(@PayloadParam("Source") URI toClone,
@EndpointParam URI vdc, @PayloadParam("name") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppTemplateOptions... options);
/**
* @see VAppTemplateClient#findVAppTemplateInOrgCatalogNamed
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VAppTemplateClient#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VAppTemplateClient#deleteVAppTemplate
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deleteVAppTemplate(@EndpointParam URI href);
}

View File

@ -0,0 +1,105 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.ovf.Envelope;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.options.CaptureVAppOptions;
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
/**
* Provides access to VApp Template functionality in vCloud
* <p/>
*
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VAppTemplateClient {
/**
* returns the vapp template corresponding to a catalog item in the catalog associated with the
* specified name. Note that the org and catalog parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that isn't present
*/
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName);
/**
*/
VApp createVAppInVDCByInstantiatingTemplate(String appName, URI vDC, URI template,
InstantiateVAppTemplateOptions... options);
Task copyVAppTemplateToVDCAndName(URI sourceVAppTemplate, URI vDC, String newName,
CloneVAppTemplateOptions... options);
Task moveVAppTemplateToVDCAndRename(URI sourceVAppTemplate, URI vDC, String newName,
CloneVAppTemplateOptions... options);
/**
* The captureVApp request creates a vApp template from an instantiated vApp. <h4>Note</h4>
* Before it can be captured, a vApp must be undeployed
*
* @param targetVdcHref
* @param sourceVAppHref
* @param newTemplateName
* @param options
* @return template in progress
*/
VAppTemplate captureVAppAsTemplateInVDC(URI sourceVAppHref, String newTemplateName, URI targetVdcHref,
CaptureVAppOptions... options);
VAppTemplate getVAppTemplate(URI vApp);
Envelope getOvfEnvelopeForVAppTemplate(URI vAppTemplate);
/**
* delete a vAppTemplate, vApp, or media image. You cannot delete an object if it is in use. Any
* object that is being copied or moved is in use. Other criteria that determine whether an
* object is in use depend on the object type.
* <ul>
* <li>A vApptemplate is in use if it is being instantiated. After instantiation is complete, the
* template is no longer in use.</li>
* <li>A vApp is in use if it is deployed.</li>
* <li>A media image is in use if it is inserted in a Vm.</li>
* </ul>
*
* @param id
* href of the vApp
* @return task of the operation in progress
*/
Task deleteVAppTemplate(URI id);
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.xml.VDCHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to VDC functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VDCAsyncClient {
/**
* @see VDCClient#getVDC(URI)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see VDCClient#findVDCInOrgNamed(String, String)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
}

View File

@ -0,0 +1,51 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.VDC;
/**
* Provides access to VDC functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VDCClient {
VDC getVDC(URI vdc);
/**
* returns the VDC in the organization associated with the specified name. Note that both
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param vdcName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or vdc name that isn't present
*/
VDC findVDCInOrgNamed(String orgName, String vdcName);
}

View File

@ -0,0 +1,232 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORKCONNECTIONSECTION_XML;
import static org.jclouds.vcloud.VCloudMediaType.RASDITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.VM_XML;
import java.io.InputStream;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCPUCountToXmlPayload;
import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindGuestCustomizationSectionToXmlPayload;
import org.jclouds.vcloud.binders.BindMemoryToXmlPayload;
import org.jclouds.vcloud.binders.BindNetworkConnectionSectionToXmlPayload;
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VmHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to Vm functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VmAsyncClient {
/**
* @see VmClient#getVm
*/
@GET
@Consumes(VM_XML)
@XMLResponseParser(VmHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Vm> getVm(@EndpointParam URI href);
/**
* @see VmClient#deployVm
*/
@POST
@Consumes(TASK_XML)
@Produces(DEPLOYVAPPPARAMS_XML)
@Path("/action/deploy")
@MapBinder(BindDeployVAppParamsToXmlPayload.class)
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVm(@EndpointParam URI href);
/**
* @see VmClient#deployAndPowerOnVm
*/
@POST
@Consumes(TASK_XML)
@Produces(DEPLOYVAPPPARAMS_XML)
@Path("/action/deploy")
@MapBinder(BindDeployVAppParamsToXmlPayload.class)
@PayloadParams(keys = "powerOn", values = "true")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployAndPowerOnVm(@EndpointParam URI href);
/**
* @see VmClient#undeployVm
*/
@POST
@Consumes(TASK_XML)
@Produces(UNDEPLOYVAPPPARAMS_XML)
@Path("/action/undeploy")
@MapBinder(BindUndeployVAppParamsToXmlPayload.class)
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVm(@EndpointParam URI href);
/**
* @see VmClient#undeployAndSaveStateOfVm
*/
@POST
@Consumes(TASK_XML)
@Produces(UNDEPLOYVAPPPARAMS_XML)
@Path("/action/undeploy")
@MapBinder(BindUndeployVAppParamsToXmlPayload.class)
@PayloadParams(keys = "saveState", values = "true")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployAndSaveStateOfVm(@EndpointParam URI href);
/**
* @see VmClient#powerOnVm
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVm(@EndpointParam URI href);
/**
* @see VmClient#powerOffVm
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVm(@EndpointParam URI href);
/**
* @see VmClient#shutdownVm
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVm(@EndpointParam URI href);
/**
* @see VmClient#resetVm
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVm(@EndpointParam URI href);
/**
* @see VmClient#rebootVm
*/
@POST
@Path("/power/action/reboot")
ListenableFuture<Void> rebootVm(@EndpointParam URI href);
/**
* @see VmClient#suspendVm
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVm(@EndpointParam URI href);
/**
* @see VmClient#updateCPUCountOfVm
*/
@PUT
@Consumes(TASK_XML)
@Produces(RASDITEM_XML)
@Path("/virtualHardwareSection/cpu")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateCPUCountOfVm(@BinderParam(BindCPUCountToXmlPayload.class) int cpuCount,
@EndpointParam URI href);
/**
* @see VmClient#updateMemoryMBOfVm
*/
@PUT
@Consumes(TASK_XML)
@Produces(RASDITEM_XML)
@Path("/virtualHardwareSection/memory")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateMemoryMBOfVm(@BinderParam(BindMemoryToXmlPayload.class) int memoryInMB,
@EndpointParam URI href);
/**
* @see VmClient#updateGuestCustomizationOfVm
*/
@PUT
@Consumes(TASK_XML)
@Produces(GUESTCUSTOMIZATIONSECTION_XML)
@Path("/guestCustomizationSection")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateGuestCustomizationOfVm(
@BinderParam(BindGuestCustomizationSectionToXmlPayload.class) GuestCustomizationSection guestCustomizationSection,
@EndpointParam URI href);
/**
* @see VmClient#updateNetworkConnectionOfVm
*/
@PUT
@Consumes(TASK_XML)
@Produces(NETWORKCONNECTIONSECTION_XML)
@Path("/networkConnectionSection")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateNetworkConnectionOfVm(
@BinderParam(BindNetworkConnectionSectionToXmlPayload.class) NetworkConnectionSection networkConnectionSection,
@EndpointParam URI href);
/**
*
* @see VmClient#getScreenThumbnailForVm
*/
@GET
@Path("/screen")
@Consumes("image/png")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<InputStream> getScreenThumbnailForVm(@EndpointParam URI vm);
}

View File

@ -0,0 +1,186 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.Vm;
/**
* Provides access to VM functionality in vCloud
* <p/>
*
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VmClient {
Vm getVm(URI vApp);
/**
* To deploy a vApp, the client makes a request to its action/deploy URL. Deploying a vApp
* automatically deploys all of the virtual machines it contains. To deploy a virtual machine,
* the client makes a request to its action/deploy URL.
* <p/>
* Deploying a Vm implicitly deploys the parent vApp if that vApp is not already deployed.
*/
Task deployVm(URI href);
/**
* like {@link #deploy(URI)}, except deploy transitions to power on state
*
*/
Task deployAndPowerOnVm(URI href);
/**
* Undeploying a vApp powers off or suspends any running virtual machines it contains, then frees
* the resources reserved for the vApp and sets the vApps deploy attribute to a value of false
* to indicate that it is not deployed.
* <p/>
* Undeploying a virtual machine powers off or suspends the virtual machine, then frees the
* resources reserved for it and sets the its deploy attribute to a value of false to indicate
* that it is not deployed. This operation has no effect on the containing vApp.
* <h4>NOTE</h4>
* Using this method will simply power off the vms. In order to save their state, use
* {@link #undeployAndSaveStateOf}
*
*/
Task undeployVm(URI href);
/**
* like {@link #undeploy(URI)}, where the undeployed virtual machines are suspended and their
* suspend state saved
*
*/
Task undeployAndSaveStateOfVm(URI href);
/**
* A powerOn request to a vApp URL powers on all of the virtual machines in the vApp, as
* specified in the vApps StartupSection field.
* <p/>
* A powerOn request to a virtual machine URL powers on the specified virtual machine and forces
* deployment of the parent vApp.
* <p/>
* <h4>NOTE</h4> A powerOn request to a vApp or virtual machine that is undeployed forces
* deployment.
*/
Task powerOnVm(URI href);
/**
* A powerOff request to a vApp URL powers off all of the virtual machines in the vApp, as
* specified in its StartupSection field.
* <p/>
* A powerOff request to a virtual machine URL powers off the specified virtual machine.
*/
Task powerOffVm(URI href);
/**
* A shutdown request to a vApp URL shuts down all of the virtual machines in the vApp, as
* specified in its StartupSection field.
* <p/>
* A shutdown request to a virtual machine URL shuts down the specified virtual machine.
* <p/>
* <h4>NOTE</h4Because this request sends a signal to the guest OS, the vCloud API cannot track
* the progress or verify the result of the requested operation. Hence, void is returned
*/
void shutdownVm(URI href);
/**
* A reset request to a vApp URL resets all of the virtual machines in the vApp, as specified in
* its StartupSection field.
* <p/>
* A reset request to a virtual machine URL resets the specified virtual machine.
*/
Task resetVm(URI href);
/**
* A reboot request to a vApp URL reboots all of the virtual machines in the vApp, as specified
* in its StartupSection field.
* <p/>
* A reboot request to a virtual machine URL reboots the specified virtual machine.
* <p/>
* <h4>NOTE</h4> Because this request sends a signal to the guest OS, the vCloud API cannot track
* the progress or verify the result of the requested operation. Hence, void is returned
*/
void rebootVm(URI href);
/**
* A suspend request to a vApp URL suspends all of the virtual machines in the vApp, as specified
* in its StartupSection field.
* <p/>
* A suspend request to a virtual machine URL suspends the specified virtual machine.
*/
Task suspendVm(URI href);
/**
* Get a Screen Thumbnail for a Virtual Machine
*
* @param href
* to snapshot
*/
InputStream getScreenThumbnailForVm(URI href);
/**
* Modify the Guest Customization Section of a Virtual Machine
*
* @param href
* uri to modify
* @param updated
* guestCustomizationSection
* @return task in progress
*/
Task updateGuestCustomizationOfVm(GuestCustomizationSection guestCustomizationSection, URI href);
/**
* Modify the Network Connection Section of a Virtual Machine
*
* @param href
* uri to modify
* @param updated
* networkConnectionSection
* @return task in progress
*/
Task updateNetworkConnectionOfVm(NetworkConnectionSection guestCustomizationSection, URI href);
/**
* update the cpuCount of an existing VM
*
* @param href
* to update
* @param cpuCount
* count to change the primary cpu to
*/
Task updateCPUCountOfVm(int cpuCount, URI href);
/**
* update the memoryInMB of an existing VM
*
* @param href
* to update
* @param memoryInMB
* memory in MB to assign to the VM
*/
Task updateMemoryMBOfVm(int memoryInMB, URI href);
}

View File

@ -93,7 +93,7 @@ public class VAppTemplatesForCatalogItems implements
@Override
public Future<VAppTemplate> apply(CatalogItem from) {
return new ExceptionParsingListenableFuture<VAppTemplate>(Futures.makeListenable(
(Future<VAppTemplate>) VCloudAsyncClient.class.cast(aclient).getVAppTemplate(
(Future<VAppTemplate>) VCloudAsyncClient.class.cast(aclient).getVAppTemplateClient().getVAppTemplate(
from.getEntity().getHref()), executor), returnNullOnAuthorizationException);
}

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.options;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
*
*/
public class CatalogItemOptions {
private String description;
private Map<String, String> properties = Maps.newLinkedHashMap();
/**
* optional description for the CatalogItem
*/
public CatalogItemOptions description(String description) {
this.description = checkNotNull(description, "description");
return this;
}
/**
* optional properties for the CatalogItem
*/
public CatalogItemOptions properties(Map<String, String> properties) {
this.properties = ImmutableMap.copyOf(checkNotNull(properties, "properties"));
return this;
}
public String getDescription() {
return description;
}
public Map<String, String> getProperties() {
return properties;
}
public static class Builder {
/**
* @see CatalogItemOptions#description
*/
public static CatalogItemOptions description(String description) {
return new CatalogItemOptions().description(description);
}
/**
* @see CatalogItemOptions#properties
*/
public static CatalogItemOptions properties(Map<String, String> properties) {
return new CatalogItemOptions().properties(properties);
}
}
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.options;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Adrian Cole
*
*/
public class CloneOptions {
private String description;
/**
* the clone should be powered on after it is deployed
*/
public CloneOptions description(String description) {
checkNotNull(description, "description");
this.description = description;
return this;
}
public String getDescription() {
return description;
}
public static class Builder {
/**
* @see CloneOptions#description(String)
*/
public static CloneOptions description(String description) {
return new CloneOptions().description(description);
}
}
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.options;
import static com.google.common.base.Preconditions.checkState;
/**
*
* @author Adrian Cole
*
*/
public class CloneVAppOptions extends CloneOptions {
private boolean deploy;
private boolean powerOn;
/**
* the clone should be deployed after it is created
*/
public CloneVAppOptions deploy() {
this.deploy = true;
return this;
}
/**
* the clone should be powered on after it is deployed
*/
public CloneVAppOptions powerOn() {
checkState(deploy, "must set deploy before setting powerOn");
powerOn = true;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public CloneVAppOptions description(String description) {
return CloneVAppOptions.class.cast(super.description(description));
}
public boolean isDeploy() {
return deploy;
}
public boolean isPowerOn() {
return powerOn;
}
public static class Builder {
/**
* @see CloneVAppOptions#deploy()
*/
public static CloneVAppOptions deploy() {
return new CloneVAppOptions().deploy();
}
/**
* @see CloneVAppOptions#powerOn()
*/
public static CloneVAppOptions powerOn() {
return new CloneVAppOptions().powerOn();
}
/**
* {@inheritDoc}
*/
public static CloneVAppOptions description(String description) {
return new CloneVAppOptions().description(description);
}
}
}

View File

@ -0,0 +1,44 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.options;
/**
*
* @author Adrian Cole
*
*/
public class CloneVAppTemplateOptions extends CloneOptions {
/**
* {@inheritDoc}
*/
@Override
public CloneVAppTemplateOptions description(String description) {
return CloneVAppTemplateOptions.class.cast(super.description(description));
}
public static class Builder {
/**
* {@inheritDoc}
*/
public static CloneVAppTemplateOptions description(String description) {
return new CloneVAppTemplateOptions().description(description);
}
}
}

View File

@ -0,0 +1,301 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* Tests behavior of {@code VCloudAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "BaseVCloudAsyncClientTest")
public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
}
@Override
protected Module createModule() {
return new VCloudRestClientModuleExtension();
}
@Override
public RestContextSpec<?, ?> createContextSpec() {
Properties overrides = new Properties();
overrides.setProperty("vcloud.endpoint", "https://vcenterprise.bluelock.com/api/v1.0");
return new RestContextFactory().createContextSpec("vcloud", "identity", "credential", overrides);
}
@RequiresHttp
@ConfiguresRestClient
public static class VCloudRestClientModuleExtension extends VCloudRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login");
}
@Override
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/org");
}
@Override
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return "org";
}
@Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog writableCatalog) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog");
}
@Override
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@Override
protected URI provideDefaultTasksList(Org org) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/taskslist");
}
@Override
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1");
}
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected URI provideDefaultNetwork(URI vdc, Injector injector) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
}
@Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override
public Map<String, ReferenceType> getOrgs() {
return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org",
VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")));
}
@Override
public String getVCloudToken() {
return "token";
}
});
}
@Override
protected void configure() {
super.configure();
bind(OrgMapSupplier.class).to(TestOrgMapSupplier.class);
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
}
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return Suppliers
.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of(
"org",
ImmutableMap
.<String, org.jclouds.vcloud.domain.VDC> of(
"vdc",
new VDCImpl(
"vdc",
null,
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
VDCStatus.READY,
null,
"description",
ImmutableSet.<Task> of(),
AllocationModel.ALLOCATION_POOL,
null,
null,
null,
ImmutableMap
.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl(
"vapp",
"application/vnd.vmware.vcloud.vApp+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")),
"network",
new ReferenceTypeImpl(
"network",
"application/vnd.vmware.vcloud.vAppTemplate+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))),
ImmutableMap.<String, ReferenceType> of(), 0, 0, 0,
false))));
}
@Singleton
public static class TestOrgMapSupplier extends OrgMapSupplier {
@Inject
protected TestOrgMapSupplier() {
super(null, null);
}
@Override
public Map<String, Org> get() {
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap
.<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog",
VCloudMediaType.CATALOG_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap
.<String, ReferenceType> of("network", new ReferenceTypeImpl("network",
VCloudMediaType.NETWORK_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))),
new ReferenceTypeImpl("tasksList", VCloudMediaType.TASKSLIST_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList
.<Task> of()));
}
}
@Singleton
public static class TestOrgCatalogSupplier extends OrgCatalogSupplier {
@Inject
protected TestOrgCatalogSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of("catalog", new CatalogImpl("catalog", "type",
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description",
ImmutableMap.<String, ReferenceType> of("item", new ReferenceTypeImpl("item",
"application/vnd.vmware.vcloud.catalogItem+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
"template", new ReferenceTypeImpl("template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
ImmutableList.<Task> of(), true, false)));
}
}
@Singleton
public static class TestOrgCatalogItemSupplier extends OrgCatalogItemSupplier {
protected TestOrgCatalogItemSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return ImmutableMap
.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
"org",
ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
"catalog",
ImmutableMap
.<String, org.jclouds.vcloud.domain.CatalogItem> of(
"template",
new CatalogItemImpl(
"template",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"),
"description",
new ReferenceTypeImpl(
"template",
"application/vnd.vmware.vcloud.vAppTemplate+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
}
}
@Override
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, String user) {
return null;
}
}
}

View File

@ -16,59 +16,63 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.bluelock;
package org.jclouds.vcloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.Constants;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.vcloud.VCloudClient;
import org.testng.annotations.AfterTest;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Module;
/**
* Tests session refresh works
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true)
public class VCloudSessionRefreshLiveTest {
@Test(groups = "live", enabled = true, singleThreaded = true)
public abstract class BaseVCloudClientLiveTest {
protected String prefix = System.getProperty("user.name");
private final static int timeOut = 40;
protected VCloudClient connection;
protected ComputeServiceContext context;
protected ComputeService client;
@Test
public void testSessionRefresh() throws Exception {
connection.findOrgNamed(null);
Thread.sleep(timeOut * 1000);
connection.findOrgNamed(null);
}
protected String provider = "bluelock-vcdirector";
protected String provider = "vcloud";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected RetryablePredicate<IPSocket> socketTester;
protected Factory sshFactory;
protected VCloudClient getVCloudApi() {
return VCloudClient.class.cast(client.getContext().getProviderSpecificContext().getApi());
}
@BeforeClass
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider
+ ".apiversion");
credential = System.getProperty("test." + provider + ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected Properties setupProperties() {
@ -76,9 +80,12 @@ public class VCloudSessionRefreshLiveTest {
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
overrides.setProperty(provider + ".endpoint", endpoint);
overrides.setProperty(provider + ".apiversion", apiversion);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@ -86,18 +93,22 @@ public class VCloudSessionRefreshLiveTest {
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
overrides.setProperty(PROPERTY_SESSION_INTERVAL, 40 + "");
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), overrides);
connection = VCloudClient.class.cast(context.getProviderSpecificContext().getApi());
client = new ComputeServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getComputeService();
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS);
sshFactory = Guice.createInjector(getSshModule()).getInstance(Factory.class);
}
@AfterTest
protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
}
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
@AfterGroups(groups = { "live" })
protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
context.close();
client.getContext().close();
}
}

View File

@ -1,133 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.getOnlyElement;
import java.net.URI;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.jclouds.Constants;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true)
public class CaptureVAppLiveTest {
protected ComputeService client;
protected String group = System.getProperty("user.name") + "cap";
protected String provider = "vcloud";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider
+ ".apiversion");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
overrides.setProperty(provider + ".endpoint", endpoint);
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
client = new ComputeServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getComputeService();
}
@Test
public void testCaptureVApp() throws Exception {
NodeMetadata node = null;
VAppTemplate vappTemplate = null;
try {
node = getOnlyElement(client.createNodesInGroup(group, 1));
VCloudClient vcloudApi = VCloudClient.class.cast(client.getContext().getProviderSpecificContext().getApi());
Predicate<URI> taskTester = new RetryablePredicate<URI>(new TaskSuccess(vcloudApi), 600, 5, TimeUnit.SECONDS);
// I have to powerOff first
Task task = vcloudApi.powerOffVAppOrVm(URI.create(node.getId()));
// wait up to ten minutes per above
assert taskTester.apply(task.getHref()) : node;
// having a problem where the api is returning an error telling us to stop!
// // I have to undeploy first
// task = vcloudApi.undeployVAppOrVm(URI.create(node.getId()));
//
// // wait up to ten minutes per above
// assert taskTester.apply(task.getHref()) : node;
// vdc is equiv to the node's location
// vapp uri is the same as the node's id
vappTemplate = vcloudApi.captureVAppInVDC(URI.create(node.getLocation().getId()), URI.create(node.getId()),
group);
task = vappTemplate.getTasks().get(0);
// wait up to ten minutes per above
assert taskTester.apply(task.getHref()) : vappTemplate;
// TODO implement delete vAppTemplate
} finally {
if (node != null)
client.destroyNode(node.getId());
}
}
}

View File

@ -32,12 +32,13 @@ import org.jclouds.vcloud.domain.Vm;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code VCloudClient}
* Tests behavior of deprecated {@code VCloudClient} features
*
* @author Adrian Cole
*/
@Deprecated
@Test(groups = "live", singleThreaded = true)
public class VCloudClientLiveTest extends CommonVCloudClientLiveTest<VCloudClient, VCloudAsyncClient> {
public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<VCloudClient, VCloudAsyncClient> {
@Test
public void testListOrgs() throws Exception {

View File

@ -18,54 +18,27 @@
*/
package org.jclouds.vcloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.concurrent.ExecutionException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.ovf.xml.EnvelopeHandler;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.CaptureVAppOptions;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -80,15 +53,9 @@ import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VAppTemplateHandler;
import org.jclouds.vcloud.xml.VDCHandler;
import org.jclouds.vcloud.xml.VmHandler;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
@ -99,12 +66,43 @@ import com.google.inject.TypeLiteral;
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "VCloudAsyncClientTest")
public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public class VCloudAsyncClientTest extends BaseVCloudAsyncClientTest<VCloudAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<VCloudAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VCloudAsyncClient>>() {
};
}
private VCloudAsyncClient asyncClient;
private VCloudClient syncClient;
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
assert syncClient.getVAppClient() != null;
assert syncClient.getCatalogClient() != null;
assert syncClient.getVmClient() != null;
assert syncClient.getVAppTemplateClient() != null;
assert syncClient.getTaskClient() != null;
assert syncClient.getVDCClient() != null;
assert syncClient.getNetworkClient() != null;
assert syncClient.getOrgClient() != null;
}
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
assert asyncClient.getVAppClient() != null;
assert asyncClient.getCatalogClient() != null;
assert asyncClient.getVmClient() != null;
assert asyncClient.getVAppTemplateClient() != null;
assert asyncClient.getTaskClient() != null;
assert asyncClient.getVDCClient() != null;
assert asyncClient.getNetworkClient() != null;
assert asyncClient.getOrgClient() != null;
}
public void testGetThumbnailOfVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getThumbnailOfVm", URI.class);
HttpRequest request = processor
.createRequest(method, URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"));
.createRequest(method, URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"));
assertRequestLineEquals(request, "GET http://vcloud.example.com/api/v1.0/vApp/vm-12/screen HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: image/png\n");
@ -119,55 +117,18 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testUpdateGuestConfiguration() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("updateGuestCustomizationOfVm", URI.class,
GuestCustomizationSection.class);
GuestCustomizationSection guest = new GuestCustomizationSection(
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection"));
GuestCustomizationSection.class);
GuestCustomizationSection guest = new GuestCustomizationSection(URI
.create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection"));
guest.setCustomizationScript("cat > /tmp/foo.txt<<EOF\nI love candy\nEOF");
HttpRequest request = processor.createRequest(method,
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), guest);
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), guest);
assertRequestLineEquals(request,
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection HTTP/1.1");
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/guestCustomizationSection.xml")),
"application/vnd.vmware.vcloud.guestCustomizationSection+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUpdateCPUCountOfVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("updateCPUCountOfVm", URI.class, int.class);
HttpRequest request = processor.createRequest(method,
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), 2);
assertRequestLineEquals(request,
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/virtualHardwareSection/cpu HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/cpuItem.xml")),
"application/vnd.vmware.vcloud.rasdItem+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUpdateMemoryMBOfVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("updateMemoryMBOfVm", URI.class, int.class);
HttpRequest request = processor.createRequest(method,
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), 512);
assertRequestLineEquals(request,
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/virtualHardwareSection/memory HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/memoryItem.xml")),
"application/vnd.vmware.vcloud.rasdItem+xml", false);
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/guestCustomizationSection.xml")), "application/vnd.vmware.vcloud.guestCustomizationSection+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -177,23 +138,21 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(
method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"),
"my-vapp",
addNetworkConfig(new NetworkConfig("aloha", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)));
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp",
addNetworkConfig(new NetworkConfig("aloha", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-network.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
@ -204,30 +163,28 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(
method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
"CentOS 01",
addNetworkConfig(new NetworkConfig(null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), null)));
String.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01",
addNetworkConfig(new NetworkConfig(null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), null)));
}
@Deprecated
public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp");
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp");
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -236,19 +193,20 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
@Deprecated
public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server",
new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp"));
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server",
new CloneVAppOptions().deploy().powerOn().description("The description of the new vApp"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -259,17 +217,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCaptureVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("captureVAppInVDC", URI.class, URI.class, String.class,
CaptureVAppOptions[].class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-template");
CaptureVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-template");
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")),
"application/vnd.vmware.vcloud.captureVAppParams+xml", false);
assertPayloadEquals(request, Strings2
.toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")),
"application/vnd.vmware.vcloud.captureVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
@ -280,17 +238,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCaptureVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("captureVAppInVDC", URI.class, URI.class, String.class,
CaptureVAppOptions[].class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "my-template",
new CaptureVAppOptions().withDescription("The description of the new vApp Template"));
CaptureVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "my-template", new CaptureVAppOptions()
.withDescription("The description of the new vApp Template"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp.xml")),
"application/vnd.vmware.vcloud.captureVAppParams+xml", false);
"application/vnd.vmware.vcloud.captureVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
@ -316,8 +274,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrg", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
@ -347,8 +305,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
@ -378,8 +336,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getNetwork", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/2"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
@ -394,7 +352,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class, String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, "org", "vdc", "network");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2 HTTP/1.1");
@ -410,8 +368,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
@ -426,7 +384,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "item");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1");
@ -442,7 +400,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class,
String.class, String.class);
String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "template");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1");
@ -458,8 +416,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
@ -474,8 +432,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetOvfEnvelopeForVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOvfEnvelopeForVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2/ovf HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: text/xml\n");
@ -547,8 +505,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
@ -563,8 +521,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTasksList", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
@ -594,13 +552,13 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testDeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -611,13 +569,13 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testDeployAndPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployAndPowerOnVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -628,8 +586,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVApp", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
@ -644,8 +602,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vm/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vm/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vm/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vm+xml\n");
@ -660,11 +618,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testRebootVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("rebootVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
@ -677,14 +635,14 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testUndeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -694,17 +652,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
public void testUndeployAndSaveStateOfVAppOrVmSaveState() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployAndSaveStateOfVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request,
"<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
"<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -715,24 +673,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testDeleteVAppTemplateVAppOrMediaImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deleteVAppTemplateVAppOrMediaImage", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
@ -747,11 +689,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOnVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
@ -762,57 +704,13 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testAddResourceEntitytoCatalogProperties() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("addResourceEntitytoCatalog", URI.class, String.class,
String.class, URI.class, Map.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), "myname", "mydescription",
URI.create("http://fooentity"), ImmutableMap.of("foo", "bar"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/catalog/1/catalogItems HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(
request,
"<CatalogItem xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" name=\"myname\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd\"><Description>mydescription</Description><Entity href=\"http://fooentity\"/><Property key=\"foo\">bar</Property></CatalogItem>",
"application/vnd.vmware.vcloud.catalogItem+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testAddResourceEntitytoCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("addResourceEntitytoCatalog", URI.class, String.class,
String.class, URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), "myname", "mydescription",
URI.create("http://fooentity"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/catalog/1/catalogItems HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(
request,
"<CatalogItem xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" name=\"myname\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd\"><Description>mydescription</Description><Entity href=\"http://fooentity\"/></CatalogItem>",
"application/vnd.vmware.vcloud.catalogItem+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testPowerOffVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOffVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
@ -825,11 +723,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testResetVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("resetVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
@ -842,11 +740,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testSuspendVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("suspendVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
@ -859,11 +757,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testShutdownVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("shutdownVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1");
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
@ -876,8 +774,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
@ -892,8 +790,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
@ -906,211 +804,12 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
@BeforeClass
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<VCloudAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VCloudAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new VCloudRestClientModuleExtension();
}
@Override
public RestContextSpec<?, ?> createContextSpec() {
Properties overrides = new Properties();
overrides.setProperty("vcloud.endpoint", "https://vcenterprise.bluelock.com/api/v1.0");
return new RestContextFactory().createContextSpec("vcloud", "identity", "credential", overrides);
}
@RequiresHttp
@ConfiguresRestClient
public static class VCloudRestClientModuleExtension extends VCloudRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login");
}
@Override
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/org");
}
@Override
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return "org";
}
@Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog");
}
@Override
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@Override
protected URI provideDefaultTasksList(Org org) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/taskslist");
}
@Override
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1");
}
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected URI provideDefaultNetwork(URI vdc, Injector injector) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
}
@Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override
public Map<String, ReferenceType> getOrgs() {
return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org",
VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")));
}
@Override
public String getVCloudToken() {
return "token";
}
});
}
@Override
protected void configure() {
super.configure();
bind(OrgMapSupplier.class).to(TestOrgMapSupplier.class);
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
}
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
"vdc",
new VDCImpl("vdc", null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(),
AllocationModel.ALLOCATION_POOL, null, null, null, ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), ImmutableMap
.<String, ReferenceType> of(), 0, 0, 0, false))));
}
@Singleton
public static class TestOrgMapSupplier extends OrgMapSupplier {
@Inject
protected TestOrgMapSupplier() {
super(null, null);
}
@Override
public Map<String, Org> get() {
return ImmutableMap.<String, Org> of(
"org",
new OrgImpl("org", null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org",
"description", ImmutableMap.<String, ReferenceType> of(
"catalog",
new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(
"network",
new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))),
new ReferenceTypeImpl("tasksList", VCloudMediaType.TASKSLIST_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList
.<Task> of()));
}
}
@Singleton
public static class TestOrgCatalogSupplier extends OrgCatalogSupplier {
@Inject
protected TestOrgCatalogSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of(
"catalog",
new CatalogImpl("catalog", "type",
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description",
ImmutableMap.<String, ReferenceType> of(
"item",
new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
"template",
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
ImmutableList.<Task> of(), true)));
}
}
@Singleton
public static class TestOrgCatalogItemSupplier extends OrgCatalogItemSupplier {
protected TestOrgCatalogItemSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
"org", ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
"catalog", ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of(
"template",
new CatalogItemImpl("template", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description",
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
}
}
@Override
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, String user) {
return null;
}
protected void setupFactory() throws IOException {
super.setupFactory();
asyncClient = injector.getInstance(VCloudAsyncClient.class);
syncClient = injector.getInstance(VCloudClient.class);
}
}

View File

@ -1,197 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.crypto.CryptoStreams.base64;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.jclouds.Constants;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Module;
/**
* This tests that we can use guest customization as an alternative to
* bootstrapping with ssh. There are a few advantages to this, including the
* fact that it can work inside google appengine where network sockets (ssh:22)
* are prohibited.
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true)
public class VCloudGuestCustomizationLiveTest {
public static final String PARSE_VMTOOLSD = "vmtoolsd --cmd=\"info-get guestinfo.ovfenv\" |grep vCloud_CustomizationInfo|sed 's/.*value=\"\\(.*\\)\".*/\\1/g'";
protected ComputeServiceContext context;
protected ComputeService client;
protected RetryablePredicate<IPSocket> socketTester;
protected Factory sshFactory;
protected String provider = "vcloud";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected NodeMetadata node;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = System.getProperty("test." + provider + ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
client = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getComputeService();
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS);
sshFactory = Guice.createInjector(getSshModule()).getInstance(Factory.class);
}
protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
}
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
// make sure the script has a lot of screwy characters, knowing our parser
// throws-out \r
private String iLoveAscii = "I '\"love\"' {asc|!}*&";
String script = "cat > /root/foo.txt<<EOF\n" + iLoveAscii + "\nEOF\n";
@Test
public void testExtendedOptionsWithCustomizationScript() throws Exception {
String group = "customize";
TemplateOptions options = client.templateOptions();
options.as(VCloudTemplateOptions.class).customizationScript(script);
options.as(VCloudTemplateOptions.class).description(group);
node = getOnlyElement(client.createNodesInGroup(group, 1, options));
VApp vapp = ((VCloudClient) client.getContext().getProviderSpecificContext().getApi()).getVApp(node.getUri());
assertEquals(vapp.getDescription(), group);
Vm vm = Iterables.get(vapp.getChildren(), 0);
String apiOutput = vm.getGuestCustomizationSection().getCustomizationScript();
checkApiOutput(apiOutput);
IPSocket socket = getSocket(node);
System.out.printf("%s:%s@%s", node.getCredentials().identity, node.getCredentials().credential, socket);
assert socketTester.apply(socket) : socket;
SshClient ssh = sshFactory.create(socket, node.getCredentials());
try {
ssh.connect();
ExecResponse vmTools = ssh.exec(PARSE_VMTOOLSD);
System.out.println(vmTools);
String fooTxt = ssh.exec("cat /root/foo.txt").getOutput();
String decodedVmToolsOutput = new String(base64(vmTools.getOutput().trim()));
checkVmOutput(fooTxt, decodedVmToolsOutput);
} finally {
if (ssh != null)
ssh.disconnect();
}
}
protected void checkApiOutput(String apiOutput) {
checkApiOutput1_0_1(apiOutput);
}
protected void checkApiOutput1_0_1(String apiOutput) {
// in 1.0.1, vcloud director seems to pass through characters via api
// flawlessly
assertEquals(apiOutput, script);
}
protected void checkApiOutput1_0_0(String apiOutput) {
// in 1.0.0, vcloud director seems to remove all newlines
assertEquals(apiOutput, script.replace("\n", ""));
}
protected void checkVmOutput(String fooTxtContentsMadeByVMwareTools, String decodedVMwareToolsOutput) {
// note that vmwaretools throws in \r characters when executing scripts
assertEquals(fooTxtContentsMadeByVMwareTools, iLoveAscii + "\r\n");
assertEquals(decodedVMwareToolsOutput, script);
}
@AfterTest
public void tearDown() {
if (node != null)
client.destroyNode(node.getId());
if (context != null)
context.close();
}
protected IPSocket getSocket(NodeMetadata node) {
return new IPSocket(get(node.getPublicAddresses(), 0), 22);
}
}

View File

@ -0,0 +1,42 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud;
import org.testng.annotations.Test;
/**
* Tests session refresh works
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true)
public class VCloudSessionRefreshLiveTest extends BaseVCloudClientLiveTest {
private final static int timeOut = 40;
@Test
public void testSessionRefresh() throws Exception {
VCloudClient connection = VCloudClient.class.cast(client.getContext().getProviderSpecificContext().getApi());
connection.getOrgClient().findOrgNamed(null);
Thread.sleep(timeOut * 1000);
connection.getOrgClient().findOrgNamed(null);
}
}

View File

@ -31,6 +31,7 @@ import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.options.CatalogItemOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@ -61,14 +62,15 @@ public class BindCatalogItemToXmlPayloadTest {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(ImmutableMap.of("foo", "bar"))).anyTimes();
expect(request.getArgs()).andReturn(
ImmutableList.<Object> of(CatalogItemOptions.Builder.description("mydescription").properties(
ImmutableMap.of("foo", "bar")))).anyTimes();
request.setPayload(expected);
replay(request);
BindCatalogItemToXmlPayload binder = injector.getInstance(BindCatalogItemToXmlPayload.class);
Map<String, String> map = ImmutableMap.of("name", "myname", "description", "mydescription", "entity",
"http://fooentity");
Map<String, String> map = ImmutableMap.of("name", "myname", "Entity", "http://fooentity");
binder.bindToRequest(request, map);
verify(request);

View File

@ -0,0 +1,120 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.binders;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import java.io.IOException;
import java.net.URI;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.name.Names;
/**
* Tests behavior of {@code BindCloneVAppParamsToXmlPayload}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class BindCloneVAppParamsToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Properties props = new Properties();
props.setProperty("jclouds.vcloud.xml.ns", "http://www.vmware.com/vcloud/v1");
props.setProperty("jclouds.vcloud.xml.schema", "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
Names.bindProperties(binder(), new PropertiesBuilder(props).build());
}
});
public void testWithDescriptionDeployOn() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml"));
CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
"The description of the new vApp");
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.<String, String> builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
binder.bindToRequest(request, map.build());
verify(request);
}
public void testWithDescriptionDeployOnSourceDelete() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVApp.xml"));
CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
"The description of the new vApp");
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.<String, String> builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
map.put("IsSourceDelete", "true");
binder.bindToRequest(request, map.build());
verify(request);
}
public void testDefault() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
request.setPayload(expected);
replay(request);
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.<String, String> builder();
map.put("name", "my-vapp");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181");
binder.bindToRequest(request, map.build());
verify(request);
}
}

View File

@ -0,0 +1,123 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.binders;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import java.io.IOException;
import java.net.URI;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.name.Names;
/**
* Tests behavior of {@code BindCloneVAppTemplateParamsToXmlPayload}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class BindCloneVAppTemplateParamsToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Properties props = new Properties();
props.setProperty("jclouds.vcloud.xml.ns", "http://www.vmware.com/vcloud/v1");
props.setProperty("jclouds.vcloud.xml.schema", "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
Names.bindProperties(binder(), new PropertiesBuilder(props).build());
}
});
public void testWithDescription() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate.xml"));
CloneVAppTemplateOptions options = new CloneVAppTemplateOptions()
.description("The description of the new vAppTemplate");
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
BindCloneVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.<String, String> builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
binder.bindToRequest(request, map.build());
verify(request);
}
public void testWithDescriptionSourceDelete() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVAppTemplate.xml"));
CloneVAppTemplateOptions options = new CloneVAppTemplateOptions()
.description("The description of the new vAppTemplate");
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
BindCloneVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.<String, String> builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
map.put("IsSourceDelete", "true");
binder.bindToRequest(request, map.build());
verify(request);
}
public void testDefault() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate-default.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
request.setPayload(expected);
replay(request);
BindCloneVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.<String, String> builder();
map.put("name", "my-vapptemplate");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181");
binder.bindToRequest(request, map.build());
verify(request);
}
}

View File

@ -42,6 +42,7 @@ import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.features.VAppTemplateClient;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.testng.annotations.Test;
@ -63,9 +64,12 @@ import com.google.inject.name.Names;
public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
Injector createInjector(URI vAppTemplate, VAppTemplate value) {
final VCloudClient client = createMock(VCloudClient.class);
final VAppTemplateClient tclient = createMock(VAppTemplateClient.class);
expect(client.getVAppTemplate(vAppTemplate)).andReturn(value).anyTimes();
expect(client.getVAppTemplateClient()).andReturn(tclient).anyTimes();
expect(tclient.getVAppTemplate(vAppTemplate)).andReturn(value).anyTimes();
replay(client);
replay(tclient);
return Guice.createInjector(new AbstractModule() {

View File

@ -56,8 +56,7 @@ public class BindNetworkConnectionSectionToXmlPayloadTest {
public void testWithIpAllocationModeNONE() throws IOException {
@SuppressWarnings("rawtypes")
HttpRequest request = new HttpRequest.Builder().endpoint(URI.create("http://localhost/key")).method("GET")
HttpRequest request = HttpRequest.builder().endpoint(URI.create("http://localhost/key")).method("GET")
.build();
BindNetworkConnectionSectionToXmlPayload binder = injector

View File

@ -69,7 +69,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory(
setupRestProperties()).createContext(provider, identity, credential, ImmutableSet.<Module> of(),
setupProperties()).getProviderSpecificContext();
VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName());
VApp vApp = tmContext.getApi().getVAppClient().findVAppInOrgVDCNamed(null, null, allData.getName());
assertEquals(vApp.getName(), allData.getName());
}
}

View File

@ -43,6 +43,7 @@ import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.compute.config.CommonVCloudComputeServiceContextModule;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.xml.VAppHandler;
@ -76,6 +77,9 @@ public class VAppToNodeMetadataTest {
protected void configure() {
Properties props = new Properties();
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
}).to(new TypeLiteral<FindLocationForResource>() {
});
bind(new TypeLiteral<Function<VApp, Hardware>>() {
}).to(new TypeLiteral<HardwareForVApp>() {
});
@ -108,8 +112,8 @@ public class VAppToNodeMetadataTest {
}
public void testWhenVDCIsLocation() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description").scope(
LocationScope.PROVIDER).build();
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
.scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class);
@ -122,8 +126,8 @@ public class VAppToNodeMetadataTest {
}
public void testGracefulWhenNoIPs() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description").scope(
LocationScope.PROVIDER).build();
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
.scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-none.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class);
@ -138,7 +142,7 @@ public class VAppToNodeMetadataTest {
@Test(expectedExceptions = NoSuchElementException.class)
public void testGracefulWhenVDCIsNotLocation() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/11111").description("description")
.scope(LocationScope.PROVIDER).build();
.scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class);

View File

@ -0,0 +1,139 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.options.CatalogItemOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code CatalogAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "CatalogAsyncClientTest")
public class CatalogAsyncClientTest extends BaseVCloudAsyncClientTest<CatalogAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<CatalogAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<CatalogAsyncClient>>() {
};
}
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = CatalogAsyncClient.class.getMethod("getCatalog", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testCatalogInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = CatalogAsyncClient.class.getMethod("findCatalogInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = CatalogAsyncClient.class.getMethod("getCatalogItem", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = CatalogAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class,
String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "item");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testAddVAppTemplateOrMediaImageToCatalogAndNameItem() throws SecurityException, NoSuchMethodException,
IOException {
Method method = CatalogAsyncClient.class.getMethod("addVAppTemplateOrMediaImageToCatalogAndNameItem", URI.class,
URI.class, String.class, CatalogItemOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("http://fooentity"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), "myname", CatalogItemOptions.Builder
.description("mydescription"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/catalog/1/catalogItems HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(
request,
"<CatalogItem xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" name=\"myname\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd\"><Description>mydescription</Description><Entity href=\"http://fooentity\"/></CatalogItem>",
"application/vnd.vmware.vcloud.catalogItem+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
}

View File

@ -0,0 +1,48 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "CatalogClientLiveTest")
public class CatalogClientLiveTest extends BaseVCloudClientLiveTest {
@Test
public void testGetCatalog() throws Exception {
Org org = getVCloudApi().getOrgClient().findOrgNamed(null);
for (ReferenceType catalog : org.getCatalogs().values()) {
assertEquals(catalog.getType(), VCloudMediaType.CATALOG_XML);
assertNotNull(getVCloudApi().getCatalogClient().getCatalog(catalog.getHref()));
}
}
@Test
public void testFindCatalogIsWriteable() throws Exception {
assertEquals(getVCloudApi().getCatalogClient().findCatalogInOrgNamed(null, null).isReadOnly(), false);
}
}

View File

@ -0,0 +1,83 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.xml.OrgNetworkHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code NetworkAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "NetworkAsyncClientTest")
public class NetworkAsyncClientTest extends BaseVCloudAsyncClientTest<NetworkAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<NetworkAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<NetworkAsyncClient>>() {
};
}
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = NetworkAsyncClient.class.getMethod("getNetwork", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgNetworkHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = NetworkAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class, String.class,
String.class);
HttpRequest request = processor.createRequest(method, "org", "vdc", "network");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgNetworkHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
}

View File

@ -0,0 +1,31 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "NetworkClientLiveTest")
public class NetworkClientLiveTest extends BaseVCloudClientLiveTest {
}

View File

@ -0,0 +1,99 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.OrgListHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code OrgAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "OrgAsyncClientTest")
public class OrgAsyncClientTest extends BaseVCloudAsyncClientTest<OrgAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<OrgAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<OrgAsyncClient>>() {
};
}
public void testlistOrgs() throws SecurityException, NoSuchMethodException, IOException {
Method method = OrgAsyncClient.class.getMethod("listOrgs");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.orgList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgListHandler.class);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(request);
}
public void testOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = OrgAsyncClient.class.getMethod("getOrg", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindOrgNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = OrgAsyncClient.class.getMethod("findOrgNamed", String.class);
HttpRequest request = processor.createRequest(method, "org");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
}

View File

@ -0,0 +1,44 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.jclouds.vcloud.domain.ReferenceType;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "OrgClientLiveTest")
public class OrgClientLiveTest extends BaseVCloudClientLiveTest {
@Test
public void testListOrgs() throws Exception {
for (ReferenceType response : getVCloudApi().getOrgClient().listOrgs().values()) {
assertNotNull(response);
assertNotNull(response.getName());
assertNotNull(response.getHref());
assertEquals(getVCloudApi().getOrgClient().getOrg(response.getHref()).getName(), response.getName());
assertEquals(getVCloudApi().getOrgClient().findOrgNamed(response.getName()).getName(), response.getName());
}
}
}

View File

@ -0,0 +1,116 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code TaskAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "TaskAsyncClientTest")
public class TaskAsyncClientTest extends BaseVCloudAsyncClientTest<TaskAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<TaskAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<TaskAsyncClient>>() {
};
}
public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTasksList", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TasksListHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindTasksListInOrgNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class);
HttpRequest request = processor.createRequest(method, "org");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TasksListHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTask", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("cancelTask", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
}

View File

@ -0,0 +1,31 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "TaskClientLiveTest")
public class TaskClientLiveTest extends BaseVCloudClientLiveTest {
}

View File

@ -0,0 +1,323 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VAppAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "VAppAsyncClientTest")
public class VAppAsyncClientTest extends BaseVCloudAsyncClientTest<VAppAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<VAppAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VAppAsyncClient>>() {
};
}
public void testopyVAppToVDCAndName() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("copyVAppToVDCAndName", URI.class, URI.class, String.class,
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "my-vapp");
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testCopyVAppToVDCAndNameOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("copyVAppToVDCAndName", URI.class, URI.class, String.class,
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server", new CloneVAppOptions()
.deploy().powerOn().description("The description of the new vApp"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testMoveVAppToVDCAndRenameOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("moveVAppToVDCAndRename", URI.class, URI.class, String.class,
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server", new CloneVAppOptions()
.deploy().powerOn().description("The description of the new vApp"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVApp.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("deployVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDeployAndPowerOnVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("deployAndPowerOnVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("getVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testRebootVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("rebootVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("undeployVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUndeployAndSaveStateOfVAppSaveState() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("undeployAndSaveStateOfVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request,
"<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("deleteVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testPowerOnVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("powerOnVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testPowerOffVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("powerOffVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testResetVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("resetVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testSuspendVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("suspendVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testShutdownVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppAsyncClient.class.getMethod("shutdownVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.testng.Assert.assertNotNull;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VAppClientLiveTest")
public class VAppClientLiveTest extends BaseVCloudClientLiveTest {
@Test
public void testGetVApp() throws Exception {
Org org = getVCloudApi().getOrgClient().findOrgNamed(null);
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = getVCloudApi().getVDCClient().getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = getVCloudApi().getVAppClient().getVApp(item.getHref());
assertNotNull(app);
} catch (RuntimeException e) {
}
}
}
}
}
}

View File

@ -0,0 +1,247 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.xml.EnvelopeHandler;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.options.CaptureVAppOptions;
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VAppTemplateHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VAppTemplateAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "VAppTemplateAsyncClientTest")
public class VAppTemplateAsyncClientTest extends BaseVCloudAsyncClientTest<VAppTemplateAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<VAppTemplateAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VAppTemplateAsyncClient>>() {
};
}
public void testCreateVAppInVDCByInstantiatingTemplate() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("createVAppInVDCByInstantiatingTemplate", String.class,
URI.class, URI.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, "my-vapp", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"),
addNetworkConfig(new NetworkConfig("aloha", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testCreateVAppInVDCByInstantiatingTemplateOptionsIllegalName() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("createVAppInVDCByInstantiatingTemplate", String.class,
URI.class, URI.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(method, "CentOS 01", URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), addNetworkConfig(new NetworkConfig(null,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), null)));
}
public void testcopyVAppTemplateToVDCAndName() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("copyVAppTemplateToVDCAndName", URI.class, URI.class,
String.class, CloneVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "my-vapptemplate");
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/copyVAppTemplate-default.xml")), "application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testcopyVAppTemplateToVDCAndNameOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("copyVAppTemplateToVDCAndName", URI.class, URI.class,
String.class, CloneVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server",
new CloneVAppTemplateOptions().description("The description of the new vAppTemplate"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate.xml")),
"application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testmoveVAppTemplateToVDCAndRenameOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("moveVAppTemplateToVDCAndRename", URI.class, URI.class,
String.class, CloneVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server",
new CloneVAppTemplateOptions().description("The description of the new vAppTemplate"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVAppTemplate.xml")),
"application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testcaptureVAppAsTemplateInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("captureVAppAsTemplateInVDC", URI.class, String.class,
URI.class, CaptureVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-template", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request, Strings2
.toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")),
"application/vnd.vmware.vcloud.captureVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testcaptureVAppAsTemplateInVDCOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("captureVAppAsTemplateInVDC", URI.class, String.class,
URI.class, CaptureVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "my-template", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), new CaptureVAppOptions()
.withDescription("The description of the new vApp Template"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp.xml")),
"application/vnd.vmware.vcloud.captureVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class,
String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "template");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("getVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetOvfEnvelopeForVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VAppTemplateAsyncClient.class.getMethod("getOvfEnvelopeForVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2/ovf HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: text/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, EnvelopeHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
}

View File

@ -0,0 +1,175 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.options.CatalogItemOptions;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VAppTemplateClientLiveTest")
public class VAppTemplateClientLiveTest extends BaseVCloudClientLiveTest {
@Test
public void testGetVAppTemplate() throws Exception {
Org org = getVCloudApi().getOrgClient().findOrgNamed(null);
for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = getVCloudApi().getCatalogClient().getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = getVCloudApi().getCatalogClient().getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
try {
assertNotNull(getVCloudApi().getVAppTemplateClient().getVAppTemplate(item.getEntity().getHref()));
} catch (AuthorizationException e) {
}
}
}
}
}
}
@Test
public void testGetOvfEnvelopeForVAppTemplate() throws Exception {
Org org = getVCloudApi().getOrgClient().findOrgNamed(null);
for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = getVCloudApi().getCatalogClient().getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
try {
CatalogItem item = getVCloudApi().getCatalogClient().getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(getVCloudApi().getVAppTemplateClient().getOvfEnvelopeForVAppTemplate(
item.getEntity().getHref()));
}
} catch (AuthorizationException e) {
}
}
}
}
}
@Test
public void testFindVAppTemplate() throws Exception {
Org org = getVCloudApi().getOrgClient().findOrgNamed(null);
for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = getVCloudApi().getCatalogClient().getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = getVCloudApi().getCatalogClient().getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
try {
assertNotNull(getVCloudApi().getVAppTemplateClient().findVAppTemplateInOrgCatalogNamed(
org.getName(), response.getName(), item.getEntity().getName()));
} catch (AuthorizationException e) {
}
}
}
}
}
}
@Test
public void testCaptureVApp() throws Exception {
String group = prefix + "cap";
NodeMetadata node = null;
VAppTemplate vappTemplate = null;
CatalogItem item = null;
try {
node = getOnlyElement(client.createNodesInGroup(group, 1));
Predicate<URI> taskTester = new RetryablePredicate<URI>(new TaskSuccess(getVCloudApi()), 600, 5,
TimeUnit.SECONDS);
// I have to powerOff first
Task task = getVCloudApi().getVAppClient().powerOffVApp(URI.create(node.getId()));
// wait up to ten minutes per above
assert taskTester.apply(task.getHref()) : node;
// having a problem where the api is returning an error telling us to stop!
// I have to undeploy first
task = getVCloudApi().getVAppClient().undeployVApp(URI.create(node.getId()));
// wait up to ten minutes per above
assert taskTester.apply(task.getHref()) : node;
// vdc is equiv to the node's location
// vapp uri is the same as the node's id
vappTemplate = getVCloudApi().getVAppTemplateClient().captureVAppAsTemplateInVDC(URI.create(node.getId()),
group, URI.create(node.getLocation().getId()));
assertEquals(vappTemplate.getName(), group);
task = vappTemplate.getTasks().get(0);
// wait up to ten minutes per above
assert taskTester.apply(task.getHref()) : vappTemplate;
item = getVCloudApi().getCatalogClient().addVAppTemplateOrMediaImageToCatalogAndNameItem(
vappTemplate.getHref(),
getVCloudApi().getCatalogClient().findCatalogInOrgNamed(null, null).getHref(), "fooname",
CatalogItemOptions.Builder.description("description").properties(ImmutableMap.of("foo", "bar")));
assertEquals(item.getName(), "fooname");
assertEquals(item.getDescription(), "description");
assertEquals(item.getProperties(), ImmutableMap.of("foo", "bar"));
assertEquals(item.getEntity().getName(), vappTemplate.getName());
assertEquals(item.getEntity().getHref(), vappTemplate.getHref());
assertEquals(item.getEntity().getType(), vappTemplate.getType());
} finally {
if (item != null)
getVCloudApi().getCatalogClient().deleteCatalogItem(item.getHref());
if (vappTemplate != null)
getVCloudApi().getVAppTemplateClient().deleteVAppTemplate(vappTemplate.getHref());
if (node != null)
client.destroyNode(node.getId());
}
}
}

View File

@ -0,0 +1,109 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.NoSuchElementException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.xml.VDCHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VDCAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "VDCAsyncClientTest")
public class VDCAsyncClientTest extends BaseVCloudAsyncClientTest<VDCAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<VDCAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VDCAsyncClient>>() {
};
}
@Test(expectedExceptions = NoSuchElementException.class)
public void testFindVDCInOrgNamedBadVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
processor.createRequest(method, "org", "vdc1");
}
@Test(expectedExceptions = NoSuchElementException.class)
public void testFindVDCInOrgNamedBadOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
processor.createRequest(method, "org1", "vdc");
}
public void testFindVDCInOrgNamedNullOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "vdc");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VDCHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindVDCInOrgNamedNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, null, null);
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VDCHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VDCAsyncClient.class.getMethod("getVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VDCHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
}

View File

@ -0,0 +1,31 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VDCClientLiveTest")
public class VDCClientLiveTest extends BaseVCloudClientLiveTest {
}

View File

@ -0,0 +1,319 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.BaseVCloudAsyncClientTest;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VmHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VmAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "VmAsyncClientTest")
public class VmAsyncClientTest extends BaseVCloudAsyncClientTest<VmAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<VmAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VmAsyncClient>>() {
};
}
public void testGetThumbnailOfVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("getScreenThumbnailForVm", URI.class);
HttpRequest request = processor
.createRequest(method, URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"));
assertRequestLineEquals(request, "GET http://vcloud.example.com/api/v1.0/vApp/vm-12/screen HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: image/png\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReturnInputStream.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testUpdateGuestConfiguration() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("updateGuestCustomizationOfVm", GuestCustomizationSection.class,
URI.class);
GuestCustomizationSection guest = new GuestCustomizationSection(URI
.create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection"));
guest.setCustomizationScript("cat > /tmp/foo.txt<<EOF\nI love candy\nEOF");
HttpRequest request = processor.createRequest(method, guest, URI
.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"));
assertRequestLineEquals(request,
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/guestCustomizationSection.xml")), "application/vnd.vmware.vcloud.guestCustomizationSection+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUpdateCPUCountOfVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("updateCPUCountOfVm", int.class, URI.class);
HttpRequest request = processor.createRequest(method, 2, URI
.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"));
assertRequestLineEquals(request,
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/virtualHardwareSection/cpu HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/cpuItem.xml")),
"application/vnd.vmware.vcloud.rasdItem+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUpdateMemoryMBOfVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("updateMemoryMBOfVm", int.class, URI.class);
HttpRequest request = processor.createRequest(method, 512, URI
.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"));
assertRequestLineEquals(request,
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/virtualHardwareSection/memory HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/memoryItem.xml")),
"application/vnd.vmware.vcloud.rasdItem+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDeployVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("deployVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDeployAndPowerOnVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("deployAndPowerOnVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testGetVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("getVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vm/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vm/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vm+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VmHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testRebootVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("rebootVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUndeployVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("undeployVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testUndeployAndSaveStateOfVmSaveState() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("undeployAndSaveStateOfVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request,
"<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testPowerOnVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("powerOnVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testPowerOffVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("powerOffVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testResetVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("resetVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testSuspendVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("suspendVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testShutdownVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VmAsyncClient.class.getMethod("shutdownVm", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
}

View File

@ -0,0 +1,173 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.features;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.crypto.CryptoStreams.base64;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient;
import org.jclouds.vcloud.BaseVCloudClientLiveTest;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.Vm;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* This tests that we can use guest customization as an alternative to bootstrapping with ssh. There
* are a few advantages to this, including the fact that it can work inside google appengine where
* network sockets (ssh:22) are prohibited.
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VmClientLiveTest")
public class VmClientLiveTest extends BaseVCloudClientLiveTest {
@Test
public void testGetThumbnailOfVm() throws Exception {
Org org = getVCloudApi().getOrgClient().findOrgNamed(null);
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = getVCloudApi().getVDCClient().getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = getVCloudApi().getVAppClient().getVApp(item.getHref());
assertNotNull(app);
for (Vm vm : app.getChildren()) {
assert getVCloudApi().getVmClient().getScreenThumbnailForVm(vm.getHref()) != null;
}
} catch (RuntimeException e) {
}
}
}
}
}
@Test
public void testGetVm() throws Exception {
Org org = getVCloudApi().getOrgClient().findOrgNamed(null);
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = getVCloudApi().getVDCClient().getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = getVCloudApi().getVAppClient().getVApp(item.getHref());
assertNotNull(app);
for (Vm vm : app.getChildren()) {
assertEquals(getVCloudApi().getVmClient().getVm(vm.getHref()).getHref(), vm.getHref());
}
} catch (RuntimeException e) {
}
}
}
}
}
@Test
public void testExtendedOptionsWithCustomizationScript() throws Exception {
String PARSE_VMTOOLSD = "vmtoolsd --cmd=\"info-get guestinfo.ovfenv\" |grep vCloud_CustomizationInfo|sed 's/.*value=\"\\(.*\\)\".*/\\1/g'";
String group = prefix + "customize";
NodeMetadata node = null;
try {
TemplateOptions options = client.templateOptions();
options.as(VCloudTemplateOptions.class).customizationScript(script);
options.as(VCloudTemplateOptions.class).description(group);
node = getOnlyElement(client.createNodesInGroup(group, 1, options));
VApp vapp = ((VCloudClient) client.getContext().getProviderSpecificContext().getApi()).getVAppClient()
.getVApp(node.getUri());
assertEquals(vapp.getDescription(), group);
Vm vm = Iterables.get(vapp.getChildren(), 0);
String apiOutput = vm.getGuestCustomizationSection().getCustomizationScript();
checkApiOutput(apiOutput);
IPSocket socket = getSocket(node);
System.out.printf("%s:%s@%s", node.getCredentials().identity, node.getCredentials().credential, socket);
assert socketTester.apply(socket) : socket;
SshClient ssh = sshFactory.create(socket, node.getCredentials());
try {
ssh.connect();
ExecResponse vmTools = ssh.exec(PARSE_VMTOOLSD);
System.out.println(vmTools);
String fooTxt = ssh.exec("cat /root/foo.txt").getOutput();
String decodedVmToolsOutput = new String(base64(vmTools.getOutput().trim()));
checkVmOutput(fooTxt, decodedVmToolsOutput);
} finally {
if (ssh != null)
ssh.disconnect();
}
} finally {
if (node != null)
client.destroyNode(node.getId());
}
}
protected void checkApiOutput(String apiOutput) {
checkApiOutput1_0_1(apiOutput);
}
// make sure the script has a lot of screwy characters, knowing our parser
// throws-out \r
String iLoveAscii = "I '\"love\"' {asc|!}*&";
String script = "cat > /root/foo.txt<<EOF\n" + iLoveAscii + "\nEOF\n";
protected void checkApiOutput1_0_1(String apiOutput) {
// in 1.0.1, vcloud director seems to pass through characters via api
// flawlessly
assertEquals(apiOutput, script);
}
protected void checkApiOutput1_0_0(String apiOutput) {
// in 1.0.0, vcloud director seems to remove all newlines
assertEquals(apiOutput, script.replace("\n", ""));
}
protected void checkVmOutput(String fooTxtContentsMadeByVMwareTools, String decodedVMwareToolsOutput) {
// note that vmwaretools throws in \r characters when executing scripts
assertEquals(fooTxtContentsMadeByVMwareTools, iLoveAscii + "\r\n");
assertEquals(decodedVMwareToolsOutput, script);
}
protected IPSocket getSocket(NodeMetadata node) {
return new IPSocket(get(node.getPublicAddresses(), 0), 22);
}
}

View File

@ -0,0 +1 @@
<CloneVAppParams xmlns="http://vcloud.safesecureweb.com/ns/vcloud.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" deploy="false" name="my-vapp" powerOn="false" xsi:schemaLocation="http://vcloud.safesecureweb.com/ns/vcloud.xsd http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Source href="https://vcenterprise.bluelock.com/api/v1.0/vapp/4181" type="application/vnd.vmware.vcloud.vApp+xml"/></CloneVAppParams>

View File

@ -0,0 +1 @@
<CloneVAppParams xmlns="http://vcloud.safesecureweb.com/ns/vcloud.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" deploy="true" name="new-linux-server" powerOn="true" xsi:schemaLocation="http://vcloud.safesecureweb.com/ns/vcloud.xsd http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Description>The description of the new vApp</Description><Source href="https://vcenterprise.bluelock.com/api/v1.0/vapp/201" type="application/vnd.vmware.vcloud.vApp+xml"/></CloneVAppParams>

View File

@ -0,0 +1 @@
<CloneVAppTemplateParams xmlns="http://vcloud.safesecureweb.com/ns/vcloud.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="my-vapptemplate" xsi:schemaLocation="http://vcloud.safesecureweb.com/ns/vcloud.xsd http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Source href="https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/></CloneVAppTemplateParams>

View File

@ -0,0 +1 @@
<CloneVAppTemplateParams xmlns="http://vcloud.safesecureweb.com/ns/vcloud.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="new-linux-server" xsi:schemaLocation="http://vcloud.safesecureweb.com/ns/vcloud.xsd http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Description>The description of the new vAppTemplate</Description><Source href="https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/></CloneVAppTemplateParams>

View File

@ -0,0 +1 @@
<CloneVAppParams xmlns="http://vcloud.safesecureweb.com/ns/vcloud.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" deploy="true" name="new-linux-server" powerOn="true" xsi:schemaLocation="http://vcloud.safesecureweb.com/ns/vcloud.xsd http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Description>The description of the new vApp</Description><Source href="https://vcenterprise.bluelock.com/api/v1.0/vapp/201" type="application/vnd.vmware.vcloud.vApp+xml"/><IsSourceDelete>true</IsSourceDelete></CloneVAppParams>

View File

@ -0,0 +1 @@
<CloneVAppTemplateParams xmlns="http://vcloud.safesecureweb.com/ns/vcloud.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="new-linux-server" xsi:schemaLocation="http://vcloud.safesecureweb.com/ns/vcloud.xsd http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Description>The description of the new vAppTemplate</Description><Source href="https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/><IsSourceDelete>true</IsSourceDelete></CloneVAppTemplateParams>

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
@ -45,11 +46,13 @@ import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
@ -57,6 +60,7 @@ import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler;
@ -72,6 +76,27 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
/**
* @see CommonVCloudClient#getCatalog
*/
@Override
@GET
@XMLResponseParser(VCloudExpressCatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see CommonVCloudClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(VCloudExpressCatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see VCloudClient#getVAppTemplate
*/

View File

@ -29,7 +29,9 @@ import org.jclouds.cim.functions.HardwareBuilderFromResourceAllocations;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import com.google.common.base.Function;
@ -42,12 +44,12 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
@Resource
protected Logger logger = Logger.NULL;
private final FindLocationForResource findLocationForResource;
private final Function<ReferenceType, Location> findLocationForResource;
private final HardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
@Inject
protected HardwareForVCloudExpressVApp(FindLocationForResource findLocationForResource,
HardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
protected HardwareForVCloudExpressVApp(Function<ReferenceType, Location> findLocationForResource,
HardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
}
@ -58,8 +60,8 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
try {
HardwareBuilder builder = rasdToHardwareBuilder.apply(from.getResourceAllocations());
builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
ImagePredicates.idEquals(from.getHref().toASCIIString()));
builder.ids(from.getHref().toASCIIString()).name(from.getName())
.supportsImage(ImagePredicates.idEquals(from.getHref().toASCIIString()));
return builder.build();
} catch (NoSuchElementException e) {
logger.debug("incomplete data to form vApp %s", from.getHref());

View File

@ -0,0 +1,103 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.xml;
import static org.jclouds.vcloud.util.Utils.newReferenceType;
import static org.jclouds.vcloud.util.Utils.putReferenceType;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.SaxUtils;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* @author Adrian Cole
*/
public class VCloudExpressCatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
protected final TaskHandler taskHandler;
@Inject
public VCloudExpressCatalogHandler(TaskHandler taskHandler) {
this.taskHandler = taskHandler;
}
private StringBuilder currentText = new StringBuilder();
private ReferenceType catalog;
private Map<String, ReferenceType> contents = Maps.newLinkedHashMap();
protected List<Task> tasks = Lists.newArrayList();
private String description;
private ReferenceType org;
private boolean published = true;
public Catalog getResult() {
return new CatalogImpl(catalog.getName(), catalog.getType(), catalog.getHref(), org, description, contents,
tasks, published, false);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.equals("Catalog")) {
catalog = newReferenceType(attributes, VCloudMediaType.CATALOG_XML);
} else if (qName.equals("CatalogItem")) {
putReferenceType(contents, attributes);
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
org = newReferenceType(attributes);
} else {
taskHandler.startElement(uri, localName, qName, attrs);
}
}
public void endElement(String uri, String name, String qName) {
taskHandler.endElement(uri, name, qName);
if (qName.equals("Task")) {
this.tasks.add(taskHandler.getResult());
} else if (qName.equals("Description")) {
description = currentOrNull();
} else if (qName.equals("IsPublished")) {
published = Boolean.parseBoolean(currentOrNull());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
protected String currentOrNull() {
String returnVal = currentText.toString().trim();
return returnVal.equals("") ? null : returnVal;
}
}

View File

@ -62,7 +62,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler;
@ -238,7 +238,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertSaxResponseParserClassEquals(method, VCloudExpressCatalogHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
@ -253,7 +253,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertSaxResponseParserClassEquals(method, VCloudExpressCatalogHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
@ -679,9 +679,8 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
}
@Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) {
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog write) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog");
}
@Override
@ -811,7 +810,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
"template",
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))), ImmutableList
.<Task> of(), true)));
.<Task> of(), true, false)));
}
}

View File

@ -53,7 +53,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
@Override
protected void configure() {
Properties props = new Properties();
props.setProperty("jclouds.vcloud.xml.ns", "http://www.vmware.com/vcloud/v1");
props.setProperty("jclouds.vcloud.xml.ns", "http://www.vmware.com/vcloud/v0.8");
props.setProperty("jclouds.vcloud.xml.schema", "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
Names.bindProperties(binder(), new PropertiesBuilder(props).build());
}
@ -74,7 +74,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
Map<String, String> map = Maps.newHashMap();
map.put("newName", "new-linux-server");
map.put("vApp", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201");
binder.bindToRequest(request, map);
verify(request);
}
@ -92,7 +92,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
Map<String, String> map = Maps.newHashMap();
map.put("newName", "my-vapp");
map.put("vApp", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181");
map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181");
binder.bindToRequest(request, map);
verify(request);
}

View File

View File

View File

Some files were not shown because too many files have changed in this diff Show More