mirror of https://github.com/apache/jclouds.git
Merge pull request #817 from KennethNagin/master
CDMI: query parameters and non-CDMI Content Type data object handling support
This commit is contained in:
commit
196b5d7c55
|
@ -24,6 +24,7 @@ import org.jclouds.concurrent.Timeout;
|
|||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.snia.cdmi.v1.features.ContainerApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DataApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DataNonCDMIContentTypeApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DomainApi;
|
||||
|
||||
/**
|
||||
|
@ -54,4 +55,11 @@ public interface CDMIApi {
|
|||
*/
|
||||
@Delegate
|
||||
DataApi getDataApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Data Object Resource Operations.
|
||||
*/
|
||||
@Delegate
|
||||
DataNonCDMIContentTypeApi getDataNonCDMIContentTypeApi();
|
||||
|
||||
}
|
||||
|
|
|
@ -50,4 +50,11 @@ public interface CDMIAsyncApi {
|
|||
*/
|
||||
@Delegate
|
||||
DataAsyncApi getDataApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Data Object Resource Operations.
|
||||
*/
|
||||
@Delegate
|
||||
DataAsyncApi getDataNonCDMIContentTypeApi();
|
||||
|
||||
}
|
||||
|
|
|
@ -21,11 +21,9 @@ package org.jclouds.snia.cdmi.v1;
|
|||
/**
|
||||
* Object Types used in CDMI.
|
||||
*
|
||||
* @see javax.ws.rs.core.MediaType;
|
||||
*/
|
||||
public interface ObjectTypes {
|
||||
|
||||
public static final String CONTAINER = "application/cdmi-container";
|
||||
public static final String DATAOBJECT = "application/cdmi-object";
|
||||
public static final String CDMIOBJECT = "application/cdmi-object";
|
||||
}
|
||||
|
|
|
@ -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.snia.cdmi.v1.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import javax.inject.Singleton;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.CDMIObjectQueryParams;
|
||||
|
||||
/**
|
||||
* This binding solves the problem jax-rs encoding ? ; : which some servers can
|
||||
* not handle
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
@Singleton
|
||||
public class BindQueryParmsToSuffix implements Binder {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
checkArgument(
|
||||
checkNotNull(input, "input") instanceof CDMIObjectQueryParams,
|
||||
"this binder is only valid for CDMIObjectQueryParams!");
|
||||
checkNotNull(request, "request");
|
||||
String queryParams = input.toString();
|
||||
return (R) request.toBuilder()
|
||||
.endpoint(request.getEndpoint() + "?" + queryParams).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -32,6 +32,8 @@ import org.jclouds.snia.cdmi.v1.features.ContainerAsyncApi;
|
|||
import org.jclouds.snia.cdmi.v1.features.ContainerApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DataAsyncApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DataApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DataNonCDMIContentTypeApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DataNonCDMIContentTypeAsyncApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DomainAsyncApi;
|
||||
import org.jclouds.snia.cdmi.v1.features.DomainApi;
|
||||
import org.jclouds.snia.cdmi.v1.handlers.CDMIErrorHandler;
|
||||
|
@ -48,7 +50,8 @@ public class CDMIRestClientModule extends RestClientModule<CDMIApi, CDMIAsyncApi
|
|||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder().put(
|
||||
DomainApi.class, DomainAsyncApi.class).put(ContainerApi.class, ContainerAsyncApi.class).put(
|
||||
DataApi.class, DataAsyncApi.class).build();
|
||||
DataApi.class, DataAsyncApi.class).put(
|
||||
DataNonCDMIContentTypeApi.class, DataNonCDMIContentTypeAsyncApi.class).build();
|
||||
|
||||
public CDMIRestClientModule() {
|
||||
super(DELEGATE_MAP);
|
||||
|
|
|
@ -160,6 +160,7 @@ public class DataObject extends CDMIObject {
|
|||
return fileOut;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get dataObject's value as a File
|
||||
*
|
||||
|
|
|
@ -23,9 +23,10 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.ContainerQueryParams;
|
||||
|
||||
/**
|
||||
* Container Object Resource Operations
|
||||
* CDMI Container Object Resource Operations
|
||||
*
|
||||
* @see ContainerAsyncApi
|
||||
* @author Kenneth Nagin
|
||||
|
@ -33,11 +34,81 @@ import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
|||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
public interface ContainerApi {
|
||||
|
||||
/**
|
||||
* get CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @return Container
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = getContainer("myContainer/");
|
||||
* container = getContainer("parentContainer/childContainer/");
|
||||
* }
|
||||
* <pre>
|
||||
*/
|
||||
Container getContainer(String containerName);
|
||||
|
||||
/**
|
||||
* get CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* @param queryParams
|
||||
* enables getting only certain fields, metadata, children range
|
||||
* @return Container
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = getContainer("myContainer/",ContainerQueryParams.Builder.mimetype("text/plain").field("objectName"))
|
||||
* container = getContainer("myContainer/",ContainerQueryParams.Builder.metadata().field("objectName"))
|
||||
* }
|
||||
* </pre>
|
||||
* @see ContainerQueryParams
|
||||
*/
|
||||
Container getContainer(String containerName,
|
||||
ContainerQueryParams queryParams);
|
||||
|
||||
/**
|
||||
* Create CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @return Container
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = createContainer("myContainer/");
|
||||
* container = createContainer("parentContainer/childContainer/");
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
Container createContainer(String containerName);
|
||||
|
||||
/**
|
||||
* Create CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* @param options
|
||||
* enables adding metadata
|
||||
* @return Container
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = createContainer("myContainer/",CreateContainerOptions.Builder..metadata(metaDataIn));
|
||||
* }
|
||||
* </pre>
|
||||
* @see CreateContainerOptions
|
||||
*/
|
||||
Container createContainer(String containerName,
|
||||
CreateContainerOptions... options);
|
||||
|
||||
Container getContainer(String containerName);
|
||||
|
||||
/**
|
||||
* Delete CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
*/
|
||||
void deleteContainer(String containerName);
|
||||
|
||||
}
|
||||
|
|
|
@ -26,61 +26,138 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
|
||||
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.snia.cdmi.v1.ObjectTypes;
|
||||
import org.jclouds.snia.cdmi.v1.binders.BindQueryParmsToSuffix;
|
||||
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||
import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
|
||||
import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.ContainerQueryParams;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Container Object Resource Operations
|
||||
* CDMI Container Object Resource Operations
|
||||
*
|
||||
* @see ContainerApi
|
||||
* @author Kenneth Nagin
|
||||
* @see <a href="http://www.snia.org/cdmi">api doc</a>
|
||||
*/
|
||||
@SkipEncoding( { '/', '=' })
|
||||
@RequestFilters( { BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class })
|
||||
@Headers(keys="X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||
@SkipEncoding({ '/', '=' })
|
||||
@RequestFilters({ BasicAuthenticationAndTenantId.class,
|
||||
StripExtraAcceptHeader.class })
|
||||
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||
public interface ContainerAsyncApi {
|
||||
|
||||
/**
|
||||
* @see ContainerApi#listContainers()
|
||||
* get CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @return Container
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = getContainer("myContainer/");
|
||||
* container = getContainer("parentContainer/childContainer/");
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
*/
|
||||
@GET
|
||||
@Consumes( { ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}/")
|
||||
ListenableFuture<Container> getContainer(@PathParam("containerName") String containerName);
|
||||
@Path("/{containerName}")
|
||||
ListenableFuture<Container> getContainer(
|
||||
@PathParam("containerName") String containerName);
|
||||
|
||||
/**
|
||||
* @see ContainerApi#createContainer
|
||||
* get CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* @param queryParams
|
||||
* enables getting only certain fields, metadata, children range
|
||||
* @return Container
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = getContainer("myContainer/",ContainerQueryParams.Builder.field("parentURI").field("objectName"))
|
||||
* container = getContainer("myContainer/",ContainerQueryParams.Builder.metadata().field("objectName"))
|
||||
* }
|
||||
* </pre>
|
||||
* @see ContainerQueryParams
|
||||
*/
|
||||
@GET
|
||||
@Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}")
|
||||
ListenableFuture<Container> getContainer(
|
||||
@PathParam("containerName") String containerName,
|
||||
@BinderParam(BindQueryParmsToSuffix.class) ContainerQueryParams queryParams);
|
||||
|
||||
/**
|
||||
* Create CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @return Container
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = createContainer("myContainer/");
|
||||
* container = createContainer("parentContainer/childContainer/");
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@PUT
|
||||
@Consumes( { ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
|
||||
@Produces( { ObjectTypes.CONTAINER})
|
||||
@Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
|
||||
@Produces({ ObjectTypes.CONTAINER })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}/")
|
||||
ListenableFuture<Container> createContainer(@PathParam("containerName") String containerName,
|
||||
@Path("/{containerName}")
|
||||
ListenableFuture<Container> createContainer(
|
||||
@PathParam("containerName") String containerName);
|
||||
|
||||
/**
|
||||
* Create CDMI Container
|
||||
*
|
||||
* @param containerName
|
||||
* @param options
|
||||
* enables adding metadata
|
||||
* @return Container
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* container = createContainer("myContainer/",CreateContainerOptions.Builder..metadata(metaDataIn));
|
||||
* }
|
||||
* </pre>
|
||||
* @see CreateContainerOptions
|
||||
*/
|
||||
@PUT
|
||||
@Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
|
||||
@Produces({ ObjectTypes.CONTAINER })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}")
|
||||
ListenableFuture<Container> createContainer(
|
||||
@PathParam("containerName") String containerName,
|
||||
CreateContainerOptions... options);
|
||||
|
||||
/**
|
||||
* @see ContainerApi#createContainer()
|
||||
* Delete Container
|
||||
*
|
||||
* @param containerName
|
||||
*/
|
||||
@DELETE
|
||||
@Consumes( MediaType.APPLICATION_JSON )
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}/")
|
||||
ListenableFuture<Void> deleteContainer(@PathParam("containerName") String containerName);
|
||||
@Path("/{containerName}")
|
||||
ListenableFuture<Void> deleteContainer(
|
||||
@PathParam("containerName") String containerName);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.jclouds.snia.cdmi.v1.features;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectNonCDMIOptions;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
|
||||
|
||||
/**
|
||||
* Data Object Resource Operations
|
||||
|
@ -33,15 +33,83 @@ import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions;
|
|||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
public interface DataApi {
|
||||
/**
|
||||
* get CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @return DataObject
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* dataObject = getDataObject("myContainer/","myDataObject");
|
||||
* dataObject = getDataObject("parentContainer/childContainer/","myDataObject");
|
||||
* }
|
||||
* <pre>
|
||||
*/
|
||||
DataObject getDataObject(String containerName, String dataObjectName);
|
||||
/**
|
||||
* get CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @param queryParams
|
||||
* enables getting only certain fields, metadata, value range
|
||||
* @return DataObject
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.field("parentURI").field("objectName"));
|
||||
* dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.value(0,10));
|
||||
* }
|
||||
* <pre>
|
||||
*/
|
||||
DataObject getDataObject(String containerName, String dataObjectName,
|
||||
DataObjectQueryParams queryParams);
|
||||
|
||||
/**
|
||||
* create CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @param options
|
||||
* enables defining the body i.e. metadata, mimetype, value
|
||||
* @return DataObject
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* dataObject = createDataObject("myContainer/",
|
||||
* "myDataObject",
|
||||
* CreateDataObjectOptions.Builder
|
||||
* .value(value)
|
||||
* .mimetype("text/plain")
|
||||
* .metadata(pDataObjectMetaDataIn);
|
||||
* }
|
||||
* <pre>
|
||||
*/
|
||||
DataObject createDataObject(String containerName, String dataObjectName,
|
||||
CreateDataObjectOptions... options);
|
||||
|
||||
void createDataObjectNonCDMI(String containerName, String dataObjectName,
|
||||
CreateDataObjectNonCDMIOptions... options );
|
||||
|
||||
DataObject getDataObject(String containerName, String dataObjectName);
|
||||
|
||||
/**
|
||||
* delete CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* deleteDataObject("myContainer/","myDataObject");
|
||||
* }
|
||||
* <pre>
|
||||
*/
|
||||
void deleteDataObject(String containerName, String dataObjectName);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,17 +27,19 @@ import javax.ws.rs.PathParam;
|
|||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.snia.cdmi.v1.ObjectTypes;
|
||||
import org.jclouds.snia.cdmi.v1.binders.BindQueryParmsToSuffix;
|
||||
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||
import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
|
||||
import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectNonCDMIOptions;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
|
@ -51,56 +53,56 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@SkipEncoding({ '/', '=' })
|
||||
@RequestFilters({ BasicAuthenticationAndTenantId.class,
|
||||
StripExtraAcceptHeader.class })
|
||||
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||
public interface DataAsyncApi {
|
||||
/**
|
||||
* @see DataApi#getDataObject()
|
||||
* @see DataApi#getDataObject(String containerName, String dataObjectName)
|
||||
*/
|
||||
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||
@GET
|
||||
@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}/{dataObjectName}")
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<DataObject> getDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName);
|
||||
|
||||
/**
|
||||
* @see DataApi#createDataObject
|
||||
* @see DataApi#getDataObject(String containerName, String dataObjectName,
|
||||
* DataObjectQueryParams queryParams)
|
||||
*/
|
||||
@GET
|
||||
@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<DataObject> getDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
@BinderParam(BindQueryParmsToSuffix.class) DataObjectQueryParams queryParams);
|
||||
|
||||
/**
|
||||
* @see DataApi#createDataObject(String containerName, String
|
||||
* dataObjectName, CreateDataObjectOptions... options)
|
||||
*/
|
||||
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||
@PUT
|
||||
@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
|
||||
@Produces({ ObjectTypes.DATAOBJECT })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}/{dataObjectName}")
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<DataObject> createDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
CreateDataObjectOptions... options);
|
||||
|
||||
/**
|
||||
* @see DataApi#createDataObjectNonCDMI
|
||||
* @see DataApi#deleteDataObject(String containerName, String
|
||||
* dataObjectName)
|
||||
*/
|
||||
@PUT
|
||||
@Consumes({ "text/plain" })
|
||||
@Produces({ "text/plain;charset=utf-8" })
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}/{dataObjectName}")
|
||||
ListenableFuture<Void> createDataObjectNonCDMI(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
CreateDataObjectNonCDMIOptions... options);
|
||||
|
||||
/**
|
||||
* @see DataApi#deleteDataObject()
|
||||
*/
|
||||
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||
@DELETE
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
// note: MediaType.APPLICATION_JSON work also, however without consumes
|
||||
// jclouds throws null exception
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}/{dataObjectName}")
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<Void> deleteDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName);
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
/**
|
||||
* 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.snia.cdmi.v1.features;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
|
||||
|
||||
/**
|
||||
* Data Object Resource Operations
|
||||
*
|
||||
* @see DataNonCDMIContentTypeAsyncApi
|
||||
* @author Kenneth Nagin
|
||||
* @see <a href="http://www.snia.org/cdmi">api doc</a>
|
||||
*/
|
||||
@Timeout(duration = 600, timeUnit = TimeUnit.SECONDS)
|
||||
public interface DataNonCDMIContentTypeApi {
|
||||
/**
|
||||
* get CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @return DataObjectNonCDMIContentType
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* dataObject = getDataObject("myContainer/","myDataObject");
|
||||
* dataObject = getDataObject("parentContainer/childContainer/","myDataObject");
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
* @see DataNonCDMIContentTypeAsyncApi#getDataObjectValue(String containerName, String dataObjectName)
|
||||
*/
|
||||
Payload getDataObjectValue(String containerName, String dataObjectName);
|
||||
|
||||
/**
|
||||
* get CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @param range
|
||||
* a valid ranges-specifier (see RFC2616 Section 14.35.1)
|
||||
* @return DataObjectNonCDMIContentType
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* dataObject = getDataObject("myContainer/","myDataObject","bytes=0-10");
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
*/
|
||||
Payload getDataObjectValue(String containerName, String dataObjectName,
|
||||
String range);
|
||||
|
||||
/**
|
||||
* get CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @param queryParams
|
||||
* enables getting only certain fields, metadata, value range
|
||||
* @return DataObject
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.field("parentURI").field("objectName"));
|
||||
* dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.value(0,10));
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
*/
|
||||
DataObject getDataObject(String containerName, String dataObjectName,
|
||||
DataObjectQueryParams queryParams);
|
||||
|
||||
/**
|
||||
* create CDMI Data object Non CDMI Content Type
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @param payload
|
||||
* enables defining the body's payload i.e. file, inputStream,
|
||||
* String, ByteArray
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* createDataObject("myContainer/","myDataObject",new StringPayload("value");
|
||||
* createDataObject("myContainer/","myDataObject",new ByteArrayPayload(bytes);
|
||||
* createDataObject("myContainer/","myDataObject",new FilePayload(myFileIn);
|
||||
* createDataObject("myContainer/","myDataObject",new InputStreamPayload(is);
|
||||
*
|
||||
* File f = new File("yellow-flowers.jpg");
|
||||
* payloadIn = new InputStreamPayload(new FileInputStream(f));
|
||||
* payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(
|
||||
* payloadIn.getContentMetadata().toBuilder()
|
||||
* .contentType(MediaType.JPEG.toString())
|
||||
* .contentLength(new Long(inFile.length()))
|
||||
* .build()));
|
||||
* dataNonCDMIContentTypeApi.createDataObject(containerName, f.getName(),
|
||||
* payloadIn);
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
*/
|
||||
void createDataObject(String containerName, String dataObjectName,
|
||||
Payload payload);
|
||||
|
||||
/**
|
||||
* create CDMI Data object partial Non CDMI Content Type Only part of the
|
||||
* object is contained in the payload and the X-CDMI-Partial header flag is
|
||||
* set to true
|
||||
*
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @param payload
|
||||
* enables defining the body's payload i.e. file, inputStream,
|
||||
* String, ByteArray
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* createDataObjectPartial("myContainer/","myDataObject",new StringPayload("value");
|
||||
* createDataObjectPartial("myContainer/","myDataObject",new ByteArrayPayload(bytes);
|
||||
* createDataObjectPartial("myContainer/","myDataObject",new FilePayload(myFileIn);
|
||||
* createDataObjectPartial("myContainer/","myDataObject",new InputStreamPayload(is);
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
*/
|
||||
void createDataObjectPartial(String containerName, String dataObjectName,
|
||||
Payload payload);
|
||||
|
||||
/**
|
||||
* create CDMI Data object Non CDMI Content Type
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
* @param inputString
|
||||
* simple string input
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* createDataObject("myContainer/","myDataObject",new String("value");
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
*/
|
||||
void createDataObject(String containerName, String dataObjectName,
|
||||
String inputString);
|
||||
|
||||
/**
|
||||
* delete CDMI Data object
|
||||
*
|
||||
* @param containerName
|
||||
* containerName must end with a forward slash, /.
|
||||
* @param dataObjectName
|
||||
* dataObjectName must not end with a forward slash, /.
|
||||
*
|
||||
* <pre>
|
||||
* Examples:
|
||||
* {@code
|
||||
* deleteDataObject("myContainer/","myDataObject");
|
||||
* }
|
||||
*
|
||||
* <pre>
|
||||
*/
|
||||
void deleteDataObject(String containerName, String dataObjectName);
|
||||
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/**
|
||||
* 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.snia.cdmi.v1.features;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.snia.cdmi.v1.binders.BindQueryParmsToSuffix;
|
||||
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||
import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
|
||||
import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
|
||||
import org.jclouds.snia.cdmi.v1.functions.ParseObjectFromHeadersAndHttpContent;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.rest.annotations.Payload;
|
||||
|
||||
/**
|
||||
* Non CDMI Content Type Data Object Resource Operations
|
||||
*
|
||||
* @see DataNonCDMIContentTypeApi
|
||||
* @see DataAsyncApi
|
||||
* @author Kenneth Nagin
|
||||
* @see <a href="http://www.snia.org/cdmi">api doc</a>
|
||||
*/
|
||||
@SkipEncoding({ '/', '=' })
|
||||
@RequestFilters({ BasicAuthenticationAndTenantId.class,
|
||||
StripExtraAcceptHeader.class })
|
||||
public interface DataNonCDMIContentTypeAsyncApi {
|
||||
/**
|
||||
* @see DataNonCDMIContentTypeApi#getDataObjectValue(String containerName,
|
||||
* String dataObjectName)
|
||||
*/
|
||||
@GET
|
||||
@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
|
||||
@ResponseParser(ParseObjectFromHeadersAndHttpContent.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<org.jclouds.io.Payload> getDataObjectValue(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName);
|
||||
|
||||
/**
|
||||
* @see DataNonCDMIContentTypeApi#getDataObjectValue(String containerName,
|
||||
* String dataObjectName, String range )
|
||||
*/
|
||||
|
||||
@GET
|
||||
@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
|
||||
@ResponseParser(ParseObjectFromHeadersAndHttpContent.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<org.jclouds.io.Payload> getDataObjectValue(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
@HeaderParam("Range") String range);
|
||||
|
||||
/**
|
||||
* @see DataNonCDMIContentTypeApi#getDataObject(String containerName, String
|
||||
* dataObjectName, DataObjectQueryParams queryParams )
|
||||
*/
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<DataObject> getDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
@BinderParam(BindQueryParmsToSuffix.class) DataObjectQueryParams queryParams);
|
||||
|
||||
/**
|
||||
* @see DataNonCDMIContentTypeApi#createDataObject(String containerName,
|
||||
* String dataObjectName, org.jclouds.io.Payload payload )
|
||||
*/
|
||||
@PUT
|
||||
@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<Void> createDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
org.jclouds.io.Payload payload);
|
||||
|
||||
/**
|
||||
* @see DataNonCDMIContentTypeApi#createDataObjectPartial(String
|
||||
* containerName, String dataObjectName, org.jclouds.io.Payload payload
|
||||
* )
|
||||
*/
|
||||
@PUT
|
||||
@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
@Headers(keys = "X-CDMI-Partial", values = "true")
|
||||
ListenableFuture<Void> createDataObjectPartial(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
org.jclouds.io.Payload payload);
|
||||
|
||||
/**
|
||||
* @see DataNonCDMIContentTypeApi#createDataObject(String containerName,
|
||||
* String dataObjectName, String input )
|
||||
*/
|
||||
@PUT
|
||||
@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
@Payload("{input}")
|
||||
ListenableFuture<Void> createDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName,
|
||||
@PayloadParam("input") String input);
|
||||
|
||||
/**
|
||||
* @see DataNonCDMIContentTypeApi#deleteDataObject(String containerName,
|
||||
* String dataObjectName)
|
||||
*/
|
||||
@DELETE
|
||||
@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/{containerName}{dataObjectName}")
|
||||
ListenableFuture<Void> deleteDataObject(
|
||||
@PathParam("containerName") String containerName,
|
||||
@PathParam("dataObjectName") String dataObjectName);
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* 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.snia.cdmi.v1.functions;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Parses payload from HTTP response .
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class ParseObjectFromHeadersAndHttpContent implements
|
||||
Function<HttpResponse, Payload>,
|
||||
InvocationContext<ParseObjectFromHeadersAndHttpContent> {
|
||||
|
||||
public Payload apply(HttpResponse from) {
|
||||
Payload object = from.getPayload();
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseObjectFromHeadersAndHttpContent setContext(HttpRequest request) {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package org.jclouds.snia.cdmi.v1.options;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
/**
|
||||
* Contains options supported in the REST API for the CREATE container
|
||||
* operation. <h2>
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class CreateCDMIObjectOptions extends BaseHttpRequestOptions {
|
||||
protected JsonObject jsonObjectBody = new JsonObject();
|
||||
/**
|
||||
* A name-value pair to associate with the container as metadata.
|
||||
*/
|
||||
public CreateCDMIObjectOptions metadata(Map<String, String> metadata) {
|
||||
JsonObject jsonObjectMetadata = new JsonObject();
|
||||
if (metadata != null) {
|
||||
for (Entry<String, String> entry : metadata.entrySet()) {
|
||||
jsonObjectMetadata
|
||||
.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
jsonObjectBody.add("metadata", jsonObjectMetadata);
|
||||
this.payload = jsonObjectBody.toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static CreateCDMIObjectOptions withMetadata(
|
||||
Map<String, String> metadata) {
|
||||
CreateCDMIObjectOptions options = new CreateCDMIObjectOptions();
|
||||
return (CreateCDMIObjectOptions) options.metadata(metadata);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +1,26 @@
|
|||
package org.jclouds.snia.cdmi.v1.options;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Contains options supported in the REST API for the CREATE container
|
||||
* operation. <h2>
|
||||
* Optional Create CDMI Contain options
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class CreateContainerOptions extends BaseHttpRequestOptions {
|
||||
public class CreateContainerOptions extends CreateCDMIObjectOptions {
|
||||
/**
|
||||
* A name-value pair to associate with the container as metadata.
|
||||
*/
|
||||
public CreateContainerOptions withMetadata(Map<String, String> metadata) {
|
||||
String s = "{ \"metadata\" : {\"key1\" : \"value1\",\"key2\" : \"value2\"} }";
|
||||
this.payload = s;
|
||||
String payload = "{ \"metadata\" : {";
|
||||
String separator = " ";
|
||||
for (Entry<String, String> entry : metadata.entrySet()) {
|
||||
payload = payload + separator + "\"" + entry.getKey() + "\" : \""
|
||||
+ entry.getValue() + "\"";
|
||||
separator = ",";
|
||||
}
|
||||
this.payload = payload + "} }";
|
||||
public CreateContainerOptions metadata(Map<String, String> metadata) {
|
||||
super.metadata(metadata);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
public static class Builder {
|
||||
public static CreateContainerOptions withMetadata(
|
||||
public static CreateContainerOptions metadata(
|
||||
Map<String, String> metadata) {
|
||||
CreateContainerOptions options = new CreateContainerOptions();
|
||||
return (CreateContainerOptions) options.withMetadata(metadata);
|
||||
return (CreateContainerOptions) options.metadata(metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,8 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
import com.google.common.base.Charsets;
|
||||
import java.nio.charset.Charset;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
|
@ -22,8 +18,7 @@ import com.google.common.io.Files;
|
|||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
||||
private JsonObject jsonObjectBody = new JsonObject();
|
||||
public class CreateDataObjectOptions extends CreateCDMIObjectOptions {
|
||||
|
||||
public CreateDataObjectOptions() {
|
||||
jsonObjectBody.addProperty("value", new String());
|
||||
|
@ -33,18 +28,10 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
* Create CDMI data object with metadata
|
||||
*
|
||||
* @param metadata
|
||||
* @return this
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions metadata(Map<String, String> metadata) {
|
||||
JsonObject jsonObjectMetadata = new JsonObject();
|
||||
if (metadata != null) {
|
||||
for (Entry<String, String> entry : metadata.entrySet()) {
|
||||
jsonObjectMetadata
|
||||
.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
jsonObjectBody.add("metadata", jsonObjectMetadata);
|
||||
this.payload = jsonObjectBody.toString();
|
||||
super.metadata(metadata);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -52,7 +39,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
* Create CDMI data object with mimetype
|
||||
*
|
||||
* @param mimetype
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions mimetype(String mimetype) {
|
||||
jsonObjectBody.addProperty("mimetype", mimetype);
|
||||
|
@ -63,7 +50,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
/**
|
||||
* Create CDMI data object with value equal to empty string
|
||||
*
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions value() {
|
||||
this.payload = jsonObjectBody.toString();
|
||||
|
@ -75,7 +62,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
*
|
||||
* @param value
|
||||
* String value
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions value(String value) {
|
||||
jsonObjectBody.addProperty("value", (value == null) ? new String()
|
||||
|
@ -89,7 +76,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
*
|
||||
* @param value
|
||||
* byte array value byte array is converted to a String value
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions value(byte[] value) throws IOException {
|
||||
jsonObjectBody.addProperty("value",
|
||||
|
@ -104,7 +91,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
*
|
||||
* @param value
|
||||
* File File is converted to a String value with charset UTF_8
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions value(File value) throws IOException {
|
||||
jsonObjectBody.addProperty("value", (value == null) ? new String()
|
||||
|
@ -120,7 +107,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
* File
|
||||
* @param charset
|
||||
* character set of file File is converted to a String value
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions value(File value, Charset charset)
|
||||
throws IOException {
|
||||
|
@ -136,7 +123,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
* @param value
|
||||
* InputSteam InputSteam is converted to a String value with
|
||||
* charset UTF_8
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions value(InputStream value) throws IOException {
|
||||
jsonObjectBody
|
||||
|
@ -157,7 +144,7 @@ public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
|||
* @param charset
|
||||
* character set of input stream InputSteam is converted to a
|
||||
* String value with charset UTF_8
|
||||
* @return
|
||||
* @return CreateDataObjectOptions
|
||||
*/
|
||||
public CreateDataObjectOptions value(InputStream value, Charset charset)
|
||||
throws IOException {
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package org.jclouds.snia.cdmi.v1.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Optional get CDMI object options Note: We use
|
||||
* BaseHttpRequestOptions.pathSuffix to include the CDMI query parameters rather
|
||||
* than queryParam or MatrixParam because the CDMI specification is not
|
||||
* following the standard usage. This is the summary of the CDMI specification:
|
||||
* To read one or more requested fields from an existing CDMI container object,
|
||||
* one of the following requests shall be performed:
|
||||
* GET <root URI>/<ContainerName>/<TheContainerName>/?<fieldname>;<fieldname>;...
|
||||
* GET <root URI>/<ContainerName>/<TheContainerName>/?children:<range>;...
|
||||
* GET <root URI>/<ContainerName>/<TheContainerName>/?metadata:<prefix>;...
|
||||
*
|
||||
* For example: GET /MyContainer/?parentURI;children HTTP/1.1
|
||||
* GET /MyContainer/?childrenrange;children:0-2 HTTP/1.1
|
||||
*
|
||||
* To read one or more requested fields from an existing data object, one of the
|
||||
* following requests shall be performed:
|
||||
* GET <root URI>/<ContainerName>/<DataObjectName>?<fieldname>;<fieldname>;...
|
||||
* GET <root URI>/<ContainerName>/<DataObjectName>?value:<range>;...
|
||||
* GET <root URI>/<ContainerName>/<DataObjectName>?metadata:<prefix>;...
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class GetCDMIObjectOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public GetCDMIObjectOptions() {
|
||||
this.pathSuffix = "?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's field
|
||||
*
|
||||
* @param fieldname
|
||||
* @return this
|
||||
*/
|
||||
public GetCDMIObjectOptions field(String fieldname) {
|
||||
this.pathSuffix = this.pathSuffix + fieldname + ";";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's metadata
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public GetCDMIObjectOptions metadata() {
|
||||
this.pathSuffix = this.pathSuffix + "metadata;";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's metadata
|
||||
*
|
||||
* @param prefix
|
||||
* @return this
|
||||
*/
|
||||
public GetCDMIObjectOptions metadata(String prefix) {
|
||||
this.pathSuffix = this.pathSuffix + "metadata:" + prefix + ";";
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static GetCDMIObjectOptions field(String fieldname) {
|
||||
GetCDMIObjectOptions options = new GetCDMIObjectOptions();
|
||||
return (GetCDMIObjectOptions) options.field(fieldname);
|
||||
}
|
||||
|
||||
public static GetCDMIObjectOptions metadata() {
|
||||
GetCDMIObjectOptions options = new GetCDMIObjectOptions();
|
||||
return (GetCDMIObjectOptions) options.metadata();
|
||||
}
|
||||
|
||||
public static GetCDMIObjectOptions metadata(String prefix) {
|
||||
GetCDMIObjectOptions options = new GetCDMIObjectOptions();
|
||||
return (GetCDMIObjectOptions) options.metadata(prefix);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package org.jclouds.snia.cdmi.v1.options;
|
||||
|
||||
|
||||
/**
|
||||
* Optional get CDMI container operations
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class GetContainerOptions extends GetCDMIObjectOptions {
|
||||
|
||||
public GetContainerOptions() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's field
|
||||
*
|
||||
* @param fieldname
|
||||
* @return this
|
||||
*/
|
||||
public GetContainerOptions field(String fieldname) {
|
||||
super.field(fieldname);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's metadata
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public GetContainerOptions metadata() {
|
||||
super.metadata();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's metadata
|
||||
*
|
||||
* @param prefix
|
||||
* @return this
|
||||
*/
|
||||
public GetContainerOptions metadata(String prefix) {
|
||||
super.metadata(prefix);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's children
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public GetContainerOptions children() {
|
||||
this.pathSuffix = this.pathSuffix + "children;";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's children in range
|
||||
*
|
||||
* @param from
|
||||
* @param to
|
||||
* @return this
|
||||
*/
|
||||
public GetContainerOptions children(int from, int to) {
|
||||
this.pathSuffix = this.pathSuffix + "children:" + from + "-" + to + ";";
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static GetContainerOptions field(String fieldname) {
|
||||
GetContainerOptions options = new GetContainerOptions();
|
||||
return (GetContainerOptions) options.field(fieldname);
|
||||
}
|
||||
|
||||
public static GetContainerOptions metadata() {
|
||||
GetContainerOptions options = new GetContainerOptions();
|
||||
return (GetContainerOptions) options.metadata();
|
||||
}
|
||||
|
||||
public static GetContainerOptions metadata(String prefix) {
|
||||
GetContainerOptions options = new GetContainerOptions();
|
||||
return (GetContainerOptions) options.metadata(prefix);
|
||||
}
|
||||
|
||||
public static GetContainerOptions children() {
|
||||
GetContainerOptions options = new GetContainerOptions();
|
||||
return (GetContainerOptions) options.children();
|
||||
}
|
||||
|
||||
public static GetContainerOptions children(int from, int to) {
|
||||
GetContainerOptions options = new GetContainerOptions();
|
||||
return (GetContainerOptions) options.children(from, to);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package org.jclouds.snia.cdmi.v1.queryparams;
|
||||
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
* Generate CDMI object query parameters
|
||||
* Note: The preferred implementation would use jax-rs queryParam.
|
||||
* However, the CDMI query parameters specification does not conform to
|
||||
* jax-rs queryParam of key=value separated by &.
|
||||
* Rather it follows the form:
|
||||
* ?<fieldname>;<fieldname>;....
|
||||
* ?metadata:<prefix>;...
|
||||
* ?children:<from>-<to>;...
|
||||
* ?value:<from>-<to>;...
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class CDMIObjectQueryParams {
|
||||
|
||||
protected String queryParams = "";
|
||||
|
||||
public CDMIObjectQueryParams() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's field value
|
||||
* @param fieldname
|
||||
* @return this
|
||||
*/
|
||||
public CDMIObjectQueryParams field(String fieldname) {
|
||||
queryParams = queryParams + fieldname + ";";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's metadata
|
||||
* @return this
|
||||
*/
|
||||
public CDMIObjectQueryParams metadata() {
|
||||
queryParams = queryParams + "metadata;";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's metadata associated with prefix
|
||||
* @param prefix
|
||||
* @return this
|
||||
*/
|
||||
public CDMIObjectQueryParams metadata(String prefix) {
|
||||
queryParams = queryParams + "metadata:"+prefix+";";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
public static CDMIObjectQueryParams field(
|
||||
String fieldname) {
|
||||
CDMIObjectQueryParams options = new CDMIObjectQueryParams();
|
||||
return (CDMIObjectQueryParams) options.field(fieldname);
|
||||
}
|
||||
public static CDMIObjectQueryParams metadata(
|
||||
String prefix) {
|
||||
CDMIObjectQueryParams options = new CDMIObjectQueryParams();
|
||||
return (CDMIObjectQueryParams) options.metadata(prefix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package org.jclouds.snia.cdmi.v1.queryparams;
|
||||
|
||||
/**
|
||||
* Generate CDMI container query parameters
|
||||
* Example:
|
||||
* container = containerApi.getContainer(containerName,ContainerQueryParams.Builder.field("parentURI"));
|
||||
* container = containerApi.getContainer(containerName,ContainerQueryParams.Builder.children(0,3));
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class ContainerQueryParams extends CDMIObjectQueryParams {
|
||||
|
||||
public ContainerQueryParams() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's field value
|
||||
* @param fieldname
|
||||
* @return this
|
||||
*/
|
||||
public ContainerQueryParams field(String fieldname) {
|
||||
super.field(fieldname);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's metadata
|
||||
* @return this
|
||||
*/
|
||||
public ContainerQueryParams metadata() {
|
||||
super.metadata();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's metadata associated with prefix
|
||||
* @param prefix
|
||||
* @return this
|
||||
*/
|
||||
public ContainerQueryParams metadata(String prefix) {
|
||||
super.metadata(prefix);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI container's children
|
||||
* @return this
|
||||
*/
|
||||
public ContainerQueryParams children() {
|
||||
queryParams = queryParams + "children;";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get CDMI container's children within range
|
||||
* @param from
|
||||
* @param to
|
||||
* @return this
|
||||
*/
|
||||
public ContainerQueryParams children(int from, int to) {
|
||||
queryParams = queryParams + "children:"+from+"-"+to+";";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
public static ContainerQueryParams field(
|
||||
String fieldname) {
|
||||
ContainerQueryParams options = new ContainerQueryParams();
|
||||
return (ContainerQueryParams) options.field(fieldname);
|
||||
}
|
||||
public static ContainerQueryParams metadata() {
|
||||
ContainerQueryParams options = new ContainerQueryParams();
|
||||
return (ContainerQueryParams) options.metadata();
|
||||
}
|
||||
|
||||
public static ContainerQueryParams metadata(
|
||||
String prefix) {
|
||||
ContainerQueryParams options = new ContainerQueryParams();
|
||||
return (ContainerQueryParams) options.metadata(prefix);
|
||||
}
|
||||
public static ContainerQueryParams children() {
|
||||
ContainerQueryParams options = new ContainerQueryParams();
|
||||
return (ContainerQueryParams) options.children();
|
||||
}
|
||||
public static ContainerQueryParams children(
|
||||
int from, int to) {
|
||||
ContainerQueryParams options = new ContainerQueryParams();
|
||||
return (ContainerQueryParams) options.children(from,to);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package org.jclouds.snia.cdmi.v1.queryparams;
|
||||
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
* Generate CDMI data object query parameters
|
||||
* Example:
|
||||
* dataObject = dataApi.getDataObject(containerName,dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI"));
|
||||
* dataObject = dataApi.getDataObject(containerName,dataObjectNameIn,DataObjectQueryParams.Builder.value());
|
||||
*
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
public class DataObjectQueryParams extends CDMIObjectQueryParams {
|
||||
|
||||
public DataObjectQueryParams() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's field value
|
||||
* @param fieldname
|
||||
* @return this
|
||||
*/
|
||||
public DataObjectQueryParams field(String fieldname) {
|
||||
super.field(fieldname);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's metadata
|
||||
* @return this
|
||||
*/
|
||||
public DataObjectQueryParams metadata() {
|
||||
super.metadata();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's metadata associated with prefix
|
||||
* @param prefix
|
||||
* @return this
|
||||
*/
|
||||
public DataObjectQueryParams metadata(String prefix) {
|
||||
super.metadata(prefix);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CDMI data object's value with range
|
||||
* @return this
|
||||
*/
|
||||
public DataObjectQueryParams value() {
|
||||
queryParams = queryParams + "value;";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get CDMI data object's value within range
|
||||
* @param from
|
||||
* @param to
|
||||
* @return this
|
||||
*/
|
||||
public DataObjectQueryParams value(int from, int to) {
|
||||
queryParams = queryParams + "value:"+from+"-"+to+";";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
public static DataObjectQueryParams field(
|
||||
String fieldname) {
|
||||
DataObjectQueryParams options = new DataObjectQueryParams();
|
||||
return (DataObjectQueryParams) options.field(fieldname);
|
||||
}
|
||||
public static DataObjectQueryParams metadata() {
|
||||
DataObjectQueryParams options = new DataObjectQueryParams();
|
||||
return (DataObjectQueryParams) options.metadata();
|
||||
}
|
||||
public static DataObjectQueryParams metadata(
|
||||
String prefix) {
|
||||
DataObjectQueryParams options = new DataObjectQueryParams();
|
||||
return (DataObjectQueryParams) options.metadata(prefix);
|
||||
}
|
||||
public static DataObjectQueryParams value() {
|
||||
DataObjectQueryParams options = new DataObjectQueryParams();
|
||||
return (DataObjectQueryParams) options.value();
|
||||
}
|
||||
public static DataObjectQueryParams value(
|
||||
int from, int to) {
|
||||
DataObjectQueryParams options = new DataObjectQueryParams();
|
||||
return (DataObjectQueryParams) options.value(from,to);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -58,7 +58,7 @@ public class ContainerApiExpectTest extends BaseCDMIApiExpectTest {
|
|||
CDMIApi apiWhenContainersExist = requestSendsResponse(getContainer, getContainerResponse);
|
||||
|
||||
assertEquals(
|
||||
apiWhenContainersExist.getContainerApi().getContainer("MyContainer"),
|
||||
apiWhenContainersExist.getContainerApi().getContainer("MyContainer/"),
|
||||
new ParseContainerTest().expected());
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.jclouds.snia.cdmi.v1.ObjectTypes;
|
|||
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||
import org.jclouds.snia.cdmi.v1.internal.BaseCDMIApiLiveTest;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.ContainerQueryParams;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -44,19 +45,23 @@ public class ContainerApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
|
||||
@Test
|
||||
public void testCreateContainer() throws Exception {
|
||||
String pContainerName = "MyContainer" + System.currentTimeMillis();
|
||||
String pContainerName = "MyContainer" + System.currentTimeMillis() + "/";
|
||||
Map<String, String> pContainerMetaDataIn = new HashMap<String, String>();
|
||||
Iterator<String> keys;
|
||||
pContainerMetaDataIn.put("containerkey1", "value1");
|
||||
pContainerMetaDataIn.put("containerkey2", "value2");
|
||||
pContainerMetaDataIn.put("containerkey3", "value3");
|
||||
|
||||
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder
|
||||
.withMetadata(pContainerMetaDataIn);
|
||||
.metadata(pContainerMetaDataIn);
|
||||
ContainerApi api = cdmiContext.getApi().getContainerApi();
|
||||
|
||||
Logger.getAnonymousLogger().info("createContainer: " + pContainerName);
|
||||
|
||||
Container container = api.createContainer(pContainerName,
|
||||
pCreateContainerOptions);
|
||||
assertNotNull(container);
|
||||
try {
|
||||
System.out.println(container);
|
||||
Logger.getAnonymousLogger().info("getContainer: " + pContainerName);
|
||||
container = api.getContainer(pContainerName);
|
||||
|
@ -65,7 +70,7 @@ public class ContainerApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
assertEquals(container.getObjectType(), ObjectTypes.CONTAINER);
|
||||
assertNotNull(container.getObjectID());
|
||||
assertNotNull(container.getObjectName());
|
||||
assertEquals(container.getObjectName(), pContainerName + "/");
|
||||
assertEquals(container.getObjectName(), pContainerName);
|
||||
assertEquals(container.getParentURI(), "/");
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().isEmpty(), true);
|
||||
|
@ -79,7 +84,8 @@ public class ContainerApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
System.out.println(key + ":" + value);
|
||||
}
|
||||
assertNotNull(container.getUserMetadata());
|
||||
Map<String, String> pContainerMetaDataOut = container.getUserMetadata();
|
||||
Map<String, String> pContainerMetaDataOut = container
|
||||
.getUserMetadata();
|
||||
keys = pContainerMetaDataIn.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
|
@ -89,24 +95,195 @@ public class ContainerApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
}
|
||||
System.out.println("UserMetaData: " + container.getUserMetadata());
|
||||
assertNotNull(container.getSystemMetadata());
|
||||
System.out.println("SystemMetaData: " + container.getSystemMetadata());
|
||||
System.out.println("SystemMetaData: "
|
||||
+ container.getSystemMetadata());
|
||||
assertNotNull(container.getACLMetadata());
|
||||
List<Map<String, String>> aclMetadataOut = container.getACLMetadata();
|
||||
assertEquals(container.getACLMetadata().size(),3);
|
||||
List<Map<String, String>> aclMetadataOut = container
|
||||
.getACLMetadata();
|
||||
System.out.println("ACLMetaData: ");
|
||||
for (Map<String, String> aclMap : aclMetadataOut) {
|
||||
System.out.println(aclMap);
|
||||
}
|
||||
container = api.getContainer("/");
|
||||
System.out.println("root container: " + container);
|
||||
assertEquals(container.getChildren().contains(pContainerName + "/"),
|
||||
assertEquals(
|
||||
container.getChildren().contains(pContainerName),
|
||||
true);
|
||||
Logger.getAnonymousLogger().info("deleteContainer: " + pContainerName);
|
||||
System.out.println("adding containers to container");
|
||||
String firstParentURI = api.getContainer(pContainerName).getObjectName();
|
||||
for(int i=0;i<10;i++) {
|
||||
// container = api.createContainer(firstParentURI+"childcontainer"+i+"/");
|
||||
container = api.createContainer(pContainerName+"childcontainer"+i+"/");
|
||||
assertNotNull(container);
|
||||
System.out.println(container);
|
||||
assertEquals(container.getParentURI(),pContainerName);
|
||||
assertEquals(container.getObjectName(),"childcontainer"+i+"/");
|
||||
container = api.createContainer(container.getParentURI()+container.getObjectName()+"grandchild/");
|
||||
assertEquals(container.getParentURI(),pContainerName+"childcontainer"+i+"/");
|
||||
assertEquals(container.getObjectName(),"grandchild/");
|
||||
System.out.println(container);
|
||||
}
|
||||
container = api.getContainer(pContainerName);
|
||||
assertNotNull(container);
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().size(), 10);
|
||||
|
||||
} finally {
|
||||
Logger.getAnonymousLogger().info(
|
||||
"deleteContainer: " + pContainerName);
|
||||
api.deleteContainer(pContainerName);
|
||||
container = api.getContainer("/");
|
||||
System.out.println("root container: " + container);
|
||||
assertEquals(container.getChildren().contains(pContainerName + "/"),
|
||||
assertEquals(
|
||||
container.getChildren().contains(pContainerName),
|
||||
false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContainer() throws Exception {
|
||||
String pContainerName = "MyContainer" + System.currentTimeMillis() + "/";
|
||||
Map<String, String> pContainerMetaDataIn = new HashMap<String, String>();
|
||||
Iterator<String> keys;
|
||||
pContainerMetaDataIn.put("containerkey1", "value1");
|
||||
pContainerMetaDataIn.put("containerkey2", "value2");
|
||||
pContainerMetaDataIn.put("containerkey3", "value3");
|
||||
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder
|
||||
.metadata(pContainerMetaDataIn);
|
||||
ContainerApi api = cdmiContext.getApi().getContainerApi();
|
||||
|
||||
Logger.getAnonymousLogger().info("createContainer: " + pContainerName);
|
||||
|
||||
Container container = api.createContainer(pContainerName,
|
||||
pCreateContainerOptions);
|
||||
assertNotNull(container);
|
||||
try {
|
||||
System.out.println(container);
|
||||
Logger.getAnonymousLogger().info("getContainer: " + pContainerName);
|
||||
container = api.getContainer(pContainerName);
|
||||
assertNotNull(container);
|
||||
System.out.println(container);
|
||||
assertEquals(container.getObjectType(), ObjectTypes.CONTAINER);
|
||||
assertNotNull(container.getObjectID());
|
||||
assertNotNull(container.getObjectName());
|
||||
assertEquals(container.getObjectName(), pContainerName);
|
||||
assertEquals(container.getParentURI(), "/");
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().isEmpty(), true);
|
||||
System.out.println("Children: " + container.getChildren());
|
||||
assertNotNull(container.getMetadata());
|
||||
System.out.println("Raw metadata: " + container.getMetadata());
|
||||
keys = container.getMetadata().keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
JsonBall value = container.getMetadata().get(key);
|
||||
System.out.println(key + ":" + value);
|
||||
}
|
||||
assertNotNull(container.getUserMetadata());
|
||||
Map<String, String> pContainerMetaDataOut = container
|
||||
.getUserMetadata();
|
||||
keys = pContainerMetaDataIn.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
assertEquals(pContainerMetaDataOut.containsKey(key), true);
|
||||
assertEquals(pContainerMetaDataOut.get(key),
|
||||
pContainerMetaDataIn.get(key));
|
||||
}
|
||||
System.out.println("UserMetaData: " + container.getUserMetadata());
|
||||
assertNotNull(container.getSystemMetadata());
|
||||
System.out.println("SystemMetaData: "
|
||||
+ container.getSystemMetadata());
|
||||
assertNotNull(container.getACLMetadata());
|
||||
List<Map<String, String>> aclMetadataOut = container
|
||||
.getACLMetadata();
|
||||
System.out.println("ACLMetaData: ");
|
||||
for (Map<String, String> aclMap : aclMetadataOut) {
|
||||
System.out.println(aclMap);
|
||||
}
|
||||
container = api.getContainer("/");
|
||||
System.out.println("root container: " + container);
|
||||
assertEquals(
|
||||
container.getChildren().contains(pContainerName),
|
||||
true);
|
||||
container = api.getContainer(pContainerName,ContainerQueryParams.Builder.field("parentURI"));
|
||||
assertNotNull(container);
|
||||
assertEquals(container.getParentURI(),"/");
|
||||
System.out.println(container);
|
||||
|
||||
container = api.getContainer(pContainerName,ContainerQueryParams.Builder.field("parentURI").field("objectName"));
|
||||
assertNotNull(container);
|
||||
assertEquals(container.getParentURI(),"/");
|
||||
assertEquals(container.getObjectName(),pContainerName);
|
||||
|
||||
container = api.getContainer(pContainerName,ContainerQueryParams.Builder.metadata());
|
||||
assertNotNull(container);
|
||||
pContainerMetaDataOut = container.getUserMetadata();
|
||||
keys = pContainerMetaDataIn.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
assertEquals(pContainerMetaDataOut.containsKey(key), true);
|
||||
assertEquals(pContainerMetaDataOut.get(key),
|
||||
pContainerMetaDataIn.get(key));
|
||||
}
|
||||
System.out.println(container);
|
||||
|
||||
System.out.println("GetContainerOptions.Builder.metadata(cdmi_acl)");
|
||||
container = api.getContainer(pContainerName,ContainerQueryParams.Builder.metadata("cdmi_acl"));
|
||||
assertNotNull(container);
|
||||
System.out.println(container);
|
||||
assertNotNull(container.getACLMetadata());
|
||||
assertEquals(container.getACLMetadata().size(),3);
|
||||
|
||||
|
||||
System.out.println("adding containers to container");
|
||||
String firstParentURI = api.getContainer(pContainerName).getObjectName();
|
||||
for(int i=0;i<10;i++) {
|
||||
container = api.createContainer(firstParentURI+"childcontainer"+i+"/");
|
||||
assertNotNull(container);
|
||||
assertEquals(container.getParentURI(),pContainerName);
|
||||
assertEquals(container.getObjectName(),"childcontainer"+i+"/");
|
||||
container = api.createContainer(container.getParentURI()+container.getObjectName()+"grandchild/",pCreateContainerOptions);
|
||||
assertEquals(container.getParentURI(),pContainerName+"childcontainer"+i+"/");
|
||||
assertEquals(container.getObjectName(),"grandchild"+"/");
|
||||
container = api.getContainer(container.getParentURI(),ContainerQueryParams.Builder.children());
|
||||
assertEquals(container.getChildren().contains("grandchild"+"/"),true);
|
||||
}
|
||||
container = api.getContainer(pContainerName,ContainerQueryParams.Builder.children());
|
||||
assertNotNull(container);
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().size(), 10);
|
||||
container = api.getContainer(pContainerName,ContainerQueryParams.Builder.children(0,3));
|
||||
assertNotNull(container);
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().size(), 4);
|
||||
|
||||
container = api.getContainer(pContainerName,ContainerQueryParams.Builder.field("parentURI").field("objectName").children().metadata());
|
||||
assertNotNull(container);
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().size(), 10);
|
||||
assertEquals(container.getParentURI(),"/");
|
||||
assertEquals(container.getObjectName(),pContainerName);
|
||||
assertEquals(container.getParentURI(),"/");
|
||||
assertEquals(container.getACLMetadata().size(),3);
|
||||
for(String childName: container.getChildren()){
|
||||
api.deleteContainer(container.getObjectName()+ childName);
|
||||
}
|
||||
assertEquals(api.getContainer(pContainerName,ContainerQueryParams.Builder.children()).getChildren().isEmpty(),true);
|
||||
|
||||
} finally {
|
||||
Logger.getAnonymousLogger().info(
|
||||
"deleteContainer: " + pContainerName);
|
||||
api.deleteContainer(pContainerName);
|
||||
container = api.getContainer("/");
|
||||
System.out.println("root container: " + container);
|
||||
assertEquals(
|
||||
container.getChildren().contains(pContainerName),
|
||||
false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ import org.jclouds.snia.cdmi.v1.domain.Container;
|
|||
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||
import org.jclouds.snia.cdmi.v1.internal.BaseCDMIApiLiveTest;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectNonCDMIOptions;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
@ -53,13 +53,18 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
@Test
|
||||
public void testCreateDataObjects() throws Exception {
|
||||
|
||||
String containerName = "MyContainer" + System.currentTimeMillis();
|
||||
String dataObjectNameIn = "dataobject1.txt";
|
||||
String containerName = "MyContainer" + System.currentTimeMillis() + "/";
|
||||
String dataObjectNameIn = "dataobject08121.txt";
|
||||
File tmpFileIn = new File("temp.txt");
|
||||
String value;
|
||||
InputStream is;
|
||||
File tmpFileOut;
|
||||
File inFile;
|
||||
Files.touch(tmpFileIn);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(bos);
|
||||
byte[] bytes;
|
||||
|
||||
CreateDataObjectOptions pCreateDataObjectOptions;
|
||||
DataObject dataObject;
|
||||
Iterator<String> keys;
|
||||
|
@ -71,7 +76,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
pDataObjectMetaDataIn.put("dataObjectkey3", "value3");
|
||||
|
||||
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder
|
||||
.withMetadata(pContainerMetaDataIn);
|
||||
.metadata(pContainerMetaDataIn);
|
||||
ContainerApi containerApi = cdmiContext.getApi()
|
||||
.getContainerApi();
|
||||
DataApi dataApi = cdmiContext.getApi().getDataApi();
|
||||
|
@ -86,34 +91,8 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().isEmpty(), true);
|
||||
|
||||
// exercise create data object with none cdmi put
|
||||
value = "Hello CDMI World1";
|
||||
CreateDataObjectNonCDMIOptions pCreateDataObjectNoneCDMIOptions = CreateDataObjectNonCDMIOptions.Builder
|
||||
.withStringPayload(value);
|
||||
dataApi.createDataObjectNonCDMI(containerName, dataObjectNameIn,
|
||||
pCreateDataObjectNoneCDMIOptions);
|
||||
System.out.println(containerApi.getContainer(containerName));
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn);
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println("value: " + dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getValueAsString(), value);
|
||||
assertEquals(dataObject.getUserMetadata().isEmpty(), true);
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
// exercise create data object with value mimetype and metadata
|
||||
value = "Hello CDMI World2";
|
||||
value = "Hello CDMI data object with value mimetype and metadata";
|
||||
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||
.value(value).mimetype("text/plain")
|
||||
.metadata(pDataObjectMetaDataIn);
|
||||
|
@ -141,9 +120,10 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName );
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
@ -177,7 +157,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -202,13 +182,13 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
assertEquals(dataObject.getValueAsString(), value);
|
||||
dataObjectMetaDataOut = dataObject.getUserMetadata();
|
||||
assertNotNull(dataObjectMetaDataOut);
|
||||
assertEquals(true, dataObjectMetaDataOut.isEmpty());
|
||||
assertEquals(dataObjectMetaDataOut.isEmpty(),true);
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -237,7 +217,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -259,13 +239,13 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
assertEquals(dataObject.getValueAsString(), value);
|
||||
dataObjectMetaDataOut = dataObject.getUserMetadata();
|
||||
assertNotNull(dataObjectMetaDataOut);
|
||||
assertEquals(true, dataObjectMetaDataOut.isEmpty());
|
||||
assertEquals(dataObjectMetaDataOut.isEmpty(),true);
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -284,11 +264,11 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println("value: " + dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getMimetype(), "");
|
||||
//assertEquals(dataObject.getMimetype(), "");
|
||||
assertEquals(dataObject.getValueAsString(), "");
|
||||
dataObjectMetaDataOut = dataObject.getUserMetadata();
|
||||
assertNotNull(dataObjectMetaDataOut);
|
||||
assertEquals(true, dataObjectMetaDataOut.isEmpty());
|
||||
//assertEquals(dataObjectMetaDataOut.isEmpty(),true);
|
||||
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
||||
|
@ -306,13 +286,13 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
assertEquals(dataObject.getValueAsString(), "");
|
||||
dataObjectMetaDataOut = dataObject.getUserMetadata();
|
||||
assertNotNull(dataObjectMetaDataOut);
|
||||
assertEquals(true, dataObjectMetaDataOut.isEmpty());
|
||||
assertEquals(dataObjectMetaDataOut.isEmpty(),true);
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -321,11 +301,11 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
|
||||
// exercise create data object with byte array
|
||||
value = "Hello CDMI World 7";
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(bos);
|
||||
out.writeUTF(value);
|
||||
out.close();
|
||||
byte[] bytes = bos.toByteArray();
|
||||
bytes = bos.toByteArray();
|
||||
// String.getBytes causes an exception CreateDataObjectOptions need to investigate byte arrays
|
||||
//bytes = value.getBytes("UTF-8");
|
||||
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||
.value(bytes);
|
||||
dataObject = dataApi.createDataObject(containerName,
|
||||
|
@ -343,7 +323,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -351,7 +331,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
// exercise create data object with an existing file
|
||||
File inFile = new File(System.getProperty("user.dir")
|
||||
inFile = new File(System.getProperty("user.dir")
|
||||
+ "/src/test/resources/container.json");
|
||||
assertEquals(true, inFile.isFile());
|
||||
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||
|
@ -373,7 +353,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
Files.toString(inFile, Charsets.UTF_8).length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -404,7 +384,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -434,7 +414,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -464,7 +444,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -497,7 +477,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
Files.toString(tmpFileIn, Charsets.UTF_8).length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -530,7 +510,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
Files.toString(tmpFileIn, Charsets.UTF_8).length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -563,7 +543,7 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
Files.toString(tmpFileIn, Charsets.ISO_8859_1).length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
|
@ -591,13 +571,12 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName + "/");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
} finally {
|
||||
tmpFileIn.delete();
|
||||
containerApi.deleteContainer(containerName);
|
||||
|
@ -606,4 +585,151 @@ public class DataApiLiveTest extends BaseCDMIApiLiveTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataObjects() throws Exception {
|
||||
|
||||
String containerName = "MyContainer" + System.currentTimeMillis() + "/";
|
||||
String dataObjectNameIn = "dataobject08121.txt";
|
||||
File tmpFileIn = new File("temp.txt");
|
||||
String value;
|
||||
Files.touch(tmpFileIn);
|
||||
|
||||
CreateDataObjectOptions pCreateDataObjectOptions;
|
||||
DataObject dataObject;
|
||||
Iterator<String> keys;
|
||||
Map<String, String> dataObjectMetaDataOut;
|
||||
Map<String, String> pContainerMetaDataIn = new HashMap<String, String>();
|
||||
Map<String, String> pDataObjectMetaDataIn = new LinkedHashMap<String, String>();
|
||||
pDataObjectMetaDataIn.put("dataObjectkey1", "value1");
|
||||
pDataObjectMetaDataIn.put("dataObjectkey2", "value2");
|
||||
pDataObjectMetaDataIn.put("dataObjectkey3", "value3");
|
||||
|
||||
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder
|
||||
.metadata(pContainerMetaDataIn);
|
||||
ContainerApi containerApi = cdmiContext.getApi()
|
||||
.getContainerApi();
|
||||
DataApi dataApi = cdmiContext.getApi().getDataApi();
|
||||
Logger.getAnonymousLogger().info("createContainer: " + containerName);
|
||||
Container container = containerApi.createContainer(containerName,
|
||||
pCreateContainerOptions);
|
||||
try {
|
||||
assertNotNull(container);
|
||||
System.out.println(container);
|
||||
container = containerApi.getContainer(containerName);
|
||||
assertNotNull(container);
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().isEmpty(), true);
|
||||
|
||||
// exercise create data object with value mimetype and metadata
|
||||
value = "Hello CDMI data object with value mimetype and metadata";
|
||||
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||
.value(value).mimetype("text/plain")
|
||||
.metadata(pDataObjectMetaDataIn);
|
||||
dataObject = dataApi.createDataObject(containerName,
|
||||
dataObjectNameIn, pCreateDataObjectOptions);
|
||||
assertNotNull(dataObject);
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn);
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println("value: " + dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getMimetype(), "text/plain");
|
||||
assertEquals(dataObject.getValueAsString(), value);
|
||||
dataObjectMetaDataOut = dataObject.getUserMetadata();
|
||||
assertNotNull(dataObjectMetaDataOut);
|
||||
keys = pDataObjectMetaDataIn.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
assertEquals(dataObjectMetaDataOut.containsKey(key), true);
|
||||
assertEquals(dataObjectMetaDataOut.get(key),
|
||||
pDataObjectMetaDataIn.get(key));
|
||||
}
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI"));
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName());
|
||||
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI").field("objectName"));
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName());
|
||||
assertEquals(dataObject.getObjectName(),dataObjectNameIn);
|
||||
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI").field("objectName").field("mimetype"));
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName());
|
||||
assertEquals(dataObject.getObjectName(),dataObjectNameIn);
|
||||
assertEquals(dataObject.getMimetype(),"text/plain");
|
||||
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI").field("objectName").field("mimetype").metadata());
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName());
|
||||
assertEquals(dataObject.getObjectName(),dataObjectNameIn);
|
||||
assertEquals(dataObject.getMimetype(),"text/plain");
|
||||
dataObjectMetaDataOut = dataObject.getUserMetadata();
|
||||
assertNotNull(dataObjectMetaDataOut);
|
||||
keys = pDataObjectMetaDataIn.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
assertEquals(dataObjectMetaDataOut.containsKey(key), true);
|
||||
assertEquals(dataObjectMetaDataOut.get(key),
|
||||
pDataObjectMetaDataIn.get(key));
|
||||
}
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn,DataObjectQueryParams.Builder.metadata("cdmi_size"));
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn,DataObjectQueryParams.Builder.field("mimetype").value());
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println(dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getMimetype(),"text/plain");
|
||||
assertEquals(dataObject.getValueAsString(),value);
|
||||
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn,DataObjectQueryParams.Builder.field("mimetype").value(0,3));
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println(dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getMimetype(),"text/plain");
|
||||
//value is SGVsbA==. This needs investigating to determine if this
|
||||
//is problem with CDMI server or the jcloud client or must understanding of spec
|
||||
|
||||
|
||||
dataApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
} finally {
|
||||
tmpFileIn.delete();
|
||||
containerApi.deleteContainer(containerName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,421 @@
|
|||
/**
|
||||
* 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.snia.cdmi.v1.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.payloads.BaseMutableContentMetadata;
|
||||
import org.jclouds.io.payloads.ByteArrayPayload;
|
||||
import org.jclouds.io.payloads.FilePayload;
|
||||
import org.jclouds.io.payloads.InputStreamPayload;
|
||||
import org.jclouds.io.payloads.StringPayload;
|
||||
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||
import org.jclouds.snia.cdmi.v1.internal.BaseCDMIApiLiveTest;
|
||||
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||
import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.net.MediaType;
|
||||
|
||||
/**
|
||||
* @author Kenneth Nagin
|
||||
*/
|
||||
@Test(groups = "live", testName = "DataNonCDMIContentTypeApiLiveTest")
|
||||
public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
|
||||
@Test
|
||||
public void testCreateDataObjectsNonCDMI() throws Exception {
|
||||
|
||||
String containerName = "MyContainer" + System.currentTimeMillis() + "/";
|
||||
String dataObjectNameIn = "dataobject.txt";
|
||||
File tmpFileIn = new File("temp.txt");
|
||||
String value;
|
||||
InputStream is;
|
||||
File tmpFileOut;
|
||||
File inFile;
|
||||
Files.touch(tmpFileIn);
|
||||
byte[] bytes;
|
||||
DataObject dataObject;
|
||||
Map<String, String> pContainerMetaDataIn = new HashMap<String, String>();
|
||||
Map<String, String> pDataObjectMetaDataIn = new LinkedHashMap<String, String>();
|
||||
pDataObjectMetaDataIn.put("dataObjectkey1", "value1");
|
||||
pDataObjectMetaDataIn.put("dataObjectkey2", "value2");
|
||||
pDataObjectMetaDataIn.put("dataObjectkey3", "value3");
|
||||
|
||||
Payload payloadIn;
|
||||
Payload payloadOut;
|
||||
FileOutputStream fos;
|
||||
|
||||
|
||||
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder
|
||||
.metadata(pContainerMetaDataIn);
|
||||
ContainerApi containerApi = cdmiContext.getApi()
|
||||
.getContainerApi();
|
||||
DataApi dataApi = cdmiContext.getApi().getDataApi();
|
||||
DataNonCDMIContentTypeApi dataNonCDMIContentTypeApi = cdmiContext.getApi().getDataNonCDMIContentTypeApi();
|
||||
Logger.getAnonymousLogger().info("createContainer: " + containerName);
|
||||
Container container = containerApi.createContainer(containerName,
|
||||
pCreateContainerOptions);
|
||||
try {
|
||||
|
||||
assertNotNull(container);
|
||||
System.out.println(container);
|
||||
container = containerApi.getContainer(containerName);
|
||||
assertNotNull(container);
|
||||
assertNotNull(container.getChildren());
|
||||
assertEquals(container.getChildren().isEmpty(), true);
|
||||
|
||||
// exercise create data object with none cdmi put with payload string.
|
||||
value = "Hello CDMI World non-cdmi String";
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn,
|
||||
value);
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn);
|
||||
assertNotNull(payloadOut);
|
||||
assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value);
|
||||
|
||||
payloadIn = new StringPayload(value);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
|
||||
.build()));
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn);
|
||||
assertNotNull(payloadOut);
|
||||
assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value);
|
||||
|
||||
dataObject = dataNonCDMIContentTypeApi.getDataObject(containerName, dataObjectNameIn,
|
||||
DataObjectQueryParams.Builder.field("parentURI"));
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
dataObject = dataNonCDMIContentTypeApi.getDataObject(containerName, dataObjectNameIn,
|
||||
DataObjectQueryParams.Builder.metadata()
|
||||
.field("parentURI")
|
||||
.field("objectName")
|
||||
.field("objectType")
|
||||
.field("mimetype"));
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(dataObject.getMimetype(),MediaType.PLAIN_TEXT_UTF_8.toString());
|
||||
|
||||
|
||||
|
||||
dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
// exercise create data object with none cdmi put with payload byte array.
|
||||
value = "Hello CDMI World non-cdmi byte array";
|
||||
bytes = value.getBytes("UTF-8");
|
||||
payloadIn = new ByteArrayPayload(bytes);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
|
||||
.build()));
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
System.out.println(containerApi.getContainer(containerName));
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn);
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println("value: " + dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getValueAsString(), value);
|
||||
assertEquals(new String(dataObject.getValueAsByteArray()), value);
|
||||
assertEquals(dataObject.getUserMetadata().isEmpty(), true);
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn);
|
||||
assertNotNull(payloadOut);
|
||||
assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value);
|
||||
|
||||
|
||||
|
||||
dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
|
||||
|
||||
|
||||
// exercise create data object with none cdmi put with payload file.
|
||||
value = "Hello CDMI World non-cdmi File";
|
||||
Files.write(value, tmpFileIn, Charsets.UTF_8);
|
||||
payloadIn = new FilePayload(tmpFileIn);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
|
||||
.build()));
|
||||
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
System.out.println(containerApi.getContainer(containerName));
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn);
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println("value: " + dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getValueAsString(), value);
|
||||
tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
|
||||
assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
|
||||
tmpFileOut.delete();
|
||||
assertEquals(dataObject.getUserMetadata().isEmpty(), true);
|
||||
System.out.println("My Metadata: "+dataObject.getUserMetadata());
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn);
|
||||
assertNotNull(payloadOut);
|
||||
//assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value);
|
||||
//byte[] _bytes = ByteStreams.toByteArray(payloadOut.getInput());
|
||||
tmpFileOut = new File(Files.createTempDir(),"temp.txt");
|
||||
fos = new FileOutputStream(tmpFileOut);
|
||||
ByteStreams.copy(payloadOut.getInput(), fos);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
assertEquals(Files.equal(tmpFileOut, tmpFileIn),true);
|
||||
tmpFileOut.delete();
|
||||
|
||||
dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
// exercise create data object with none cdmi put with text file payload file.
|
||||
inFile = new File(System.getProperty("user.dir")
|
||||
+ "/src/test/resources/container.json");
|
||||
assertEquals(true, inFile.isFile());
|
||||
payloadIn = new FilePayload(inFile);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.JSON_UTF_8.toString())
|
||||
.build()));
|
||||
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, inFile.getName(),
|
||||
payloadIn);
|
||||
System.out.println(containerApi.getContainer(containerName));
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
inFile.getName());
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
//System.out.println("value: " + dataObject.getValueAsString());
|
||||
//assertEquals(dataObject.getValueAsString(), value);
|
||||
tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
|
||||
assertEquals(true, Files.equal(tmpFileOut, inFile));
|
||||
tmpFileOut.delete();
|
||||
assertEquals(dataObject.getUserMetadata().isEmpty(), true);
|
||||
//System.out.println("My Metadata: "+dataObject.getUserMetadata());
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), inFile.length());
|
||||
assertEquals(dataObject.getObjectName(), inFile.getName());
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(inFile.getName()), true);
|
||||
dataApi.deleteDataObject(containerName, inFile.getName());
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
// exercise create data object with none cdmi put with text file payload file.
|
||||
//inFile = new File(System.getProperty("user.dir")
|
||||
// + "/src/test/resources/Jellyfish.jpg"); // takes too long when working from home
|
||||
inFile = new File(System.getProperty("user.dir")
|
||||
+ "/src/test/resources/yellow-flowers.jpg");
|
||||
assertEquals(true, inFile.isFile());
|
||||
payloadIn = new FilePayload(inFile);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.JPEG.toString())
|
||||
.build()));
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, inFile.getName(),
|
||||
payloadIn);
|
||||
System.out.println(containerApi.getContainer(containerName));
|
||||
//note dataApi.getDataObject when the data object is not a string
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, inFile.getName());
|
||||
assertNotNull(payloadOut);
|
||||
tmpFileOut = new File(Files.createTempDir(),"temp.jpg");
|
||||
fos = new FileOutputStream(tmpFileOut);
|
||||
ByteStreams.copy(payloadOut.getInput(), fos);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
assertEquals(Files.equal(tmpFileOut, inFile),true);
|
||||
tmpFileOut.delete();
|
||||
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(inFile.getName()), true);
|
||||
dataApi.deleteDataObject(containerName, inFile.getName());
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(inFile.getName()), false);
|
||||
|
||||
|
||||
// exercise create data object with none cdmi put with payload inputStream riginating from string.
|
||||
value = "Hello CDMI World non-cdmi inputStream originating from string";
|
||||
is = new ByteArrayInputStream(value.getBytes());
|
||||
payloadIn = new InputStreamPayload(is);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
|
||||
.contentLength(new Long(value.length()))
|
||||
.build()));
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
System.out.println(containerApi.getContainer(containerName));
|
||||
dataObject = dataApi.getDataObject(containerName,
|
||||
dataObjectNameIn);
|
||||
assertNotNull(dataObject);
|
||||
System.out.println(dataObject);
|
||||
System.out.println("value: " + dataObject.getValueAsString());
|
||||
assertEquals(dataObject.getValueAsString(), value);
|
||||
assertNotNull(dataObject.getValueAsInputSupplier());
|
||||
assertEquals(CharStreams.toString(CharStreams.newReaderSupplier(dataObject
|
||||
.getValueAsInputSupplier(Charsets.UTF_8),Charsets.UTF_8)), value);
|
||||
assertEquals(dataObject.getUserMetadata().isEmpty(), true);
|
||||
System.out.println("My Metadata: "+dataObject.getUserMetadata());
|
||||
assertEquals(
|
||||
Integer.parseInt(dataObject.getSystemMetadata().get(
|
||||
"cdmi_size")), value.length());
|
||||
assertEquals(dataObject.getObjectName(), dataObjectNameIn);
|
||||
assertEquals(dataObject.getObjectType(), "application/cdmi-object");
|
||||
assertEquals(dataObject.getParentURI(), "/" + containerName);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), true);
|
||||
dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
// exercise create data object with none cdmi put with payload inputStream originating from jpeg file.
|
||||
inFile = new File(System.getProperty("user.dir")
|
||||
+ "/src/test/resources/yellow-flowers.jpg");
|
||||
assertEquals(true, inFile.isFile());
|
||||
FileInputStream fileInputStream = new FileInputStream(inFile);
|
||||
payloadIn = new InputStreamPayload(fileInputStream);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.JPEG.toString())
|
||||
.contentLength(new Long(inFile.length()))
|
||||
.build()));
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, inFile.getName(),
|
||||
payloadIn);
|
||||
System.out.println(containerApi.getContainer(containerName));
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, inFile.getName());
|
||||
assertNotNull(payloadOut);
|
||||
tmpFileOut = new File(Files.createTempDir(),"temp.jpg");
|
||||
fos = new FileOutputStream(tmpFileOut);
|
||||
ByteStreams.copy(payloadOut.getInput(), fos);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
assertEquals(Files.equal(tmpFileOut, inFile),true);
|
||||
tmpFileOut.delete();
|
||||
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(inFile.getName()), true);
|
||||
dataApi.deleteDataObject(containerName, inFile.getName());
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(inFile.getName()), false);
|
||||
|
||||
// exercise get with none cdmi get range.
|
||||
value = "Hello CDMI World non-cdmi String";
|
||||
payloadIn = new StringPayload(value);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
|
||||
.build()));
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn, "bytes=0-10");
|
||||
assertNotNull(payloadOut);
|
||||
assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value.substring(0, 11));
|
||||
assertEquals(payloadOut.getContentMetadata().getContentLength(),new Long(11));
|
||||
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn, "bytes=11-20");
|
||||
assertNotNull(payloadOut);
|
||||
assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value.substring(11, 21));
|
||||
assertEquals(payloadOut.getContentMetadata().getContentLength(),new Long(10));
|
||||
|
||||
dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn);
|
||||
assertEquals(containerApi.getContainer(containerName)
|
||||
.getChildren().contains(dataObjectNameIn), false);
|
||||
|
||||
// exercise create data object with none cdmi partial.
|
||||
// server does not actually support cdmi partial but
|
||||
// trace allows me to see that request was constructed properly
|
||||
value = "Hello CDMI World non-cdmi String";
|
||||
payloadIn = new StringPayload(value);
|
||||
payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder()
|
||||
.contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
|
||||
.build()));
|
||||
dataNonCDMIContentTypeApi.createDataObjectPartial(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn);
|
||||
assertNotNull(payloadOut);
|
||||
System.out.println("payload "+payloadOut);
|
||||
|
||||
dataNonCDMIContentTypeApi.createDataObjectPartial(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn);
|
||||
assertNotNull(payloadOut);
|
||||
System.out.println("payload "+payloadOut);
|
||||
|
||||
|
||||
|
||||
dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn,
|
||||
payloadIn);
|
||||
|
||||
|
||||
payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn);
|
||||
assertNotNull(payloadOut);
|
||||
System.out.println("payload "+payloadOut);
|
||||
|
||||
|
||||
} finally {
|
||||
tmpFileIn.delete();
|
||||
containerApi.deleteContainer(containerName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 758 KiB |
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue