extract out metadata + upload clients

This commit is contained in:
danikov 2012-02-29 11:33:28 +00:00
parent 8cb04758ce
commit 781c0b538c
7 changed files with 333 additions and 0 deletions

View File

@ -21,17 +21,20 @@ package org.jclouds.vcloud.director.v1_5;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
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.Org;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.ovf.Network;
import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.QueryAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.VdcAsyncClient;
import com.google.inject.Provides;
@ -92,6 +95,17 @@ public interface VCloudDirectorAsyncClient {
@Delegate
VdcAsyncClient getVdcClient();
/**
* @return asynchronous access to Upload features
*/
@Delegate
UploadAsyncClient getUploadClient();
/**
* @return asynchronous access to {@link Metadata} features
*/
@Delegate
MetadataAsyncClient getMetadataClient();
/**
* @return asynchronous access to {@link org.jclouds.vcloud.director.v1_5.domain.VAppTemplate} features
*/

View File

@ -24,6 +24,7 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
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.Org;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.domain.Task;
@ -31,11 +32,13 @@ import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.ovf.Network;
import org.jclouds.vcloud.director.v1_5.features.CatalogClient;
import org.jclouds.vcloud.director.v1_5.features.MediaClient;
import org.jclouds.vcloud.director.v1_5.features.MetadataClient;
import org.jclouds.vcloud.director.v1_5.features.NetworkClient;
import org.jclouds.vcloud.director.v1_5.features.OrgClient;
import org.jclouds.vcloud.director.v1_5.features.QueryClient;
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient;
import org.jclouds.vcloud.director.v1_5.features.UploadClient;
import org.jclouds.vcloud.director.v1_5.features.VdcClient;
import com.google.inject.Provides;
@ -96,6 +99,17 @@ public interface VCloudDirectorClient {
@Delegate
VdcClient getVdcClient();
/**
* @return synchronous access to {@link Upload} features
*/
@Delegate
UploadClient getUploadClient();
/**
* @return synchronous access to {@link Metadata} features
*/
@Delegate
MetadataClient getMetadataClient();
/*
* @return synchronous access to {@link org.jclouds.vcloud.director.v1_5.domain.VAppTemplate} features
*/

View File

@ -43,6 +43,10 @@ import org.jclouds.vcloud.director.v1_5.annotations.Login;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.jclouds.vcloud.director.v1_5.features.*;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.MetadataClient;
import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.UploadClient;
import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword;
import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401AndLogoutOnClose;
import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler;
@ -78,6 +82,8 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
.put(TaskClient.class, TaskAsyncClient.class)
.put(VdcClient.class, VdcAsyncClient.class)
.put(VAppTemplateClient.class, VAppTemplateAsyncClient.class)
.put(UploadClient.class, UploadAsyncClient.class)
.put(MetadataClient.class, MetadataAsyncClient.class)
.build();
public VCloudDirectorRestClientModule() {

View File

@ -0,0 +1,115 @@
/**
* 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.features;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.URISupplier;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
import org.jclouds.vcloud.director.v1_5.functions.URISupplierToEndpoint;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see NetworkClient
* @author danikov
*/
@RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface MetadataAsyncClient {
public static interface Readable extends MetadataAsyncClient {
/**
* @see MetadataClient.Readable#getMetadata(URISupplier)
*/
@GET
@Path("/metadata")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Metadata> getMetadata(@EndpointParam(parser = URISupplierToEndpoint.class) URISupplier parent);
/**
* @see MetadataClient.Readable#getMetadataEntry(URISupplier, String)
*/
@GET
@Path("/metadata/{key}")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<MetadataValue> getMetadataValue(@EndpointParam(parser = URISupplierToEndpoint.class) URISupplier parent ,
@PathParam("key") String key);
}
public static interface Writable extends Readable {
/**
* @see MetadataClient.Writable#mergeMetadata(URISupplier, Metadata))
*/
@POST
@Path("/metadata")
@Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> mergeMetadata(@EndpointParam(parser = URISupplierToEndpoint.class) URISupplier mediaRef,
@BinderParam(BindToXMLPayload.class) Metadata metadata);
/**
* @see MetadataClient.Writable#setMetadata(URISupplier, String, MetadataEntry))
*/
@PUT
@Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA_VALUE)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> setMetadata(@EndpointParam(parser = URISupplierToEndpoint.class) URISupplier metaDataRef,
@PathParam("key") String key,
@BinderParam(BindToXMLPayload.class) MetadataValue metadataValue);
/**
* @see MetadataClient.Writable#deleteMetadataEntry(URISupplier, String))
*/
@DELETE
@Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> deleteMetadataEntry(@EndpointParam(parser = URISupplierToEndpoint.class) URISupplier metaDataRef,
@PathParam("key") String key);
}
}

View File

@ -0,0 +1,81 @@
/**
* 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.features;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.URISupplier;
/**
* Provides synchronous access to Upload.
* <p/>
*
* @see MetadataAsyncClient
* @see <a href= "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID=" />
* @author danikov
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface MetadataClient {
public static interface Readable extends MetadataClient {
/**
* Retrieves an list of metadata
*
* @return a list of metadata
*/
Metadata getMetadata(URISupplier vdcRef);
/**
* Retrieves a metadata value
*
* @return the metadata value, or null if not found
*/
MetadataValue getMetadataValue(URISupplier vdcRef, String key);
}
public static interface Writable extends Readable {
/**
* Merges the metadata for a media with the information provided.
*
* @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
*/
Task mergeMetadata(URISupplier mediaRef, Metadata metadata);
/**
* Sets the metadata for the particular key for the media to the value provided.
* Note: this will replace any existing metadata information
*
* @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
*/
Task setMetadata(URISupplier mediaRef, String key, MetadataValue metadataValue);
/**
* Deletes a metadata entry.
*
* @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
*/
Task deleteMetadataEntry(URISupplier mediaRef, String key);
}
}

View File

@ -0,0 +1,55 @@
/**
* 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.features;
import java.io.File;
import javax.ws.rs.PUT;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.vcloud.director.v1_5.domain.URISupplier;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see UploadClient
* @author danikov
*/
@RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface UploadAsyncClient { // TODO: implement these operations correctly
/**
* @see UploadClient#uploadFile(URISupplier, File)
*/
@PUT
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Object> uploadFile(URISupplier target, File file);
/**
* @see UploadClient#uploadBigFile(URISupplier, File)
*/
@PUT
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Object> uploadBigFile(URISupplier target, File file);
}

View File

@ -0,0 +1,48 @@
/**
* 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.features;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.URISupplier;
/**
* Provides synchronous access to Upload.
* <p/>
*
* @see UploadAsyncClient
* @see <a href= "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID=" />
* @author danikov
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface UploadClient {
/**
* Uploads a file.
*/
void uploadFile(URISupplier target, File file);
/**
* Uploads a file using ranged PUTs.
*/
void uploadBigFile(URISupplier target, File file);
}