refactored Metadata to implement Immutable Map<String, String>; addGroupToOrg GroupApi, MediaApi to use urn

This commit is contained in:
Adrian Cole 2012-08-19 21:48:04 -07:00
parent e016367280
commit aff96befbe
26 changed files with 397 additions and 381 deletions

View File

@ -42,6 +42,7 @@
<test.vcloud-director.template></test.vcloud-director.template> <test.vcloud-director.template></test.vcloud-director.template>
<!-- URN format: ex. urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4 --> <!-- URN format: ex. urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.catalog-id></test.vcloud-director.catalog-id> <test.vcloud-director.catalog-id></test.vcloud-director.catalog-id>
<!-- URN format: ex. urn:vcloud:media:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.media-id></test.vcloud-director.media-id> <test.vcloud-director.media-id></test.vcloud-director.media-id>
<!-- URN format: ex. urn:vcloud:vapptemplate:7212e451-76e1-4631-b2de-ba1dfd8080e4 --> <!-- URN format: ex. urn:vcloud:vapptemplate:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id> <test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id>

View File

@ -21,7 +21,8 @@ package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections; import java.util.Collection;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@ -31,20 +32,22 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
* Represents a set of metadata * Represents a set of metadata
* <p/> * <p/>
*
* <pre> * <pre>
* &lt;xs:complexType name="Metadata"&gt; * &lt;xs:complexType name="Metadata"&gt;
* </pre> * </pre>
* *
* @author danikov * @author danikov
*/ */
@XmlRootElement(name = "Metadata") @XmlRootElement(name = "Metadata")
public class Metadata extends Resource { public class Metadata extends Resource implements Map<String, String> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA; public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA;
@ -59,7 +62,7 @@ public class Metadata extends Resource {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
} }
public static abstract class Builder<B extends Builder<B>> extends Resource.Builder<B> { public static abstract class Builder<B extends Builder<B>> extends Resource.Builder<B> {
private Set<MetadataEntry> metadataEntries = Sets.newLinkedHashSet(); private Set<MetadataEntry> metadataEntries = Sets.newLinkedHashSet();
@ -99,12 +102,19 @@ public class Metadata extends Resource {
this.metadataEntries = ImmutableSet.copyOf(builder.metadataEntries); this.metadataEntries = ImmutableSet.copyOf(builder.metadataEntries);
} }
@XmlElement(name = "MetadataEntry") @XmlElement(name = "MetadataEntry")
private Set<MetadataEntry> metadataEntries = Sets.newLinkedHashSet(); private Set<MetadataEntry> metadataEntries = Sets.newLinkedHashSet();
public Set<MetadataEntry> getMetadataEntries() { public Set<MetadataEntry> getMetadataEntries() {
return Collections.unmodifiableSet(metadataEntries); return ImmutableSet.copyOf(metadataEntries);
}
protected Map<String, String> toMap() {
ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder();
for (MetadataEntry entry : metadataEntries) {
builder.put(entry.getKey(), entry.getValue());
}
return builder.build();
} }
@Override @Override
@ -127,4 +137,64 @@ public class Metadata extends Resource {
return super.string().add("metadataEntries", metadataEntries); return super.string().add("metadataEntries", metadataEntries);
} }
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public boolean containsKey(Object arg0) {
return toMap().containsKey(arg0);
}
@Override
public boolean containsValue(Object arg0) {
return toMap().containsValue(arg0);
}
@Override
public Set<Map.Entry<String, String>> entrySet() {
return toMap().entrySet();
}
@Override
public String get(Object arg0) {
return toMap().get(arg0);
}
@Override
public boolean isEmpty() {
return getMetadataEntries().size() == 0;
}
@Override
public Set<String> keySet() {
return toMap().keySet();
}
@Override
public String put(String arg0, String arg1) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map<? extends String, ? extends String> arg0) {
throw new UnsupportedOperationException();
}
@Override
public String remove(Object arg0) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
return getMetadataEntries().size();
}
@Override
public Collection<String> values() {
return toMap().values();
}
} }

View File

@ -137,7 +137,7 @@ public class MetadataEntry extends Resource {
} }
private MetadataEntry() { MetadataEntry() {
// for JAXB // for JAXB
} }

View File

@ -131,7 +131,7 @@ public class IpScope {
} }
} }
private IpScope() { IpScope() {
// For JAXB // For JAXB
} }

View File

@ -140,7 +140,7 @@ public class NatRule {
this.vmRule = vmRule; this.vmRule = vmRule;
} }
private NatRule() { NatRule() {
// for JAXB // for JAXB
} }

View File

@ -227,7 +227,7 @@ public class NetworkConnection {
this.needsCustomization = needsCustomization; this.needsCustomization = needsCustomization;
} }
private NetworkConnection() { NetworkConnection() {
// for JAXB // for JAXB
} }

View File

@ -76,7 +76,7 @@ public class NetworkFeatures {
} }
} }
private NetworkFeatures() { NetworkFeatures() {
// for JAXB // for JAXB
} }

View File

@ -84,7 +84,7 @@ public abstract class NetworkServiceType<T extends NetworkServiceType<T>> {
return true; return true;
if (o == null || getClass() != o.getClass()) if (o == null || getClass() != o.getClass())
return false; return false;
NetworkServiceType that = NetworkServiceType.class.cast(o); NetworkServiceType<?> that = NetworkServiceType.class.cast(o);
return equal(isEnabled, that.isEnabled); return equal(isEnabled, that.isEnabled);
} }

View File

@ -147,7 +147,7 @@ public class SourcedCompositionItemParam {
this.sourceDelete = sourceDelete; this.sourceDelete = sourceDelete;
} }
private SourcedCompositionItemParam() { SourcedCompositionItemParam() {
// for JAXB // for JAXB
} }

View File

@ -61,7 +61,7 @@ public class QueryList extends ContainerType {
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
} }
private QueryList() { QueryList() {
// for JAXB // for JAXB
} }

View File

@ -168,7 +168,7 @@ public class QueryResultNetworkRecord extends QueryResultRecordType {
isBusy = builder.isBusy; isBusy = builder.isBusy;
} }
private QueryResultNetworkRecord() { QueryResultNetworkRecord() {
// for JAXB // for JAXB
} }

View File

@ -35,7 +35,7 @@ import org.jclouds.vcloud.director.v1_5.functions.href.MediaURNToHref;
* Provides synchronous access to {@link Media}. * Provides synchronous access to {@link Media}.
* *
* @see MediaAsyncApi * @see MediaAsyncApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface MediaApi { public interface MediaApi {
@ -45,44 +45,55 @@ public interface MediaApi {
* *
* @return the media or null if not found * @return the media or null if not found
*/ */
Media getMedia(URI mediaUri); Media get(String mediaUrn);
Media get(URI mediaHref);
/** /**
* 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 addMedia(URI uploadLink, Media media); Media add(URI uploadHref, Media media);
/** /**
* Clones a media into new one. * Clones a media into new one. The status of the returned media is UNRESOLVED(0) until the task
* The status of the returned media is UNRESOLVED(0) until the task for cloning finish. * for cloning finish.
* *
* @return a Media resource which will contain a task. * @return a Media resource which will contain a task. The user should monitor the contained task
* The user should monitor the contained task status in order to check when it is completed. * status in order to check when it is completed.
*/ */
Media cloneMedia(URI cloneLink, CloneMediaParams params); Media clone(String mediaUrn, CloneMediaParams params);
Media clone(URI mediaHref, CloneMediaParams params);
/** /**
* Updates the name/description of a media. * Updates the name/description of a media.
* *
* @return a task. This operation is asynchronous and the user should monitor the returned * @return a task. This operation is asynchronous and the user should monitor the returned task
* task status in order to check when it is completed. * status in order to check when it is completed.
*/ */
Task editMedia(URI mediaUri, Media media); Task edit(String mediaUrn, Media media);
Task edit(URI mediaHref, Media media);
/** /**
* Deletes a media. * Deletes a media.
*/ */
Task removeMedia(URI mediaUri); Task remove(String mediaUrn);
Task remove(URI mediaHref);
/** /**
* Retrieves an owner. * Retrieves an owner.
* *
* @return the owner or null if not found * @return the owner or null if not found
*/ */
Owner getOwner(URI mediaUri); Owner getOwner(String mediaUrn);
Owner getOwner(URI mediaHref);
/** /**
* @return synchronous access to {@link Metadata.Writeable} features * @return synchronous access to {@link Metadata.Writeable} features
*/ */
@ -90,6 +101,6 @@ public interface MediaApi {
MetadataApi.Writeable getMetadataApi(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn); MetadataApi.Writeable getMetadataApi(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn);
@Delegate @Delegate
MetadataApi.Writeable getMetadataApi(@EndpointParam URI mediaUri); MetadataApi.Writeable getMetadataApi(@EndpointParam URI mediaHref);
} }

View File

@ -49,59 +49,105 @@ import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see MediaApi * @see MediaApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface MediaAsyncApi { public interface MediaAsyncApi {
/** /**
* @see MediaApi#getMedia(URI) * @see MediaApi#get(String)
*/ */
@GET @GET
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Media> getMedia(@EndpointParam URI uri); ListenableFuture<Media> get(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn);
/** /**
* @see MediaApi#addMedia(URI, Media) * @see MediaApi#add(URI, Media)
*/ */
@POST @POST
@Consumes(VCloudDirectorMediaType.MEDIA) @Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.MEDIA) @Produces(VCloudDirectorMediaType.MEDIA)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Media> addMedia(@EndpointParam URI link, ListenableFuture<Media> add(@EndpointParam URI updateHref, @BinderParam(BindToXMLPayload.class) Media media);
@BinderParam(BindToXMLPayload.class) Media media);
/** /**
* @see MediaApi#cloneMedia(URI, CloneMediaParams) * @see MediaApi#clone(String, CloneMediaParams)
*/ */
@POST @POST
@Path("/action/cloneMedia") @Path("/action/cloneMedia")
@Consumes(VCloudDirectorMediaType.MEDIA) @Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS) @Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Media> cloneMedia(@EndpointParam URI vdcRef, ListenableFuture<Media> clone(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn,
@BinderParam(BindToXMLPayload.class) CloneMediaParams params); @BinderParam(BindToXMLPayload.class) CloneMediaParams params);
/** /**
* @see MediaApi#editMedia(URI, Media)) * @see MediaApi#editMedia(String, Media)
*/ */
@PUT @PUT
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.MEDIA) @Produces(VCloudDirectorMediaType.MEDIA)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> editMedia(@EndpointParam URI uri, @BinderParam(BindToXMLPayload.class) Media media); ListenableFuture<Task> edit(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn,
@BinderParam(BindToXMLPayload.class) Media media);
/** /**
* @see MediaApi#removeMedia(URI)) * @see MediaApi#removeMedia(String)
*/ */
@DELETE @DELETE
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> removeMedia(@EndpointParam URI uri); ListenableFuture<Task> remove(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn);
/**
* @see MediaApi#getOwner(String)
*/
@GET
@Path("/owner")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Owner> getOwner(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn);
/**
* @see MediaApi#get(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Media> get(@EndpointParam URI mediaHref);
/**
* @see MediaApi#clone(URI, CloneMediaParams)
*/
@POST
@Path("/action/cloneMedia")
@Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS)
@JAXBResponseParser
ListenableFuture<Media> clone(@EndpointParam URI mediaHref,
@BinderParam(BindToXMLPayload.class) CloneMediaParams params);
/**
* @see MediaApi#editMedia(URI, Media)
*/
@PUT
@Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.MEDIA)
@JAXBResponseParser
ListenableFuture<Task> edit(@EndpointParam URI mediaHref, @BinderParam(BindToXMLPayload.class) Media media);
/**
* @see MediaApi#removeMedia(URI)
*/
@DELETE
@Consumes(VCloudDirectorMediaType.TASK)
@JAXBResponseParser
ListenableFuture<Task> remove(@EndpointParam URI mediaHref);
/** /**
* @see MediaApi#getOwner(URI) * @see MediaApi#getOwner(URI)
*/ */
@ -110,14 +156,14 @@ public interface MediaAsyncApi {
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Owner> getOwner(@EndpointParam URI uri); ListenableFuture<Owner> getOwner(@EndpointParam URI mediaHref);
/** /**
* @return asynchronous access to {@link Metadata.Writeable} features * @return asynchronous access to {@link Metadata.Writeable} features
*/ */
@Delegate @Delegate
MetadataAsyncApi.Writeable getMetadataApi(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn); MetadataAsyncApi.Writeable getMetadataApi(@EndpointParam(parser = MediaURNToHref.class) String mediaUrn);
@Delegate @Delegate
MetadataAsyncApi.Writeable getMetadataApi(@EndpointParam URI uri); MetadataAsyncApi.Writeable getMetadataApi(@EndpointParam URI mediaHref);
} }

View File

@ -28,7 +28,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Group;
* Provides synchronous access to {@link Group} objects. * Provides synchronous access to {@link Group} objects.
* *
* @see GroupAsyncApi * @see GroupAsyncApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface GroupApi { public interface GroupApi {
@ -40,11 +40,13 @@ public interface GroupApi {
* POST /admin/org/{id}/groups * POST /admin/org/{id}/groups
* </pre> * </pre>
* *
* @param orgUri the admin org to add the group in * @param orgUrn the admin org to add the group in
* @return the addd group * @return the addd group
*/ */
Group addGroup(URI adminOrgUri, Group group); Group addGroupToOrg(Group group, String orgUrn);
Group addGroupToOrg(Group group, URI orgHref);
/** /**
* Retrieves a group. * Retrieves a group.
* *
@ -52,10 +54,12 @@ public interface GroupApi {
* GET /admin/group/{id} * GET /admin/group/{id}
* </pre> * </pre>
* *
* @param groupURI the reference for the group * @param groupString the reference for the group
* @return a group * @return a group
*/ */
Group getGroup(URI groupUri); Group get(String groupUrn);
Group get(URI groupHref);
/** /**
* Modifies a group. * Modifies a group.
@ -66,7 +70,9 @@ public interface GroupApi {
* *
* @return the edited group * @return the edited group
*/ */
Group editGroup(URI groupRef, Group group); Group edit(String groupUrn, Group group);
Group edit(URI groupHref, Group group);
/** /**
* Deletes a group. * Deletes a group.
@ -75,5 +81,8 @@ public interface GroupApi {
* DELETE /admin/group/{id} * DELETE /admin/group/{id}
* </pre> * </pre>
*/ */
void removeGroup(URI groupRef); void remove(String groupUrn);
void remove(URI groupHref);
} }

View File

@ -38,48 +38,89 @@ 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.Group; import org.jclouds.vcloud.director.v1_5.domain.Group;
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.GroupURNToHref;
import org.jclouds.vcloud.director.v1_5.functions.href.OrgURNToAdminHref;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see GroupApi * @see GroupApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface GroupAsyncApi { public interface GroupAsyncApi {
/**
* @see GroupApi#addGroupToOrg(Group, String)
*/
@POST @POST
@Path("/groups") @Path("/groups")
@Consumes(VCloudDirectorMediaType.GROUP) @Consumes(VCloudDirectorMediaType.GROUP)
@Produces(VCloudDirectorMediaType.GROUP) @Produces(VCloudDirectorMediaType.GROUP)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Group> addGroup(@EndpointParam URI adminOrgUri, ListenableFuture<Group> addGroupToOrg(@BinderParam(BindToXMLPayload.class) Group group,
@BinderParam(BindToXMLPayload.class) Group group); @EndpointParam(parser = OrgURNToAdminHref.class) String adminUrn);
/** /**
* @see GroupApi#getGroup(URI) * @see GroupApi#get(String)
*/ */
@GET @GET
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Group> getGroup(@EndpointParam URI groupUri); ListenableFuture<Group> get(@EndpointParam(parser = GroupURNToHref.class) String groupUri);
/** /**
* @see GroupApi#editGroup(URI, Group) * @see GroupApi#edit(String, Group)
*/ */
@PUT @PUT
@Consumes(VCloudDirectorMediaType.GROUP) @Consumes(VCloudDirectorMediaType.GROUP)
@Produces(VCloudDirectorMediaType.GROUP) @Produces(VCloudDirectorMediaType.GROUP)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Group> editGroup(@EndpointParam URI groupRef, ListenableFuture<Group> edit(@EndpointParam(parser = GroupURNToHref.class) String groupUrn,
@BinderParam(BindToXMLPayload.class) Group group); @BinderParam(BindToXMLPayload.class) Group group);
/** /**
* @see GroupApi#removeGroup(URI) * @see GroupApi#remove(String)
*/ */
@DELETE @DELETE
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Void> removeGroup(@EndpointParam URI groupRef); ListenableFuture<Void> remove(@EndpointParam(parser = GroupURNToHref.class) String groupUrn);
/**
* @see GroupApi#addGroupToOrg(Group, URI)
*/
@POST
@Path("/groups")
@Consumes(VCloudDirectorMediaType.GROUP)
@Produces(VCloudDirectorMediaType.GROUP)
@JAXBResponseParser
ListenableFuture<Group> addGroupToOrg(@BinderParam(BindToXMLPayload.class) Group group, @EndpointParam URI adminUrn);
/**
* @see GroupApi#get(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Group> get(@EndpointParam URI groupUri);
/**
* @see GroupApi#edit(URI, Group)
*/
@PUT
@Consumes(VCloudDirectorMediaType.GROUP)
@Produces(VCloudDirectorMediaType.GROUP)
@JAXBResponseParser
ListenableFuture<Group> edit(@EndpointParam URI groupUrn, @BinderParam(BindToXMLPayload.class) Group group);
/**
* @see GroupApi#remove(URI)
*/
@DELETE
@Consumes
@JAXBResponseParser
ListenableFuture<Void> remove(@EndpointParam URI groupUrn);
} }

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 GroupURNToHref extends URNToHref {
@Inject
public GroupURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.GROUP;
}
}

View File

@ -114,7 +114,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
if (media != null) { if (media != null) {
try { try {
Task remove = context.getApi().getMediaApi().removeMedia(media.getHref()); Task remove = context.getApi().getMediaApi().remove(media.getId());
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting media '%s'", media.getName()); logger.warn(e, "Error when deleting media '%s'", media.getName());
@ -153,7 +153,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
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)
.imageType(Media.ImageType.ISO).description("Test media generated by testAddMedia()").build(); .imageType(Media.ImageType.ISO).description("Test media generated by testAddMedia()").build();
media = context.getApi().getMediaApi().addMedia(addMedia.getHref(), sourceMedia); media = context.getApi().getMediaApi().add(addMedia.getHref(), sourceMedia);
Checks.checkMediaFor(VCloudDirectorMediaType.MEDIA, media); Checks.checkMediaFor(VCloudDirectorMediaType.MEDIA, media);

View File

@ -75,7 +75,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build(); .build();
Media expected = addMedia(); Media expected = addMedia();
assertEquals(api.getMediaApi().addMedia(uploadLink, source), expected); assertEquals(api.getMediaApi().add(uploadLink, source), expected);
} }
@Test @Test
@ -104,7 +104,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build(); .build();
Media expected = cloneMedia(); Media expected = cloneMedia();
assertEquals(api.getMediaApi().cloneMedia(vdcURI, params), expected); assertEquals(api.getMediaApi().clone(vdcURI, params), expected);
} }
@Test @Test
@ -121,7 +121,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.httpResponseBuilder().build()); .httpResponseBuilder().build());
Media expected = getMedia(); Media expected = getMedia();
assertEquals(api.getMediaApi().getMedia(mediaUri), expected); assertEquals(api.getMediaApi().get(mediaUri), expected);
} }
@Test @Test
@ -144,7 +144,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build(); .build();
try { try {
api.getMediaApi().getMedia(mediaUri); api.getMediaApi().get(mediaUri);
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);
@ -166,7 +166,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR) .xmlFilePayload("/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR)
.httpResponseBuilder().statusCode(403).build()); .httpResponseBuilder().statusCode(403).build());
assertNull(api.getMediaApi().getMedia(mediaUri)); assertNull(api.getMediaApi().get(mediaUri));
} }
@Test @Test
@ -182,7 +182,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/media/error403-fake.xml", VCloudDirectorMediaType.ERROR) .xmlFilePayload("/media/error403-fake.xml", VCloudDirectorMediaType.ERROR)
.httpResponseBuilder().statusCode(403).build()); .httpResponseBuilder().statusCode(403).build());
assertNull(api.getMediaApi().getMedia(mediaUri)); assertNull(api.getMediaApi().get(mediaUri));
} }
@Test @Test
@ -202,7 +202,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Media edit = editMedia(); Media edit = editMedia();
Task expected = editMediaTask(); Task expected = editMediaTask();
assertEquals(api.getMediaApi().editMedia(mediaUri, edit), expected); assertEquals(api.getMediaApi().edit(mediaUri, edit), expected);
} }
@Test @Test
@ -220,7 +220,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Task expected = removeMediaTask(); Task expected = removeMediaTask();
assertEquals(api.getMediaApi().removeMedia(mediaUri), expected); assertEquals(api.getMediaApi().remove(mediaUri), expected);
} }
@Test @Test

View File

@ -109,7 +109,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
protected void tidyUp() { protected void tidyUp() {
if (media != null) { if (media != null) {
try { try {
Task remove = mediaApi.removeMedia(media.getHref()); Task remove = mediaApi.remove(media.getId());
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting media '%s': %s", media.getName()); logger.warn(e, "Error when deleting media '%s': %s", media.getName());
@ -117,7 +117,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
if (oldMedia != null) { if (oldMedia != null) {
try { try {
Task remove = mediaApi.removeMedia(oldMedia.getHref()); Task remove = mediaApi.remove(oldMedia.getId());
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting media '%s': %s", oldMedia.getName()); logger.warn(e, "Error when deleting media '%s': %s", oldMedia.getName());
@ -136,7 +136,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name("Test media " + random.nextInt()) Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name("Test media " + random.nextInt())
.size(iso.length).imageType(Media.ImageType.ISO).description("Test media generated by testAddMedia()") .size(iso.length).imageType(Media.ImageType.ISO).description("Test media generated by testAddMedia()")
.build(); .build();
media = mediaApi.addMedia(addMedia.getHref(), sourceMedia); media = mediaApi.add(addMedia.getHref(), sourceMedia);
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
@ -162,19 +162,19 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
Link uploadLink = Iterables.find(links, LinkPredicates.relEquals(Link.Rel.UPLOAD_DEFAULT)); Link uploadLink = Iterables.find(links, LinkPredicates.relEquals(Link.Rel.UPLOAD_DEFAULT));
context.getApi().getUploadApi().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso)); context.getApi().getUploadApi().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
if (media.getTasks().size() == 1) { if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks()); Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask); Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), Task.Status.RUNNING); assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask")); assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
} }
} }
@Test(description = "GET /media/{id}", dependsOnMethods = { "testAddMedia" }) @Test(description = "GET /media/{id}", dependsOnMethods = { "testAddMedia" })
public void testGetMedia() { public void testGetMedia() {
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
assertNotNull(media, String.format(OBJ_REQ_LIVE, MEDIA)); assertNotNull(media, String.format(OBJ_REQ_LIVE, MEDIA));
owner = media.getOwner(); owner = media.getOwner();
@ -186,7 +186,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /media/{id}/owner", dependsOnMethods = { "testGetMedia" }) @Test(description = "GET /media/{id}/owner", dependsOnMethods = { "testGetMedia" })
public void testGetMediaOwner() { public void testGetMediaOwner() {
Owner directOwner = mediaApi.getOwner(media.getHref()); Owner directOwner = mediaApi.getOwner(media.getId());
assertEquals(owner.toBuilder().user(owner.getUser()).build(), assertEquals(owner.toBuilder().user(owner.getUser()).build(),
directOwner.toBuilder().links(Collections.<Link> emptySet()).build(), String.format( directOwner.toBuilder().links(Collections.<Link> emptySet()).build(), String.format(
GETTER_RETURNS_SAME_OBJ, "getOwner()", "owner", "media.getOwner()", owner.toString(), GETTER_RETURNS_SAME_OBJ, "getOwner()", "owner", "media.getOwner()", owner.toString(),
@ -215,7 +215,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
if (copyTask != null) { if (copyTask != null) {
Checks.checkTask(copyTask); Checks.checkTask(copyTask);
assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask")); assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask"));
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
} }
} }
@ -236,7 +236,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
if (copyTask != null) { if (copyTask != null) {
Checks.checkTask(copyTask); Checks.checkTask(copyTask);
assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask")); assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask"));
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
} }
} }
@ -253,10 +253,10 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
String newDescription = "new " + oldDescription; String newDescription = "new " + oldDescription;
media = media.toBuilder().name(newName).description(newDescription).build(); media = media.toBuilder().name(newName).description(newDescription).build();
Task editMedia = mediaApi.editMedia(media.getHref(), media); Task editMedia = mediaApi.edit(media.getId(), media);
Checks.checkTask(editMedia); Checks.checkTask(editMedia);
assertTrue(retryTaskSuccess.apply(editMedia), String.format(TASK_COMPLETE_TIMELY, "editMedia")); assertTrue(retryTaskSuccess.apply(editMedia), String.format(TASK_COMPLETE_TIMELY, "editMedia"));
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
assertTrue(equal(media.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, MEDIA, "name")); assertTrue(equal(media.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, MEDIA, "name"));
assertTrue(equal(media.getDescription(), newDescription), assertTrue(equal(media.getDescription(), newDescription),
@ -268,10 +268,10 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
media = media.toBuilder().name(oldName).description(oldDescription).build(); media = media.toBuilder().name(oldName).description(oldDescription).build();
editMedia = mediaApi.editMedia(media.getHref(), media); editMedia = mediaApi.edit(media.getId(), media);
Checks.checkTask(editMedia); Checks.checkTask(editMedia);
assertTrue(retryTaskSuccess.apply(editMedia), String.format(TASK_COMPLETE_TIMELY, "editMedia")); assertTrue(retryTaskSuccess.apply(editMedia), String.format(TASK_COMPLETE_TIMELY, "editMedia"));
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
} }
@Test(description = "GET /media/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "GET /media/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
@ -296,7 +296,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
Checks.checkMetadataFor(MEDIA, metadata); Checks.checkMetadataFor(MEDIA, metadata);
checkMetadataContainsEntries(metadata, inputEntries); checkMetadataContainsEntries(metadata, inputEntries);
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
// test edit // test edit
@ -310,7 +310,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
Checks.checkMetadataFor(MEDIA, metadata); Checks.checkMetadataFor(MEDIA, metadata);
checkMetadataContainsEntries(metadata, inputEntries); checkMetadataContainsEntries(metadata, inputEntries);
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
} }
@ -364,20 +364,20 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
metadataValue = mediaApi.getMetadataApi(media.getId()).getValue("key"); metadataValue = mediaApi.getMetadataApi(media.getId()).getValue("key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
} }
@Test(description = "DELETE /media/{id}", dependsOnMethods = { "testRemoveMetadata" }) @Test(description = "DELETE /media/{id}", dependsOnMethods = { "testRemoveMetadata" })
public void testRemoveMedia() { public void testRemoveMedia() {
Task removeMedia = mediaApi.removeMedia(media.getHref()); Task removeMedia = mediaApi.remove(media.getId());
Checks.checkTask(removeMedia); Checks.checkTask(removeMedia);
assertTrue(retryTaskSuccess.apply(removeMedia), String.format(TASK_COMPLETE_TIMELY, "removeMedia")); assertTrue(retryTaskSuccess.apply(removeMedia), String.format(TASK_COMPLETE_TIMELY, "removeMedia"));
media = mediaApi.getMedia(media.getHref()); media = mediaApi.get(media.getId());
assertNull(media, String.format(OBJ_DEL, MEDIA, media != null ? media.toString() : "")); assertNull(media, String.format(OBJ_DEL, MEDIA, media != null ? media.toString() : ""));
removeMedia = mediaApi.removeMedia(oldMedia.getHref()); removeMedia = mediaApi.remove(oldMedia.getId());
Checks.checkTask(removeMedia); Checks.checkTask(removeMedia);
assertTrue(retryTaskSuccess.apply(removeMedia), String.format(TASK_COMPLETE_TIMELY, "removeMedia")); assertTrue(retryTaskSuccess.apply(removeMedia), String.format(TASK_COMPLETE_TIMELY, "removeMedia"));
oldMedia = null; oldMedia = null;

View File

@ -18,10 +18,6 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static com.google.common.base.Predicates.and;
import static com.google.common.collect.Iterables.contains;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.getFirst;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT;
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.ENTITY_EQUAL; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_EQUAL;
@ -43,8 +39,6 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOwner;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkProductSectionList; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkProductSectionList;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkStartupSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkStartupSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVApp; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVApp;
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.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.assertNull; import static org.testng.Assert.assertNull;
@ -60,13 +54,9 @@ import org.jclouds.dmtf.ovf.MsgType;
import org.jclouds.dmtf.ovf.NetworkSection; import org.jclouds.dmtf.ovf.NetworkSection;
import org.jclouds.dmtf.ovf.ProductSection; import org.jclouds.dmtf.ovf.ProductSection;
import org.jclouds.dmtf.ovf.StartupSection; import org.jclouds.dmtf.ovf.StartupSection;
import org.jclouds.io.Payloads;
import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest; import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AccessSetting; import org.jclouds.vcloud.director.v1_5.domain.AccessSetting;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Link;
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.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
@ -118,43 +108,11 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
private MetadataValue metadataValue; private MetadataValue metadataValue;
private String key; private String key;
private boolean mediaCreated = false;
private boolean testUserCreated = false; private boolean testUserCreated = false;
private User user; private User user;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
protected void setupRequiredEntities() { protected void setupRequiredEntities() {
Set<Link> links = lazyGetVdc().getLinks();
if (mediaURI == null) {
Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA));
if (contains(links, addMediaLink)) {
Link addMedia = find(links, addMediaLink);
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name(name("media"))
.size(iso.length).imageType(Media.ImageType.ISO)
.description("Test media generated by VAppApiLiveTest").build();
Media media = context.getApi().getMediaApi().addMedia(addMedia.getHref(), sourceMedia);
Link uploadLink = getFirst(getFirst(media.getFiles(), null).getLinks(), null);
context.getApi().getUploadApi().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
media = context.getApi().getMediaApi().getMedia(media.getHref());
if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = context.getApi().getMediaApi().getMedia(media.getHref());
}
mediaURI = media.getHref();
mediaCreated = true;
}
}
if (adminContext != null) { if (adminContext != null) {
userUrn = adminContext.getApi().getUserApi().addUserToOrg(randomTestUser("VAppAccessTest"), org.getId()) userUrn = adminContext.getApi().getUserApi().addUserToOrg(randomTestUser("VAppAccessTest"), org.getId())
@ -165,14 +123,6 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" }) @AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
public void cleanUp() { public void cleanUp() {
if (adminContext != null && mediaCreated && mediaURI != null) {
try {
Task remove = context.getApi().getMediaApi().removeMedia(mediaURI);
taskDoneEventually(remove);
} catch (Exception e) {
logger.warn(e, "Error when deleting media");
}
}
if (adminContext != null && testUserCreated && userUrn != null) { if (adminContext != null && testUserCreated && userUrn != null) {
try { try {
adminContext.getApi().getUserApi().remove(userUrn); adminContext.getApi().getUserApi().remove(userUrn);

View File

@ -18,10 +18,6 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static com.google.common.base.Predicates.and;
import static com.google.common.collect.Iterables.contains;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.getFirst;
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.ENTITY_EQUAL; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_EQUAL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
@ -44,8 +40,6 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkScreenTicket;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVirtualHardwareSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVirtualHardwareSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVm; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVm;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVmPendingQuestion; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVmPendingQuestion;
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.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;
@ -62,12 +56,8 @@ import org.jclouds.dmtf.cim.OSType;
import org.jclouds.dmtf.cim.ResourceAllocationSettingData; import org.jclouds.dmtf.cim.ResourceAllocationSettingData;
import org.jclouds.dmtf.ovf.MsgType; import org.jclouds.dmtf.ovf.MsgType;
import org.jclouds.dmtf.ovf.ProductSection; import org.jclouds.dmtf.ovf.ProductSection;
import org.jclouds.io.Payloads;
import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest; import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Link;
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.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
@ -116,42 +106,10 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
private MetadataValue metadataValue; private MetadataValue metadataValue;
private String key; private String key;
private boolean mediaCreated = false;
private boolean testUserCreated = false; private boolean testUserCreated = false;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
protected void setupRequiredEntities() { protected void setupRequiredEntities() {
Set<Link> links = vdcApi.get(vdcUrn).getLinks();
if (mediaURI == null) {
Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA));
if (contains(links, addMediaLink)) {
Link addMedia = find(links, addMediaLink);
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name(name("media"))
.size(iso.length).imageType(Media.ImageType.ISO)
.description("Test media generated by VmApiLiveTest").build();
Media media = context.getApi().getMediaApi().addMedia(addMedia.getHref(), sourceMedia);
Link uploadLink = getFirst(getFirst(media.getFiles(), null).getLinks(), null);
context.getApi().getUploadApi().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
media = context.getApi().getMediaApi().getMedia(media.getHref());
if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = context.getApi().getMediaApi().getMedia(media.getHref());
}
mediaURI = media.getHref();
mediaCreated = true;
}
}
if (adminContext != null) { if (adminContext != null) {
userUrn = adminContext.getApi().getUserApi().addUserToOrg(randomTestUser("VAppAccessTest"), org.getId()) userUrn = adminContext.getApi().getUserApi().addUserToOrg(randomTestUser("VAppAccessTest"), org.getId())
@ -161,9 +119,9 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" }) @AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
public void cleanUp() { public void cleanUp() {
if (adminContext != null && mediaCreated && mediaURI != null) { if (adminContext != null && mediaUrn != null) {
try { try {
Task remove = context.getApi().getMediaApi().removeMedia(mediaURI); Task remove = context.getApi().getMediaApi().remove(mediaUrn);
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error when deleting media: %s", e.getMessage()); logger.warn("Error when deleting media: %s", e.getMessage());
@ -462,7 +420,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
public void testInsertMedia() { public void testInsertMedia() {
// Setup media params from configured media id // Setup media params from configured media id
MediaInsertOrEjectParams params = MediaInsertOrEjectParams.builder() MediaInsertOrEjectParams params = MediaInsertOrEjectParams.builder()
.media(Reference.builder().href(mediaURI).type(MEDIA).build()).build(); .media(Reference.builder().href(lazyGetMedia().getHref()).type(MEDIA).build()).build();
// The method under test // The method under test
Task insertMedia = vmApi.insertMedia(vmUrn, params); Task insertMedia = vmApi.insertMedia(vmUrn, params);
@ -473,7 +431,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
public void testEjectMedia() { public void testEjectMedia() {
// Setup media params from configured media id // Setup media params from configured media id
MediaInsertOrEjectParams params = MediaInsertOrEjectParams.builder() MediaInsertOrEjectParams params = MediaInsertOrEjectParams.builder()
.media(Reference.builder().href(mediaURI).type(MEDIA).build()).build(); .media(Reference.builder().href(lazyGetMedia().getHref()).type(MEDIA).build()).build();
// The method under test // The method under test
Task ejectMedia = vmApi.ejectMedia(vmUrn, params); Task ejectMedia = vmApi.ejectMedia(vmUrn, params);
@ -864,8 +822,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
RasdItemsList newSection = oldSection.toBuilder().build(); RasdItemsList newSection = oldSection.toBuilder().build();
// Method under test // Method under test
Task editVirtualHardwareSectionNetworkCards = vmApi.editVirtualHardwareSectionNetworkCards(vmUrn, Task editVirtualHardwareSectionNetworkCards = vmApi.editVirtualHardwareSectionNetworkCards(vmUrn, newSection);
newSection);
assertTrue(retryTaskSuccess.apply(editVirtualHardwareSectionNetworkCards), assertTrue(retryTaskSuccess.apply(editVirtualHardwareSectionNetworkCards),
String.format(TASK_COMPLETE_TIMELY, "editVirtualHardwareSectionNetworkCards")); String.format(TASK_COMPLETE_TIMELY, "editVirtualHardwareSectionNetworkCards"));
@ -896,8 +853,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
RasdItemsList newSection = oldSection.toBuilder().build(); RasdItemsList newSection = oldSection.toBuilder().build();
// Method under test // Method under test
Task editVirtualHardwareSectionSerialPorts = vmApi Task editVirtualHardwareSectionSerialPorts = vmApi.editVirtualHardwareSectionSerialPorts(vmUrn, newSection);
.editVirtualHardwareSectionSerialPorts(vmUrn, newSection);
assertTrue(retryTaskSuccess.apply(editVirtualHardwareSectionSerialPorts), assertTrue(retryTaskSuccess.apply(editVirtualHardwareSectionSerialPorts),
String.format(TASK_COMPLETE_TIMELY, "editVirtualHardwareSectionSerialPorts")); String.format(TASK_COMPLETE_TIMELY, "editVirtualHardwareSectionSerialPorts"));

View File

@ -56,7 +56,7 @@ public class GroupApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Group expected = group(); Group expected = group();
assertEquals(api.getGroupApi().getGroup(groupRef.getHref()), expected); assertEquals(api.getGroupApi().get(groupRef.getHref()), expected);
} }
public static final Group group() { public static final Group group() {
@ -79,7 +79,7 @@ public class GroupApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Group expected = editGroup(); Group expected = editGroup();
assertEquals(api.getGroupApi().editGroup(groupRef.getHref(), expected), expected); assertEquals(api.getGroupApi().edit(groupRef.getHref(), expected), expected);
} }
public static Group editGroup() { public static Group editGroup() {
@ -96,6 +96,6 @@ public class GroupApiExpectTest extends VCloudDirectorAdminApiExpectTest {
new VcloudHttpResponsePrimer() new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build()); .httpResponseBuilder().statusCode(204).build());
api.getGroupApi().removeGroup(groupRef.getHref()); api.getGroupApi().remove(groupRef.getHref());
} }
} }

View File

@ -50,7 +50,6 @@ public class GroupApiLiveTest extends BaseVCloudDirectorApiLiveTest {
/* /*
* Shared state between dependant tests. * Shared state between dependant tests.
*/ */
private Reference groupRef;
private Group group; private Group group;
private OrgLdapSettings oldLdapSettings, newLdapSettings; private OrgLdapSettings oldLdapSettings, newLdapSettings;
@ -61,7 +60,7 @@ public class GroupApiLiveTest extends BaseVCloudDirectorApiLiveTest {
Reference orgRef = null; Reference orgRef = null;
// TODO: requisite LDAP settings // TODO: requisite LDAP settings
// oldLdapSettings = adminContext.getApi().getAdminOrgApi().getLdapSettings(orgRef.getHref()); // oldLdapSettings = adminContext.getApi().getAdminOrgApi().getLdapSettings(orgRef.getId());
// OrgLdapSettings newLdapSettings = oldLdapSettings.toBuilder() // OrgLdapSettings newLdapSettings = oldLdapSettings.toBuilder()
// .ldapMode(OrgLdapSettings.LdapMode.SYSTEM) // .ldapMode(OrgLdapSettings.LdapMode.SYSTEM)
// .build(); // .build();
@ -79,7 +78,7 @@ public class GroupApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /admin/group/{id}", dependsOnMethods = { "testAddGroup" }) @Test(description = "GET /admin/group/{id}", dependsOnMethods = { "testAddGroup" })
public void testGetGroup() { public void testGetGroup() {
group = groupApi.getGroup(groupRef.getHref()); group = groupApi.get(group.getId());
Checks.checkGroup(group); Checks.checkGroup(group);
} }
@ -98,7 +97,7 @@ public class GroupApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.description(newDescription) .description(newDescription)
.build(); .build();
group = groupApi.editGroup(group.getHref(), group); group = groupApi.edit(group.getId(), group);
assertTrue(equal(group.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, GROUP, "name")); assertTrue(equal(group.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, GROUP, "name"));
assertTrue(equal(group.getDescription(), newDescription), assertTrue(equal(group.getDescription(), newDescription),
@ -113,13 +112,13 @@ public class GroupApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.description(oldDescription) .description(oldDescription)
.build(); .build();
group = groupApi.editGroup(group.getHref(), group); group = groupApi.edit(group.getId(), group);
} }
} }
@Test(description = "DELETE /admin/group/{id}", dependsOnMethods = { "testEditGroup" } ) @Test(description = "DELETE /admin/group/{id}", dependsOnMethods = { "testEditGroup" } )
public void testRemoveGroup() { public void testRemoveGroup() {
groupApi.removeGroup(groupRef.getHref()); groupApi.remove(group.getId());
// TODO stronger assertion of error expected // TODO stronger assertion of error expected
// Error expected = Error.builder() // Error expected = Error.builder()
@ -129,7 +128,7 @@ public class GroupApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// .build(); // .build();
try { try {
group = groupApi.getGroup(groupRef.getHref()); group = groupApi.get(group.getId());
fail("Should give HTTP 403 error"); fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
// success // success

View File

@ -18,12 +18,13 @@
*/ */
package org.jclouds.vcloud.director.v1_5.internal; package org.jclouds.vcloud.director.v1_5.internal;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.Iterables.any; import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.contains;
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.tryFind; import static com.google.common.collect.Iterables.tryFind;
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;
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.VCloudDirectorLiveTestConstants.URN_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
@ -34,6 +35,9 @@ 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.VAPP;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VAPP_TEMPLATE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VAPP_TEMPLATE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VDC; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VDC;
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.testng.Assert.assertEquals;
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;
@ -42,7 +46,6 @@ import java.net.URI;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Properties;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
@ -51,17 +54,21 @@ import javax.inject.Inject;
import org.jclouds.apis.BaseContextLiveTest; import org.jclouds.apis.BaseContextLiveTest;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.testng.FormatApiResultsListener; import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata; 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.VCloudDirectorMediaType;
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.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
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.Link.Rel; import org.jclouds.vcloud.director.v1_5.domain.Link.Rel;
import org.jclouds.vcloud.director.v1_5.domain.Media;
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;
import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles; import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
@ -89,8 +96,6 @@ import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
import org.jclouds.vcloud.director.v1_5.predicates.TaskStatusEquals; import org.jclouds.vcloud.director.v1_5.predicates.TaskStatusEquals;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners; import org.testng.annotations.Listeners;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -131,8 +136,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
public Predicate<Task> retryTaskSuccessLong; public Predicate<Task> retryTaskSuccessLong;
protected RestContext<VCloudDirectorAdminApi, VCloudDirectorAdminAsyncApi> adminContext; protected RestContext<VCloudDirectorAdminApi, VCloudDirectorAdminAsyncApi> adminContext;
protected RestContext<VCloudDirectorApi, VCloudDirectorAsyncApi> context; // FIXME: rename to
// userContext?
protected Session adminSession; protected Session adminSession;
protected Session session; protected Session session;
@ -142,7 +146,8 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
private Catalog catalog; private Catalog catalog;
protected String vAppTemplateUrn; protected String vAppTemplateUrn;
private VAppTemplate vAppTemplate; private VAppTemplate vAppTemplate;
protected URI mediaURI; protected String mediaUrn;
private Media media;
protected String networkUrn; protected String networkUrn;
private Network network; private Network network;
protected String vdcUrn; protected String vdcUrn;
@ -159,8 +164,6 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
protected DateService dateService; protected DateService dateService;
protected VCloudDirectorTestSession testSession;
protected static String testStamp; protected static String testStamp;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
@ -182,24 +185,13 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
retryTaskSuccessLong = new RetryablePredicate<Task>(taskSuccess, LONG_TASK_TIMEOUT_SECONDS * 1000L); retryTaskSuccessLong = new RetryablePredicate<Task>(taskSuccess, LONG_TASK_TIMEOUT_SECONDS * 1000L);
} }
@AfterClass(alwaysRun = true) @BeforeClass(groups = { "integration", "live" })
protected void tearDownTestSession() { public void setupContext() {
closeQuietly(testSession); super.setupContext();
} adminContext = context.getAdminContext();
@Override adminSession = adminContext.getApi().getCurrentSession();
protected void initializeContext() { adminContext.utils().injector().injectMembers(this);
Properties overrides = setupProperties();
testSession = VCloudDirectorTestSession.builder().provider(provider).identity(identity).credential(credential)
.endpoint(endpoint).overrides(overrides).build();
context = testSession.getUserContext();
adminContext = testSession.getAdminContext();
if (adminContext != null) {
adminSession = adminContext.getApi().getCurrentSession();
adminContext.utils().injector().injectMembers(this);
}
session = context.getApi().getCurrentSession(); session = context.getApi().getCurrentSession();
context.utils().injector().injectMembers(this); context.utils().injector().injectMembers(this);
@ -246,9 +238,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
vdcUrn = emptyToNull(System.getProperty("test." + provider + ".vdc-id")); vdcUrn = emptyToNull(System.getProperty("test." + provider + ".vdc-id"));
String mediaId = emptyToNull(System.getProperty("test." + provider + ".media-id")); mediaUrn = emptyToNull(System.getProperty("test." + provider + ".media-id"));
if (mediaId != null)
mediaURI = URI.create(endpoint + "/media/" + mediaId);
networkUrn = emptyToNull(System.getProperty("test." + provider + ".network-id")); networkUrn = emptyToNull(System.getProperty("test." + provider + ".network-id"));
@ -344,7 +334,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
} }
}; };
public Optional<Network> tryFindBridgedNetworkInOrg() { public Optional<Network> tryFindBridgedNetworkInOrg() {
FluentIterable<Network> networks = FluentIterable.from(org.getLinks()) FluentIterable<Network> networks = FluentIterable.from(org.getLinks())
.filter(ReferencePredicates.<Link> typeEquals(ORG_NETWORK)).transform(new Function<Link, Network>() { .filter(ReferencePredicates.<Link> typeEquals(ORG_NETWORK)).transform(new Function<Link, Network>() {
@ -412,6 +402,37 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
return user; return user;
} }
protected Media lazyGetMedia(){
if (media == null || mediaUrn == null) {
Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA));
if (contains(lazyGetVdc().getLinks(), addMediaLink)) {
Link addMedia = find(lazyGetVdc().getLinks(), addMediaLink);
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name(name("media"))
.size(iso.length).imageType(Media.ImageType.ISO)
.description("Test media generated by VmApiLiveTest").build();
media = context.getApi().getMediaApi().add(addMedia.getHref(), sourceMedia);
Link uploadLink = getFirst(getFirst(media.getFiles(), null).getLinks(), null);
context.getApi().getUploadApi().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
media = context.getApi().getMediaApi().get(media.getId());
if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = context.getApi().getMediaApi().get(media.getId());
}
mediaUrn = media.getId();
}
}
return media;
}
protected VAppTemplate lazyGetVAppTemplate() { protected VAppTemplate lazyGetVAppTemplate() {
if (vAppTemplate == null) { if (vAppTemplate == null) {
assertNotNull(vAppTemplateUrn, String.format(URN_REQ_LIVE, VAPP_TEMPLATE)); assertNotNull(vAppTemplateUrn, String.format(URN_REQ_LIVE, VAPP_TEMPLATE));

View File

@ -30,7 +30,6 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.internal.BaseRestApiExpectTest; import org.jclouds.rest.internal.BaseRestApiExpectTest;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
@ -249,15 +248,6 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
} }
} }
public URI toAdminUri(Reference ref) {
return toAdminUri(ref.getHref());
}
public URI toAdminUri(URI uri) {
return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref();
}
protected static XMLBuilder createXMLBuilder(String root){ protected static XMLBuilder createXMLBuilder(String root){
try { try {
return XMLBuilder.create(root); return XMLBuilder.create(root);

View File

@ -1,121 +0,0 @@
package org.jclouds.vcloud.director.v1_5.internal;
import static org.testng.Assert.assertEquals;
import java.io.Closeable;
import java.util.Properties;
import org.jclouds.ContextBuilder;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
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.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.io.Closeables;
import com.google.inject.Module;
public class VCloudDirectorTestSession implements Closeable {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String provider;
private String identity;
private String credential;
private Properties overrides;
private String endpoint;
public Builder provider(String provider) {
this.provider = provider;
return this;
}
public Builder identity(String identity) {
this.identity = identity;
return this;
}
public Builder credential(String credential) {
this.credential = credential;
return this;
}
public Builder overrides(Properties overrides) {
this.overrides = overrides;
return this;
}
public Builder endpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}
public VCloudDirectorTestSession build() {
return new VCloudDirectorTestSession(provider, identity, credential, overrides, endpoint);
}
}
private VCloudDirectorContext userContext;
private RestContext<VCloudDirectorAdminApi, VCloudDirectorAdminAsyncApi> adminContext;
private VCloudDirectorTestSession(String provider, String identity, String credential, Properties overrides, String endpoint) {
ContextBuilder builder = ContextBuilder.newBuilder(provider)
.credentials(identity, credential)
.endpoint(endpoint)
.modules(ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule()))
.overrides(overrides);
userContext = VCloudDirectorContext.class.cast(builder.build());
// Look for the admin link in the current session
Link admin = Iterables.tryFind(
userContext.getApi().getCurrentSession().getLinks(),
Predicates.and(LinkPredicates.relEquals(Link.Rel.DOWN), ReferencePredicates.typeEquals(VCloudDirectorMediaType.ADMIN)))
.orNull();
// Get the admin context if the link exists
if (admin != null) {
adminContext = userContext.getAdminContext();
// Lookup the user details
Reference orgRef = Iterables.getFirst(userContext.getApi().getOrgApi().list(), null)
.toAdminReference(endpoint);
Reference userRef = Iterables.find(
adminContext.getApi().getOrgApi().get(orgRef.getHref()).getUsers(),
ReferencePredicates.nameEquals(adminContext.getApi().getCurrentSession().getUser()));
User user = adminContext.getApi().getUserApi().get(userRef.getHref());
// Check that the user has the org admin role
Reference userRole = user.getRole();
assertEquals(userRole.getName(), DefaultRoles.ORG_ADMIN.value());
}
}
@Override
public void close() {
// NOTE we only need to close the user context to log out
Closeables.closeQuietly(userContext);
}
public VCloudDirectorContext getUserContext() {
return userContext;
}
public RestContext<VCloudDirectorAdminApi, VCloudDirectorAdminAsyncApi> getAdminContext() {
return adminContext;
}
}