mirror of
https://github.com/apache/jclouds.git
synced 2025-02-22 10:29:37 +00:00
exposed MetaData as proper types
git-svn-id: http://jclouds.googlecode.com/svn/trunk@417 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
c20e124dad
commit
9287a2a6c1
@ -219,8 +219,8 @@ public class JCloudsS3Service extends S3Service {
|
||||
org.jets3t.service.model.S3Bucket jsBucket = new org.jets3t.service.model.S3Bucket(
|
||||
jcBucket.getName());
|
||||
jsBucket.setOwner(new org.jets3t.service.model.S3Owner(jcBucket
|
||||
.getCanonicalUser().getId(), jcBucket
|
||||
.getCanonicalUser().getDisplayName()));
|
||||
.getMetaData().getCanonicalUser().getId(), jcBucket
|
||||
.getMetaData().getCanonicalUser().getDisplayName()));
|
||||
jsBucketList.add(jsBucket);
|
||||
}
|
||||
return (org.jets3t.service.model.S3Bucket[]) jsBucketList
|
||||
|
@ -128,7 +128,7 @@ public class JCloudsS3ServiceTest extends S3IntegrationTest {
|
||||
|
||||
service.deleteObject(bucketName, objectKey);
|
||||
|
||||
assertEquals(client.headObject(jcloudsBucket, objectKey).get(10,
|
||||
assertEquals(client.getObjectMetaData(jcloudsBucket, objectKey).get(10,
|
||||
TimeUnit.SECONDS), org.jclouds.aws.s3.domain.S3Object.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ public class JCloudsS3ServiceTest extends S3IntegrationTest {
|
||||
org.jclouds.aws.s3.domain.S3Bucket jcloudsBucket = createBucket(name);
|
||||
org.jclouds.aws.s3.domain.S3Object jcloudsObject = new org.jclouds.aws.s3.domain.S3Object(
|
||||
objectKey);
|
||||
jcloudsObject.setContent(objectValue);
|
||||
jcloudsObject.setData(objectValue);
|
||||
client.addObject(jcloudsBucket, jcloudsObject)
|
||||
.get(10, TimeUnit.SECONDS);
|
||||
return jcloudsBucket;
|
||||
@ -185,28 +185,32 @@ public class JCloudsS3ServiceTest extends S3IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAllBucketsImpl()
|
||||
throws InterruptedException, ExecutionException, TimeoutException, S3ServiceException {
|
||||
// Ensure there is at least 1 bucket in S3 account to list and compare.
|
||||
public void testListAllBucketsImpl() throws InterruptedException,
|
||||
ExecutionException, TimeoutException, S3ServiceException {
|
||||
// Ensure there is at least 1 bucket in S3 account to list and compare.
|
||||
String bucketName = bucketPrefix + ".testListAllBucketsImplString";
|
||||
org.jclouds.aws.s3.domain.S3Bucket jcloudsBucket = createBucket(bucketName);
|
||||
|
||||
|
||||
S3Bucket[] jsBuckets = service.listAllBuckets();
|
||||
|
||||
List<org.jclouds.aws.s3.domain.S3Bucket> jcBuckets = client.getBuckets().get(10, TimeUnit.SECONDS);
|
||||
|
||||
List<org.jclouds.aws.s3.domain.S3Bucket> jcBuckets = client
|
||||
.getBuckets().get(10, TimeUnit.SECONDS);
|
||||
|
||||
assert jsBuckets.length == jcBuckets.size();
|
||||
|
||||
Iterator<org.jclouds.aws.s3.domain.S3Bucket> jcBucketsIter = jcBuckets.iterator();
|
||||
for (S3Bucket jsBucket: jsBuckets) {
|
||||
assert jcBucketsIter.hasNext();
|
||||
|
||||
org.jclouds.aws.s3.domain.S3Bucket jcBucket = jcBucketsIter.next();
|
||||
assert jsBucket.getName().equals(jcBucket.getName());
|
||||
assert jsBucket.getOwner().getId().equals(jcBucket.getCanonicalUser().getId());
|
||||
assert jsBucket.getOwner().getDisplayName().equals(jcBucket.getCanonicalUser().getDisplayName());
|
||||
|
||||
Iterator<org.jclouds.aws.s3.domain.S3Bucket> jcBucketsIter = jcBuckets
|
||||
.iterator();
|
||||
for (S3Bucket jsBucket : jsBuckets) {
|
||||
assert jcBucketsIter.hasNext();
|
||||
|
||||
org.jclouds.aws.s3.domain.S3Bucket jcBucket = jcBucketsIter.next();
|
||||
assert jsBucket.getName().equals(jcBucket.getName());
|
||||
assert jsBucket.getOwner().getId().equals(
|
||||
jcBucket.getMetaData().getCanonicalUser().getId());
|
||||
assert jsBucket.getOwner().getDisplayName().equals(
|
||||
jcBucket.getMetaData().getCanonicalUser().getDisplayName());
|
||||
}
|
||||
|
||||
|
||||
client.deleteBucket(jcloudsBucket);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adriancole@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF 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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>com.google.appengine</groupId>
|
||||
|
@ -1,4 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adriancole@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF 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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>com.google.appengine</groupId>
|
||||
|
@ -45,8 +45,8 @@ public abstract class BaseJCloudsPerformance extends BasePerformance {
|
||||
// object.setKey(id + "");
|
||||
// //object.setContentType("text/plain");
|
||||
// object.setContentType("application/octetstream");
|
||||
// //object.setContent("this is a test");
|
||||
// object.setContent(test);
|
||||
// //object.setData("this is a test");
|
||||
// object.setData(test);
|
||||
// return clientProvider.getObject(s3Bucket,
|
||||
// object.getKey()).get(120,TimeUnit.SECONDS) !=
|
||||
// org.jclouds.aws.s3.domain.S3Object.NOT_FOUND;
|
||||
@ -59,8 +59,8 @@ public abstract class BaseJCloudsPerformance extends BasePerformance {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucket);
|
||||
org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(
|
||||
key);
|
||||
object.setContentType(contentType);
|
||||
object.setContent(data);
|
||||
object.getMetaData().setContentType(contentType);
|
||||
object.setData(data);
|
||||
return client.addObject(s3Bucket, object).get(120, TimeUnit.SECONDS) != null;
|
||||
}
|
||||
|
||||
@ -70,8 +70,8 @@ public abstract class BaseJCloudsPerformance extends BasePerformance {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucket);
|
||||
org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(
|
||||
key);
|
||||
object.setContentType(contentType);
|
||||
object.setContent(data);
|
||||
object.getMetaData().setContentType(contentType);
|
||||
object.setData(data);
|
||||
return client.addObject(s3Bucket, object).get(120, TimeUnit.SECONDS) != null;
|
||||
}
|
||||
|
||||
@ -81,9 +81,9 @@ public abstract class BaseJCloudsPerformance extends BasePerformance {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucket);
|
||||
org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(
|
||||
key);
|
||||
object.setContentType(contentType);
|
||||
object.setContent(data);
|
||||
object.setSize(data.available());
|
||||
object.getMetaData().setContentType(contentType);
|
||||
object.setData(data);
|
||||
object.getMetaData().setSize(data.available());
|
||||
return client.addObject(s3Bucket, object).get(120, TimeUnit.SECONDS) != null;
|
||||
}
|
||||
|
||||
@ -93,8 +93,8 @@ public abstract class BaseJCloudsPerformance extends BasePerformance {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucket);
|
||||
org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(
|
||||
key);
|
||||
object.setContentType(contentType);
|
||||
object.setContent(data);
|
||||
object.getMetaData().setContentType(contentType);
|
||||
object.setData(data);
|
||||
return client.addObject(s3Bucket, object).get(120, TimeUnit.SECONDS) != null;
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ import org.jclouds.aws.s3.domain.S3Object;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface S3Connection {
|
||||
Future<S3Object> getObject(S3Bucket s3Bucket, String key);
|
||||
|
||||
Future<S3Object> headObject(S3Bucket s3Bucket, String key);
|
||||
Future<S3Object.MetaData> getObjectMetaData(S3Bucket s3Bucket, String key);
|
||||
|
||||
Future<Boolean> deleteObject(S3Bucket s3Bucket, String key);
|
||||
|
||||
@ -47,7 +47,8 @@ public interface S3Connection {
|
||||
|
||||
Future<Boolean> deleteBucket(S3Bucket s3Bucket);
|
||||
|
||||
Future<Boolean> copyObject(S3Bucket sourceBucket, S3Object sourceObject, S3Bucket destinationBucket, S3Object destinationObject);
|
||||
Future<Boolean> copyObject(S3Bucket sourceBucket, S3Object sourceObject,
|
||||
S3Bucket destinationBucket, S3Object destinationObject);
|
||||
|
||||
Future<Boolean> bucketExists(S3Bucket s3Bucket);
|
||||
|
||||
|
@ -122,12 +122,12 @@ public class S3Utils extends Utils {
|
||||
public static String getContentAsStringAndClose(S3Object object)
|
||||
throws IOException {
|
||||
checkNotNull(object, "s3Object");
|
||||
checkNotNull(object.getContent(), "s3Object.content");
|
||||
Object o = object.getContent();
|
||||
checkNotNull(object.getData(), "s3Object.content");
|
||||
Object o = object.getData();
|
||||
|
||||
if (o instanceof InputStream) {
|
||||
String returnVal = toStringAndClose((InputStream) o);
|
||||
if (object.getContentType().indexOf("xml") >= 0) {
|
||||
if (object.getMetaData().getContentType().indexOf("xml") >= 0) {
|
||||
|
||||
}
|
||||
return returnVal;
|
||||
|
@ -30,10 +30,10 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
public class HeadBucket extends S3FutureCommand<Boolean> {
|
||||
public class BucketExists extends S3FutureCommand<Boolean> {
|
||||
|
||||
@Inject
|
||||
public HeadBucket(@Named("jclouds.http.address") String amazonHost,
|
||||
public BucketExists(@Named("jclouds.http.address") String amazonHost,
|
||||
ReturnTrueIf200 callable, @Assisted S3Bucket s3Bucket) {
|
||||
super("HEAD", "/", callable, amazonHost, s3Bucket);
|
||||
}
|
@ -25,7 +25,7 @@ package org.jclouds.aws.s3.commands;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.aws.s3.commands.callables.RetrieveObjectCallable;
|
||||
import org.jclouds.aws.s3.commands.callables.GetObjectCallable;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
|
||||
@ -33,14 +33,20 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
public class RetrieveObject extends S3FutureCommand<S3Object> {
|
||||
/**
|
||||
* Retrieves the S3Object associated with the Key or {@link S3Object#NOT_FOUND}
|
||||
* if not available;
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class GetObject extends S3FutureCommand<S3Object> {
|
||||
|
||||
@Inject
|
||||
public RetrieveObject(@Named("jclouds.http.address") String amazonHost,
|
||||
RetrieveObjectCallable callable, @Assisted S3Bucket s3Bucket,
|
||||
@Assisted String key, @Assisted boolean getContent) {
|
||||
super(getContent ? "GET" : "HEAD", "/" + checkNotNull(key), callable,
|
||||
amazonHost, s3Bucket);
|
||||
public GetObject(@Named("jclouds.http.address") String amazonHost,
|
||||
GetObjectCallable callable, @Assisted S3Bucket s3Bucket,
|
||||
@Assisted String key) {
|
||||
super("GET", "/" + checkNotNull(key), callable, amazonHost, s3Bucket);
|
||||
callable.setKey(key);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Adrian Cole <adriancole@jclouds.org>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.aws.s3.commands;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.aws.s3.commands.callables.HeadMetaDataCallable;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
/**
|
||||
* Retrieves the metadata associated with the Key or
|
||||
* {@link S3Object.MetaData#NOT_FOUND} if not available;
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class HeadMetaData extends S3FutureCommand<S3Object.MetaData> {
|
||||
|
||||
@Inject
|
||||
public HeadMetaData(@Named("jclouds.http.address") String amazonHost,
|
||||
HeadMetaDataCallable callable, @Assisted S3Bucket s3Bucket,
|
||||
@Assisted String key) {
|
||||
super("HEAD", "/" + checkNotNull(key), callable, amazonHost, s3Bucket);
|
||||
callable.setKey(key);
|
||||
}
|
||||
}
|
@ -42,12 +42,11 @@ public class PutObject extends S3FutureCommand<String> {
|
||||
super("PUT", "/" + checkNotNull(object.getKey()), callable, amazonHost,
|
||||
s3Bucket);
|
||||
getRequest().setContent(
|
||||
checkNotNull(object.getContent(), "object.getContent()"));
|
||||
getRequest()
|
||||
.setContentType(
|
||||
checkNotNull(object.getContentType(),
|
||||
"object.getContentType()"));
|
||||
getRequest().setContentLength(object.getSize());
|
||||
checkNotNull(object.getData(), "object.getContent()"));
|
||||
getRequest().setContentType(
|
||||
checkNotNull(object.getMetaData().getContentType(),
|
||||
"object.metaData.contentType()"));
|
||||
getRequest().setContentLength(object.getMetaData().getSize());
|
||||
}
|
||||
|
||||
}
|
@ -23,22 +23,23 @@
|
||||
*/
|
||||
package org.jclouds.aws.s3.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.name.Named;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.aws.s3.commands.callables.xml.ListAllMyBucketsHandler;
|
||||
import org.jclouds.aws.s3.commands.callables.xml.ListBucketHandler;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
import org.jclouds.http.commands.callables.xml.ParseSax;
|
||||
|
||||
import java.util.List;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class S3CommandFactory {
|
||||
@ -47,117 +48,132 @@ public class S3CommandFactory {
|
||||
private CopyObjectFactory copyObjectFactory;
|
||||
|
||||
public static interface CopyObjectFactory {
|
||||
CopyObject create(@Assisted("sourceBucket") S3Bucket sourceBucket, @Assisted("sourceObject") S3Object sourceObject, @Assisted("destinationBucket") S3Bucket destinationBucket, @Assisted("destinationObject") S3Object destinationObject);
|
||||
CopyObject create(@Assisted("sourceBucket") S3Bucket sourceBucket,
|
||||
@Assisted("sourceObject") S3Object sourceObject,
|
||||
@Assisted("destinationBucket") S3Bucket destinationBucket,
|
||||
@Assisted("destinationObject") S3Object destinationObject);
|
||||
}
|
||||
|
||||
public CopyObject createCopyObject(S3Bucket sourceBucket, S3Object sourceObject, S3Bucket destinationBucket, S3Object destinationObject) {
|
||||
return copyObjectFactory.create(sourceBucket, sourceObject, destinationBucket, destinationObject);
|
||||
public CopyObject createCopyObject(S3Bucket sourceBucket,
|
||||
S3Object sourceObject, S3Bucket destinationBucket,
|
||||
S3Object destinationObject) {
|
||||
return copyObjectFactory.create(sourceBucket, sourceObject,
|
||||
destinationBucket, destinationObject);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private DeleteBucketFactory deleteBucketFactory;
|
||||
|
||||
public static interface DeleteBucketFactory {
|
||||
DeleteBucket create(S3Bucket s3Bucket);
|
||||
DeleteBucket create(S3Bucket s3Bucket);
|
||||
}
|
||||
|
||||
public DeleteBucket createDeleteBucket(S3Bucket s3Bucket) {
|
||||
return deleteBucketFactory.create(s3Bucket);
|
||||
return deleteBucketFactory.create(s3Bucket);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private DeleteObjectFactory deleteObjectFactory;
|
||||
|
||||
public static interface DeleteObjectFactory {
|
||||
DeleteObject create(S3Bucket s3Bucket, String key);
|
||||
DeleteObject create(S3Bucket s3Bucket, String key);
|
||||
}
|
||||
|
||||
public DeleteObject createDeleteObject(S3Bucket s3Bucket, String key) {
|
||||
return deleteObjectFactory.create(s3Bucket, key);
|
||||
return deleteObjectFactory.create(s3Bucket, key);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private HeadBucketFactory headBucketFactory;
|
||||
private BucketExistsFactory headBucketFactory;
|
||||
|
||||
public static interface HeadBucketFactory {
|
||||
HeadBucket create(S3Bucket s3Bucket);
|
||||
public static interface BucketExistsFactory {
|
||||
BucketExists create(S3Bucket s3Bucket);
|
||||
}
|
||||
|
||||
public HeadBucket createHeadBucket(S3Bucket s3Bucket) {
|
||||
return headBucketFactory.create(s3Bucket);
|
||||
public BucketExists createHeadBucket(S3Bucket s3Bucket) {
|
||||
return headBucketFactory.create(s3Bucket);
|
||||
}
|
||||
|
||||
|
||||
@Inject
|
||||
private PutBucketFactory putBucketFactory;
|
||||
|
||||
public static interface PutBucketFactory {
|
||||
PutBucket create(S3Bucket s3Bucket);
|
||||
PutBucket create(S3Bucket s3Bucket);
|
||||
}
|
||||
|
||||
public PutBucket createPutBucket(S3Bucket s3Bucket) {
|
||||
return putBucketFactory.create(s3Bucket);
|
||||
return putBucketFactory.create(s3Bucket);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private PutObjectFactory putObjectFactory;
|
||||
|
||||
public static interface PutObjectFactory {
|
||||
PutObject create(S3Bucket s3Bucket, S3Object object);
|
||||
PutObject create(S3Bucket s3Bucket, S3Object object);
|
||||
}
|
||||
|
||||
public PutObject createPutObject(S3Bucket s3Bucket, S3Object s3Object) {
|
||||
return putObjectFactory.create(s3Bucket, s3Object);
|
||||
return putObjectFactory.create(s3Bucket, s3Object);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private RetrieveObjectFactory retrieveObjectFactory;
|
||||
private GetObjectFactory getObjectFactory;
|
||||
|
||||
public static interface RetrieveObjectFactory {
|
||||
RetrieveObject create(S3Bucket s3Bucket, String key, boolean getContent);
|
||||
public static interface GetObjectFactory {
|
||||
GetObject create(S3Bucket s3Bucket, String key);
|
||||
}
|
||||
|
||||
public RetrieveObject createRetrieveObject(S3Bucket s3Bucket, String key, boolean getContent) {
|
||||
return retrieveObjectFactory.create(s3Bucket, key, getContent);
|
||||
public GetObject createGetObject(S3Bucket s3Bucket, String key) {
|
||||
return getObjectFactory.create(s3Bucket, key);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private HeadMetaDataFactory headMetaDataFactory;
|
||||
|
||||
public static interface HeadMetaDataFactory {
|
||||
HeadMetaData create(S3Bucket s3Bucket, String key);
|
||||
}
|
||||
|
||||
public HeadMetaData createHeadMetaData(S3Bucket s3Bucket, String key) {
|
||||
return headMetaDataFactory.create(s3Bucket, key);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Named("jclouds.http.address")
|
||||
String amazonHost;
|
||||
|
||||
|
||||
@Inject
|
||||
private GenericParseFactory<List<S3Bucket>> parseListAllMyBucketsFactory;
|
||||
|
||||
public static interface GenericParseFactory<T> {
|
||||
ParseSax<T> create(ParseSax.HandlerWithResult<T> handler);
|
||||
ParseSax<T> create(ParseSax.HandlerWithResult<T> handler);
|
||||
}
|
||||
|
||||
@Inject
|
||||
Provider<ListAllMyBucketsHandler> ListAllMyBucketsHandlerprovider;
|
||||
|
||||
@VisibleForTesting
|
||||
public ParseSax<List<S3Bucket>> createListBucketsParser(){
|
||||
return parseListAllMyBucketsFactory.create(ListAllMyBucketsHandlerprovider.get());
|
||||
public ParseSax<List<S3Bucket>> createListBucketsParser() {
|
||||
return parseListAllMyBucketsFactory
|
||||
.create(ListAllMyBucketsHandlerprovider.get());
|
||||
}
|
||||
|
||||
|
||||
public ListAllMyBuckets createListAllMyBuckets() {
|
||||
return new ListAllMyBuckets(amazonHost,createListBucketsParser());
|
||||
return new ListAllMyBuckets(amazonHost, createListBucketsParser());
|
||||
}
|
||||
|
||||
@Inject
|
||||
private GenericParseFactory<S3Bucket> parseListBucketFactory;
|
||||
|
||||
|
||||
@Inject
|
||||
Provider<ListBucketHandler> ListBucketHandlerprovider;
|
||||
|
||||
@VisibleForTesting
|
||||
public ParseSax<S3Bucket> createListBucketParser(){
|
||||
public ParseSax<S3Bucket> createListBucketParser() {
|
||||
return parseListBucketFactory.create(ListBucketHandlerprovider.get());
|
||||
}
|
||||
|
||||
public ListBucket createListBucket(S3Bucket bucket) {
|
||||
return new ListBucket(amazonHost, createListBucketParser(), bucket);
|
||||
return new ListBucket(amazonHost, createListBucketParser(), bucket);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Adrian Cole <adriancole@jclouds.org>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.aws.s3.commands.callables;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.Utils;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpFutureCommand;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class GetObjectCallable extends
|
||||
HttpFutureCommand.ResponseCallable<S3Object> {
|
||||
private final HeadMetaDataCallable metaDataParser;
|
||||
private String key;
|
||||
|
||||
@Inject
|
||||
public GetObjectCallable(HeadMetaDataCallable metaDataParser) {
|
||||
this.metaDataParser = metaDataParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return S3Content.NOT_FOUND, if not found.
|
||||
* @throws org.jclouds.http.HttpException
|
||||
*/
|
||||
public S3Object call() throws HttpException {
|
||||
metaDataParser.setResponse(getResponse());
|
||||
S3Object.MetaData metaData = metaDataParser.call();
|
||||
if (metaData == S3Object.MetaData.NOT_FOUND)
|
||||
return S3Object.NOT_FOUND;
|
||||
if (getResponse().getContent() != null) {
|
||||
return new S3Object(metaData,getResponse().getContent());
|
||||
} else {
|
||||
String reason = null;
|
||||
try {
|
||||
reason = Utils.toStringAndClose(getResponse().getContent());
|
||||
} catch (IOException e) {
|
||||
logger.error(e, "error parsing reason");
|
||||
}
|
||||
throw new HttpException("No content retrieving object " + key + ":"
|
||||
+ getResponse() + " reason: " + reason);
|
||||
}
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.metaDataParser.setKey(key);
|
||||
}
|
||||
|
||||
}
|
@ -34,17 +34,18 @@ import org.jclouds.http.HttpFutureCommand;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
* This parses @{link {@link S3Object.MetaData} from http headers or returns
|
||||
* {@link S3Object.MetaData#NOT_FOUND} on 404.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class RetrieveObjectCallable extends
|
||||
HttpFutureCommand.ResponseCallable<S3Object> {
|
||||
public class HeadMetaDataCallable extends
|
||||
HttpFutureCommand.ResponseCallable<S3Object.MetaData> {
|
||||
private final DateService dateParser;
|
||||
private String key;
|
||||
|
||||
@Inject
|
||||
public RetrieveObjectCallable(DateService dateParser) {
|
||||
public HeadMetaDataCallable(DateService dateParser) {
|
||||
this.dateParser = dateParser;
|
||||
}
|
||||
|
||||
@ -52,31 +53,30 @@ public class RetrieveObjectCallable extends
|
||||
* @return S3Content.NOT_FOUND, if not found.
|
||||
* @throws org.jclouds.http.HttpException
|
||||
*/
|
||||
public S3Object call() throws HttpException {
|
||||
public S3Object.MetaData call() throws HttpException {
|
||||
if (getResponse().getStatusCode() == 200) {
|
||||
S3Object object = new S3Object(key);
|
||||
S3Object.MetaData metaData = new S3Object.MetaData(key);
|
||||
String md5Header = getResponse().getFirstHeaderOrNull(
|
||||
"x-amz-meta-object-md5");
|
||||
if (md5Header != null)
|
||||
object.setContentMD5(md5Header);
|
||||
object.setLastModified(dateParser
|
||||
.dateTimeFromHeaderFormat(getResponse()
|
||||
metaData.setContentMD5(md5Header);
|
||||
metaData.setLastModified(
|
||||
dateParser.dateTimeFromHeaderFormat(getResponse()
|
||||
.getFirstHeaderOrNull("Last-Modified")));
|
||||
String eTag = getResponse().getFirstHeaderOrNull("ETag");
|
||||
if (eTag != null) {
|
||||
object.setETag(eTag.replaceAll("\"", ""));
|
||||
metaData.setETag(eTag.replaceAll("\"", ""));
|
||||
}
|
||||
object.setContentType(getResponse().getFirstHeaderOrNull(
|
||||
"Content-Type"));
|
||||
object.setSize(Long.parseLong(getResponse().getFirstHeaderOrNull(
|
||||
"Content-Length")));
|
||||
object.setServer(getResponse().getFirstHeaderOrNull("Server"));
|
||||
if (getResponse().getContent() != null) {
|
||||
object.setContent(getResponse().getContent());
|
||||
}
|
||||
return object;
|
||||
metaData.setContentType(
|
||||
getResponse().getFirstHeaderOrNull("Content-Type"));
|
||||
metaData.setSize(
|
||||
Long.parseLong(getResponse().getFirstHeaderOrNull(
|
||||
"Content-Length")));
|
||||
metaData.setServer(
|
||||
getResponse().getFirstHeaderOrNull("Server"));
|
||||
return metaData;
|
||||
} else if (getResponse().getStatusCode() == 404) {
|
||||
return S3Object.NOT_FOUND;
|
||||
return S3Object.MetaData.NOT_FOUND;
|
||||
} else {
|
||||
String reason = null;
|
||||
try {
|
||||
@ -93,7 +93,4 @@ public class RetrieveObjectCallable extends
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
@ -23,15 +23,16 @@
|
||||
*/
|
||||
package org.jclouds.aws.s3.commands.callables.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.aws.s3.DateService;
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Owner;
|
||||
import org.jclouds.http.commands.callables.xml.ParseSax;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
@ -71,15 +72,14 @@ public class ListAllMyBucketsHandler extends
|
||||
} else if (qName.equals("DisplayName")) {
|
||||
currentOwner.setDisplayName(currentText.toString());
|
||||
} else if (qName.equals("Bucket")) {
|
||||
currentS3Bucket.setCanonicalUser(currentOwner);
|
||||
currentS3Bucket.getMetaData().setCanonicalUser(currentOwner);
|
||||
buckets.add(currentS3Bucket);
|
||||
} else if (qName.equals("Name")) {
|
||||
currentS3Bucket = new S3Bucket(currentText.toString());
|
||||
currentS3Bucket.setHasData(false);
|
||||
currentS3Bucket.setComplete(false);
|
||||
} else if (qName.equals("CreationDate")) {
|
||||
currentS3Bucket.setCreationDate(dateParser
|
||||
.dateTimeFromXMLFormat(currentText.toString()));
|
||||
currentS3Bucket.getMetaData().setCreationDate(
|
||||
dateParser.dateTimeFromXMLFormat(currentText.toString()));
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<S3Bucket> {
|
||||
}
|
||||
|
||||
private S3Bucket s3Bucket;
|
||||
private S3Object currentObject;
|
||||
private S3Object.MetaData currentObjectMetaData;
|
||||
private S3Owner currentOwner;
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
@Inject
|
||||
@ -79,20 +79,23 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<S3Bucket> {
|
||||
} else if (qName.equals("DisplayName")) {
|
||||
currentOwner.setDisplayName(currentText.toString());
|
||||
} else if (qName.equals("Key")) { // content stuff
|
||||
currentObject = new S3Object(currentText.toString());
|
||||
currentObjectMetaData = new S3Object.MetaData(currentText
|
||||
.toString());
|
||||
} else if (qName.equals("LastModified")) {
|
||||
currentObject.setLastModified(dateParser
|
||||
currentObjectMetaData.setLastModified(dateParser
|
||||
.dateTimeFromXMLFormat(currentText.toString()));
|
||||
} else if (qName.equals("ETag")) {
|
||||
currentObject.setETag(currentText.toString().replaceAll("\"", ""));
|
||||
currentObjectMetaData.setETag(currentText.toString().replaceAll(
|
||||
"\"", ""));
|
||||
} else if (qName.equals("Size")) {
|
||||
currentObject.setSize(Long.parseLong(currentText.toString()));
|
||||
currentObjectMetaData.setSize(Long
|
||||
.parseLong(currentText.toString()));
|
||||
} else if (qName.equals("Owner")) {
|
||||
currentObject.setOwner(currentOwner);
|
||||
currentObjectMetaData.setOwner(currentOwner);
|
||||
} else if (qName.equals("StorageClass")) {
|
||||
currentObject.setStorageClass(currentText.toString());
|
||||
currentObjectMetaData.setStorageClass(currentText.toString());
|
||||
} else if (qName.equals("Contents")) {
|
||||
s3Bucket.getContents().add(currentObject);
|
||||
s3Bucket.getContents().add(currentObjectMetaData);
|
||||
} else if (qName.equals("Name")) {// bucket stuff last, as least likely
|
||||
// } else if (qName.equals("Prefix")) {
|
||||
// // no-op
|
||||
|
@ -25,13 +25,14 @@ package org.jclouds.aws.s3.commands.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.aws.s3.commands.BucketExists;
|
||||
import org.jclouds.aws.s3.commands.CopyObject;
|
||||
import org.jclouds.aws.s3.commands.DeleteBucket;
|
||||
import org.jclouds.aws.s3.commands.DeleteObject;
|
||||
import org.jclouds.aws.s3.commands.HeadBucket;
|
||||
import org.jclouds.aws.s3.commands.GetObject;
|
||||
import org.jclouds.aws.s3.commands.HeadMetaData;
|
||||
import org.jclouds.aws.s3.commands.PutBucket;
|
||||
import org.jclouds.aws.s3.commands.PutObject;
|
||||
import org.jclouds.aws.s3.commands.RetrieveObject;
|
||||
import org.jclouds.aws.s3.commands.S3CommandFactory;
|
||||
import org.jclouds.aws.s3.commands.callables.xml.ListAllMyBucketsHandler;
|
||||
import org.jclouds.aws.s3.commands.callables.xml.ListBucketHandler;
|
||||
@ -68,10 +69,10 @@ public class S3CommandsModule extends AbstractModule {
|
||||
S3CommandFactory.DeleteObjectFactory.class,
|
||||
DeleteObject.class));
|
||||
|
||||
bind(S3CommandFactory.HeadBucketFactory.class).toProvider(
|
||||
bind(S3CommandFactory.BucketExistsFactory.class).toProvider(
|
||||
FactoryProvider.newFactory(
|
||||
S3CommandFactory.HeadBucketFactory.class,
|
||||
HeadBucket.class));
|
||||
S3CommandFactory.BucketExistsFactory.class,
|
||||
BucketExists.class));
|
||||
|
||||
final TypeLiteral<S3CommandFactory.GenericParseFactory<List<S3Bucket>>> listBucketsTypeLiteral = new TypeLiteral<S3CommandFactory.GenericParseFactory<List<S3Bucket>>>() {
|
||||
};
|
||||
@ -104,10 +105,15 @@ public class S3CommandsModule extends AbstractModule {
|
||||
S3CommandFactory.PutObjectFactory.class,
|
||||
PutObject.class));
|
||||
|
||||
bind(S3CommandFactory.RetrieveObjectFactory.class).toProvider(
|
||||
bind(S3CommandFactory.GetObjectFactory.class).toProvider(
|
||||
FactoryProvider.newFactory(
|
||||
S3CommandFactory.RetrieveObjectFactory.class,
|
||||
RetrieveObject.class));
|
||||
S3CommandFactory.GetObjectFactory.class,
|
||||
GetObject.class));
|
||||
|
||||
bind(S3CommandFactory.HeadMetaDataFactory.class).toProvider(
|
||||
FactoryProvider.newFactory(
|
||||
S3CommandFactory.HeadMetaDataFactory.class,
|
||||
HeadMetaData.class));
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,49 +32,81 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
* A container that provides namespace, access control and aggregation of
|
||||
* {@link S3Object}s
|
||||
*
|
||||
* @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class S3Bucket {
|
||||
|
||||
public static class MetaData {
|
||||
public static enum LocationConstraint {
|
||||
EU
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private DateTime creationDate;
|
||||
private S3Owner canonicalUser;
|
||||
private LocationConstraint locationConstraint;
|
||||
|
||||
public MetaData(String name) {
|
||||
this.name = checkNotNull(name, "name").toLowerCase();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public DateTime getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(DateTime creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public S3Owner getCanonicalUser() {
|
||||
return canonicalUser;
|
||||
}
|
||||
|
||||
public void setCanonicalUser(S3Owner canonicalUser) {
|
||||
this.canonicalUser = canonicalUser;
|
||||
}
|
||||
|
||||
public LocationConstraint getLocationConstraint() {
|
||||
return locationConstraint;
|
||||
}
|
||||
|
||||
public void setLocationConstraint(LocationConstraint locationConstraint) {
|
||||
this.locationConstraint = locationConstraint;
|
||||
}
|
||||
}
|
||||
|
||||
public static final S3Bucket NOT_FOUND = new S3Bucket("NOT_FOUND");
|
||||
|
||||
private final String name;
|
||||
private DateTime creationDate;
|
||||
private S3Owner canonicalUser;
|
||||
private Set<S3Object> objects = new HashSet<S3Object>();
|
||||
boolean isComplete;
|
||||
boolean hasData;
|
||||
private Set<S3Object.MetaData> objects = new HashSet<S3Object.MetaData>();
|
||||
private final MetaData metaData;
|
||||
|
||||
private boolean isComplete;
|
||||
|
||||
public S3Bucket(String name) {
|
||||
this.name = checkNotNull(name).toLowerCase();
|
||||
this.metaData = new MetaData(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.metaData.getName();
|
||||
}
|
||||
|
||||
public DateTime getCreationDate() {
|
||||
return creationDate;
|
||||
public S3Bucket(MetaData metaData) {
|
||||
this.metaData = checkNotNull(metaData, "metaData");
|
||||
}
|
||||
|
||||
public void setCreationDate(DateTime creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public S3Owner getCanonicalUser() {
|
||||
return canonicalUser;
|
||||
}
|
||||
|
||||
public void setCanonicalUser(S3Owner canonicalUser) {
|
||||
this.canonicalUser = canonicalUser;
|
||||
}
|
||||
|
||||
public Set<S3Object> getContents() {
|
||||
public Set<S3Object.MetaData> getContents() {
|
||||
return objects;
|
||||
}
|
||||
|
||||
public void setContents(Set<S3Object> objects) {
|
||||
public void setContents(Set<S3Object.MetaData> objects) {
|
||||
this.objects = objects;
|
||||
}
|
||||
|
||||
@ -86,53 +118,8 @@ public class S3Bucket {
|
||||
isComplete = complete;
|
||||
}
|
||||
|
||||
public boolean isHasData() {
|
||||
return hasData;
|
||||
public MetaData getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public void setHasData(boolean hasData) {
|
||||
this.hasData = hasData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof S3Bucket))
|
||||
return false;
|
||||
|
||||
S3Bucket s3Bucket = (S3Bucket) o;
|
||||
|
||||
if (hasData != s3Bucket.hasData)
|
||||
return false;
|
||||
if (isComplete != s3Bucket.isComplete)
|
||||
return false;
|
||||
if (canonicalUser != null ? !canonicalUser
|
||||
.equals(s3Bucket.canonicalUser)
|
||||
: s3Bucket.canonicalUser != null)
|
||||
return false;
|
||||
if (objects != null ? !objects.equals(s3Bucket.objects)
|
||||
: s3Bucket.objects != null)
|
||||
return false;
|
||||
if (creationDate != null ? !creationDate.equals(s3Bucket.creationDate)
|
||||
: s3Bucket.creationDate != null)
|
||||
return false;
|
||||
if (!name.equals(s3Bucket.name))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
result = 31 * result
|
||||
+ (creationDate != null ? creationDate.hashCode() : 0);
|
||||
result = 31 * result
|
||||
+ (canonicalUser != null ? canonicalUser.hashCode() : 0);
|
||||
result = 31 * result + (objects != null ? objects.hashCode() : 0);
|
||||
result = 31 * result + (isComplete ? 1 : 0);
|
||||
result = 31 * result + (hasData ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -23,162 +23,140 @@
|
||||
*/
|
||||
package org.jclouds.aws.s3.domain;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class S3Object {
|
||||
public static final S3Object NOT_FOUND = new S3Object("NOT_FOUND");
|
||||
public static final S3Object NOT_FOUND = new S3Object(MetaData.NOT_FOUND);
|
||||
|
||||
public static final String UNKNOWN_MIME_TYPE = "application/x-unknown-mime-type";
|
||||
public static class MetaData {
|
||||
public static final MetaData NOT_FOUND = new MetaData("NOT_FOUND");
|
||||
|
||||
private final String key;
|
||||
private DateTime lastModified;
|
||||
private String eTag;
|
||||
private long size = -1;
|
||||
private S3Owner owner;
|
||||
private String contentType = UNKNOWN_MIME_TYPE;
|
||||
private String storageClass = "STANDARD"; // there is currently no other
|
||||
// type.
|
||||
private String contentMD5;
|
||||
private String server;
|
||||
private Object content;
|
||||
public static final String UNKNOWN_MIME_TYPE = "application/x-unknown-mime-type";
|
||||
|
||||
private final String key;
|
||||
private DateTime lastModified;
|
||||
private String eTag;
|
||||
private long size = -1;
|
||||
private S3Owner owner;
|
||||
private String contentType = UNKNOWN_MIME_TYPE;
|
||||
private String storageClass = "STANDARD";
|
||||
private String contentMD5;
|
||||
private String server;
|
||||
|
||||
public MetaData(String key) {
|
||||
this.key = checkNotNull(key, "key");
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public DateTime getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public void setLastModified(DateTime lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
public String getETag() {
|
||||
return eTag;
|
||||
}
|
||||
|
||||
public void setETag(String tag) {
|
||||
eTag = tag;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public S3Owner getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(S3Owner owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getStorageClass() {
|
||||
return storageClass;
|
||||
}
|
||||
|
||||
public void setStorageClass(String storageClass) {
|
||||
this.storageClass = storageClass;
|
||||
}
|
||||
|
||||
public String getContentMD5() {
|
||||
return contentMD5;
|
||||
}
|
||||
|
||||
public void setContentMD5(String contentMD5) {
|
||||
this.contentMD5 = contentMD5;
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
}
|
||||
|
||||
private Object data;
|
||||
private MetaData metaData;
|
||||
|
||||
public S3Object(String key) {
|
||||
this.key = checkNotNull(key);
|
||||
this(new MetaData(key));
|
||||
}
|
||||
|
||||
public S3Object(MetaData metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public S3Object(MetaData metaData, Object data) {
|
||||
this(metaData);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return metaData.getKey();
|
||||
}
|
||||
|
||||
public DateTime getLastModified() {
|
||||
return lastModified;
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setLastModified(DateTime lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getETag() {
|
||||
return eTag;
|
||||
public void setMetaData(MetaData metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public void setETag(String eTag) {
|
||||
this.eTag = eTag;
|
||||
public MetaData getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public S3Owner getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(S3Owner owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getStorageClass() {
|
||||
return storageClass;
|
||||
}
|
||||
|
||||
public void setStorageClass(String storageClass) {
|
||||
this.storageClass = storageClass;
|
||||
}
|
||||
|
||||
public String getContentMD5() {
|
||||
return contentMD5;
|
||||
}
|
||||
|
||||
public void setContentMD5(String contentMD5) {
|
||||
this.contentMD5 = contentMD5;
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public Object getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(Object content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof S3Object))
|
||||
return false;
|
||||
|
||||
S3Object s3Object = (S3Object) o;
|
||||
|
||||
if (size != s3Object.size)
|
||||
return false;
|
||||
if (contentMD5 != null ? !contentMD5.equals(s3Object.contentMD5)
|
||||
: s3Object.contentMD5 != null)
|
||||
return false;
|
||||
if (contentType != null ? !contentType.equals(s3Object.contentType)
|
||||
: s3Object.contentType != null)
|
||||
return false;
|
||||
if (eTag != null ? !eTag.equals(s3Object.eTag) : s3Object.eTag != null)
|
||||
return false;
|
||||
if (!key.equals(s3Object.key))
|
||||
return false;
|
||||
if (lastModified != null ? !lastModified.equals(s3Object.lastModified)
|
||||
: s3Object.lastModified != null)
|
||||
return false;
|
||||
if (owner != null ? !owner.equals(s3Object.owner)
|
||||
: s3Object.owner != null)
|
||||
return false;
|
||||
if (server != null ? !server.equals(s3Object.server)
|
||||
: s3Object.server != null)
|
||||
return false;
|
||||
if (storageClass != null ? !storageClass.equals(s3Object.storageClass)
|
||||
: s3Object.storageClass != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = key.hashCode();
|
||||
result = 31 * result
|
||||
+ (lastModified != null ? lastModified.hashCode() : 0);
|
||||
result = 31 * result + (eTag != null ? eTag.hashCode() : 0);
|
||||
result = 31 * result + (int) (size ^ (size >>> 32));
|
||||
result = 31 * result + (owner != null ? owner.hashCode() : 0);
|
||||
result = 31 * result
|
||||
+ (contentType != null ? contentType.hashCode() : 0);
|
||||
result = 31 * result
|
||||
+ (storageClass != null ? storageClass.hashCode() : 0);
|
||||
result = 31 * result + (contentMD5 != null ? contentMD5.hashCode() : 0);
|
||||
result = 31 * result + (server != null ? server.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public abstract class BaseS3Map<T> implements Map<String, T>, S3Map {
|
||||
public int size() {
|
||||
try {
|
||||
S3Bucket bucket = refreshBucket();
|
||||
Set<S3Object> contents = bucket.getContents();
|
||||
Set<S3Object.MetaData> contents = bucket.getContents();
|
||||
return contents.size();
|
||||
} catch (Exception e) {
|
||||
Utils.<S3RuntimeException> rethrowIfRuntimeOrSameType(e);
|
||||
@ -84,8 +84,8 @@ public abstract class BaseS3Map<T> implements Map<String, T>, S3Map {
|
||||
|
||||
protected boolean containsETag(String eTagOfValue)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
for (S3Object object : refreshBucket().getContents()) {
|
||||
if (object.getETag().equals(eTagOfValue))
|
||||
for (S3Object.MetaData metaData : refreshBucket().getContents()) {
|
||||
if (metaData.getETag().equals(eTagOfValue))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -106,11 +106,11 @@ public abstract class BaseS3Map<T> implements Map<String, T>, S3Map {
|
||||
md5 = S3Utils.md5(new FileInputStream((File) value));
|
||||
} else if (value instanceof S3Object) {
|
||||
S3Object object = (S3Object) value;
|
||||
object = connection.headObject(bucket, object.getKey()).get(
|
||||
object = connection.getObject(bucket, object.getKey()).get(
|
||||
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
||||
if (S3Object.NOT_FOUND.equals(object))
|
||||
throw new FileNotFoundException("not found: " + object.getKey());
|
||||
md5 = S3Utils.fromHexString(object.getETag());
|
||||
md5 = S3Utils.fromHexString(object.getMetaData().getETag());
|
||||
} else {
|
||||
throw new IllegalArgumentException("unsupported value type: "
|
||||
+ value.getClass());
|
||||
@ -202,7 +202,7 @@ public abstract class BaseS3Map<T> implements Map<String, T>, S3Map {
|
||||
public Set<String> keySet() {
|
||||
try {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
for (S3Object object : refreshBucket().getContents())
|
||||
for (S3Object.MetaData object : refreshBucket().getContents())
|
||||
keys.add(object.getKey());
|
||||
return keys;
|
||||
} catch (Exception e) {
|
||||
@ -214,8 +214,8 @@ public abstract class BaseS3Map<T> implements Map<String, T>, S3Map {
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
try {
|
||||
return connection.headObject(bucket, key.toString()).get(
|
||||
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS) != S3Object.NOT_FOUND;
|
||||
return connection.getObjectMetaData(bucket, key.toString()).get(
|
||||
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS) != S3Object.MetaData.NOT_FOUND;
|
||||
} catch (Exception e) {
|
||||
Utils.<S3RuntimeException> rethrowIfRuntimeOrSameType(e);
|
||||
throw new S3RuntimeException(String.format(
|
||||
|
@ -27,15 +27,16 @@ import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.jclouds.aws.s3.S3Connection;
|
||||
import org.jclouds.aws.s3.commands.BucketExists;
|
||||
import org.jclouds.aws.s3.commands.CopyObject;
|
||||
import org.jclouds.aws.s3.commands.DeleteBucket;
|
||||
import org.jclouds.aws.s3.commands.DeleteObject;
|
||||
import org.jclouds.aws.s3.commands.HeadBucket;
|
||||
import org.jclouds.aws.s3.commands.GetObject;
|
||||
import org.jclouds.aws.s3.commands.HeadMetaData;
|
||||
import org.jclouds.aws.s3.commands.ListAllMyBuckets;
|
||||
import org.jclouds.aws.s3.commands.ListBucket;
|
||||
import org.jclouds.aws.s3.commands.PutBucket;
|
||||
import org.jclouds.aws.s3.commands.PutObject;
|
||||
import org.jclouds.aws.s3.commands.RetrieveObject;
|
||||
import org.jclouds.aws.s3.commands.S3CommandFactory;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
@ -64,17 +65,16 @@ public class LiveS3Connection implements S3Connection {
|
||||
}
|
||||
|
||||
public Future<S3Object> getObject(S3Bucket s3Bucket, String key) {
|
||||
RetrieveObject getRequestObject = factory.createRetrieveObject(
|
||||
s3Bucket, key, true);
|
||||
client.submit(getRequestObject);
|
||||
return getRequestObject;
|
||||
GetObject getObject = factory.createGetObject(s3Bucket, key);
|
||||
client.submit(getObject);
|
||||
return getObject;
|
||||
}
|
||||
|
||||
public Future<S3Object> headObject(S3Bucket s3Bucket, String key) {
|
||||
RetrieveObject getRequestObject = factory.createRetrieveObject(
|
||||
s3Bucket, key, false);
|
||||
client.submit(getRequestObject);
|
||||
return getRequestObject;
|
||||
public Future<S3Object.MetaData> getObjectMetaData(S3Bucket s3Bucket,
|
||||
String key) {
|
||||
HeadMetaData headMetaData = factory.createHeadMetaData(s3Bucket, key);
|
||||
client.submit(headMetaData);
|
||||
return headMetaData;
|
||||
}
|
||||
|
||||
public Future<Boolean> deleteObject(S3Bucket s3Bucket, String key) {
|
||||
@ -111,7 +111,7 @@ public class LiveS3Connection implements S3Connection {
|
||||
}
|
||||
|
||||
public Future<Boolean> bucketExists(S3Bucket s3Bucket) {
|
||||
HeadBucket headRequestObject = factory.createHeadBucket(s3Bucket);
|
||||
BucketExists headRequestObject = factory.createHeadBucket(s3Bucket);
|
||||
client.submit(headRequestObject);
|
||||
return headRequestObject;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class LiveS3InputStreamMap extends BaseS3Map<InputStream> implements
|
||||
try {
|
||||
return (InputStream) (connection.getObject(bucket, o.toString())
|
||||
.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS))
|
||||
.getContent();
|
||||
.getData();
|
||||
} catch (Exception e) {
|
||||
Utils.<S3RuntimeException> rethrowIfRuntimeOrSameType(e);
|
||||
throw new S3RuntimeException(String.format(
|
||||
@ -105,7 +105,7 @@ public class LiveS3InputStreamMap extends BaseS3Map<InputStream> implements
|
||||
Collection<InputStream> values = new LinkedList<InputStream>();
|
||||
Set<S3Object> objects = getAllObjects();
|
||||
for (S3Object object : objects) {
|
||||
values.add((InputStream) object.getContent());
|
||||
values.add((InputStream) object.getData());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
@ -152,7 +152,7 @@ public class LiveS3InputStreamMap extends BaseS3Map<InputStream> implements
|
||||
S3Object object = new S3Object(s);
|
||||
try {
|
||||
InputStream returnVal = containsKey(s) ? get(s) : null;
|
||||
object.setContent(o);
|
||||
object.setData(o);
|
||||
setSizeIfContentIsInputStream(object);
|
||||
connection.addObject(bucket, object).get(
|
||||
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
||||
@ -190,7 +190,7 @@ public class LiveS3InputStreamMap extends BaseS3Map<InputStream> implements
|
||||
List<Future<String>> puts = new ArrayList<Future<String>>();
|
||||
for (String key : map.keySet()) {
|
||||
S3Object object = new S3Object(key);
|
||||
object.setContent(map.get(key));
|
||||
object.setData(map.get(key));
|
||||
setSizeIfContentIsInputStream(object);
|
||||
puts.add(connection.addObject(bucket, object));
|
||||
}
|
||||
@ -206,11 +206,11 @@ public class LiveS3InputStreamMap extends BaseS3Map<InputStream> implements
|
||||
|
||||
private void setSizeIfContentIsInputStream(S3Object object)
|
||||
throws IOException {
|
||||
if (object.getContent() instanceof InputStream) {
|
||||
if (object.getData() instanceof InputStream) {
|
||||
byte[] buffer = IOUtils.toByteArray((InputStream) object
|
||||
.getContent());
|
||||
object.setSize(buffer.length);
|
||||
object.setContent(new ByteArrayInputStream(buffer));
|
||||
.getData());
|
||||
object.getMetaData().setSize(buffer.length);
|
||||
object.setData(new ByteArrayInputStream(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,20 +44,20 @@ public class AmazonS3Test extends S3IntegrationTest {
|
||||
private String returnedString;
|
||||
|
||||
List<S3Bucket> listAllMyBuckets() throws Exception {
|
||||
return client.getBuckets().get(10,TimeUnit.SECONDS);
|
||||
return client.getBuckets().get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
S3Object getObject() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
return client.getObject(s3Bucket, "3366").get(10,TimeUnit.SECONDS);
|
||||
return client.getObject(s3Bucket, "3366").get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
String putFileObject() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
S3Object object = new S3Object("meat");
|
||||
object.setContentType("text/xml");
|
||||
object.setContent(new File("pom.xml"));
|
||||
return client.addObject(s3Bucket, object).get(10,TimeUnit.SECONDS);
|
||||
object.getMetaData().setContentType("text/xml");
|
||||
object.setData(new File("pom.xml"));
|
||||
return client.addObject(s3Bucket, object).get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@DataProvider(name = "putTests")
|
||||
@ -76,17 +76,21 @@ public class AmazonS3Test extends S3IntegrationTest {
|
||||
void testPutObject(String key, String type, Object content,
|
||||
Object realObject) throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "filetestsforadrian");
|
||||
client.createBucketIfNotExists(s3Bucket).get(10,TimeUnit.SECONDS);
|
||||
client.createBucketIfNotExists(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
context.createS3ObjectMap(s3Bucket).clear();
|
||||
assertEquals(client.getBucket(s3Bucket).get(10,TimeUnit.SECONDS).getContents().size(), 0);
|
||||
assertEquals(client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS)
|
||||
.getContents().size(), 0);
|
||||
S3Object object = new S3Object(key);
|
||||
object.setContentType(type);
|
||||
object.setContent(content);
|
||||
assertNotNull(client.addObject(s3Bucket, object).get(10,TimeUnit.SECONDS));
|
||||
object = client.getObject(s3Bucket, object.getKey()).get(10,TimeUnit.SECONDS);
|
||||
object.getMetaData().setContentType(type);
|
||||
object.setData(content);
|
||||
assertNotNull(client.addObject(s3Bucket, object).get(10,
|
||||
TimeUnit.SECONDS));
|
||||
object = client.getObject(s3Bucket, object.getKey()).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
returnedString = S3Utils.getContentAsStringAndClose(object);
|
||||
assertEquals(returnedString, realObject);
|
||||
assertEquals(client.getBucket(s3Bucket).get(10,TimeUnit.SECONDS).getContents().size(), 1);
|
||||
assertEquals(client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS)
|
||||
.getContents().size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,72 +98,75 @@ public class AmazonS3Test extends S3IntegrationTest {
|
||||
String realObject = IOUtils.toString(new FileInputStream("pom.xml"));
|
||||
|
||||
S3Bucket sourceBucket = new S3Bucket(bucketPrefix + "copysource");
|
||||
client.createBucketIfNotExists(sourceBucket).get(10,TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(sourceBucket).get(10,TimeUnit.SECONDS).getContents().size(),
|
||||
0);
|
||||
client.createBucketIfNotExists(sourceBucket).get(10, TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(sourceBucket).get(10, TimeUnit.SECONDS)
|
||||
.getContents().size(), 0);
|
||||
|
||||
S3Object sourceObject = new S3Object("file");
|
||||
sourceObject.setContentType("text/xml");
|
||||
sourceObject.setContent(new File("pom.xml"));
|
||||
sourceObject.getMetaData().setContentType("text/xml");
|
||||
sourceObject.setData(new File("pom.xml"));
|
||||
|
||||
client.addObject(sourceBucket, sourceObject).get(10,TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(sourceBucket).get(10,TimeUnit.SECONDS).getContents().size(),
|
||||
1);
|
||||
client.addObject(sourceBucket, sourceObject).get(10, TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(sourceBucket).get(10, TimeUnit.SECONDS)
|
||||
.getContents().size(), 1);
|
||||
|
||||
sourceObject = client.getObject(sourceBucket, sourceObject.getKey())
|
||||
.get(10,TimeUnit.SECONDS);
|
||||
.get(10, TimeUnit.SECONDS);
|
||||
assertEquals(S3Utils.getContentAsStringAndClose(sourceObject),
|
||||
realObject);
|
||||
|
||||
S3Bucket destinationBucket = new S3Bucket(bucketPrefix
|
||||
+ "copydestination");
|
||||
client.createBucketIfNotExists(destinationBucket).get(10,TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(destinationBucket).get(10,TimeUnit.SECONDS).getContents()
|
||||
.size(), 0);
|
||||
client.createBucketIfNotExists(destinationBucket).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(destinationBucket).get(10,
|
||||
TimeUnit.SECONDS).getContents().size(), 0);
|
||||
|
||||
S3Object destinationObject = new S3Object(sourceObject.getKey());
|
||||
|
||||
client.copyObject(sourceBucket, sourceObject, destinationBucket,
|
||||
destinationObject).get(10,TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(destinationBucket).get(10,TimeUnit.SECONDS).getContents()
|
||||
.size(), 1);
|
||||
destinationObject).get(10, TimeUnit.SECONDS);
|
||||
assertEquals(client.getBucket(destinationBucket).get(10,
|
||||
TimeUnit.SECONDS).getContents().size(), 1);
|
||||
|
||||
destinationObject = client.getObject(destinationBucket,
|
||||
destinationObject.getKey()).get(10,TimeUnit.SECONDS);
|
||||
destinationObject.getKey()).get(10, TimeUnit.SECONDS);
|
||||
|
||||
assertEquals(S3Utils.getContentAsStringAndClose(destinationObject),
|
||||
realObject);
|
||||
|
||||
}
|
||||
|
||||
S3Object headObject() throws Exception {
|
||||
S3Object.MetaData headObject() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
return client.headObject(s3Bucket, "3366").get(10,TimeUnit.SECONDS);
|
||||
return client.getObjectMetaData(s3Bucket, "3366").get(10,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Boolean bucketExists() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
return client.bucketExists(s3Bucket).get(10,TimeUnit.SECONDS);
|
||||
return client.bucketExists(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Boolean deleteBucket() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
return client.deleteBucket(s3Bucket).get(10,TimeUnit.SECONDS);
|
||||
return client.deleteBucket(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Boolean deleteObject() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
return client.deleteObject(s3Bucket, "3366").get(10,TimeUnit.SECONDS);
|
||||
return client.deleteObject(s3Bucket, "3366").get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Boolean createBucketIfNotExists() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
return client.createBucketIfNotExists(s3Bucket).get(10,TimeUnit.SECONDS);
|
||||
return client.createBucketIfNotExists(s3Bucket).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
S3Bucket getBucket() throws Exception {
|
||||
S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest");
|
||||
return client.getBucket(s3Bucket).get(10,TimeUnit.SECONDS);
|
||||
return client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
@ -154,9 +154,9 @@ public class S3IntegrationTest {
|
||||
for (S3Bucket bucket : buckets) {
|
||||
if (bucket.getName().startsWith(bucketPrefix.toLowerCase())) {
|
||||
bucket = client.getBucket(bucket).get(10, TimeUnit.SECONDS);
|
||||
for (S3Object object : bucket.getContents()) {
|
||||
for (S3Object.MetaData metaData : bucket.getContents()) {
|
||||
results.add(client
|
||||
.deleteObject(bucket, object.getKey()));
|
||||
.deleteObject(bucket, metaData.getKey()));
|
||||
}
|
||||
Iterator<Future<Boolean>> iterator = results.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
@ -91,7 +91,7 @@ public class S3ObjectMapTest extends BaseS3MapTest<S3Object> {
|
||||
assertEquals(S3Utils.getContentAsStringAndClose(entry.getValue()),
|
||||
fiveStrings.get(entry.getKey()));
|
||||
S3Object value = entry.getValue();
|
||||
value.setContent("");
|
||||
value.setData("");
|
||||
entry.setValue(value);
|
||||
}
|
||||
assertEquals(map.size(), 5);
|
||||
@ -104,7 +104,7 @@ public class S3ObjectMapTest extends BaseS3MapTest<S3Object> {
|
||||
public void testContains() {
|
||||
putString("one", "apple");
|
||||
S3Object object = new S3Object("one");
|
||||
object.setContent("apple");
|
||||
object.setData("apple");
|
||||
assert map.containsValue(object);
|
||||
}
|
||||
|
||||
@ -125,12 +125,12 @@ public class S3ObjectMapTest extends BaseS3MapTest<S3Object> {
|
||||
@Test
|
||||
public void testPut() throws IOException {
|
||||
S3Object object = new S3Object("one");
|
||||
object.setContent(IOUtils.toInputStream("apple"));
|
||||
object.setSize("apple".getBytes().length);
|
||||
object.setData(IOUtils.toInputStream("apple"));
|
||||
object.getMetaData().setSize("apple".getBytes().length);
|
||||
S3Object old = map.put(object.getKey(), object);
|
||||
getOneReturnsAppleAndOldValueIsNull(old);
|
||||
object.setContent(IOUtils.toInputStream("bear"));
|
||||
object.setSize("bear".getBytes().length);
|
||||
object.setData(IOUtils.toInputStream("bear"));
|
||||
object.getMetaData().setSize("bear".getBytes().length);
|
||||
S3Object apple = map.put(object.getKey(), object);
|
||||
getOneReturnsBearAndOldValueIsApple(apple);
|
||||
}
|
||||
@ -140,8 +140,8 @@ public class S3ObjectMapTest extends BaseS3MapTest<S3Object> {
|
||||
Map<String, S3Object> newMap = new HashMap<String, S3Object>();
|
||||
for (String key : fiveInputs.keySet()) {
|
||||
S3Object object = new S3Object(key);
|
||||
object.setContent(fiveInputs.get(key));
|
||||
object.setSize(fiveBytes.get(key).length);
|
||||
object.setData(fiveInputs.get(key));
|
||||
object.getMetaData().setSize(fiveBytes.get(key).length);
|
||||
newMap.put(key, object);
|
||||
}
|
||||
map.putAll(newMap);
|
||||
@ -154,7 +154,7 @@ public class S3ObjectMapTest extends BaseS3MapTest<S3Object> {
|
||||
@Override
|
||||
protected void putString(String key, String value) {
|
||||
S3Object object = new S3Object(key);
|
||||
object.setContent(value);
|
||||
object.setData(value);
|
||||
map.put(key, object);
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ public class S3ObjectMapTest extends BaseS3MapTest<S3Object> {
|
||||
Map<String, S3Object> newMap = new HashMap<String, S3Object>();
|
||||
for (Map.Entry<String, String> entry : fiveStrings.entrySet()) {
|
||||
S3Object object = new S3Object(entry.getKey());
|
||||
object.setContent(entry.getValue());
|
||||
object.setData(entry.getValue());
|
||||
newMap.put(entry.getKey(), object);
|
||||
}
|
||||
map.putAll(newMap);
|
||||
|
@ -56,14 +56,27 @@ public class StubS3Connection implements S3Connection {
|
||||
if (!realContents.containsKey(key))
|
||||
return S3Object.NOT_FOUND;
|
||||
S3Object object = new S3Object(key);
|
||||
object.setContent(realContents.get(key));
|
||||
object.setData(realContents.get(key));
|
||||
return object;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Future<S3Object> headObject(S3Bucket s3Bucket, String key) {
|
||||
return getObject(s3Bucket, key);
|
||||
public Future<S3Object.MetaData> getObjectMetaData(final S3Bucket s3Bucket,
|
||||
final String key) {
|
||||
return new FutureBase<S3Object.MetaData>() {
|
||||
public S3Object.MetaData get() throws InterruptedException,
|
||||
ExecutionException {
|
||||
if (!bucketToContents.containsKey(s3Bucket))
|
||||
return S3Object.MetaData.NOT_FOUND;
|
||||
Map<String, Object> realContents = bucketToContents
|
||||
.get(s3Bucket);
|
||||
if (!realContents.containsKey(key))
|
||||
return S3Object.MetaData.NOT_FOUND;
|
||||
S3Object.MetaData metaData = new S3Object.MetaData(key);
|
||||
return metaData;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Future<Boolean> deleteObject(final S3Bucket s3Bucket,
|
||||
@ -152,14 +165,13 @@ public class StubS3Connection implements S3Connection {
|
||||
return new FutureBase<S3Bucket>() {
|
||||
public S3Bucket get() throws InterruptedException,
|
||||
ExecutionException {
|
||||
Set<S3Object> contents = new HashSet<S3Object>();
|
||||
Set<S3Object.MetaData> contents = new HashSet<S3Object.MetaData>();
|
||||
Map<String, Object> realContents = bucketToContents
|
||||
.get(s3Bucket);
|
||||
if (realContents != null) {
|
||||
for (String key : realContents.keySet()) {
|
||||
S3Object object = new S3Object(key);
|
||||
object.setContent(realContents.get(key));
|
||||
contents.add(object);
|
||||
S3Object.MetaData metaData = new S3Object.MetaData(key);
|
||||
contents.add(metaData);
|
||||
}
|
||||
}
|
||||
s3Bucket.setContents(contents);
|
||||
|
@ -39,7 +39,6 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ -84,8 +83,7 @@ public class S3CommandFactoryTest {
|
||||
|
||||
@Test
|
||||
void testCreateDeleteObject() {
|
||||
assert commandFactory.createDeleteObject(new S3Bucket("test"),
|
||||
"blah") != null;
|
||||
assert commandFactory.createDeleteObject(new S3Bucket("test"), "blah") != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -100,22 +98,26 @@ public class S3CommandFactoryTest {
|
||||
|
||||
@Test
|
||||
void testCreatePutObject() {
|
||||
S3Object object = createMock(S3Object.class);
|
||||
expect(object.getKey()).andReturn("rawr");
|
||||
expect(object.getContentType()).andReturn("text/xml").atLeastOnce();
|
||||
expect(object.getContent()).andReturn("<a></a>");
|
||||
expect(object.getSize()).andReturn(4L);
|
||||
S3Object.MetaData metaData = createMock(S3Object.MetaData.class);
|
||||
S3Object object = new S3Object(metaData);
|
||||
object.setData("<a></a>");
|
||||
expect(metaData.getKey()).andReturn("rawr");
|
||||
expect(metaData.getContentType()).andReturn("text/xml").atLeastOnce();
|
||||
expect(metaData.getSize()).andReturn(4L);
|
||||
|
||||
replay(object);
|
||||
replay(metaData);
|
||||
|
||||
assert commandFactory.createPutObject(new S3Bucket("test"),
|
||||
object) != null;
|
||||
assert commandFactory.createPutObject(new S3Bucket("test"), object) != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateRetrieveObject() {
|
||||
assert commandFactory.createRetrieveObject(new S3Bucket("test"),
|
||||
"blah", false) != null;
|
||||
void testCreateGetObject() {
|
||||
assert commandFactory.createGetObject(new S3Bucket("test"), "blah") != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateHeadMetaData() {
|
||||
assert commandFactory.createHeadMetaData(new S3Bucket("test"), "blah") != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -118,23 +118,21 @@ public class S3ParserTest extends PerformanceTest {
|
||||
S3Bucket bucket1 = s3Buckets.get(0);
|
||||
assert bucket1.getName().equals("adrianjbosstest");
|
||||
DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z");
|
||||
DateTime date1 = bucket1.getCreationDate();
|
||||
DateTime date1 = bucket1.getMetaData().getCreationDate();
|
||||
assert date1.equals(expectedDate1);
|
||||
S3Bucket bucket2 = s3Buckets.get(1);
|
||||
assert bucket2.getName().equals("adrianjbosstest2");
|
||||
DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z");
|
||||
DateTime date2 = bucket2.getCreationDate();
|
||||
DateTime date2 = bucket2.getMetaData().getCreationDate();
|
||||
assert date2.equals(expectedDate2);
|
||||
assert s3Buckets.size() == 2;
|
||||
S3Owner owner = new S3Owner();
|
||||
owner
|
||||
.setId("e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0");
|
||||
assert bucket1.getCanonicalUser().equals(owner);
|
||||
assert bucket2.getCanonicalUser().equals(owner);
|
||||
assert bucket1.getMetaData().getCanonicalUser().equals(owner);
|
||||
assert bucket2.getMetaData().getCanonicalUser().equals(owner);
|
||||
assert !bucket1.isComplete();
|
||||
assert !bucket2.isComplete();
|
||||
assert !bucket1.isHasData();
|
||||
assert !bucket2.isHasData();
|
||||
assert bucket1.getContents().size() == 0;
|
||||
assert bucket2.getContents().size() == 0;
|
||||
|
||||
@ -146,9 +144,8 @@ public class S3ParserTest extends PerformanceTest {
|
||||
S3Bucket bucket = runParseListBucketResult();
|
||||
assert bucket.isComplete();
|
||||
assert bucket.getName().equals("adrianjbosstest");
|
||||
assert !bucket.isHasData();
|
||||
assert bucket.getContents().size() == 1;
|
||||
S3Object object = bucket.getContents().iterator().next();
|
||||
S3Object.MetaData object = bucket.getContents().iterator().next();
|
||||
assert object.getKey().equals("3366");
|
||||
DateTime expected = new DateTime("2009-03-12T02:00:13.000Z");
|
||||
assert object.getLastModified().equals(expected) : String
|
||||
|
@ -37,8 +37,8 @@ public class S3ObjectTest {
|
||||
void testSetNoContentType() {
|
||||
S3Object object = new S3Object("test");
|
||||
File file = new File("hello.txt");
|
||||
object.setContent(file);
|
||||
assertEquals(object.getContentType(),
|
||||
S3Object.UNKNOWN_MIME_TYPE);
|
||||
object.setData(file);
|
||||
assertEquals(object.getMetaData().getContentType(),
|
||||
S3Object.MetaData.UNKNOWN_MIME_TYPE);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user