corrected imports

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1432 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-16 22:05:40 +00:00
parent 2fb0c79e0f
commit f5135f3868
2 changed files with 36 additions and 42 deletions

View File

@ -31,15 +31,13 @@ import org.jclouds.http.HttpHeaders;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx; import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import sun.util.logging.resources.logging;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named; import com.google.inject.name.Named;
/** /**
* A PUT request operation directed at a bucket URI with the "acl" parameter * A PUT request operation directed at a bucket URI with the "acl" parameter sets the Access Control
* sets the Access Control List (ACL) settings for that S3 item. * List (ACL) settings for that S3 item.
* <p /> * <p />
* To set a bucket or object's ACL, you must have WRITE_ACP or FULL_CONTROL access to the item. * To set a bucket or object's ACL, you must have WRITE_ACP or FULL_CONTROL access to the item.
* *
@ -52,21 +50,19 @@ public class PutBucketAccessControlList extends S3FutureCommand<Boolean> {
@Inject @Inject
public PutBucketAccessControlList(@Named("jclouds.http.address") String amazonHost, public PutBucketAccessControlList(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket, ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted AccessControlList acl) @Assisted AccessControlList acl) {
{
super("PUT", "/?acl", callable, amazonHost, bucket); super("PUT", "/?acl", callable, amazonHost, bucket);
String aclPayload = ""; String aclPayload = "";
try { try {
aclPayload = (new AccessControlListBuilder(acl)).getXmlString(); aclPayload = (new AccessControlListBuilder(acl)).getXmlString();
} catch (Exception e) { } catch (Exception e) {
// TODO: How do we handle this sanely? // TODO: How do we handle this sanely?
logger.error(e, "Unable to build XML document for Access Control List: " + acl); logger.error(e, "Unable to build XML document for Access Control List: " + acl);
} }
getRequest().setPayload(aclPayload); getRequest().setPayload(aclPayload);
getRequest().getHeaders().put( getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, aclPayload.getBytes().length + "");
HttpHeaders.CONTENT_LENGTH, aclPayload.getBytes().length + "");
} }
} }

View File

@ -54,7 +54,6 @@ import org.jclouds.aws.s3.commands.options.ListBucketOptions;
import org.jclouds.aws.s3.commands.options.PutBucketOptions; import org.jclouds.aws.s3.commands.options.PutBucketOptions;
import org.jclouds.aws.s3.commands.options.PutObjectOptions; import org.jclouds.aws.s3.commands.options.PutObjectOptions;
import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.domain.CanonicalUser;
import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Bucket;
import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee; import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee;
@ -77,14 +76,14 @@ import com.google.common.collect.Sets;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
/** /**
* // TODO: Adrian: Document this! * Implementation of {@link S3Connection} which keeps all data in a local Map object.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class StubS3Connection implements S3Connection { public class StubS3Connection implements S3Connection {
private static Map<String, Map<String, S3Object>> bucketToContents = new ConcurrentHashMap<String, Map<String, S3Object>>(); private static Map<String, Map<String, S3Object>> bucketToContents = new ConcurrentHashMap<String, Map<String, S3Object>>();
private static Map<String, Metadata.LocationConstraint> bucketToLocation = new ConcurrentHashMap<String, Metadata.LocationConstraint>(); private static Map<String, Metadata.LocationConstraint> bucketToLocation = new ConcurrentHashMap<String, Metadata.LocationConstraint>();
/** /**
* An S3 item's "ACL" may be a {@link CannedAccessPolicy} or an {@link AccessControlList}. * An S3 item's "ACL" may be a {@link CannedAccessPolicy} or an {@link AccessControlList}.
*/ */
@ -354,15 +353,15 @@ public class StubS3Connection implements S3Connection {
} }
if (options.getMaxKeys() != null) { if (options.getMaxKeys() != null) {
SortedSet<S3Object.Metadata> contentsSlice = firstSliceOfSize( SortedSet<S3Object.Metadata> contentsSlice = firstSliceOfSize(contents, Integer
contents, Integer.parseInt(options.getMaxKeys())); .parseInt(options.getMaxKeys()));
returnVal.setMaxKeys(Integer.parseInt(options.getMaxKeys())); returnVal.setMaxKeys(Integer.parseInt(options.getMaxKeys()));
if (!contentsSlice.contains(contents.last())) { if (!contentsSlice.contains(contents.last())) {
// Partial listing // Partial listing
returnVal.setTruncated(true); returnVal.setTruncated(true);
returnVal.setMarker(contentsSlice.last().getKey()); returnVal.setMarker(contentsSlice.last().getKey());
} else { } else {
returnVal.setTruncated(false); returnVal.setTruncated(false);
returnVal.setMarker(null); returnVal.setMarker(null);
} }
contents = contentsSlice; contents = contentsSlice;
@ -452,22 +451,22 @@ public class StubS3Connection implements S3Connection {
if (options.getAcl() != null) if (options.getAcl() != null)
keyToAcl.put(bucketName + "/" + object.getKey(), options.getAcl()); keyToAcl.put(bucketName + "/" + object.getKey(), options.getAcl());
bucketToContents.get(bucketName).put(object.getKey(), new S3Object(newMd, data)); bucketToContents.get(bucketName).put(object.getKey(), new S3Object(newMd, data));
// Set HTTP headers to match metadata // Set HTTP headers to match metadata
newMd.getAllHeaders().put(HttpConstants.LAST_MODIFIED, newMd.getAllHeaders().put(HttpConstants.LAST_MODIFIED,
dateService.rfc822DateFormat(newMd.getLastModified())); dateService.rfc822DateFormat(newMd.getLastModified()));
newMd.getAllHeaders().put(HttpConstants.CONTENT_MD5, S3Utils.toHexString(md5)); newMd.getAllHeaders().put(HttpConstants.CONTENT_MD5, S3Utils.toHexString(md5));
newMd.getAllHeaders().put(HttpConstants.CONTENT_TYPE, newMd.getContentType()); newMd.getAllHeaders().put(HttpConstants.CONTENT_TYPE, newMd.getContentType());
newMd.getAllHeaders().put(HttpConstants.CONTENT_LENGTH, newMd.getSize() + ""); newMd.getAllHeaders().put(HttpConstants.CONTENT_LENGTH, newMd.getSize() + "");
for (Entry<String, String> userMD : newMd.getUserMetadata().entries()) { for (Entry<String, String> userMD : newMd.getUserMetadata().entries()) {
newMd.getAllHeaders().put(userMD.getKey(), userMD.getValue()); newMd.getAllHeaders().put(userMD.getKey(), userMD.getValue());
} }
return new FutureBase<byte[]>() { return new FutureBase<byte[]>() {
public byte[] get() throws InterruptedException, ExecutionException { public byte[] get() throws InterruptedException, ExecutionException {
return md5; return md5;
} }
}; };
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -542,20 +541,20 @@ public class StubS3Connection implements S3Connection {
} }
}; };
} }
protected AccessControlList getACLforS3Item(String bucketAndObjectKey) { protected AccessControlList getACLforS3Item(String bucketAndObjectKey) {
AccessControlList acl = null; AccessControlList acl = null;
Object aclObj = keyToAcl.get(bucketAndObjectKey); Object aclObj = keyToAcl.get(bucketAndObjectKey);
if (aclObj instanceof AccessControlList) { if (aclObj instanceof AccessControlList) {
acl = (AccessControlList) aclObj; acl = (AccessControlList) aclObj;
} else if (aclObj instanceof CannedAccessPolicy) { } else if (aclObj instanceof CannedAccessPolicy) {
acl = AccessControlList.fromCannedAccessPolicy( acl = AccessControlList.fromCannedAccessPolicy((CannedAccessPolicy) aclObj,
(CannedAccessPolicy) aclObj, DEFAULT_OWNER_ID); DEFAULT_OWNER_ID);
} else if (aclObj == null) { } else if (aclObj == null) {
// Default to private access policy // Default to private access policy
acl = AccessControlList.fromCannedAccessPolicy( acl = AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE,
CannedAccessPolicy.PRIVATE, DEFAULT_OWNER_ID); DEFAULT_OWNER_ID);
} }
return acl; return acl;
} }
@ -563,23 +562,23 @@ public class StubS3Connection implements S3Connection {
return new FutureBase<AccessControlList>() { return new FutureBase<AccessControlList>() {
public AccessControlList get() throws InterruptedException, ExecutionException { public AccessControlList get() throws InterruptedException, ExecutionException {
return getACLforS3Item(bucket); return getACLforS3Item(bucket);
} }
}; };
} }
public Future<AccessControlList> getObjectACL(final String bucket, final String objectKey) { public Future<AccessControlList> getObjectACL(final String bucket, final String objectKey) {
return new FutureBase<AccessControlList>() { return new FutureBase<AccessControlList>() {
public AccessControlList get() throws InterruptedException, ExecutionException { public AccessControlList get() throws InterruptedException, ExecutionException {
return getACLforS3Item(bucket + "/" + objectKey); return getACLforS3Item(bucket + "/" + objectKey);
} }
}; };
} }
/** /**
* Replace any AmazonCustomerByEmail grantees with a somewhat-arbitrary canonical user * Replace any AmazonCustomerByEmail grantees with a somewhat-arbitrary canonical user grantee,
* grantee, to match S3 which substitutes each email address grantee with that * to match S3 which substitutes each email address grantee with that user's corresponding ID. In
* user's corresponding ID. In short, although you can PUT email address grantees, * short, although you can PUT email address grantees, these are actually subsequently returned
* these are actually subsequently returned by S3 as canonical user grantees. * by S3 as canonical user grantees.
* *
* @param acl * @param acl
* @return * @return
@ -589,8 +588,8 @@ public class StubS3Connection implements S3Connection {
// the acl's owner ID as the surrogate replacement. // the acl's owner ID as the surrogate replacement.
for (Grant grant : acl.getGrants()) { for (Grant grant : acl.getGrants()) {
if (grant.getGrantee() instanceof EmailAddressGrantee) { if (grant.getGrantee() instanceof EmailAddressGrantee) {
grant.setGrantee(new CanonicalUserGrantee( grant.setGrantee(new CanonicalUserGrantee(acl.getOwner().getId(), acl.getOwner()
acl.getOwner().getId(), acl.getOwner().getDisplayName())); .getDisplayName()));
} }
} }
return acl; return acl;
@ -601,18 +600,17 @@ public class StubS3Connection implements S3Connection {
public Boolean get() throws InterruptedException, ExecutionException { public Boolean get() throws InterruptedException, ExecutionException {
keyToAcl.put(bucket, sanitizeUploadedACL(acl)); keyToAcl.put(bucket, sanitizeUploadedACL(acl));
return true; return true;
} }
}; };
} }
public Future<Boolean> putObjectACL(final String bucket, final String objectKey, public Future<Boolean> putObjectACL(final String bucket, final String objectKey,
final AccessControlList acl) final AccessControlList acl) {
{
return new FutureBase<Boolean>() { return new FutureBase<Boolean>() {
public Boolean get() throws InterruptedException, ExecutionException { public Boolean get() throws InterruptedException, ExecutionException {
keyToAcl.put(bucket + "/" + objectKey, sanitizeUploadedACL(acl)); keyToAcl.put(bucket + "/" + objectKey, sanitizeUploadedACL(acl));
return true; return true;
} }
}; };
} }