mirror of https://github.com/apache/jclouds.git
Issue 15: removed abandoned jets3t module
This commit is contained in:
parent
a9794364da
commit
93d420c114
|
@ -1,27 +0,0 @@
|
|||
====
|
||||
|
||||
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
====================================================================
|
||||
====
|
||||
|
||||
#
|
||||
# A JetS3t (http://jets3t.s3.amazonaws.com/) S3Service implementation using
|
||||
# jclouds. Can be used on Google App Engine.
|
||||
#
|
||||
# Expects jets3t to be present on your application's classpath.
|
||||
#
|
||||
# TODO: Supported features.
|
||||
# TODO: Usage example.
|
|
@ -1,48 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-aws-extensions-project</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>jclouds-jets3t</artifactId>
|
||||
<name>jclouds JetS3t Adapter</name>
|
||||
<description>JetS3t plug-in implemented by JClouds</description>
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk</connection>
|
||||
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk</developerConnection>
|
||||
<url>http://jclouds.googlecode.com/svn/trunk</url>
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jets3t</groupId>
|
||||
<artifactId>jets3t</artifactId>
|
||||
<version>0.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,356 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.aws.s3.jets3t;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.s3.S3Client;
|
||||
import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore;
|
||||
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
||||
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
||||
import org.jclouds.aws.s3.options.CopyObjectOptions;
|
||||
import org.jclouds.aws.s3.options.ListBucketOptions;
|
||||
import org.jclouds.aws.s3.options.PutObjectOptions;
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jets3t.service.S3ObjectsChunk;
|
||||
import org.jets3t.service.S3Service;
|
||||
import org.jets3t.service.S3ServiceException;
|
||||
import org.jets3t.service.acl.AccessControlList;
|
||||
import org.jets3t.service.model.S3Bucket;
|
||||
import org.jets3t.service.model.S3BucketLoggingStatus;
|
||||
import org.jets3t.service.model.S3Object;
|
||||
import org.jets3t.service.security.AWSCredentials;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* A JetS3t S3Service implemented by JClouds
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author James Murty
|
||||
*/
|
||||
public class JCloudsS3Service extends S3Service {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final BlobStoreContext context;
|
||||
private final S3Client connection;
|
||||
|
||||
/**
|
||||
* Initializes a JClouds context to S3.
|
||||
*
|
||||
* @param awsCredentials
|
||||
* - credentials to access S3
|
||||
* @param modules
|
||||
* - Module that configures a FutureHttpClient, if not specified, default is
|
||||
* URLFetchServiceClientModule
|
||||
* @throws S3ServiceException
|
||||
*/
|
||||
protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules) throws S3ServiceException {
|
||||
super(awsCredentials);
|
||||
context = new BlobStoreContextFactory().createContext("s3", awsCredentials.getAccessKey(), awsCredentials
|
||||
.getSecretKey(), ImmutableList.<Module> copyOf(modules));
|
||||
connection = (S3Client) context.getProviderSpecificContext().getApi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkBucketStatus(final String bucketName) throws S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Map copyObjectImpl(String sourceBucketName, String sourceObjectKey, String destinationBucketName,
|
||||
String destinationObjectKey, AccessControlList acl, Map destinationMetadata, Calendar ifModifiedSince,
|
||||
Calendar ifUnmodifiedSince, String[] ifMatchTags, String[] ifNoneMatchTags) throws S3ServiceException {
|
||||
try {
|
||||
CopyObjectOptions options = Util.convertCopyObjectOptions(acl, destinationMetadata, ifModifiedSince,
|
||||
ifUnmodifiedSince, ifMatchTags, ifNoneMatchTags);
|
||||
ObjectMetadata jcObjectMetadata = connection.copyObject(sourceBucketName, sourceObjectKey,
|
||||
destinationBucketName, destinationObjectKey, options);
|
||||
|
||||
Map map = new HashMap();
|
||||
// Result fields returned when copy is successful.
|
||||
map.put("Last-Modified", jcObjectMetadata.getLastModified());
|
||||
map.put("ETag", jcObjectMetadata.getETag());
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error copying object", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3Bucket createBucketImpl(String bucketName, String location, AccessControlList acl)
|
||||
throws S3ServiceException {
|
||||
if (location != null)
|
||||
throw new UnsupportedOperationException("Bucket location is not yet supported");
|
||||
if (acl != null)
|
||||
throw new UnsupportedOperationException("Bucket ACL is not yet supported");
|
||||
|
||||
try {
|
||||
if (connection.putBucketInRegion(null, bucketName)) {
|
||||
// Bucket created.
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error creating bucket: " + bucketName, e);
|
||||
}
|
||||
return new S3Bucket(bucketName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see S3AsyncBlobStore#deleteContainer(String)
|
||||
*/
|
||||
@Override
|
||||
protected void deleteBucketImpl(String bucketName) throws S3ServiceException {
|
||||
try {
|
||||
connection.deleteBucketIfEmpty(bucketName);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error deleting bucket: " + bucketName, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see S3AsyncBlobStore#removeBlob(String, String)
|
||||
*/
|
||||
@Override
|
||||
protected void deleteObjectImpl(String bucketName, String objectKey) throws S3ServiceException {
|
||||
try {
|
||||
connection.deleteObject(bucketName, objectKey);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException(String.format("error deleting object: %1$s:%2$s", bucketName, objectKey), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AccessControlList getBucketAclImpl(String bucketName) throws S3ServiceException {
|
||||
try {
|
||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = connection.getBucketACL(bucketName);
|
||||
return Util.convertAccessControlList(jcACL);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error getting bucket's ACL: " + bucketName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketLocationImpl(String bucketName) throws S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3BucketLoggingStatus getBucketLoggingStatusImpl(String bucketName) throws S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AccessControlList getObjectAclImpl(String bucketName, String objectKey) throws S3ServiceException {
|
||||
try {
|
||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = connection.getObjectACL(bucketName, objectKey);
|
||||
return Util.convertAccessControlList(jcACL);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error getting object's ACL", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3Object getObjectDetailsImpl(String bucketName, String objectKey, Calendar ifModifiedSince,
|
||||
Calendar ifUnmodifiedSince, String[] ifMatchTags, String[] ifNoneMatchTags) throws S3ServiceException {
|
||||
try {
|
||||
if (ifModifiedSince != null)
|
||||
throw new IllegalArgumentException("ifModifiedSince");
|
||||
if (ifUnmodifiedSince != null)
|
||||
throw new IllegalArgumentException("ifUnmodifiedSince");
|
||||
if (ifMatchTags != null)
|
||||
throw new IllegalArgumentException("ifMatchTags");
|
||||
if (ifNoneMatchTags != null)
|
||||
throw new IllegalArgumentException("ifNoneMatchTags");
|
||||
|
||||
return Util.convertObjectHead(connection.headObject(bucketName, objectKey));
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException(String.format("error retrieving object head: %1$s:%2$s", bucketName, objectKey),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3Object getObjectImpl(String bucketName, String objectKey, Calendar ifModifiedSince,
|
||||
Calendar ifUnmodifiedSince, String[] ifMatchTags, String[] ifNoneMatchTags, Long byteRangeStart,
|
||||
Long byteRangeEnd) throws S3ServiceException {
|
||||
try {
|
||||
GetOptions options = Util.convertGetObjectOptions(ifModifiedSince, ifUnmodifiedSince, ifMatchTags,
|
||||
ifNoneMatchTags);
|
||||
return Util.convertObject(connection.getObject(bucketName, objectKey, options));
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException(String.format("error retrieving object: %1$s:%2$s", bucketName, objectKey), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBucketAccessible(String bucketName) throws S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRequesterPaysBucketImpl(String bucketName) throws S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3Bucket[] listAllBucketsImpl() throws S3ServiceException {
|
||||
try {
|
||||
Set<org.jclouds.aws.s3.domain.BucketMetadata> jcBucketList = connection.listOwnedBuckets();
|
||||
return Util.convertBuckets(jcBucketList);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error listing buckets", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3ObjectsChunk listObjectsChunkedImpl(String bucketName, String prefix, String delimiter,
|
||||
long maxListingLength, String priorLastKey, boolean completeListing) throws S3ServiceException {
|
||||
try {
|
||||
List<S3Object> jsObjects = new ArrayList<S3Object>();
|
||||
List<String> commonPrefixes = new ArrayList<String>();
|
||||
ListBucketResponse jcBucket = null;
|
||||
do {
|
||||
ListBucketOptions options = Util.convertListObjectOptions(prefix, priorLastKey, delimiter,
|
||||
(int) maxListingLength);
|
||||
|
||||
jcBucket = connection.listBucket(bucketName, options);
|
||||
|
||||
jsObjects.addAll(Arrays.asList(Util.convertObjectHeads(jcBucket)));
|
||||
commonPrefixes.addAll(jcBucket.getCommonPrefixes());
|
||||
if (jcBucket.isTruncated()) {
|
||||
priorLastKey = jsObjects.get(jsObjects.size() - 1).getKey();
|
||||
} else {
|
||||
priorLastKey = null;
|
||||
}
|
||||
} while (completeListing && jcBucket.isTruncated()); // Build entire listing if requested
|
||||
|
||||
return new S3ObjectsChunk(
|
||||
prefix, // Return the supplied prefix, not the one in the S3
|
||||
// response.
|
||||
jcBucket.getDelimiter(), (S3Object[]) jsObjects.toArray(new S3Object[jsObjects.size()]),
|
||||
(String[]) commonPrefixes.toArray(new String[commonPrefixes.size()]), priorLastKey);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error listing objects in bucket " + bucketName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3Object[] listObjectsImpl(String bucketName, String prefix, String delimiter, long maxListingLength)
|
||||
throws S3ServiceException {
|
||||
try {
|
||||
return listObjectsChunked(bucketName, prefix, delimiter, maxListingLength, null, true).getObjects();
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error listing objects in bucket " + bucketName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putBucketAclImpl(String bucketName, AccessControlList jsACL) throws S3ServiceException {
|
||||
try {
|
||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = Util.convertAccessControlList(jsACL);
|
||||
connection.putBucketACL(bucketName, jcACL);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error putting bucket's ACL: " + bucketName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putObjectAclImpl(String bucketName, String objectKey, AccessControlList jsACL)
|
||||
throws S3ServiceException {
|
||||
try {
|
||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = Util.convertAccessControlList(jsACL);
|
||||
connection.putObjectACL(bucketName, objectKey, jcACL);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error putting object's ACL", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3Object putObjectImpl(String bucketName, S3Object jsObject) throws S3ServiceException {
|
||||
try {
|
||||
PutObjectOptions options = Util.convertPutObjectOptions(jsObject.getAcl());
|
||||
org.jclouds.aws.s3.domain.S3Object jcObject = Util.convertObject(jsObject, connection.newS3Object());
|
||||
String eTag = connection.putObject(bucketName, jcObject, options);
|
||||
jsObject.setETag(eTag);
|
||||
return jsObject;
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, S3ServiceException.class);
|
||||
throw new S3ServiceException("error putting object", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setBucketLoggingStatusImpl(String bucketName, S3BucketLoggingStatus status) throws S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setRequesterPaysBucketImpl(String bucketName, boolean requesterPays) throws S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
}
|
||||
|
||||
protected org.jets3t.service.model.S3Owner getAccountOwnerImpl() throws org.jets3t.service.S3ServiceException {
|
||||
// TODO Unimplemented
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,343 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.aws.s3.jets3t;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.aws.s3.domain.CannedAccessPolicy;
|
||||
import org.jclouds.aws.s3.domain.CanonicalUser;
|
||||
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
||||
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
||||
import org.jclouds.aws.s3.domain.ObjectMetadata.StorageClass;
|
||||
import org.jclouds.aws.s3.options.CopyObjectOptions;
|
||||
import org.jclouds.aws.s3.options.ListBucketOptions;
|
||||
import org.jclouds.aws.s3.options.PutObjectOptions;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jets3t.service.S3ServiceException;
|
||||
import org.jets3t.service.acl.AccessControlList;
|
||||
import org.jets3t.service.acl.CanonicalGrantee;
|
||||
import org.jets3t.service.acl.EmailAddressGrantee;
|
||||
import org.jets3t.service.acl.GrantAndPermission;
|
||||
import org.jets3t.service.acl.GranteeInterface;
|
||||
import org.jets3t.service.acl.GroupGrantee;
|
||||
import org.jets3t.service.acl.Permission;
|
||||
import org.jets3t.service.model.S3Bucket;
|
||||
import org.jets3t.service.model.S3Object;
|
||||
import org.jets3t.service.model.S3Owner;
|
||||
import org.jets3t.service.utils.RestUtils;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* Convert between jCloud and JetS3t objects.
|
||||
*
|
||||
* @author James Murty
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
public static S3Bucket convertBucket(org.jclouds.aws.s3.domain.BucketMetadata jcBucketMD) {
|
||||
S3Bucket jsBucket = new S3Bucket(jcBucketMD.getName());
|
||||
if (jcBucketMD.getOwner() != null) {
|
||||
jsBucket.setOwner(new S3Owner(jcBucketMD.getOwner().getId(), jcBucketMD.getOwner().getDisplayName()));
|
||||
}
|
||||
return jsBucket;
|
||||
}
|
||||
|
||||
public static S3Bucket[] convertBuckets(Set<org.jclouds.aws.s3.domain.BucketMetadata> jcBucketMDs) {
|
||||
List<S3Bucket> jsBuckets = new ArrayList<S3Bucket>(jcBucketMDs.size());
|
||||
for (org.jclouds.aws.s3.domain.BucketMetadata jcBucketMD : jcBucketMDs) {
|
||||
jsBuckets.add(convertBucket(jcBucketMD));
|
||||
}
|
||||
return (S3Bucket[]) jsBuckets.toArray(new S3Bucket[jsBuckets.size()]);
|
||||
}
|
||||
|
||||
public static S3Object[] convertObjectHeads(ListBucketResponse jcBucket) {
|
||||
List<S3Object> jsObjects = new ArrayList<S3Object>(jcBucket.size());
|
||||
for (ObjectMetadata jcObjectMD : jcBucket) {
|
||||
jsObjects.add(convertObjectHead(jcObjectMD));
|
||||
}
|
||||
return (S3Object[]) jsObjects.toArray(new S3Object[jsObjects.size()]);
|
||||
}
|
||||
|
||||
public static S3Object convertObjectHead(ObjectMetadata jcObjectMD) {
|
||||
S3Object jsObject = new S3Object(jcObjectMD.getKey());
|
||||
if (jcObjectMD.getOwner() != null) {
|
||||
jsObject.setOwner(new S3Owner(jcObjectMD.getOwner().getId(), jcObjectMD.getOwner().getDisplayName()));
|
||||
}
|
||||
jsObject.setContentLength(jcObjectMD.getSize());
|
||||
jsObject.setContentDisposition(jcObjectMD.getContentDisposition());
|
||||
jsObject.setContentEncoding(jcObjectMD.getContentEncoding());
|
||||
jsObject.setLastModifiedDate(jcObjectMD.getLastModified());
|
||||
jsObject.setETag(jcObjectMD.getETag());
|
||||
jsObject.setMd5Hash(jcObjectMD.getContentMD5());
|
||||
jsObject.addAllMetadata(jcObjectMD.getUserMetadata());
|
||||
jsObject.addMetadata(S3Object.METADATA_HEADER_DATE, jcObjectMD.getLastModified());
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
public static S3Object convertObject(org.jclouds.aws.s3.domain.S3Object jcObject) {
|
||||
S3Object jsObject = convertObjectHead(jcObject.getMetadata());
|
||||
if (jcObject.getPayload().getInput() != null) {
|
||||
jsObject.setDataInputStream(jcObject.getPayload().getInput());
|
||||
}
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
public static S3Object[] convertObjects(List<org.jclouds.aws.s3.domain.S3Object> jcObjects) {
|
||||
List<S3Object> jsObjects = new ArrayList<S3Object>(jcObjects.size());
|
||||
for (org.jclouds.aws.s3.domain.S3Object jcObject : jcObjects) {
|
||||
jsObjects.add(convertObject(jcObject));
|
||||
}
|
||||
return (S3Object[]) jsObjects.toArray(new S3Object[jsObjects.size()]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static org.jclouds.aws.s3.domain.S3Object convertObject(S3Object jsObject,
|
||||
org.jclouds.aws.s3.domain.S3Object jcObject) throws S3ServiceException {
|
||||
if (jsObject.getDataInputStream() != null) {
|
||||
jcObject.setPayload(jsObject.getDataInputStream());
|
||||
} else {
|
||||
jcObject.setPayload(""); // Must explicitly set data for empty jClouds objects.
|
||||
}
|
||||
jcObject.getPayload().setContentLength(jsObject.getContentLength());
|
||||
|
||||
jcObject.getMetadata().setKey(jsObject.getKey());
|
||||
jcObject.getMetadata().setCacheControl((String) jsObject.getMetadata("Cache-Control"));
|
||||
jcObject.getMetadata().setContentDisposition(jsObject.getContentDisposition());
|
||||
jcObject.getMetadata().setContentEncoding(jsObject.getContentEncoding());
|
||||
jcObject.getMetadata().setLastModified(jsObject.getLastModifiedDate());
|
||||
if (jsObject.getStorageClass() != null)
|
||||
jcObject.getMetadata().setStorageClass(StorageClass.valueOf(jsObject.getStorageClass()));
|
||||
|
||||
if (jsObject.getMd5HashAsHex() != null) {
|
||||
jcObject.getMetadata().setETag(jsObject.getMd5HashAsHex());
|
||||
}
|
||||
|
||||
if (jsObject.getOwner() != null) {
|
||||
jcObject.getMetadata().setOwner(new CanonicalUser(jsObject.getOwner().getId()));
|
||||
}
|
||||
|
||||
if (jsObject.getContentType() != null) {
|
||||
jcObject.getMetadata().setContentType(jsObject.getContentType());
|
||||
} else {
|
||||
// Must always provide a content type for jClouds objects.
|
||||
jcObject.getMetadata().setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
jsObject.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
}
|
||||
|
||||
// User metadata
|
||||
DateService dateService = new SimpleDateFormatDateService();
|
||||
for (Object maybeUserMetadataObj : jsObject.getMetadataMap().entrySet()) {
|
||||
String name = ((Entry<String, Object>) maybeUserMetadataObj).getKey();
|
||||
Object value = ((Entry<String, Object>) maybeUserMetadataObj).getValue();
|
||||
if (!RestUtils.HTTP_HEADER_METADATA_NAMES.contains(name.toLowerCase())) {
|
||||
if (value instanceof Date) {
|
||||
value = dateService.rfc822DateFormat((Date) value);
|
||||
}
|
||||
jcObject.getMetadata().getUserMetadata().put(name, (String) value);
|
||||
}
|
||||
}
|
||||
|
||||
return jcObject;
|
||||
}
|
||||
|
||||
public static GetOptions convertGetObjectOptions(Calendar ifModifiedSince, Calendar ifUnmodifiedSince,
|
||||
String[] ifMatchTags, String[] ifNoneMatchTags) throws UnsupportedEncodingException {
|
||||
GetOptions options = new GetOptions();
|
||||
if (ifModifiedSince != null) {
|
||||
options.ifModifiedSince(ifModifiedSince.getTime());
|
||||
}
|
||||
if (ifUnmodifiedSince != null) {
|
||||
options.ifUnmodifiedSince(ifUnmodifiedSince.getTime());
|
||||
}
|
||||
// TODO: options.ifETagMatches should accept multiple match tags
|
||||
if (ifMatchTags != null && ifMatchTags.length > 0) {
|
||||
options.ifETagMatches(ifMatchTags[0]);
|
||||
}
|
||||
// TODO: options.ifETagDoesntMatch should accept multiple match tags
|
||||
if (ifNoneMatchTags != null && ifNoneMatchTags.length > 0) {
|
||||
options.ifETagDoesntMatch(ifNoneMatchTags[0]);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
public static ListBucketOptions convertListObjectOptions(String prefix, String marker, String delimiter,
|
||||
Integer maxKeys) throws UnsupportedEncodingException {
|
||||
ListBucketOptions options = new ListBucketOptions();
|
||||
if (prefix != null) {
|
||||
options.withPrefix(prefix);
|
||||
}
|
||||
if (marker != null) {
|
||||
options.afterMarker(marker);
|
||||
}
|
||||
if (maxKeys != null) {
|
||||
options.maxResults(maxKeys);
|
||||
}
|
||||
if (delimiter != null) {
|
||||
options.delimiter(delimiter);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
public static CannedAccessPolicy convertACLToCannedAccessPolicy(AccessControlList acl) {
|
||||
if (acl == null) {
|
||||
return null;
|
||||
} else if (acl == AccessControlList.REST_CANNED_AUTHENTICATED_READ) {
|
||||
return CannedAccessPolicy.AUTHENTICATED_READ;
|
||||
} else if (acl == AccessControlList.REST_CANNED_PRIVATE) {
|
||||
return CannedAccessPolicy.PRIVATE;
|
||||
} else if (acl == AccessControlList.REST_CANNED_PUBLIC_READ) {
|
||||
return CannedAccessPolicy.PUBLIC_READ;
|
||||
} else if (acl == AccessControlList.REST_CANNED_PUBLIC_READ_WRITE) {
|
||||
return CannedAccessPolicy.PUBLIC_READ_WRITE;
|
||||
}
|
||||
throw new IllegalArgumentException("Only 'canned' AccessControlList options are supported: " + acl);
|
||||
}
|
||||
|
||||
public static AccessControlList convertAccessControlList(org.jclouds.aws.s3.domain.AccessControlList jcACL) {
|
||||
AccessControlList jsACL = new AccessControlList();
|
||||
if (jcACL.getOwner() != null) {
|
||||
jsACL.setOwner(new S3Owner(jcACL.getOwner().getId(), jcACL.getOwner().getDisplayName()));
|
||||
}
|
||||
for (org.jclouds.aws.s3.domain.AccessControlList.Grant jcGrant : jcACL.getGrants()) {
|
||||
Permission jsPermission = null;
|
||||
org.jclouds.aws.s3.domain.AccessControlList.Permission jcPerm = jcGrant.getPermission();
|
||||
if (org.jclouds.aws.s3.domain.AccessControlList.Permission.FULL_CONTROL == jcPerm) {
|
||||
jsPermission = Permission.PERMISSION_FULL_CONTROL;
|
||||
} else if (org.jclouds.aws.s3.domain.AccessControlList.Permission.READ == jcPerm) {
|
||||
jsPermission = Permission.PERMISSION_READ;
|
||||
} else if (org.jclouds.aws.s3.domain.AccessControlList.Permission.READ_ACP == jcPerm) {
|
||||
jsPermission = Permission.PERMISSION_READ_ACP;
|
||||
} else if (org.jclouds.aws.s3.domain.AccessControlList.Permission.WRITE == jcPerm) {
|
||||
jsPermission = Permission.PERMISSION_WRITE;
|
||||
} else if (org.jclouds.aws.s3.domain.AccessControlList.Permission.WRITE_ACP == jcPerm) {
|
||||
jsPermission = Permission.PERMISSION_WRITE_ACP;
|
||||
}
|
||||
|
||||
GranteeInterface jsGrantee = null;
|
||||
org.jclouds.aws.s3.domain.AccessControlList.Grantee jcGrantee = jcGrant.getGrantee();
|
||||
if (jcGrantee instanceof org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee) {
|
||||
jsGrantee = new EmailAddressGrantee(jcGrantee.getIdentifier());
|
||||
} else if (jcGrantee instanceof org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee) {
|
||||
jsGrantee = new CanonicalGrantee(jcGrantee.getIdentifier());
|
||||
} else if (jcGrantee instanceof org.jclouds.aws.s3.domain.AccessControlList.GroupGrantee) {
|
||||
jsGrantee = new GroupGrantee(jcGrantee.getIdentifier());
|
||||
}
|
||||
|
||||
jsACL.grantPermission(jsGrantee, jsPermission);
|
||||
}
|
||||
return jsACL;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static org.jclouds.aws.s3.domain.AccessControlList convertAccessControlList(AccessControlList jsACL) {
|
||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = new org.jclouds.aws.s3.domain.AccessControlList();
|
||||
if (jsACL.getOwner() != null) {
|
||||
jcACL.setOwner(new org.jclouds.aws.s3.domain.CanonicalUser(jsACL.getOwner().getId()));
|
||||
}
|
||||
Iterator jsGrantAndPermissionIter = jsACL.getGrants().iterator();
|
||||
while (jsGrantAndPermissionIter.hasNext()) {
|
||||
GrantAndPermission jsGrantAndPermission = (GrantAndPermission) jsGrantAndPermissionIter.next();
|
||||
|
||||
org.jclouds.aws.s3.domain.AccessControlList.Permission jcPermission = null;
|
||||
Permission jsPerm = jsGrantAndPermission.getPermission();
|
||||
if (Permission.PERMISSION_FULL_CONTROL == jsPerm) {
|
||||
jcPermission = org.jclouds.aws.s3.domain.AccessControlList.Permission.FULL_CONTROL;
|
||||
} else if (Permission.PERMISSION_READ == jsPerm) {
|
||||
jcPermission = org.jclouds.aws.s3.domain.AccessControlList.Permission.READ;
|
||||
} else if (Permission.PERMISSION_READ_ACP == jsPerm) {
|
||||
jcPermission = org.jclouds.aws.s3.domain.AccessControlList.Permission.READ_ACP;
|
||||
} else if (Permission.PERMISSION_WRITE == jsPerm) {
|
||||
jcPermission = org.jclouds.aws.s3.domain.AccessControlList.Permission.WRITE;
|
||||
} else if (Permission.PERMISSION_WRITE_ACP == jsPerm) {
|
||||
jcPermission = org.jclouds.aws.s3.domain.AccessControlList.Permission.WRITE_ACP;
|
||||
}
|
||||
|
||||
org.jclouds.aws.s3.domain.AccessControlList.Grantee jcGrantee = null;
|
||||
GranteeInterface jsGrantee = jsGrantAndPermission.getGrantee();
|
||||
if (jsGrantee instanceof EmailAddressGrantee) {
|
||||
jcGrantee = new org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee(jsGrantee.getIdentifier());
|
||||
} else if (jsGrantee instanceof CanonicalGrantee) {
|
||||
jcGrantee = new org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee(jsGrantee.getIdentifier());
|
||||
} else if (jsGrantee instanceof GroupGrantee) {
|
||||
jcGrantee = new org.jclouds.aws.s3.domain.AccessControlList.GroupGrantee(
|
||||
org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI.fromURI(jsGrantee.getIdentifier()));
|
||||
}
|
||||
|
||||
jcACL.addPermission(jcGrantee, jcPermission);
|
||||
}
|
||||
return jcACL;
|
||||
}
|
||||
|
||||
public static PutObjectOptions convertPutObjectOptions(AccessControlList acl) {
|
||||
PutObjectOptions options = new PutObjectOptions();
|
||||
if (acl != null) {
|
||||
options.withAcl(convertACLToCannedAccessPolicy(acl));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static CopyObjectOptions convertCopyObjectOptions(AccessControlList acl, Map destinationMetadata,
|
||||
Calendar ifModifiedSince, Calendar ifUnmodifiedSince, String[] ifMatchTags, String[] ifNoneMatchTags)
|
||||
throws UnsupportedEncodingException {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
if (acl != null) {
|
||||
options.overrideAcl(convertACLToCannedAccessPolicy(acl));
|
||||
}
|
||||
if (ifModifiedSince != null) {
|
||||
options.ifSourceModifiedSince(ifModifiedSince.getTime());
|
||||
}
|
||||
if (ifUnmodifiedSince != null) {
|
||||
options.ifSourceUnmodifiedSince(ifUnmodifiedSince.getTime());
|
||||
}
|
||||
// TODO: options.ifETagMatches should accept multiple match tags
|
||||
if (ifMatchTags != null && ifMatchTags.length > 0) {
|
||||
options.ifSourceETagMatches(ifMatchTags[0]);
|
||||
}
|
||||
// TODO: options.ifETagDoesntMatch should accept multiple match tags
|
||||
if (ifNoneMatchTags != null && ifNoneMatchTags.length > 0) {
|
||||
options.ifSourceETagDoesntMatch(ifNoneMatchTags[0]);
|
||||
}
|
||||
if (destinationMetadata != null) {
|
||||
Map<String, String> newMetadata = Maps.newHashMap();
|
||||
for (Object maybeUserMetadataObj : destinationMetadata.entrySet()) {
|
||||
String name = ((Entry<String, String>) maybeUserMetadataObj).getKey();
|
||||
String value = ((Entry<String, String>) maybeUserMetadataObj).getValue();
|
||||
newMetadata.put(name, value);
|
||||
}
|
||||
options.overrideMetadataWith(newMetadata);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,678 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.aws.s3.jets3t;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.aws.s3.S3Client;
|
||||
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
||||
import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
|
||||
import org.jclouds.aws.s3.domain.AccessControlList.Permission;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jets3t.service.S3ObjectsChunk;
|
||||
import org.jets3t.service.S3Service;
|
||||
import org.jets3t.service.S3ServiceException;
|
||||
import org.jets3t.service.acl.AccessControlList;
|
||||
import org.jets3t.service.acl.GrantAndPermission;
|
||||
import org.jets3t.service.acl.GroupGrantee;
|
||||
import org.jets3t.service.model.S3Bucket;
|
||||
import org.jets3t.service.model.S3Object;
|
||||
import org.jets3t.service.multithread.CreateObjectsEvent;
|
||||
import org.jets3t.service.multithread.S3ServiceEventAdaptor;
|
||||
import org.jets3t.service.multithread.S3ServiceEventListener;
|
||||
import org.jets3t.service.multithread.S3ServiceMulti;
|
||||
import org.jets3t.service.security.AWSCredentials;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests to cover JCloudsS3Service
|
||||
*
|
||||
* @author James Murty
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "live" }, testName = "jets3t.JCloudsS3ServiceIntegrationTest")
|
||||
public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest {
|
||||
AWSCredentials credentials;
|
||||
S3Service service;
|
||||
|
||||
public S3Client getApi() {
|
||||
return (S3Client) context.getProviderSpecificContext().getApi();
|
||||
}
|
||||
|
||||
/**
|
||||
* overridden only to get access to the amazon credentials used for jets3t initialization.
|
||||
*
|
||||
* @throws S3ServiceException
|
||||
*/
|
||||
@BeforeClass(groups = { "live" }, dependsOnMethods = "setUpResourcesOnThisThread")
|
||||
protected void createLiveS3Context(ITestContext testContext) throws S3ServiceException {
|
||||
|
||||
String identity = System.getProperty("jclouds.test.identity");
|
||||
String credential = System.getProperty("jclouds.test.credential");
|
||||
|
||||
if (identity != null) {
|
||||
credentials = new AWSCredentials(identity, credential);
|
||||
service = new JCloudsS3Service(credentials);
|
||||
} else {
|
||||
assert false : "credentials not present";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateBucketImpl() throws S3ServiceException, InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
S3Bucket bucket = service.createBucket(new S3Bucket(bucketName));
|
||||
assertEquals(bucket.getName(), bucketName);
|
||||
assertTrue(getApi().bucketExists(bucketName));
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBucketImpl() throws S3ServiceException, InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
final String bucketName = getContainerName();
|
||||
service.deleteBucket(bucketName);
|
||||
assertConsistencyAware(new Runnable() {
|
||||
public void run() {
|
||||
assertFalse(getApi().bucketExists(bucketName));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteObjectImpl() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
S3ServiceException, IOException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
String objectKey = "key-testDeleteObjectImpl";
|
||||
String objectValue = "test";
|
||||
Blob blob = context.getAsyncBlobStore().newBlob(objectKey);
|
||||
blob.setPayload(objectValue);
|
||||
addBlobToContainer(bucketName, blob);
|
||||
|
||||
service.deleteObject(bucketName, objectKey);
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetObjectDetailsImpl() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
S3ServiceException, IOException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
String objectKey = "key-testGetObjectDetailsImpl".toLowerCase();
|
||||
String objectValue = "test";
|
||||
String metadataName = "metadata-name-1";
|
||||
String metadataValue = "metadata-value-1";
|
||||
|
||||
Blob blob = context.getAsyncBlobStore().newBlob(objectKey);
|
||||
blob.setPayload(objectValue);
|
||||
blob.getMetadata().getUserMetadata().put(metadataName, metadataValue);
|
||||
addBlobToContainer(bucketName, blob);
|
||||
|
||||
S3Object objectDetails = service.getObjectDetails(new S3Bucket(bucketName), objectKey);
|
||||
|
||||
// TODO null keys from s3object! assertEquals(objectDetails.getKey(), objectKey);
|
||||
assertEquals(objectDetails.getContentLength(), 4);
|
||||
assertNull(objectDetails.getDataInputStream());
|
||||
assertEquals(objectDetails.getMetadata(metadataName), metadataValue);
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetObjectImpl() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
S3ServiceException, IOException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
String objectKey = "key-testGetObjectImpl".toLowerCase();
|
||||
String objectValue = "test";
|
||||
String metadataName = "metadata-name-2";
|
||||
String metadataValue = "metadata-value-2";
|
||||
|
||||
Blob blob = context.getAsyncBlobStore().newBlob(objectKey);
|
||||
blob.setPayload(objectValue);
|
||||
blob.getMetadata().getUserMetadata().put(metadataName, metadataValue);
|
||||
addBlobToContainer(bucketName, blob);
|
||||
|
||||
S3Object object = service.getObject(new S3Bucket(bucketName), objectKey);
|
||||
|
||||
// TODO null keys from s3object! assertEquals(object.getKey(), objectKey);
|
||||
assertNotNull(object.getDataInputStream());
|
||||
assertEquals(Utils.toStringAndClose(object.getDataInputStream()), objectValue);
|
||||
assertEquals(object.getContentLength(), objectValue.length());
|
||||
assertEquals(object.getMetadata(metadataName), metadataValue);
|
||||
|
||||
// TODO: Test conditional gets
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAllBucketsImpl() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
S3ServiceException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
// Ensure there is at least 1 bucket in S3 identity to list and compare.
|
||||
S3Bucket[] jsBuckets = service.listAllBuckets();
|
||||
|
||||
Set<org.jclouds.aws.s3.domain.BucketMetadata> jcBuckets = getApi().listOwnedBuckets();
|
||||
|
||||
assert jsBuckets.length == jcBuckets.size();
|
||||
|
||||
Iterator<org.jclouds.aws.s3.domain.BucketMetadata> jcBucketsIter = jcBuckets.iterator();
|
||||
for (S3Bucket jsBucket : jsBuckets) {
|
||||
assert jcBucketsIter.hasNext();
|
||||
|
||||
org.jclouds.aws.s3.domain.BucketMetadata jcBucket = jcBucketsIter.next();
|
||||
assert jsBucket.getName().equals(jcBucket.getName());
|
||||
}
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListObjectsChunkedImpl() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
IOException, S3ServiceException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
addBlobToContainer(bucketName, "item1/subobject2");
|
||||
addBlobToContainer(bucketName, "item2");
|
||||
addBlobToContainer(bucketName, "object1");
|
||||
addBlobToContainer(bucketName, "object2/subobject1");
|
||||
|
||||
S3ObjectsChunk chunk;
|
||||
|
||||
// Normal complete listing
|
||||
chunk = service.listObjectsChunked(bucketName, null, null, 1000, null, true);
|
||||
assertEquals(chunk.getObjects().length, 4);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 0);
|
||||
assertNull(chunk.getDelimiter());
|
||||
assertNull(chunk.getPrefix());
|
||||
assertNull(chunk.getPriorLastKey());
|
||||
|
||||
// Partial listing
|
||||
chunk = service.listObjectsChunked(bucketName, null, null, 2, null, false);
|
||||
assertEquals(chunk.getObjects().length, 2);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 0);
|
||||
assertNull(chunk.getDelimiter());
|
||||
assertNull(chunk.getPrefix());
|
||||
assertEquals(chunk.getPriorLastKey(), "item2");
|
||||
|
||||
// Complete listing, in two chunks
|
||||
chunk = service.listObjectsChunked(bucketName, null, null, 2, null, true);
|
||||
assertEquals(chunk.getObjects().length, 4);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 0);
|
||||
assertNull(chunk.getDelimiter());
|
||||
assertNull(chunk.getPrefix());
|
||||
assertNull(chunk.getPriorLastKey());
|
||||
|
||||
// Partial listing with marker
|
||||
chunk = service.listObjectsChunked(bucketName, null, null, 1000, "item1/subobject2", true);
|
||||
assertEquals(chunk.getObjects().length, 3);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 0);
|
||||
assertNull(chunk.getDelimiter());
|
||||
assertNull(chunk.getPrefix());
|
||||
assertNull(chunk.getPriorLastKey());
|
||||
|
||||
// Partial listing with marker
|
||||
chunk = service.listObjectsChunked(bucketName, null, null, 1000, "object1", true);
|
||||
assertEquals(chunk.getObjects().length, 1);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 0);
|
||||
assertNull(chunk.getDelimiter());
|
||||
assertNull(chunk.getPrefix());
|
||||
assertNull(chunk.getPriorLastKey());
|
||||
|
||||
// Prefix test
|
||||
chunk = service.listObjectsChunked(bucketName, "item", null, 1000, null, true);
|
||||
assertEquals(chunk.getObjects().length, 2);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 0);
|
||||
assertNull(chunk.getDelimiter());
|
||||
assertEquals(chunk.getPrefix(), "item");
|
||||
assertNull(chunk.getPriorLastKey());
|
||||
|
||||
// Delimiter test
|
||||
chunk = service.listObjectsChunked(bucketName, null, "/", 1000, null, true);
|
||||
assertEquals(chunk.getObjects().length, 2);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 2);
|
||||
assertEquals(chunk.getDelimiter(), "/");
|
||||
assertNull(chunk.getPrefix());
|
||||
assertNull(chunk.getPriorLastKey());
|
||||
|
||||
// Prefix & delimiter test
|
||||
chunk = service.listObjectsChunked(bucketName, "item", "/", 1000, null, true);
|
||||
assertEquals(chunk.getObjects().length, 1);
|
||||
assertEquals(chunk.getCommonPrefixes().length, 1);
|
||||
assertEquals(chunk.getDelimiter(), "/");
|
||||
assertEquals(chunk.getPrefix(), "item");
|
||||
assertNull(chunk.getPriorLastKey());
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListObjectsImpl() throws InterruptedException, ExecutionException, TimeoutException, IOException,
|
||||
S3ServiceException {
|
||||
String bucketName = null;
|
||||
try {
|
||||
bucketName = getContainerName();
|
||||
addBlobToContainer(bucketName, "item1/subobject2");
|
||||
addBlobToContainer(bucketName, "item2");
|
||||
addBlobToContainer(bucketName, "object1");
|
||||
addBlobToContainer(bucketName, "object2/subobject1");
|
||||
|
||||
S3Object[] objects;
|
||||
|
||||
// Normal complete listing
|
||||
objects = service.listObjects(bucketName, null, null, 1000);
|
||||
assertEquals(objects.length, 4);
|
||||
|
||||
// Complete listing, in two chunks
|
||||
objects = service.listObjects(bucketName, null, null, 2);
|
||||
assertEquals(objects.length, 4);
|
||||
assertEquals(objects[0].getKey(), "item1/subobject2");
|
||||
assertEquals(objects[3].getKey(), "object2/subobject1");
|
||||
|
||||
// Prefix test
|
||||
objects = service.listObjects(bucketName, "item", null, 1000);
|
||||
assertEquals(objects.length, 2);
|
||||
|
||||
// Delimiter test
|
||||
objects = service.listObjects(bucketName, null, "/", 1000);
|
||||
assertEquals(objects.length, 2);
|
||||
assertEquals(objects[0].getKey(), "item2");
|
||||
assertEquals(objects[1].getKey(), "object1");
|
||||
|
||||
// Prefix & delimiter test
|
||||
objects = service.listObjects(bucketName, "item", "/", 1000);
|
||||
assertEquals(objects.length, 1);
|
||||
assertEquals(objects[0].getKey(), "item2");
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutObjectImpl() throws S3ServiceException, InterruptedException, ExecutionException,
|
||||
TimeoutException, NoSuchAlgorithmException, IOException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
String objectKey = "putObject";
|
||||
|
||||
S3Object requestObject, jsResultObject;
|
||||
org.jclouds.aws.s3.domain.S3Object jcObject;
|
||||
|
||||
// Upload empty object
|
||||
requestObject = new S3Object(objectKey);
|
||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
||||
jcObject = getApi().getObject(bucketName, objectKey);
|
||||
// TODO null keys from s3object! assertEquals(jcObject.getKey(), objectKey);
|
||||
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
|
||||
assertEquals(jcObject.getMetadata().getContentType(), MediaType.APPLICATION_OCTET_STREAM);
|
||||
assertEquals(jsResultObject.getKey(), requestObject.getKey());
|
||||
assertEquals(jsResultObject.getContentLength(), 0);
|
||||
assertEquals(jsResultObject.getContentType(), MediaType.APPLICATION_OCTET_STREAM);
|
||||
|
||||
// Upload unicode-named object
|
||||
requestObject = new S3Object("₪n₪₪₪d₪-object");
|
||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
||||
jcObject = getApi().getObject(bucketName, requestObject.getKey());
|
||||
// TODO null keys from s3object! assertEquals(jcObject.getKey(), requestObject.getKey());
|
||||
assertEquals(jcObject.getMetadata().getSize(), new Long(0));
|
||||
assertEquals(jcObject.getMetadata().getContentType(), MediaType.APPLICATION_OCTET_STREAM);
|
||||
assertEquals(jsResultObject.getKey(), requestObject.getKey());
|
||||
assertEquals(jsResultObject.getContentLength(), 0);
|
||||
assertEquals(jsResultObject.getContentType(), MediaType.APPLICATION_OCTET_STREAM);
|
||||
|
||||
// Upload string object
|
||||
String data = "This is my ₪n₪₪₪d₪ data";
|
||||
requestObject = new S3Object(objectKey, data);
|
||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
||||
jcObject = getApi().getObject(bucketName, objectKey);
|
||||
assertEquals(jcObject.getMetadata().getSize(), new Long(data.getBytes("UTF-8").length));
|
||||
assertTrue(jcObject.getMetadata().getContentType().startsWith("text/plain"));
|
||||
assertEquals(jsResultObject.getContentLength(), data.getBytes("UTF-8").length);
|
||||
assertTrue(jsResultObject.getContentType().startsWith("text/plain"));
|
||||
|
||||
// Upload object with metadata
|
||||
requestObject = new S3Object(objectKey);
|
||||
requestObject.addMetadata("x-amz-meta-" + "my-metadata-1", "value-1");
|
||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
||||
jcObject = getApi().getObject(bucketName, objectKey);
|
||||
assertEquals(jcObject.getMetadata().getUserMetadata().get("my-metadata-1"), "value-1");
|
||||
assertEquals(jsResultObject.getMetadata("x-amz-meta-" + "my-metadata-1"), "value-1");
|
||||
|
||||
// Upload object with canned public-read ACL
|
||||
requestObject = new S3Object(objectKey);
|
||||
requestObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
|
||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = getApi().getObjectACL(bucketName, objectKey);
|
||||
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
||||
assertEquals(jcACL.getGrants().size(), 2);
|
||||
|
||||
// TODO : Any way to test a URL lookup that works for live and stub testing?
|
||||
// URL publicUrl = new URL(
|
||||
// "http://" + bucketName + ".s3.amazonaws.com:80/" + requestObject.getKey());
|
||||
// assertEquals(((HttpURLClient) publicUrl.openClient()).getResponseCode(), 200);
|
||||
|
||||
// Upload object and check MD5
|
||||
requestObject = new S3Object(objectKey);
|
||||
data = "Here is some d₪t₪ for you";
|
||||
requestObject.setDataInputStream(new ByteArrayInputStream(data.getBytes("UTF-8")));
|
||||
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
|
||||
jcObject = getApi().getObject(bucketName, objectKey);
|
||||
assertTrue(jsResultObject.verifyData(data.getBytes("UTF-8")));
|
||||
assertEquals(jsResultObject.getETag(), jcObject.getMetadata().getETag().replaceAll("\"", ""));
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCopyObjectImpl() throws InterruptedException, ExecutionException, TimeoutException, IOException,
|
||||
S3ServiceException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
String data = "This is my data";
|
||||
String sourceObjectKey = "₪riginalObject"; // Notice the use of non-ASCII
|
||||
String destinationObjectKey = "d₪stinationObject"; // characters here.
|
||||
String metadataName = "metadata-name";
|
||||
String sourceMetadataValue = "souce-metadata-value";
|
||||
String destinationMetadataValue = "destination-metadata-value";
|
||||
|
||||
Blob blob = context.getAsyncBlobStore().newBlob(sourceObjectKey);
|
||||
blob.setPayload(data);
|
||||
blob.getMetadata().getUserMetadata().put(metadataName, sourceMetadataValue);
|
||||
addBlobToContainer(bucketName, blob);
|
||||
|
||||
S3Object destinationObject;
|
||||
Map copyResult;
|
||||
org.jclouds.aws.s3.domain.S3Object jcDestinationObject;
|
||||
|
||||
// Copy with metadata and ACL retained
|
||||
destinationObject = new S3Object(destinationObjectKey);
|
||||
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject, false);
|
||||
jcDestinationObject = getApi().getObject(bucketName, destinationObject.getKey());
|
||||
// TODO null keys from s3object! assertEquals(jcDestinationObject.getKey(),
|
||||
// destinationObjectKey);
|
||||
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName), sourceMetadataValue);
|
||||
assertEquals(copyResult.get("ETag"), jcDestinationObject.getMetadata().getETag());
|
||||
// Test destination ACL is unchanged (ie private)
|
||||
org.jclouds.aws.s3.domain.AccessControlList jcACL = getApi().getObjectACL(bucketName,
|
||||
destinationObject.getKey());
|
||||
assertEquals(jcACL.getGrants().size(), 1);
|
||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
||||
|
||||
// Copy with metadata replaced
|
||||
destinationObject = new S3Object(destinationObjectKey);
|
||||
destinationObject.addMetadata("x-amz-meta-" + metadataName, destinationMetadataValue);
|
||||
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject, true);
|
||||
jcDestinationObject = getApi().getObject(bucketName, destinationObject.getKey());
|
||||
assertEquals(jcDestinationObject.getMetadata().getUserMetadata().get(metadataName), destinationMetadataValue);
|
||||
// Test destination ACL is unchanged (ie private)
|
||||
jcACL = getApi().getObjectACL(bucketName, destinationObject.getKey());
|
||||
assertEquals(jcACL.getGrants().size(), 1);
|
||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
||||
|
||||
// Copy with ACL modified
|
||||
destinationObject = new S3Object(destinationObjectKey);
|
||||
destinationObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
|
||||
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject, false);
|
||||
// Test destination ACL is changed (ie public-read)
|
||||
jcACL = getApi().getObjectACL(bucketName, destinationObject.getKey());
|
||||
assertEquals(jcACL.getGrants().size(), 2);
|
||||
assertTrue(jcACL.hasPermission(jcACL.getOwner().getId(), Permission.FULL_CONTROL));
|
||||
assertTrue(jcACL.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
|
||||
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testPutAndGetBucketAclImpl() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
S3ServiceException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
S3Bucket bucket = new S3Bucket(bucketName);
|
||||
AccessControlList acl = null;
|
||||
|
||||
// Confirm bucket is created private by default.
|
||||
acl = service.getBucketAcl(bucket);
|
||||
final String ownerId = acl.getOwner().getId();
|
||||
assertEquals(acl.getGrants().size(), 1);
|
||||
GrantAndPermission gap = (GrantAndPermission) Iterables.find(acl.getGrants(),
|
||||
new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(ownerId);
|
||||
}
|
||||
});
|
||||
assertNotNull(gap);
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_FULL_CONTROL);
|
||||
|
||||
// Add read access for public, and read-acp access for authenticated users.
|
||||
acl.grantPermission(GroupGrantee.ALL_USERS, org.jets3t.service.acl.Permission.PERMISSION_READ);
|
||||
acl.grantPermission(GroupGrantee.AUTHENTICATED_USERS, org.jets3t.service.acl.Permission.PERMISSION_READ_ACP);
|
||||
service.putBucketAcl(bucketName, acl);
|
||||
acl = service.getBucketAcl(bucket);
|
||||
assertEquals(acl.getGrants().size(), 3);
|
||||
gap = (GrantAndPermission) Iterables.find(acl.getGrants(), new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(ownerId);
|
||||
}
|
||||
});
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_FULL_CONTROL);
|
||||
gap = (GrantAndPermission) Iterables.find(acl.getGrants(), new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(GroupGrantee.ALL_USERS.getIdentifier());
|
||||
}
|
||||
});
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_READ);
|
||||
gap = (GrantAndPermission) Iterables.find(acl.getGrants(), new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(GroupGrantee.AUTHENTICATED_USERS.getIdentifier());
|
||||
}
|
||||
});
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_READ_ACP);
|
||||
} finally {
|
||||
// need to delete this container as we've modified its acls
|
||||
destroyContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testGetAndPutObjectAclImpl() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
S3ServiceException, NoSuchAlgorithmException, IOException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
S3Bucket bucket = new S3Bucket(bucketName);
|
||||
S3Object object = new S3Object("testGetAndPutObjectAclImpl", "my data");
|
||||
AccessControlList acl = null;
|
||||
|
||||
// Create default object.
|
||||
service.putObject(bucket, object);
|
||||
|
||||
// Confirm object is created private by default.
|
||||
acl = service.getObjectAcl(bucket, object.getKey());
|
||||
final String ownerId = acl.getOwner().getId();
|
||||
assertEquals(acl.getGrants().size(), 1);
|
||||
GrantAndPermission gap = (GrantAndPermission) Iterables.find(acl.getGrants(),
|
||||
new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(ownerId);
|
||||
}
|
||||
});
|
||||
assertNotNull(gap);
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_FULL_CONTROL);
|
||||
|
||||
// Add read access for public, and read-acp access for authenticated users.
|
||||
acl.grantPermission(GroupGrantee.ALL_USERS, org.jets3t.service.acl.Permission.PERMISSION_READ);
|
||||
acl.grantPermission(GroupGrantee.AUTHENTICATED_USERS, org.jets3t.service.acl.Permission.PERMISSION_READ_ACP);
|
||||
service.putObjectAcl(bucketName, object.getKey(), acl);
|
||||
acl = service.getObjectAcl(bucket, object.getKey());
|
||||
assertEquals(acl.getGrants().size(), 3);
|
||||
gap = (GrantAndPermission) Iterables.find(acl.getGrants(), new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(ownerId);
|
||||
}
|
||||
});
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_FULL_CONTROL);
|
||||
gap = (GrantAndPermission) Iterables.find(acl.getGrants(), new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(GroupGrantee.ALL_USERS.getIdentifier());
|
||||
}
|
||||
});
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_READ);
|
||||
gap = (GrantAndPermission) Iterables.find(acl.getGrants(), new Predicate<GrantAndPermission>() {
|
||||
public boolean apply(GrantAndPermission gap) {
|
||||
return gap.getGrantee().getIdentifier().equals(GroupGrantee.AUTHENTICATED_USERS.getIdentifier());
|
||||
}
|
||||
});
|
||||
assertEquals(gap.getPermission(), org.jets3t.service.acl.Permission.PERMISSION_READ_ACP);
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiService() throws S3ServiceException, NoSuchAlgorithmException, IOException,
|
||||
InterruptedException, ExecutionException, TimeoutException {
|
||||
int OBJECT_COUNT = 50;
|
||||
int OBJECT_SIZE = 1024; // 1 KB
|
||||
|
||||
byte[] dataBuffer = new byte[OBJECT_SIZE];
|
||||
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
S3Bucket bucket = new S3Bucket(bucketName);
|
||||
S3Object[] objects = new S3Object[OBJECT_COUNT];
|
||||
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
InputStream dataInputStream = new ByteArrayInputStream(dataBuffer);
|
||||
objects[i] = new S3Object("testMultiServiceObject" + i);
|
||||
objects[i].setDataInputStream(dataInputStream);
|
||||
objects[i].setContentLength(dataBuffer.length);
|
||||
}
|
||||
|
||||
final long[] countOfUploadCompletions = new long[1];
|
||||
S3ServiceEventListener eventListener = new S3ServiceEventAdaptor() {
|
||||
@Override
|
||||
public synchronized void s3ServiceEventPerformed(CreateObjectsEvent event) {
|
||||
if (CreateObjectsEvent.EVENT_STARTED == event.getEventCode()) {
|
||||
// Do nothing
|
||||
} else if (CreateObjectsEvent.EVENT_COMPLETED == event.getEventCode()) {
|
||||
// Do nothing
|
||||
} else if (CreateObjectsEvent.EVENT_ERROR == event.getEventCode()) {
|
||||
fail("Upload should not result in error", event.getErrorCause());
|
||||
} else if (CreateObjectsEvent.EVENT_IGNORED_ERRORS == event.getEventCode()) {
|
||||
fail("Upload should not result in ignored errors: " + event.getIgnoredErrors());
|
||||
} else if (CreateObjectsEvent.EVENT_CANCELLED == event.getEventCode()) {
|
||||
fail("Upload should not be cancelled");
|
||||
} else if (CreateObjectsEvent.EVENT_IN_PROGRESS == event.getEventCode()) {
|
||||
countOfUploadCompletions[0] = event.getThreadWatcher().getCompletedThreads();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
S3ServiceMulti multiService = new S3ServiceMulti(service, eventListener);
|
||||
multiService.putObjects(bucket, objects);
|
||||
|
||||
assertEquals(countOfUploadCompletions[0], OBJECT_COUNT);
|
||||
ListBucketResponse theBucket = getApi().listBucket(bucketName);
|
||||
assertEquals(theBucket.size(), OBJECT_COUNT);
|
||||
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testCheckBucketStatus() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testGetBucketLocationImpl() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testGetBucketLoggingStatus() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testSetBucketLoggingStatusImpl() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testSetRequesterPaysBucketImpl() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testIsBucketAccessible() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testIsRequesterPaysBucketImpl() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue