mirror of https://github.com/apache/jclouds.git
issue 15: implemented deleteobject
git-svn-id: http://jclouds.googlecode.com/svn/trunk@247 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
4f3ac2ead6
commit
032cd8717c
|
@ -27,6 +27,8 @@ import java.util.Calendar;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.Utils;
|
||||||
|
import org.jclouds.aws.s3.S3Connection;
|
||||||
import org.jclouds.aws.s3.S3Context;
|
import org.jclouds.aws.s3.S3Context;
|
||||||
import org.jclouds.aws.s3.S3ContextFactory;
|
import org.jclouds.aws.s3.S3ContextFactory;
|
||||||
import org.jets3t.service.S3ObjectsChunk;
|
import org.jets3t.service.S3ObjectsChunk;
|
||||||
|
@ -51,8 +53,20 @@ public class JCloudsS3Service extends S3Service {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final S3Context context;
|
private final S3Context context;
|
||||||
|
private final S3Connection connection;
|
||||||
|
|
||||||
private final long requestTimeoutMilliseconds = 10000;
|
private final long requestTimeoutMilliseconds = 10000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules)
|
||||||
throws S3ServiceException {
|
throws S3ServiceException {
|
||||||
super(awsCredentials);
|
super(awsCredentials);
|
||||||
|
@ -60,6 +74,7 @@ public class JCloudsS3Service extends S3Service {
|
||||||
modules = new Module[] { new org.jclouds.gae.config.URLFetchServiceClientModule() };
|
modules = new Module[] { new org.jclouds.gae.config.URLFetchServiceClientModule() };
|
||||||
context = S3ContextFactory.createS3Context(awsCredentials
|
context = S3ContextFactory.createS3Context(awsCredentials
|
||||||
.getAccessKey(), awsCredentials.getSecretKey(), modules);
|
.getAccessKey(), awsCredentials.getSecretKey(), modules);
|
||||||
|
connection = context.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,24 +101,44 @@ public class JCloudsS3Service extends S3Service {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @see S3Connection#deleteBucket(org.jclouds.aws.s3.domain.S3Bucket)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void deleteBucketImpl(String bucketName)
|
protected void deleteBucketImpl(String bucketName)
|
||||||
throws S3ServiceException {
|
throws S3ServiceException {
|
||||||
try {
|
try {
|
||||||
context.getConnection().deleteBucket(
|
connection.deleteBucket(
|
||||||
new org.jclouds.aws.s3.domain.S3Bucket(bucketName)).get(
|
new org.jclouds.aws.s3.domain.S3Bucket(bucketName)).get(
|
||||||
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Utils.<S3ServiceException> rethrowIfRuntimeOrSameType(e);
|
||||||
throw new S3ServiceException(
|
throw new S3ServiceException(
|
||||||
"error deleting bucket: " + bucketName, e);
|
"error deleting bucket: " + bucketName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @see S3Connection#deleteObject(org.jclouds.aws.s3.domain.S3Bucket,
|
||||||
|
* String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void deleteObjectImpl(String bucketName, String objectKey)
|
protected void deleteObjectImpl(String bucketName, String objectKey)
|
||||||
throws S3ServiceException {
|
throws S3ServiceException {
|
||||||
// TODO Unimplemented
|
try {
|
||||||
throw new UnsupportedOperationException();
|
connection.deleteObject(
|
||||||
|
new org.jclouds.aws.s3.domain.S3Bucket(bucketName),
|
||||||
|
objectKey).get(requestTimeoutMilliseconds,
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Utils.<S3ServiceException> rethrowIfRuntimeOrSameType(e);
|
||||||
|
throw new S3ServiceException(String.format(
|
||||||
|
"error deleting object: %1s:%2s", bucketName, objectKey), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.jets3t;
|
package org.jclouds.aws.s3.jets3t;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
@ -31,6 +32,7 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.aws.s3.S3Context;
|
import org.jclouds.aws.s3.S3Context;
|
||||||
import org.jclouds.aws.s3.S3IntegrationTest;
|
import org.jclouds.aws.s3.S3IntegrationTest;
|
||||||
|
import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule;
|
||||||
import org.jets3t.service.S3Service;
|
import org.jets3t.service.S3Service;
|
||||||
import org.jets3t.service.S3ServiceException;
|
import org.jets3t.service.S3ServiceException;
|
||||||
import org.jets3t.service.model.S3Bucket;
|
import org.jets3t.service.model.S3Bucket;
|
||||||
|
@ -49,6 +51,15 @@ public class JCloudsS3ServiceTest extends S3IntegrationTest {
|
||||||
AWSCredentials credentials;
|
AWSCredentials credentials;
|
||||||
S3Service service;
|
S3Service service;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean debugEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* overridden only to get access to the amazon credentials used for jets3t
|
||||||
|
* initialization.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected S3Context createS3Context(String AWSAccessKeyId,
|
protected S3Context createS3Context(String AWSAccessKeyId,
|
||||||
String AWSSecretAccessKey) {
|
String AWSSecretAccessKey) {
|
||||||
|
@ -56,12 +67,17 @@ public class JCloudsS3ServiceTest extends S3IntegrationTest {
|
||||||
return super.createS3Context(AWSAccessKeyId, AWSSecretAccessKey);
|
return super.createS3Context(AWSAccessKeyId, AWSSecretAccessKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize a new JCloudsS3Service, but passing
|
||||||
|
* JavaUrlHttpFutureCommandClientModule(), as it is easier to debug in unit
|
||||||
|
* tests.
|
||||||
|
*
|
||||||
|
* @throws S3ServiceException
|
||||||
|
*/
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void testJCloudsS3Service() throws S3ServiceException {
|
public void testJCloudsS3Service() throws S3ServiceException {
|
||||||
service = new JCloudsS3Service(
|
service = new JCloudsS3Service(credentials,
|
||||||
credentials,
|
new JavaUrlHttpFutureCommandClientModule());
|
||||||
new org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -82,17 +98,48 @@ public class JCloudsS3ServiceTest extends S3IntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteBucketImplString() throws S3ServiceException,
|
public void testDeleteBucketImplString() throws S3ServiceException,
|
||||||
InterruptedException, ExecutionException, TimeoutException {
|
InterruptedException, ExecutionException, TimeoutException {
|
||||||
String name = bucketPrefix + ".testDeleteBucketImplString";
|
String bucketName = bucketPrefix + ".testDeleteBucketImplString";
|
||||||
org.jclouds.aws.s3.domain.S3Bucket jcloudsBucket = new org.jclouds.aws.s3.domain.S3Bucket(
|
org.jclouds.aws.s3.domain.S3Bucket jcloudsBucket = createBucket(bucketName);
|
||||||
name);
|
|
||||||
client.createBucketIfNotExists(jcloudsBucket).get(10, TimeUnit.SECONDS);
|
service.deleteBucket(new S3Bucket(bucketName));
|
||||||
service.deleteBucket(new S3Bucket(name));
|
|
||||||
assert !client.bucketExists(jcloudsBucket).get(10, TimeUnit.SECONDS);
|
assert !client.bucketExists(jcloudsBucket).get(10, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private org.jclouds.aws.s3.domain.S3Bucket createBucket(String bucketName)
|
||||||
|
throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
org.jclouds.aws.s3.domain.S3Bucket jcloudsBucket = new org.jclouds.aws.s3.domain.S3Bucket(
|
||||||
|
bucketName);
|
||||||
|
client.createBucketIfNotExists(jcloudsBucket).get(10, TimeUnit.SECONDS);
|
||||||
|
return jcloudsBucket;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteObjectImplStringString() {
|
public void testDeleteObjectImplStringString() throws InterruptedException,
|
||||||
fail("Not yet implemented");
|
ExecutionException, TimeoutException, S3ServiceException {
|
||||||
|
String bucketName = bucketPrefix + ".testDeleteObjectImplStringString";
|
||||||
|
String objectKey = "key";
|
||||||
|
String objectValue = "test";
|
||||||
|
|
||||||
|
org.jclouds.aws.s3.domain.S3Bucket jcloudsBucket = addNewObject(
|
||||||
|
bucketName, objectKey, objectValue);
|
||||||
|
|
||||||
|
service.deleteObject(bucketName, objectKey);
|
||||||
|
|
||||||
|
assertEquals(client.headObject(jcloudsBucket, objectKey).get(10,
|
||||||
|
TimeUnit.SECONDS), org.jclouds.aws.s3.domain.S3Object.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
private org.jclouds.aws.s3.domain.S3Bucket addNewObject(String name,
|
||||||
|
String objectKey, String objectValue) throws InterruptedException,
|
||||||
|
ExecutionException, TimeoutException {
|
||||||
|
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);
|
||||||
|
client.addObject(jcloudsBucket, jcloudsObject)
|
||||||
|
.get(10, TimeUnit.SECONDS);
|
||||||
|
return jcloudsBucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue