Issue 830: refactored VdcApi,AdminVdcApi to use urn

This commit is contained in:
Adrian Cole 2012-08-19 16:08:16 -07:00
parent 206af90b77
commit cb844928c0
20 changed files with 631 additions and 352 deletions

View File

@ -46,6 +46,7 @@
<test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id> <test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id>
<!-- URN format: ex. urn:vcloud:network:7212e451-76e1-4631-b2de-ba1dfd8080e4 --> <!-- URN format: ex. urn:vcloud:network:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.network-id></test.vcloud-director.network-id> <test.vcloud-director.network-id></test.vcloud-director.network-id>
<!-- URN format: ex. urn:vcloud:vdc:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.vdc-id></test.vcloud-director.vdc-id> <test.vcloud-director.vdc-id></test.vcloud-director.vdc-id>
<!-- URN format: ex. urn:vcloud:user:7212e451-76e1-4631-b2de-ba1dfd8080e4 --> <!-- URN format: ex. urn:vcloud:user:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.user-id></test.vcloud-director.user-id> <test.vcloud-director.user-id></test.vcloud-director.user-id>

View File

@ -50,7 +50,9 @@ public interface VdcApi {
* *
* @return the vdc or null if not found * @return the vdc or null if not found
*/ */
Vdc getVdc(URI vdcUri); Vdc get(String vdcUrn);
Vdc get(URI vdcHref);
/** /**
* Captures a vApp into vApp template. * Captures a vApp into vApp template.
@ -62,8 +64,10 @@ public interface VdcApi {
* @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able * @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able
* to use the vApp. * to use the vApp.
*/ */
VAppTemplate captureVApp(URI vdcUri, CaptureVAppParams params); VAppTemplate captureVApp(String vdcUrn, CaptureVAppParams params);
VAppTemplate captureVApp(URI vdcHref, CaptureVAppParams params);
/** /**
* Clones a media into new one. * Clones a media into new one.
* *
@ -74,8 +78,10 @@ public interface VdcApi {
* @return a Media resource which will contain a task. The user should monitor the contained task status in order to * @return a Media resource which will contain a task. The user should monitor the contained task status in order to
* check when it is completed. * check when it is completed.
*/ */
Media cloneMedia(URI vdcUri, CloneMediaParams params); Media cloneMedia(String vdcUrn, CloneMediaParams params);
Media cloneMedia(URI vdcHref, CloneMediaParams params);
/** /**
* Clones a vApp into new one. * Clones a vApp into new one.
* *
@ -85,8 +91,10 @@ public interface VdcApi {
* @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able * @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able
* to use the vApp. * to use the vApp.
*/ */
VApp cloneVApp(URI vdcUri, CloneVAppParams params); VApp cloneVApp(String vdcUrn, CloneVAppParams params);
VApp cloneVApp(URI vdcHref, CloneVAppParams params);
/** /**
* Clones a vApp template into new one. * Clones a vApp template into new one.
* *
@ -97,8 +105,10 @@ public interface VdcApi {
* @return a VAppTemplate resource which will contain a task. The user should should wait for this task to finish to * @return a VAppTemplate resource which will contain a task. The user should should wait for this task to finish to
* be able to use the VAppTemplate. * be able to use the VAppTemplate.
*/ */
VAppTemplate cloneVAppTemplate(URI vdcUri, CloneVAppTemplateParams params); VAppTemplate cloneVAppTemplate(String vdcUrn, CloneVAppTemplateParams params);
VAppTemplate cloneVAppTemplate(URI vdcHref, CloneVAppTemplateParams params);
/** /**
* Composes a new vApp using VMs from other vApps or vApp templates. * Composes a new vApp using VMs from other vApps or vApp templates.
* *
@ -129,8 +139,10 @@ public interface VdcApi {
* @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able * @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able
* to use the vApp. * to use the vApp.
*/ */
VApp composeVApp(URI vdcUri, ComposeVAppParams params); VApp composeVApp(String vdcUrn, ComposeVAppParams params);
VApp composeVApp(URI vdcHref, ComposeVAppParams params);
/** /**
* Instantiate a vApp template into a new vApp. * Instantiate a vApp template into a new vApp.
* *
@ -144,8 +156,10 @@ public interface VdcApi {
* @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able * @return a VApp resource which will contain a task. The user should should wait for this task to finish to be able
* to use the vApp. * to use the vApp.
*/ */
VApp instantiateVApp(URI vdcUri, InstantiateVAppParams params); VApp instantiateVApp(String vdcUrn, InstantiateVAppParams params);
VApp instantiateVApp(URI vdcHref, InstantiateVAppParams params);
/** /**
* Uploading vApp template to a vDC. * Uploading vApp template to a vDC.
* *
@ -165,15 +179,19 @@ public interface VdcApi {
* @return a VAppTemplate resource which will contain a task. The user should should wait for this task to finish to * @return a VAppTemplate resource which will contain a task. The user should should wait for this task to finish to
* be able to use the VAppTemplate. * be able to use the VAppTemplate.
*/ */
VAppTemplate uploadVAppTemplate(URI vdcUri, UploadVAppTemplateParams params); VAppTemplate uploadVAppTemplate(String vdcUrn, UploadVAppTemplateParams params);
VAppTemplate uploadVAppTemplate(URI vdcHref, UploadVAppTemplateParams params);
/** /**
* Creates a media (and present upload link for the floppy/iso file). * Creates a media (and present upload link for the floppy/iso file).
* *
* @return The response will return a link to transfer site to be able to continue with uploading the media. * @return The response will return a link to transfer site to be able to continue with uploading the media.
*/ */
Media createMedia(URI vdcUri, Media media); Media createMedia(String vdcUrn, Media media);
Media createMedia(URI vdcHref, Media media);
/** /**
* @return synchronous access to {@link Metadata.Readable} features * @return synchronous access to {@link Metadata.Readable} features
*/ */

View File

@ -36,6 +36,7 @@ import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Media;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.VApp; import org.jclouds.vcloud.director.v1_5.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.Vdc;
@ -47,25 +48,124 @@ import org.jclouds.vcloud.director.v1_5.domain.params.ComposeVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiateVAppParams; import org.jclouds.vcloud.director.v1_5.domain.params.InstantiateVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.params.UploadVAppTemplateParams; import org.jclouds.vcloud.director.v1_5.domain.params.UploadVAppTemplateParams;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.VdcURNToHref;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see VdcApi * @see VdcApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface VdcAsyncApi { public interface VdcAsyncApi {
/** /**
* @see VdcApi#getVdc(URI) * @see VdcApi#get(String)
*/ */
@GET @GET
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Vdc> getVdc(@EndpointParam URI vdcURI); ListenableFuture<? extends Vdc> get(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn);
/**
* @see VdcApi#captureVApp(String, CaptureVAppParams)
*/
@POST
@Path("/action/captureVApp")
@Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE)
@Produces(VCloudDirectorMediaType.CAPTURE_VAPP_PARAMS)
@JAXBResponseParser
ListenableFuture<VAppTemplate> captureVApp(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) CaptureVAppParams params);
/**
* @see VdcApi#cloneMedia(String, CloneMediaParams)
*/
@POST
@Path("/action/cloneMedia")
@Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS)
@JAXBResponseParser
ListenableFuture<Media> cloneMedia(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) CloneMediaParams params);
/**
* @see VdcApi#cloneVApp(String, CloneVAppParams)
*/
@POST
@Path("/action/cloneVApp")
@Consumes(VCloudDirectorMediaType.VAPP)
@Produces(VCloudDirectorMediaType.CLONE_VAPP_PARAMS)
// TODO fix these etc.
@JAXBResponseParser
ListenableFuture<VApp> cloneVApp(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) CloneVAppParams params);
/**
* @see VdcApi#cloneVAppTemplate(String, CloneVAppTemplateParams)
*/
@POST
@Path("/action/cloneVAppTemplate")
@Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE)
@Produces(VCloudDirectorMediaType.CLONE_VAPP_TEMPLATE_PARAMS)
@JAXBResponseParser
ListenableFuture<VAppTemplate> cloneVAppTemplate(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) CloneVAppTemplateParams params);
/**
* @see VdcApi#composeVApp(String, ComposeVAppParams)
*/
@POST
@Path("/action/composeVApp")
@Consumes(VCloudDirectorMediaType.VAPP)
@Produces(VCloudDirectorMediaType.COMPOSE_VAPP_PARAMS)
@JAXBResponseParser
ListenableFuture<VApp> composeVApp(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) ComposeVAppParams params);
/**
* @see VdcApi#instantiateVApp(String, InstantiateVAppParamsType)
*/
@POST
@Path("/action/instantiateVAppTemplate")
@Consumes(VCloudDirectorMediaType.VAPP)
@Produces(VCloudDirectorMediaType.INSTANTIATE_VAPP_TEMPLATE_PARAMS)
@JAXBResponseParser
ListenableFuture<VApp> instantiateVApp(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) InstantiateVAppParams params);
/**
* @see VdcApi#uploadVAppTemplate(String, UploadVAppTemplateParams)
*/
@POST
@Path("/action/uploadVAppTemplate")
@Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE)
@Produces(VCloudDirectorMediaType.UPLOAD_VAPP_TEMPLATE_PARAMS)
@JAXBResponseParser
ListenableFuture<VAppTemplate> uploadVAppTemplate(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) UploadVAppTemplateParams params);
/**
* @see VdcApi#createMedia(String, Media)
*/
@POST
@Path("/media")
@Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.MEDIA)
@JAXBResponseParser
ListenableFuture<Media> createMedia(@EndpointParam(parser = VdcURNToHref.class) String vdcUrn,
@BinderParam(BindToXMLPayload.class) Media media);
/**
* @see VdcApi#get(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Vdc> get(@EndpointParam URI vdcHref);
/** /**
* @see VdcApi#captureVApp(URI, CaptureVAppParams) * @see VdcApi#captureVApp(URI, CaptureVAppParams)
*/ */
@ -74,9 +174,9 @@ public interface VdcAsyncApi {
@Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE) @Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE)
@Produces(VCloudDirectorMediaType.CAPTURE_VAPP_PARAMS) @Produces(VCloudDirectorMediaType.CAPTURE_VAPP_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<VAppTemplate> captureVApp(@EndpointParam URI vdcURI, ListenableFuture<VAppTemplate> captureVApp(@EndpointParam URI vdcHref,
@BinderParam(BindToXMLPayload.class) CaptureVAppParams params); @BinderParam(BindToXMLPayload.class) CaptureVAppParams params);
/** /**
* @see VdcApi#cloneMedia(URI, CloneMediaParams) * @see VdcApi#cloneMedia(URI, CloneMediaParams)
*/ */
@ -85,20 +185,21 @@ public interface VdcAsyncApi {
@Consumes(VCloudDirectorMediaType.MEDIA) @Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS) @Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Media> cloneMedia(@EndpointParam URI vdcURI, ListenableFuture<Media> cloneMedia(@EndpointParam URI vdcHref,
@BinderParam(BindToXMLPayload.class) CloneMediaParams params); @BinderParam(BindToXMLPayload.class) CloneMediaParams params);
/** /**
* @see VdcApi#cloneVApp(URI, CloneVAppParams) * @see VdcApi#cloneVApp(URI, CloneVAppParams)
*/ */
@POST @POST
@Path("/action/cloneVApp") @Path("/action/cloneVApp")
@Consumes(VCloudDirectorMediaType.VAPP) @Consumes(VCloudDirectorMediaType.VAPP)
@Produces(VCloudDirectorMediaType.CLONE_VAPP_PARAMS) //TODO fix these etc. @Produces(VCloudDirectorMediaType.CLONE_VAPP_PARAMS)
// TODO fix these etc.
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<VApp> cloneVApp(@EndpointParam URI vdcURI, ListenableFuture<VApp> cloneVApp(@EndpointParam URI vdcHref,
@BinderParam(BindToXMLPayload.class) CloneVAppParams params); @BinderParam(BindToXMLPayload.class) CloneVAppParams params);
/** /**
* @see VdcApi#cloneVAppTemplate(URI, CloneVAppTemplateParams) * @see VdcApi#cloneVAppTemplate(URI, CloneVAppTemplateParams)
*/ */
@ -107,9 +208,9 @@ public interface VdcAsyncApi {
@Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE) @Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE)
@Produces(VCloudDirectorMediaType.CLONE_VAPP_TEMPLATE_PARAMS) @Produces(VCloudDirectorMediaType.CLONE_VAPP_TEMPLATE_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<VAppTemplate> cloneVAppTemplate(@EndpointParam URI vdcURI, ListenableFuture<VAppTemplate> cloneVAppTemplate(@EndpointParam URI vdcHref,
@BinderParam(BindToXMLPayload.class) CloneVAppTemplateParams params); @BinderParam(BindToXMLPayload.class) CloneVAppTemplateParams params);
/** /**
* @see VdcApi#composeVApp(URI, ComposeVAppParams) * @see VdcApi#composeVApp(URI, ComposeVAppParams)
*/ */
@ -118,9 +219,9 @@ public interface VdcAsyncApi {
@Consumes(VCloudDirectorMediaType.VAPP) @Consumes(VCloudDirectorMediaType.VAPP)
@Produces(VCloudDirectorMediaType.COMPOSE_VAPP_PARAMS) @Produces(VCloudDirectorMediaType.COMPOSE_VAPP_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<VApp> composeVApp(@EndpointParam URI vdcURI, ListenableFuture<VApp> composeVApp(@EndpointParam URI vdcHref,
@BinderParam(BindToXMLPayload.class) ComposeVAppParams params); @BinderParam(BindToXMLPayload.class) ComposeVAppParams params);
/** /**
* @see VdcApi#instantiateVApp(URI, InstantiateVAppParamsType) * @see VdcApi#instantiateVApp(URI, InstantiateVAppParamsType)
*/ */
@ -129,9 +230,9 @@ public interface VdcAsyncApi {
@Consumes(VCloudDirectorMediaType.VAPP) @Consumes(VCloudDirectorMediaType.VAPP)
@Produces(VCloudDirectorMediaType.INSTANTIATE_VAPP_TEMPLATE_PARAMS) @Produces(VCloudDirectorMediaType.INSTANTIATE_VAPP_TEMPLATE_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<VApp> instantiateVApp(@EndpointParam URI vdcURI, ListenableFuture<VApp> instantiateVApp(@EndpointParam URI vdcHref,
@BinderParam(BindToXMLPayload.class) InstantiateVAppParams params); @BinderParam(BindToXMLPayload.class) InstantiateVAppParams params);
/** /**
* @see VdcApi#uploadVAppTemplate(URI, UploadVAppTemplateParams) * @see VdcApi#uploadVAppTemplate(URI, UploadVAppTemplateParams)
*/ */
@ -140,9 +241,9 @@ public interface VdcAsyncApi {
@Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE) @Consumes(VCloudDirectorMediaType.VAPP_TEMPLATE)
@Produces(VCloudDirectorMediaType.UPLOAD_VAPP_TEMPLATE_PARAMS) @Produces(VCloudDirectorMediaType.UPLOAD_VAPP_TEMPLATE_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<VAppTemplate> uploadVAppTemplate(@EndpointParam URI vdcURI, ListenableFuture<VAppTemplate> uploadVAppTemplate(@EndpointParam URI vdcHref,
@BinderParam(BindToXMLPayload.class) UploadVAppTemplateParams params); @BinderParam(BindToXMLPayload.class) UploadVAppTemplateParams params);
/** /**
* @see VdcApi#createMedia(URI, Media) * @see VdcApi#createMedia(URI, Media)
*/ */
@ -151,13 +252,12 @@ public interface VdcAsyncApi {
@Consumes(VCloudDirectorMediaType.MEDIA) @Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.MEDIA) @Produces(VCloudDirectorMediaType.MEDIA)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Media> createMedia(@EndpointParam URI vdcURI, ListenableFuture<Media> createMedia(@EndpointParam URI vdcHref, @BinderParam(BindToXMLPayload.class) Media media);
@BinderParam(BindToXMLPayload.class) Media media);
/** /**
* @return asynchronous access to {@link Metadata.Readable} features * @return asynchronous access to {@link Metadata.Readable} features
*/ */
@Delegate @Delegate
MetadataAsyncApi.Readable getMetadataApi(); MetadataAsyncApi.Readable getMetadataApi();
} }

View File

@ -23,17 +23,17 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.vcloud.director.v1_5.domain.AdminVdc; import org.jclouds.vcloud.director.v1_5.domain.AdminVdc;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.features.MetadataApi; import org.jclouds.vcloud.director.v1_5.features.MetadataApi;
import org.jclouds.vcloud.director.v1_5.features.MetadataApi.Writeable;
import org.jclouds.vcloud.director.v1_5.features.VdcApi; import org.jclouds.vcloud.director.v1_5.features.VdcApi;
/** /**
* Provides synchronous access to {@link AdminVdc}. * Provides synchronous access to {@link AdminVdc}.
* *
* @see AdminVdcAsyncApi * @see AdminVdcAsyncApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminVdcApi extends VdcApi { public interface AdminVdcApi extends VdcApi {
@ -48,34 +48,45 @@ public interface AdminVdcApi extends VdcApi {
* @return the admin vDC or null if not found * @return the admin vDC or null if not found
*/ */
@Override @Override
AdminVdc getVdc(URI vdcRef); AdminVdc get(String vdcUrn);
@Override
AdminVdc get(URI vdcHref);
/** /**
* Modifies a Virtual Data Center. Virtual Data Center could be enabled or disabled. * Modifies a Virtual Data Center. Virtual Data Center could be enabled or disabled.
* Additionally it could have one of these states FAILED_CREATION(-1), NOT_READY(0), * Additionally it could have one of these states FAILED_CREATION(-1), NOT_READY(0),
* READY(1), UNKNOWN(1) and UNRECOGNIZED(3). * READY(1), UNKNOWN(1) and UNRECOGNIZED(3).
*/ */
Task editVdc(URI vdcRef, AdminVdc vdc); Task update(String vdcUrn, AdminVdc vdc);
Task update(URI vdcHref, AdminVdc vdc);
/** /**
* Deletes a Virtual Data Center. The Virtual Data Center should be disabled when delete is issued. * Deletes a Virtual Data Center. The Virtual Data Center should be disabled when delete is issued.
* Otherwise error code 400 Bad Request is returned. * Otherwise error code 400 Bad Request is returned.
*/ */
// TODO Saw what exception, instead of 400 // TODO Saw what exception, instead of 400
Task deleteVdc(URI vdcRef); Task delete(String vdcUrn);
Task delete(URI vdcHref);
/** /**
* Enables a Virtual Data Center. This operation enables disabled Virtual Data Center. * Enables a Virtual Data Center. This operation enables disabled Virtual Data Center.
* If it is already enabled this operation has no effect. * If it is already enabled this operation has no effect.
*/ */
void enableVdc(@EndpointParam URI vdcRef); void enable(String vdcUrn);
void enable(URI vdcHref);
/** /**
* Disables a Virtual Data Center. If the Virtual Data Center is disabled this operation does not * Disables a Virtual Data Center. If the Virtual Data Center is disabled this operation does not
* have an effect. * have an effect.
*/ */
void disableVdc(URI vdcRef); void disable(String vdcUrn);
void disable(URI vdcHref);
/** /**
* @return synchronous access to {@link Writeable} features * @return synchronous access to {@link Writeable} features
*/ */

View File

@ -38,48 +38,109 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AdminVdc; import org.jclouds.vcloud.director.v1_5.domain.AdminVdc;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi; import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi.Writeable;
import org.jclouds.vcloud.director.v1_5.features.VdcAsyncApi; import org.jclouds.vcloud.director.v1_5.features.VdcAsyncApi;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.VdcURNToAdminHref;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see AdminVdcApi * @see AdminVdcApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface AdminVdcAsyncApi extends VdcAsyncApi { public interface AdminVdcAsyncApi extends VdcAsyncApi {
/**
* @see AdminVdcApi#get(String)
*/
@Override @Override
@GET @GET
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AdminVdc> getVdc(@EndpointParam URI vdcRef); ListenableFuture<AdminVdc> get(@EndpointParam(parser = VdcURNToAdminHref.class) String vdcUrn);
/**
* @see AdminVdcApi#update(String, AdminVdc)
*/
@PUT @PUT
@Consumes @Consumes
@Produces(VCloudDirectorMediaType.ADMIN_VDC) @Produces(VCloudDirectorMediaType.ADMIN_VDC)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> editVdc(@EndpointParam URI vdcRef, AdminVdc vdc); ListenableFuture<Task> update(@EndpointParam(parser = VdcURNToAdminHref.class) String vdcUrn, AdminVdc vdc);
/**
* @see AdminVdcApi#delete(String)
*/
@DELETE @DELETE
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> deleteVdc(@EndpointParam URI vdcRef); ListenableFuture<Task> delete(@EndpointParam(parser = VdcURNToAdminHref.class) String vdcUrn);
/**
* @see AdminVdcApi#enable(String)
*/
@POST @POST
@Consumes @Consumes
@Path("/action/enable") @Path("/action/enable")
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Void> enableVdc(@EndpointParam URI vdcRef); ListenableFuture<Void> enable(@EndpointParam(parser = VdcURNToAdminHref.class) String vdcUrn);
/**
* @see AdminVdcApi#disable(String)
*/
@POST @POST
@Consumes @Consumes
@Path("/action/disable") @Path("/action/disable")
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Void> disableVdc(@EndpointParam URI vdcRef); ListenableFuture<Void> disable(@EndpointParam(parser = VdcURNToAdminHref.class) String vdcUrn);
/**
* @see AdminVdcApi#get(URI)
*/
@Override
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AdminVdc> get(@EndpointParam URI vdcHref);
/**
* @see AdminVdcApi#update(URI, AdminVdc)
*/
@PUT
@Consumes
@Produces(VCloudDirectorMediaType.ADMIN_VDC)
@JAXBResponseParser
ListenableFuture<Task> update(@EndpointParam URI vdcHref, AdminVdc vdc);
/**
* @see AdminVdcApi#delete(URI)
*/
@DELETE
@Consumes
@JAXBResponseParser
ListenableFuture<Task> delete(@EndpointParam URI vdcHref);
/**
* @see AdminVdcApi#enable(URI)
*/
@POST
@Consumes
@Path("/action/enable")
@JAXBResponseParser
ListenableFuture<Void> enable(@EndpointParam URI vdcHref);
/**
* @see AdminVdcApi#disable(URI)
*/
@POST
@Consumes
@Path("/action/disable")
@JAXBResponseParser
ListenableFuture<Void> disable(@EndpointParam URI vdcHref);
/** /**
* @return asynchronous access to {@link Writeable} features * @return asynchronous access to {@link Writeable} features
*/ */

View File

@ -61,7 +61,7 @@ public class AllVdcsInOrg implements Function<AdminOrg, Iterable<? extends Vdc>>
new Function<Reference, Future<? extends Vdc>>() { new Function<Reference, Future<? extends Vdc>>() {
@Override @Override
public Future<? extends Vdc> apply(Reference from) { public Future<? extends Vdc> apply(Reference from) {
return aapi.getVdcApi().getVdc(from.getHref()); return aapi.getVdcApi().get(from.getHref());
} }
}, executor, null, logger, "vdcs in org " + org.getName()); }, executor, null, logger, "vdcs in org " + org.getName());

View File

@ -0,0 +1,43 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class VdcURNToAdminHref extends URNToHref {
@Inject
public VdcURNToAdminHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.ADMIN_VDC;
}
}

View File

@ -0,0 +1,43 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class VdcURNToHref extends URNToHref {
@Inject
public VdcURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.VDC;
}
}

View File

@ -134,8 +134,7 @@ public abstract class AbstractVAppApiLiveTest extends BaseVCloudDirectorApiLiveT
@BeforeClass(alwaysRun = true, description = "Retrieves the required apis from the REST API context") @BeforeClass(alwaysRun = true, description = "Retrieves the required apis from the REST API context")
protected void setupEnvironment() { protected void setupEnvironment() {
// Get the configured Vdc for the tests // Get the configured Vdc for the tests
vdc = vdcApi.getVdc(vdcURI); vdc = lazyGetVdc();
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
// Get the configured VAppTemplate for the tests // Get the configured VAppTemplate for the tests
vAppTemplate = vAppTemplateApi.getVAppTemplate(vAppTemplateURI); vAppTemplate = vAppTemplateApi.getVAppTemplate(vAppTemplateURI);
@ -192,7 +191,7 @@ public abstract class AbstractVAppApiLiveTest extends BaseVCloudDirectorApiLiveT
@AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps") @AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps")
protected void cleanUpEnvironment() { protected void cleanUpEnvironment() {
vdc = vdcApi.getVdc(vdcURI); // Refresh vdc = vdcApi.get(vdcUrn); // Refresh
// Find references in the Vdc with the VApp type and in the list of instantiated VApp names // Find references in the Vdc with the VApp type and in the list of instantiated VApp names
Iterable<Reference> vApps = Iterables.filter(vdc.getResourceEntities(), Iterable<Reference> vApps = Iterables.filter(vdc.getResourceEntities(),

View File

@ -21,8 +21,6 @@ package org.jclouds.vcloud.director.v1_5.features;
import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.and;
import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.find;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkCatalogItem; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkCatalogItem;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
@ -134,7 +132,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /catalog/{id}") @Test(description = "GET /catalog/{id}")
public void testGetCatalog() { public void testGetCatalog() {
Catalog catalog = catalogApi.get(catalogUrn); Catalog catalog = lazyGetCatalog();
assertNotNull(catalog); assertNotNull(catalog);
// Double check it's pointing at the correct catalog // Double check it's pointing at the correct catalog
assertEquals(catalog.getId(), catalogUrn); assertEquals(catalog.getId(), catalogUrn);
@ -149,11 +147,8 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /catalog/{id}/catalogItems") @Test(description = "POST /catalog/{id}/catalogItems")
public void testAddCatalogItem() { public void testAddCatalogItem() {
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC));
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Vdc vdc = context.getApi().getVdcApi().getVdc(vdcURI); Vdc vdc = lazyGetVdc();
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA))); Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name("Test media 1").size(iso.length) Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name("Test media 1").size(iso.length)
@ -189,13 +184,13 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /catalog/{id}/metadata") @Test(description = "GET /catalog/{id}/metadata")
public void testGetCatalogMetadata() { public void testGetCatalogMetadata() {
Metadata catalogMetadata = catalogApi.getMetadataApi().get(catalogApi.get(catalogUrn).getHref()); Metadata catalogMetadata = catalogApi.getMetadataApi().get(lazyGetCatalog().getHref());
checkMetadata(catalogMetadata); checkMetadata(catalogMetadata);
} }
@Test(description = "GET /catalog/{id}/metadata/{key}") @Test(description = "GET /catalog/{id}/metadata/{key}")
public void testGetCatalogMetadataValue() { public void testGetCatalogMetadataValue() {
Metadata catalogMetadata = catalogApi.getMetadataApi().get(catalogApi.get(catalogUrn).getHref()); Metadata catalogMetadata = catalogApi.getMetadataApi().get(lazyGetCatalog().getHref());
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(),
new Predicate<MetadataEntry>() { new Predicate<MetadataEntry>() {
@Override @Override

View File

@ -35,7 +35,6 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals; import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals; import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals;
@ -128,9 +127,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /vdc/{id}/media") @Test(description = "POST /vdc/{id}/media")
public void testCreateMedia() throws URISyntaxException { public void testCreateMedia() throws URISyntaxException {
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC)); Vdc vdc = lazyGetVdc();
Vdc vdc = vdcApi.getVdc(vdcURI);
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA))); Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
// TODO: generate an iso // TODO: generate an iso
@ -207,7 +204,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /vdc/{id}/action/cloneMedia", dependsOnMethods = { "testGetMediaOwner" }) @Test(description = "POST /vdc/{id}/action/cloneMedia", dependsOnMethods = { "testGetMediaOwner" })
public void testCloneMedia() { public void testCloneMedia() {
oldMedia = media; oldMedia = media;
media = vdcApi.cloneMedia(vdcURI, CloneMediaParams.builder() media = vdcApi.cloneMedia(vdcUrn, CloneMediaParams.builder()
.source(Reference.builder().fromEntity(media).build()) .source(Reference.builder().fromEntity(media).build())
.name("copied "+media.getName()) .name("copied "+media.getName())
.description("copied by testCloneMedia()") .description("copied by testCloneMedia()")
@ -230,7 +227,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
mediaApi.getMetadataApi().putEntry(media.getHref(), "key", MetadataValue.builder().value("value").build()); mediaApi.getMetadataApi().putEntry(media.getHref(), "key", MetadataValue.builder().value("value").build());
media = vdcApi.cloneMedia(vdcURI, CloneMediaParams.builder() media = vdcApi.cloneMedia(vdcUrn, CloneMediaParams.builder()
.source(Reference.builder().fromEntity(media).build()) .source(Reference.builder().fromEntity(media).build())
.name("moved test media") .name("moved test media")
.description("moved by testCloneMedia()") .description("moved by testCloneMedia()")

View File

@ -47,10 +47,10 @@ import org.testng.annotations.Test;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
* Tests live behavior of {@link OrgApi}. * Tests live behavior of {@link OrgApi}.
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "OrgApiLiveTest") @Test(groups = { "live", "user" }, singleThreaded = true, testName = "OrgApiLiveTest")
public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest { public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@ -65,18 +65,18 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void setupRequiredApis() { public void setupRequiredApis() {
orgApi = context.getApi().getOrgApi(); orgApi = context.getApi().getOrgApi();
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void cleanUp() throws Exception { public void cleanUp() throws Exception {
if (adminMembersSet) { if (adminMembersSet) {
try { try {
Task delete = adminContext.getApi().getOrgApi().getMetadataApi().deleteEntry(toAdminUri(orgURI), "KEY"); Task delete = adminContext.getApi().getOrgApi().getMetadataApi().deleteEntry(toAdminUri(orgURI), "KEY");
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry"); logger.warn(e, "Error when deleting metadata entry");
} }
try { try {
adminContext.getApi().getCatalogApi().delete(catalogUrn); adminContext.getApi().getCatalogApi().delete(catalogUrn);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting catalog'%s': %s", catalogUrn); logger.warn(e, "Error when deleting catalog'%s': %s", catalogUrn);
} }
@ -96,14 +96,15 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testGetOrgList() { public void testGetOrgList() {
// Call the method being tested // Call the method being tested
orgList = orgApi.list(); orgList = orgApi.list();
// NOTE The environment MUST have at least one organisation configured // NOTE The environment MUST have at least one organisation configured
// Check test requirements // Check test requirements
assertFalse(Iterables.isEmpty(orgList), String.format(NOT_EMPTY_OBJECT_FMT, "Org", "OrgList")); assertFalse(Iterables.isEmpty(orgList), String.format(NOT_EMPTY_OBJECT_FMT, "Org", "OrgList"));
for (Reference orgRef : orgList) { for (Reference orgRef : orgList) {
assertEquals(orgRef.getType(), VCloudDirectorMediaType.ORG, String.format(CONDITION_FMT, "Reference.Type", VCloudDirectorMediaType.ORG, orgRef.getType())); assertEquals(orgRef.getType(), VCloudDirectorMediaType.ORG,
String.format(CONDITION_FMT, "Reference.Type", VCloudDirectorMediaType.ORG, orgRef.getType()));
checkReferenceType(orgRef); checkReferenceType(orgRef);
} }
} }
@ -112,64 +113,66 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testGetOrg() { public void testGetOrg() {
Reference orgRef = Iterables.getFirst(orgList, null); Reference orgRef = Iterables.getFirst(orgList, null);
assertNotNull(orgRef); assertNotNull(orgRef);
orgURI = orgRef.getHref(); orgURI = orgRef.getHref();
// Call the method being tested // Call the method being tested
org = orgApi.get(orgURI); org = orgApi.get(orgURI);
assertEquals(orgApi.get(org.getId()), org); assertEquals(orgApi.get(org.getId()), org);
checkOrg(org); checkOrg(org);
if (adminContext != null) { if (adminContext != null) {
setupAdminMembers(); setupAdminMembers();
} }
} }
/** /**
* If we're running in an admin context, it's cleaner to make temporary entities, plus eliminates the need for configuration * If we're running in an admin context, it's cleaner to make temporary entities, plus eliminates
* the need for configuration
*/ */
private void setupAdminMembers() { private void setupAdminMembers() {
adminContext.getApi().getOrgApi().getMetadataApi().putEntry(toAdminUri(orgURI), adminContext.getApi().getOrgApi().getMetadataApi()
"KEY", MetadataValue.builder().value("VALUE").build()); .putEntry(toAdminUri(orgURI), "KEY", MetadataValue.builder().value("VALUE").build());
AdminCatalog newCatalog = AdminCatalog.builder() AdminCatalog newCatalog = AdminCatalog.builder().name("Test Catalog " + getTestDateTimeStamp())
.name("Test Catalog "+getTestDateTimeStamp()) .description("created by testOrg()").build();
.description("created by testOrg()")
.build();
newCatalog = adminContext.getApi().getCatalogApi().createCatalogInOrg(newCatalog, org.getId()); newCatalog = adminContext.getApi().getCatalogApi().createCatalogInOrg(newCatalog, org.getId());
catalogUrn = newCatalog.getId(); catalogUrn = newCatalog.getId();
adminMembersSet = true; adminMembersSet = true;
} }
@Test(description = "GET /org/{id}/metadata", dependsOnMethods = { "testGetOrg" }) @Test(description = "GET /org/{id}/metadata", dependsOnMethods = { "testGetOrg" })
public void testGetOrgMetadata() { public void testGetOrgMetadata() {
// Call the method being tested // Call the method being tested
Metadata metadata = orgApi.getMetadataApi().get(orgURI); Metadata metadata = orgApi.getMetadataApi().get(orgURI);
// NOTE The environment MUST have at one metadata entry for the first organisation configured // NOTE The environment MUST have at one metadata entry for the first organisation configured
checkMetadata(metadata); checkMetadata(metadata);
// Check requirements for this test // Check requirements for this test
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), String.format(NOT_EMPTY_OBJECT_FMT, "MetadataEntry", "Org")); assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
String.format(NOT_EMPTY_OBJECT_FMT, "MetadataEntry", "Org"));
} }
@Test(description = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" }) @Test(description = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" })
public void testGetOrgMetadataValue() { public void testGetOrgMetadataValue() {
// Call the method being tested // Call the method being tested
MetadataValue value = orgApi.getMetadataApi().getValue(orgURI, "KEY"); MetadataValue value = orgApi.getMetadataApi().getValue(orgURI, "KEY");
// NOTE The environment MUST have configured the metadata entry as '{ key="KEY", value="VALUE" )' // NOTE The environment MUST have configured the metadata entry as '{ key="KEY", value="VALUE"
// )'
String expected = "VALUE"; String expected = "VALUE";
checkMetadataValue(value); checkMetadataValue(value);
assertEquals(value.getValue(), expected, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value.getValue())); assertEquals(value.getValue(), expected,
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value.getValue()));
} }
} }

View File

@ -124,7 +124,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
protected void setupRequiredEntities() { protected void setupRequiredEntities() {
Set<Link> links = vdcApi.getVdc(vdcURI).getLinks(); Set<Link> links = lazyGetVdc().getLinks();
if (mediaURI == null) { if (mediaURI == null) {
Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA)); Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA));
@ -214,7 +214,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
public void testRecomposeVApp() { public void testRecomposeVApp() {
Set<Vm> vms = getAvailableVMsFromVAppTemplates(); Set<Vm> vms = getAvailableVMsFromVAppTemplates();
VApp composedVApp = vdcApi.composeVApp(vdcURI, ComposeVAppParams.builder() VApp composedVApp = vdcApi.composeVApp(vdcUrn, ComposeVAppParams.builder()
.name(name("composed-")) .name(name("composed-"))
.instantiationParams(instantiationParams()) .instantiationParams(instantiationParams())
.build()); .build());

View File

@ -105,7 +105,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
.isSourceDelete(false) .isSourceDelete(false)
.name("clone") .name("clone")
.build(); .build();
VAppTemplate clonedVappTemplate = vdcApi.cloneVAppTemplate(vdcURI, cloneVAppTemplateParams); VAppTemplate clonedVappTemplate = vdcApi.cloneVAppTemplate(vdcUrn, cloneVAppTemplateParams);
if (waitForTask) { if (waitForTask) {
Task cloneTask = Iterables.getFirst(clonedVappTemplate.getTasks(), null); Task cloneTask = Iterables.getFirst(clonedVappTemplate.getTasks(), null);

View File

@ -83,7 +83,7 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Vdc expected = getVdc(); Vdc expected = getVdc();
assertEquals(api.getVdcApi().getVdc(vdcURI), expected); assertEquals(api.getVdcApi().get(vdcURI), expected);
} }
@Test @Test
@ -105,7 +105,7 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build(); .build();
try { try {
api.getVdcApi().getVdc(URI.create(endpoint + "/vdc/NOTAUUID")); api.getVdcApi().get(URI.create(endpoint + "/vdc/NOTAUUID"));
fail("Should give HTTP 400 error"); fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected); assertEquals(vde.getError(), expected);
@ -124,7 +124,7 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/vdc/error403-fake.xml", VCloudDirectorMediaType.ERROR) .xmlFilePayload("/vdc/error403-fake.xml", VCloudDirectorMediaType.ERROR)
.httpResponseBuilder().statusCode(403).build()); .httpResponseBuilder().statusCode(403).build());
assertNull(api.getVdcApi().getVdc(URI.create(endpoint + "/vdc/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))); assertNull(api.getVdcApi().get(URI.create(endpoint + "/vdc/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")));
} }
@Test(enabled = false) @Test(enabled = false)

View File

@ -25,7 +25,6 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.U
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.util.Map; import java.util.Map;
@ -69,7 +68,7 @@ import com.google.common.collect.Iterables;
*/ */
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "VdcApiLiveTest") @Test(groups = { "live", "user" }, singleThreaded = true, testName = "VdcApiLiveTest")
public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest { public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public static final String VDC = "vdc"; public static final String VDC = "vdc";
/* /*
@ -78,7 +77,7 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
protected VdcApi vdcApi; protected VdcApi vdcApi;
protected VAppTemplateApi vappTemplateApi; protected VAppTemplateApi vappTemplateApi;
protected VAppApi vappApi; protected VAppApi vappApi;
private VApp instantiatedVApp; private VApp instantiatedVApp;
private VApp clonedVApp; private VApp clonedVApp;
private VApp composedVApp; private VApp composedVApp;
@ -87,18 +86,18 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
private VAppTemplate uploadedVAppTemplate; private VAppTemplate uploadedVAppTemplate;
private boolean metadataSet = false; private boolean metadataSet = false;
private Network network; private Network network;
@Override @Override
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setupRequiredApis() { public void setupRequiredApis() {
vdcApi = context.getApi().getVdcApi(); vdcApi = context.getApi().getVdcApi();
vappTemplateApi = context.getApi().getVAppTemplateApi(); vappTemplateApi = context.getApi().getVAppTemplateApi();
vappApi = context.getApi().getVAppApi(); vappApi = context.getApi().getVAppApi();
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC)); assertNotNull(vdcUrn, String.format(URN_REQ_LIVE, VDC));
network = lazyGetNetwork(); network = lazyGetNetwork();
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void cleanUp() throws Exception { public void cleanUp() throws Exception {
if (clonedVAppTemplate != null) { if (clonedVAppTemplate != null) {
@ -119,236 +118,218 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
if (composedVApp != null) { if (composedVApp != null) {
cleanUpVApp(composedVApp); cleanUpVApp(composedVApp);
} }
if (metadataSet) { if (metadataSet) {
try { try {
Task delete = adminContext.getApi().getVdcApi().getMetadataApi().deleteEntry(toAdminUri(vdcURI), "key"); Task delete = adminContext.getApi().getVdcApi().getMetadataApi().deleteEntry(lazyGetVdc().getHref(), "key");
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error deleting metadata entry"); logger.warn(e, "Error deleting metadata entry");
} }
} }
} }
@Test(description = "GET /vdc/{id}") @Test(description = "GET /vdc/{id}")
public void testGetVdc() { public void testGetVdc() {
Vdc vdc = vdcApi.getVdc(vdcURI); Vdc vdc = lazyGetVdc();
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC)); assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
assertTrue(!vdc.getDescription().equals("DO NOT USE"), "vDC isn't to be used for testing"); assertFalse("DO NOT USE".equals(vdc.getDescription()), "vDC isn't to be used for testing");
Checks.checkVdc(vdc); Checks.checkVdc(vdc);
} }
@Test(description = "POST /vdc/{id}/action/captureVApp", dependsOnMethods = { "testInstantiateVAppTemplate" } ) @Test(description = "POST /vdc/{id}/action/captureVApp", dependsOnMethods = { "testInstantiateVAppTemplate" })
public void testCaptureVApp() { public void testCaptureVApp() {
String name = name("captured-"); String name = name("captured-");
CaptureVAppParams captureVappParams = CaptureVAppParams.builder() CaptureVAppParams captureVappParams = CaptureVAppParams.builder().name(name).source(instantiatedVApp.getHref())
.name(name) // TODO: test optional params
.source(instantiatedVApp.getHref()) // .description("")
// TODO: test optional params // .sections(sections) // TODO: ovf sections
//.description("")
//.sections(sections) // TODO: ovf sections
.build(); .build();
capturedVAppTemplate = vdcApi.captureVApp(vdcURI, captureVappParams); capturedVAppTemplate = vdcApi.captureVApp(vdcUrn, captureVappParams);
Task task = Iterables.getFirst(capturedVAppTemplate.getTasks(), null); Task task = Iterables.getFirst(capturedVAppTemplate.getTasks(), null);
assertTaskSucceedsLong(task); assertTaskSucceedsLong(task);
Checks.checkVAppTemplate(capturedVAppTemplate); Checks.checkVAppTemplate(capturedVAppTemplate);
assertEquals(capturedVAppTemplate.getName(), name, assertEquals(capturedVAppTemplate.getName(), name,
String.format(OBJ_FIELD_EQ, "VAppTemplate", "name", name, capturedVAppTemplate.getName())); String.format(OBJ_FIELD_EQ, "VAppTemplate", "name", name, capturedVAppTemplate.getName()));
} }
@Test(description = "POST /vdc/{id}/action/cloneVApp", dependsOnMethods = { "testInstantiateVAppTemplate" } ) @Test(description = "POST /vdc/{id}/action/cloneVApp", dependsOnMethods = { "testInstantiateVAppTemplate" })
public void testCloneVApp() { public void testCloneVApp() {
CloneVAppParams cloneVappParams = CloneVAppParams.builder() CloneVAppParams cloneVappParams = CloneVAppParams.builder().source(instantiatedVApp.getHref())
.source(instantiatedVApp.getHref()) // TODO: test optional params
// TODO: test optional params // .name("")
//.name("") // .description("")
//.description("") // .deploy(true)
//.deploy(true) // .isSourceDelete(true)
//.isSourceDelete(true) // .powerOn(true)
//.powerOn(true) // .instantiationParams(InstantiationParams.builder()
//.instantiationParams(InstantiationParams.builder() // .sections(sections) // TODO: ovf sections? various tests?
// .sections(sections) // TODO: ovf sections? various tests? // .build())
// .build())
// Reserved. Unimplemented params; may test eventually when implemented // Reserved. Unimplemented params; may test eventually when implemented
//.vAppParent(vAppParentRef) // .vAppParent(vAppParentRef)
//.linkedClone(true) // .linkedClone(true)
.build(); .build();
clonedVApp = vdcApi.cloneVApp(vdcURI, cloneVappParams); clonedVApp = vdcApi.cloneVApp(vdcUrn, cloneVappParams);
Task task = Iterables.getFirst(clonedVApp.getTasks(), null); Task task = Iterables.getFirst(clonedVApp.getTasks(), null);
assertNotNull(task, "vdcApi.cloneVApp returned VApp that did not contain any tasks"); assertNotNull(task, "vdcApi.cloneVApp returned VApp that did not contain any tasks");
assertTaskSucceedsLong(task); assertTaskSucceedsLong(task);
Checks.checkVApp(clonedVApp); Checks.checkVApp(clonedVApp);
} }
@Test(description = "POST /vdc/{id}/action/cloneVAppTemplate") @Test(description = "POST /vdc/{id}/action/cloneVAppTemplate")
public void testCloneVAppTemplate() { public void testCloneVAppTemplate() {
clonedVAppTemplate = vdcApi.cloneVAppTemplate(vdcURI, CloneVAppTemplateParams.builder() clonedVAppTemplate = vdcApi.cloneVAppTemplate(vdcUrn, CloneVAppTemplateParams.builder().source(vAppTemplateURI)
.source(vAppTemplateURI)
.build()); .build());
Task task = Iterables.getFirst(clonedVAppTemplate.getTasks(), null); Task task = Iterables.getFirst(clonedVAppTemplate.getTasks(), null);
assertNotNull(task, "vdcApi.cloneVAppTemplate returned VAppTemplate that did not contain any tasks"); assertNotNull(task, "vdcApi.cloneVAppTemplate returned VAppTemplate that did not contain any tasks");
assertTaskSucceedsLong(task); assertTaskSucceedsLong(task);
Checks.checkVAppTemplate(clonedVAppTemplate); Checks.checkVAppTemplate(clonedVAppTemplate);
} }
@Test(description = "POST /vdc/{id}/action/composeVApp") @Test(description = "POST /vdc/{id}/action/composeVApp")
public void testComposeVApp() { public void testComposeVApp() {
String name = name("composed-"); String name = name("composed-");
composedVApp = vdcApi.composeVApp(vdcURI, ComposeVAppParams.builder()
.name(name)
// TODO: test optional params
//.sourcedItem(SourcedCompositionItemParam.builder()
//.sourcedItem(vAppTemplateURI)
//.build())
//.description("")
//.deploy(true)
//.isSourceDelete(false)
//.powerOn(true)
//.instantiationParams(InstantiationParams.builder()
// .sections(sections) // TODO: ovf sections? various tests?
// .build())
// Reserved. Unimplemented params; may test eventually when implemented composedVApp = vdcApi.composeVApp(vdcUrn, ComposeVAppParams.builder().name(name)
//.linkedClone() // TODO: test optional params
.build()); // .sourcedItem(SourcedCompositionItemParam.builder()
// .sourcedItem(vAppTemplateURI)
// .build())
// .description("")
// .deploy(true)
// .isSourceDelete(false)
// .powerOn(true)
// .instantiationParams(InstantiationParams.builder()
// .sections(sections) // TODO: ovf sections? various tests?
// .build())
// Reserved. Unimplemented params; may test eventually when implemented
// .linkedClone()
.build());
Task task = Iterables.getFirst(composedVApp.getTasks(), null); Task task = Iterables.getFirst(composedVApp.getTasks(), null);
assertNotNull(task, "vdcApi.composeVApp returned VApp that did not contain any tasks"); assertNotNull(task, "vdcApi.composeVApp returned VApp that did not contain any tasks");
assertTaskSucceedsLong(task); assertTaskSucceedsLong(task);
Checks.checkVApp(composedVApp); Checks.checkVApp(composedVApp);
assertEquals(composedVApp.getName(), name, assertEquals(composedVApp.getName(), name,
String.format(OBJ_FIELD_EQ, "VApp", "name", name, composedVApp.getName())); String.format(OBJ_FIELD_EQ, "VApp", "name", name, composedVApp.getName()));
} }
// TODO Duplicates code in VAppApiLiveTest // TODO Duplicates code in VAppApiLiveTest
@Test(description = "POST /vdc/{id}/action/instantiateVAppTemplate") @Test(description = "POST /vdc/{id}/action/instantiateVAppTemplate")
public void testInstantiateVAppTemplate() { public void testInstantiateVAppTemplate() {
Vdc vdc = vdcApi.getVdc(vdcURI); Vdc vdc = vdcApi.get(vdcUrn);
Set<Reference> networks = vdc.getAvailableNetworks(); Set<Reference> networks = vdc.getAvailableNetworks();
Optional<Reference> parentNetwork = Iterables.tryFind( Optional<Reference> parentNetwork = Iterables.tryFind(networks, new Predicate<Reference>() {
networks, new Predicate<Reference>() { @Override
@Override public boolean apply(Reference reference) {
public boolean apply(Reference reference) { return reference.getHref().equals(network.getHref());
return reference.getHref().equals(network.getHref()); }
} });
});
if (!parentNetwork.isPresent()) { if (!parentNetwork.isPresent()) {
fail(String.format("Could not find network %s in vdc", network.getHref().toASCIIString())); fail(String.format("Could not find network %s in vdc", network.getHref().toASCIIString()));
} }
NetworkConfiguration networkConfiguration = NetworkConfiguration.builder() NetworkConfiguration networkConfiguration = NetworkConfiguration.builder().parentNetwork(parentNetwork.get())
.parentNetwork(parentNetwork.get()) .fenceMode(FenceMode.BRIDGED).build();
.fenceMode(FenceMode.BRIDGED)
.build(); NetworkConfigSection networkConfigSection = NetworkConfigSection
.builder()
NetworkConfigSection networkConfigSection = NetworkConfigSection.builder()
.info("Configuration parameters for logical networks") .info("Configuration parameters for logical networks")
.networkConfigs( .networkConfigs(
ImmutableSet.of(VAppNetworkConfiguration.builder() ImmutableSet.of(VAppNetworkConfiguration.builder().networkName("vAppNetwork")
.networkName("vAppNetwork") .configuration(networkConfiguration).build())).build();
.configuration(networkConfiguration)
.build()))
.build();
InstantiationParams instantiationParams = InstantiationParams.builder() InstantiationParams instantiationParams = InstantiationParams.builder()
.sections(ImmutableSet.of(networkConfigSection)) .sections(ImmutableSet.of(networkConfigSection)).build();
.build();
InstantiateVAppTemplateParams instantiate = InstantiateVAppTemplateParams.builder()
.name(name("test-vapp-"))
.notDeploy()
.notPowerOn()
.description("Test VApp")
.instantiationParams(instantiationParams)
.source(vAppTemplateURI)
.build();
instantiatedVApp = vdcApi.instantiateVApp(vdcURI, instantiate); InstantiateVAppTemplateParams instantiate = InstantiateVAppTemplateParams.builder().name(name("test-vapp-"))
.notDeploy().notPowerOn().description("Test VApp").instantiationParams(instantiationParams)
.source(vAppTemplateURI).build();
instantiatedVApp = vdcApi.instantiateVApp(vdcUrn, instantiate);
Task instantiationTask = Iterables.getFirst(instantiatedVApp.getTasks(), null); Task instantiationTask = Iterables.getFirst(instantiatedVApp.getTasks(), null);
assertTaskSucceedsLong(instantiationTask); assertTaskSucceedsLong(instantiationTask);
Checks.checkVApp(instantiatedVApp); Checks.checkVApp(instantiatedVApp);
} }
@Test(description = "POST /vdc/{id}/action/uploadVAppTemplate") @Test(description = "POST /vdc/{id}/action/uploadVAppTemplate")
public void testUploadVAppTemplate() { public void testUploadVAppTemplate() {
// TODO Should test all 4 stages of upload; currently doing only stage 1 here. // TODO Should test all 4 stages of upload; currently doing only stage 1 here.
// 1. creating empty vApp template entity // 1. creating empty vApp template entity
// 2. uploading an OVF of vApp template // 2. uploading an OVF of vApp template
// 3. uploading disks described from the OVF // 3. uploading disks described from the OVF
// 4. finishing task for uploading // 4. finishing task for uploading
String name = name("uploaded-"); String name = name("uploaded-");
UploadVAppTemplateParams uploadVAppTemplateParams = UploadVAppTemplateParams.builder() UploadVAppTemplateParams uploadVAppTemplateParams = UploadVAppTemplateParams.builder().name(name)
.name(name) // TODO: test optional params
// TODO: test optional params // .description("")
//.description("") // .transferFormat("")
//.transferFormat("") // .manifestRequired(true)
//.manifestRequired(true)
.build(); .build();
uploadedVAppTemplate = vdcApi.uploadVAppTemplate(vdcURI, uploadVAppTemplateParams); uploadedVAppTemplate = vdcApi.uploadVAppTemplate(vdcUrn, uploadVAppTemplateParams);
Checks.checkVAppTemplateWhenNotReady(uploadedVAppTemplate); Checks.checkVAppTemplateWhenNotReady(uploadedVAppTemplate);
assertEquals(uploadedVAppTemplate.getName(), name, assertEquals(uploadedVAppTemplate.getName(), name,
String.format(OBJ_FIELD_EQ, "VAppTemplate", "name", name, uploadedVAppTemplate.getName())); String.format(OBJ_FIELD_EQ, "VAppTemplate", "name", name, uploadedVAppTemplate.getName()));
ResourceEntity.Status expectedStatus = ResourceEntity.Status.UNRESOLVED; ResourceEntity.Status expectedStatus = ResourceEntity.Status.UNRESOLVED;
ResourceEntity.Status actualStatus = uploadedVAppTemplate.getStatus(); ResourceEntity.Status actualStatus = uploadedVAppTemplate.getStatus();
assertEquals(actualStatus, expectedStatus, assertEquals(actualStatus, expectedStatus,
String.format(OBJ_FIELD_EQ, "VAppTemplate", "status", expectedStatus, actualStatus)); String.format(OBJ_FIELD_EQ, "VAppTemplate", "status", expectedStatus, actualStatus));
} }
private void setupMetadata() { private void setupMetadata() {
adminContext.getApi().getVdcApi().getMetadataApi().putEntry(toAdminUri(vdcURI), adminContext.getApi().getVdcApi().getMetadataApi()
"key", MetadataValue.builder().value("value").build()); .putEntry(lazyGetVdc().getHref(), "key", MetadataValue.builder().value("value").build());
metadataSet = true; metadataSet = true;
} }
@Test(description = "GET /vdc/{id}/metadata", dependsOnMethods = { "testGetVdc" } ) @Test(description = "GET /vdc/{id}/metadata", dependsOnMethods = { "testGetVdc" })
public void testGetMetadata() { public void testGetMetadata() {
if(adminContext != null) { if (adminContext != null) {
setupMetadata(); setupMetadata();
} }
Metadata metadata = vdcApi.getMetadataApi().get(vdcURI); Metadata metadata = vdcApi.getMetadataApi().get(lazyGetVdc().getHref());
// required for testing // required for testing
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
String.format(OBJ_FIELD_REQ_LIVE, VDC, "metadata.entries")); String.format(OBJ_FIELD_REQ_LIVE, VDC, "metadata.entries"));
Checks.checkMetadataFor(VDC, metadata); Checks.checkMetadataFor(VDC, metadata);
} }
@Test(description = "GET /vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" } ) @Test(description = "GET /vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
// First find a key // First find a key
Metadata metadata = vdcApi.getMetadataApi().get(vdcURI); Metadata metadata = vdcApi.getMetadataApi().get(lazyGetVdc().getHref());
Map<String, String> metadataMap = Checks.metadataToMap(metadata); Map<String, String> metadataMap = Checks.metadataToMap(metadata);
String key = Iterables.getFirst(metadataMap.keySet(), "MadeUpKey!"); String key = Iterables.getFirst(metadataMap.keySet(), "MadeUpKey!");
String value = metadataMap.get(key); String value = metadataMap.get(key);
MetadataValue metadataValue = vdcApi.getMetadataApi().getValue(vdcURI, key); MetadataValue metadataValue = vdcApi.getMetadataApi().getValue(lazyGetVdc().getHref(), key);
Checks.checkMetadataValueFor(VDC, metadataValue, value); Checks.checkMetadataValueFor(VDC, metadataValue, value);
} }
} }

View File

@ -122,7 +122,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
protected void setupRequiredEntities() { protected void setupRequiredEntities() {
Set<Link> links = vdcApi.getVdc(vdcURI).getLinks(); Set<Link> links = vdcApi.get(vdcUrn).getLinks();
if (mediaURI == null) { if (mediaURI == null) {
Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA)); Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA));

View File

@ -56,7 +56,7 @@ public class AdminVdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
AdminVdc expected = adminVdc(); AdminVdc expected = adminVdc();
assertEquals(api.getVdcApi().getVdc(vdcRef.getHref()), expected); assertEquals(api.getVdcApi().get(vdcRef.getHref()), expected);
} }
public static final AdminVdc adminVdc() { public static final AdminVdc adminVdc() {

View File

@ -19,13 +19,10 @@
package org.jclouds.vcloud.director.v1_5.features.admin; package org.jclouds.vcloud.director.v1_5.features.admin;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.AdminVdc; import org.jclouds.vcloud.director.v1_5.domain.AdminVdc;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
@ -47,34 +44,30 @@ import org.testng.annotations.Test;
*/ */
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "AdminVdcApiLiveTest") @Test(groups = { "live", "admin" }, singleThreaded = true, testName = "AdminVdcApiLiveTest")
public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest { public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public static final String VDC = "admin vdc"; public static final String VDC = "admin vdc";
/* /*
* Convenience reference to API api. * Convenience reference to API api.
*/ */
protected AdminVdcApi vdcApi; protected AdminVdcApi vdcApi;
protected MetadataApi.Writeable metadataApi; protected MetadataApi.Writeable metadataApi;
protected URI adminVdcUri;
private String metadataKey; private String metadataKey;
private String metadataValue; private String metadataValue;
@Override @Override
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setupRequiredApis() { public void setupRequiredApis() {
vdcApi = adminContext.getApi().getVdcApi(); vdcApi = adminContext.getApi().getVdcApi();
metadataApi = vdcApi.getMetadataApi(); metadataApi = vdcApi.getMetadataApi();
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC));
adminVdcUri = toAdminUri(vdcURI);
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void cleanUp() throws Exception { public void cleanUp() throws Exception {
if (metadataKey != null) { if (metadataKey != null) {
try { try {
Task task = metadataApi.deleteEntry(adminVdcUri, metadataKey); Task task = metadataApi.deleteEntry(lazyGetVdc().getHref(), metadataKey);
taskDoneEventually(task); taskDoneEventually(task);
} catch (VCloudDirectorException e) { } catch (VCloudDirectorException e) {
logger.warn(e, "Error deleting metadata-value (perhaps it doesn't exist?); continuing..."); logger.warn(e, "Error deleting metadata-value (perhaps it doesn't exist?); continuing...");
@ -84,31 +77,29 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /admin/vdc/{id}") @Test(description = "GET /admin/vdc/{id}")
public void testGetVdc() { public void testGetVdc() {
AdminVdc vdc = vdcApi.getVdc(adminVdcUri); AdminVdc vdc = vdcApi.get(vdcUrn);
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC)); assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
// parent type // parent type
Checks.checkAdminVdc(vdc); Checks.checkAdminVdc(vdc);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "PUT /admin/vdc/{id}", enabled=false) @Test(description = "PUT /admin/vdc/{id}", enabled = false)
public void testEditVdc() throws Exception { public void testEditVdc() throws Exception {
String origName = vdcApi.getVdc(adminVdcUri).getName(); String origName = lazyGetVdc().getName();
String newName = name("a"); String newName = name("a");
Exception exception = null; Exception exception = null;
AdminVdc vdc = AdminVdc.builder() AdminVdc vdc = AdminVdc.builder().name(newName).build();
.name(newName)
.build();
try { try {
Task task = vdcApi.editVdc(adminVdcUri, vdc); Task task = vdcApi.update(vdcUrn, vdc);
assertTaskSucceeds(task); assertTaskSucceeds(task);
AdminVdc modified = vdcApi.getVdc(adminVdcUri); AdminVdc modified = vdcApi.get(vdcUrn);
assertEquals(modified.getName(), newName); assertEquals(modified.getName(), newName);
// parent type // parent type
Checks.checkAdminVdc(vdc); Checks.checkAdminVdc(vdc);
} catch (Exception e) { } catch (Exception e) {
@ -116,7 +107,7 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} finally { } finally {
try { try {
AdminVdc restorableVdc = AdminVdc.builder().name(origName).build(); AdminVdc restorableVdc = AdminVdc.builder().name(origName).build();
Task task = vdcApi.editVdc(adminVdcUri, restorableVdc); Task task = vdcApi.update(vdcUrn, restorableVdc);
assertTaskSucceeds(task); assertTaskSucceeds(task);
} catch (Exception e) { } catch (Exception e) {
if (exception != null) { if (exception != null) {
@ -128,34 +119,35 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
} }
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "DELETE /admin/vdc/{id}", enabled=false) @Test(description = "DELETE /admin/vdc/{id}", enabled = false)
public void testDeleteVdc() throws Exception { public void testDeleteVdc() throws Exception {
// TODO Need to have a VDC that we're happy to delete! // TODO Need to have a VDC that we're happy to delete!
Task task = vdcApi.deleteVdc(adminVdcUri); Task task = vdcApi.delete(vdcUrn);
assertTaskSucceeds(task); assertTaskSucceeds(task);
try { try {
vdcApi.getVdc(adminVdcUri); vdcApi.get(vdcUrn);
} catch (VCloudDirectorException e) { } catch (VCloudDirectorException e) {
// success; unreachable because it has been deleted // success; unreachable because it has been deleted
// TODO: ^^ wrong. this should return null
} }
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "DISABLE/ENABLE /admin/vdc/{id}", enabled=false) @Test(description = "DISABLE/ENABLE /admin/vdc/{id}", enabled = false)
public void testDisableAndEnableVdc() throws Exception { public void testDisableAndEnableVdc() throws Exception {
// TODO Need to have a VDC that we're happy to delete! // TODO Need to have a VDC that we're happy to delete!
Exception exception = null; Exception exception = null;
try { try {
vdcApi.disableVdc(adminVdcUri); vdcApi.disable(vdcUrn);
} catch (Exception e) { } catch (Exception e) {
exception = e; exception = e;
} finally { } finally {
try { try {
vdcApi.enableVdc(adminVdcUri); vdcApi.enable(vdcUrn);
} catch (Exception e) { } catch (Exception e) {
if (exception != null) { if (exception != null) {
logger.warn(e, "Error resetting adminVdc.name; rethrowing original test exception..."); logger.warn(e, "Error resetting adminVdc.name; rethrowing original test exception...");
@ -166,63 +158,62 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
} }
} }
@Test(description = "GET /admin/vdc/{id}/metadata") @Test(description = "GET /admin/vdc/{id}/metadata")
public void testGetMetadata() throws Exception { public void testGetMetadata() throws Exception {
Metadata metadata = metadataApi.get(adminVdcUri); Metadata metadata = metadataApi.get(lazyGetVdc().getHref());
Checks.checkMetadata(metadata); Checks.checkMetadata(metadata);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "PUT /admin/vdc/{id}/metadata", enabled=false) @Test(description = "PUT /admin/vdc/{id}/metadata", enabled = false)
public void testSetMetadata() throws Exception { public void testSetMetadata() throws Exception {
metadataKey = name("key-"); metadataKey = name("key-");
metadataValue = name("value-"); metadataValue = name("value-");
Metadata metadata = Metadata.builder() Metadata metadata = Metadata.builder().entry(MetadataEntry.builder().entry(metadataKey, metadataValue).build())
.entry(MetadataEntry.builder().entry(metadataKey, metadataValue).build())
.build(); .build();
Task task = metadataApi.merge(adminVdcUri, metadata); Task task = metadataApi.merge(lazyGetVdc().getHref(), metadata);
assertTaskSucceeds(task); assertTaskSucceeds(task);
MetadataValue modified = metadataApi.getValue(adminVdcUri, metadataKey); MetadataValue modified = metadataApi.getValue(lazyGetVdc().getHref(), metadataKey);
Checks.checkMetadataValueFor("AdminVdc", modified, metadataValue); Checks.checkMetadataValueFor("AdminVdc", modified, metadataValue);
Checks.checkMetadata(metadata); Checks.checkMetadata(metadata);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "GET /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadata" }, enabled=false) @Test(description = "GET /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadata" }, enabled = false)
public void testGetMetadataValue() throws Exception { public void testGetMetadataValue() throws Exception {
MetadataValue retrievedMetadataValue = metadataApi.getValue(adminVdcUri, metadataKey); MetadataValue retrievedMetadataValue = metadataApi.getValue(lazyGetVdc().getHref(), metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue); Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "PUT /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" }, enabled=false ) @Test(description = "PUT /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" }, enabled = false)
public void testSetMetadataValue() throws Exception { public void testSetMetadataValue() throws Exception {
metadataValue = name("value-"); metadataValue = name("value-");
MetadataValue newV = MetadataValue.builder().value(metadataValue).build(); MetadataValue newV = MetadataValue.builder().value(metadataValue).build();
Task task = metadataApi.putEntry(adminVdcUri, metadataKey, newV); Task task = metadataApi.putEntry(lazyGetVdc().getHref(), metadataKey, newV);
assertTaskSucceeds(task); assertTaskSucceeds(task);
MetadataValue retrievedMetadataValue = metadataApi.getValue(adminVdcUri, metadataKey); MetadataValue retrievedMetadataValue = metadataApi.getValue(lazyGetVdc().getHref(), metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue); Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "DELETE /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }, enabled=false ) @Test(description = "DELETE /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }, enabled = false)
public void testDeleteMetadataValue() throws Exception { public void testDeleteMetadataValue() throws Exception {
// TODO Remove dependency on other tests; make cleanUp delete a list of metadata entries? // TODO Remove dependency on other tests; make cleanUp delete a list of metadata entries?
Task task = metadataApi.deleteEntry(adminVdcUri, metadataKey); Task task = metadataApi.deleteEntry(lazyGetVdc().getHref(), metadataKey);
assertTaskSucceeds(task); assertTaskSucceeds(task);
try { try {
metadataApi.getValue(adminVdcUri, metadataKey); metadataApi.getValue(lazyGetVdc().getHref(), metadataKey);
fail("Retrieval of metadata value "+metadataKey+" should have fail after deletion"); fail("Retrieval of metadata value " + metadataKey + " should have fail after deletion");
} catch (VCloudDirectorException e) { } catch (VCloudDirectorException e) {
// success; should not be accessible // success; should not be accessible
} }

View File

@ -19,12 +19,10 @@
package org.jclouds.vcloud.director.v1_5.internal; package org.jclouds.vcloud.director.v1_5.internal;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.FluentIterable.from; import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Iterables.any; import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.getFirst; import static com.google.common.collect.Iterables.getFirst;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.tryFind; import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.io.Closeables.closeQuietly; import static com.google.common.io.Closeables.closeQuietly;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_NON_NULL; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_NON_NULL;
@ -33,6 +31,9 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.U
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NETWORK; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG_NETWORK; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG_NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.USER;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VAPP;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VDC;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
@ -58,6 +59,7 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext; import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status; import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
@ -97,7 +99,6 @@ import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -120,9 +121,6 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
protected static final long TASK_TIMEOUT_SECONDS = 100L; protected static final long TASK_TIMEOUT_SECONDS = 100L;
protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L; protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L;
public static final String VAPP = "vApp";
public static final String VAPP_TEMPLATE = "vAppTemplate";
public static final String VDC = "vdc";
public static final int REQUIRED_ADMIN_VM_QUOTA = 0; public static final int REQUIRED_ADMIN_VM_QUOTA = 0;
public static final int REQUIRED_USER_VM_QUOTA = 0; public static final int REQUIRED_USER_VM_QUOTA = 0;
@ -135,11 +133,13 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
protected Session session; protected Session session;
protected String catalogUrn; protected String catalogUrn;
private Catalog catalog;
protected URI vAppTemplateURI; protected URI vAppTemplateURI;
protected URI mediaURI; protected URI mediaURI;
protected String networkUrn; protected String networkUrn;
private Network network; private Network network;
protected URI vdcURI; protected String vdcUrn;
private Vdc vdc;
protected String userUrn; protected String userUrn;
private User user; private User user;
@ -255,9 +255,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
if (vAppTemplateId != null) if (vAppTemplateId != null)
vAppTemplateURI = URI.create(endpoint + "/vAppTemplate/" + vAppTemplateId); vAppTemplateURI = URI.create(endpoint + "/vAppTemplate/" + vAppTemplateId);
String vdcId = emptyToNull(System.getProperty("test." + provider + ".vdc-id")); vdcUrn = emptyToNull(System.getProperty("test." + provider + ".vdc-id"));
if (vdcId != null)
vdcURI = URI.create(endpoint + "/vdc/" + vdcId);
String mediaId = emptyToNull(System.getProperty("test." + provider + ".media-id")); String mediaId = emptyToNull(System.getProperty("test." + provider + ".media-id"));
if (mediaId != null) if (mediaId != null)
@ -271,11 +269,13 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
find(context.getApi().getOrgApi().list(), find(context.getApi().getOrgApi().list(),
ReferencePredicates.<Reference> nameEquals(session.get())).getHref()); ReferencePredicates.<Reference> nameEquals(session.get())).getHref());
if (any(Lists.newArrayList(vAppTemplateURI, networkUrn, vdcURI), Predicates.isNull())) { if (any(Lists.newArrayList(vAppTemplateURI, networkUrn, vdcUrn), Predicates.isNull())) {
if (vdcURI == null) if (vdcUrn == null) {
vdcURI = find(org.getLinks(), vdc = context.getApi().getVdcApi().get(find(org.getLinks(),
ReferencePredicates.<Link> typeEquals(VDC)).getHref(); ReferencePredicates.<Link> typeEquals(VDC)).getHref());
vdcUrn = vdc.getId();
}
if (networkUrn == null) { if (networkUrn == null) {
network = context.getApi().getNetworkApi().get(find(org.getLinks(), network = context.getApi().getNetworkApi().get(find(org.getLinks(),
@ -283,14 +283,29 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
networkUrn = network.getId(); networkUrn = network.getId();
} }
// FIXME the URI should be opaque if (catalogUrn == null) {
if (isNullOrEmpty(catalogUrn)) { catalog = context.getApi().getCatalogApi().get(find(org.getLinks(),
String uri = find(org.getLinks(), ReferencePredicates.<Link> typeEquals(CATALOG)).getHref());
ReferencePredicates.<Link> typeEquals(CATALOG)).getHref().toASCIIString(); catalogUrn = catalog.getId();
catalogUrn = getLast(Splitter.on('/').split(uri));
} }
} }
} }
protected Vdc lazyGetVdc() {
if (vdc == null) {
assertNotNull(vdcUrn, String.format(URN_REQ_LIVE, VDC));
vdc = from(org.getLinks()).filter(LinkPredicates.typeEquals(VDC))
.transform(new Function<Link, Vdc>() {
@Override
public Vdc apply(Link in) {
return context.getApi().getVdcApi().get(in.getHref());
}
}).firstMatch(EntityPredicates.idEquals(vdcUrn)).get();
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
}
return vdc;
}
protected Network lazyGetNetwork() { protected Network lazyGetNetwork() {
if (network == null) { if (network == null) {
@ -303,21 +318,42 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
return context.getApi().getNetworkApi().get(in.getHref()); return context.getApi().getNetworkApi().get(in.getHref());
} }
}).firstMatch(EntityPredicates.idEquals(networkUrn)).get(); }).firstMatch(EntityPredicates.idEquals(networkUrn)).get();
assertNotNull(network, String.format(ENTITY_NON_NULL, NETWORK));
} }
return network; return network;
} }
protected Catalog lazyGetCatalog() {
if (catalog == null) {
assertNotNull(catalogUrn, String.format(URN_REQ_LIVE, CATALOG));
catalog = from(org.getLinks()).filter(LinkPredicates.typeEquals(CATALOG))
.transform(new Function<Link, Catalog>() {
@Override
public Catalog apply(Link in) {
return context.getApi().getCatalogApi().get(in.getHref());
}
}).firstMatch(EntityPredicates.idEquals(catalogUrn)).get();
assertNotNull(catalog, String.format(ENTITY_NON_NULL, CATALOG));
}
return catalog;
}
protected User lazyGetUser() { protected User lazyGetUser() {
if (user == null) { if (user == null) {
assertNotNull(userUrn, String.format(URN_REQ_LIVE, USER));
user = adminContext.getApi().getUserApi().get(userUrn); user = adminContext.getApi().getUserApi().get(userUrn);
assertNotNull(user, String.format(ENTITY_NON_NULL, USER));
} }
return user; return user;
} }
@Deprecated
public URI toAdminUri(Reference ref) { public URI toAdminUri(Reference ref) {
return toAdminUri(ref.getHref()); return toAdminUri(ref.getHref());
} }
@Deprecated
public URI toAdminUri(URI uri) { public URI toAdminUri(URI uri) {
return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref(); return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref();
} }
@ -377,7 +413,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
.build(); .build();
VdcApi vdcApi = context.getApi().getVdcApi(); VdcApi vdcApi = context.getApi().getVdcApi();
VApp vAppInstantiated = vdcApi.instantiateVApp(vdcURI, instantiate); VApp vAppInstantiated = vdcApi.instantiateVApp(vdcUrn, instantiate);
assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP)); assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP));
Task instantiationTask = getFirst(vAppInstantiated.getTasks(), null); Task instantiationTask = getFirst(vAppInstantiated.getTasks(), null);
@ -415,7 +451,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
/** Build a {@link NetworkConfiguration} object. */ /** Build a {@link NetworkConfiguration} object. */
private NetworkConfiguration networkConfiguration() { private NetworkConfiguration networkConfiguration() {
Vdc vdc = context.getApi().getVdcApi().getVdc(vdcURI); Vdc vdc = context.getApi().getVdcApi().get(vdcUrn);
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC)); assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
Set<Reference> networks = vdc.getAvailableNetworks(); Set<Reference> networks = vdc.getAvailableNetworks();