/** * First, calls {@link ParseSystemAndUserMetadataFromHeaders}. * * Then, sets the object size based on the Content-Length header and adds the content to the * {@link AtmosObject} result. * * @throws org.jclouds.http.HttpException */ public AtmosObject apply(HttpResponse from) { checkNotNull(from, "http response"); AtmosObject object = objectProvider.create(systemMetadataParser.apply(from), userMetadataParser.apply(from)); object.getContentMetadata().setName(object.getSystemMetadata().getObjectName()); object.getContentMetadata().setPath(path); object.getContentMetadata().setUri(uri); object.getAllHeaders().putAll(from.getHeaders()); object.setPayload(from.getPayload()); object.getContentMetadata().setContentLength(attemptToParseSizeAndRangeFromHeaders(from)); return object; }
public MutableBlobMetadata apply(AtmosObject from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.setId(from.getSystemMetadata().getObjectID()); to.setLastModified(from.getSystemMetadata().getLastUserDataModification()); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setName(objectName.apply(from)); to.setUri(from.getContentMetadata().getUri()); to.setContainer(Iterables.get(Splitter.on('/').split(from.getContentMetadata().getPath()), 0)); if (from.getAllHeaders().containsEntry("x-emc-groupacl", "other=READ")) to.setPublicUri(shareUrl.apply(from.getContentMetadata().getPath())); if (from.getSystemMetadata().getType() == FileType.DIRECTORY) { to.setType(StorageType.FOLDER); } else { to.setType(StorageType.BLOB); } Map<String, String> lowerKeyMetadata = Maps.newHashMap(); for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) { String key = entry.getKey().toLowerCase(); if (!systemMetadata.contains(key)) lowerKeyMetadata.put(key, entry.getValue()); } to.setUserMetadata(lowerKeyMetadata); to.setSize(from.getContentMetadata().getContentLength()); return to; } }
private void createOrReplaceObject(String name, Object data, HashCode hashCode, String metadataValue) throws Exception { // Test PUT with string data, ETag hash, and a piece of metadata AtmosObject object = getApi().newObject(); object.getContentMetadata().setName(name); object.setPayload(Payloads.newPayload(data)); object.getContentMetadata().setContentLength(16L); object.getContentMetadata().setContentMD5(hashCode.asBytes()); object.getContentMetadata().setContentType("text/plain"); object.getUserMetadata().getMetadata().put("Metadata", metadataValue); replaceObject(object); }
private void createOrReplaceObject(String name, Object data, String metadataValue) throws Exception { // Test PUT with string data, ETag hash, and a piece of metadata AtmosObject object = getApi().newObject(); object.getContentMetadata().setName(name); object.setPayload(Payloads.newPayload(data)); object.getContentMetadata().setContentLength(16l); Payloads.calculateMD5(object); object.getContentMetadata().setContentType("text/plain"); object.getUserMetadata().getMetadata().put("Metadata", metadataValue); replaceObject(object); }
@Override public ListenableFuture<URI> createFile(String parent, AtmosObject object, PutOptions... options) { final String uri = "http://stub/containers/" + parent + "/" + object.getContentMetadata().getName(); String file = object.getContentMetadata().getName(); String container = parent; if (parent.indexOf('/') != -1) { container = parent.substring(0, parent.indexOf('/')); String path = parent.substring(parent.indexOf('/') + 1); if (!path.equals("")) object.getContentMetadata().setName(path + "/" + file); } Blob blob = object2Blob.apply(object); return Futures.transform(blobStore.putBlob(container, blob), new Function<String, URI>() { public URI apply(String from) { return URI.create(uri); } }, userExecutor); }
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testFileOperations" }) public void testPutZeroLengthBlob() throws Exception { AtmosObject object = getApi().newObject(); object.getContentMetadata().setName("object"); byte[] payload = new byte[0]; object.setPayload(Payloads.newPayload(payload)); object.getContentMetadata().setContentLength(Long.valueOf(payload.length)); replaceObject(object); }
public MutableBlobMetadata apply(AtmosObject from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.setId(from.getSystemMetadata().getObjectID()); to.setLastModified(from.getSystemMetadata().getLastUserDataModification()); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setName(objectName.apply(from)); to.setUri(from.getContentMetadata().getUri()); to.setContainer(Iterables.get(Splitter.on('/').split(from.getContentMetadata().getPath()),0)); if (from.getAllHeaders().containsEntry("x-emc-groupacl", "other=READ")) to.setPublicUri(shareUrl.apply(from.getContentMetadata().getPath())); if (from.getSystemMetadata().getType() == FileType.DIRECTORY) { to.setType(StorageType.FOLDER); } else { to.setType(StorageType.BLOB); } Map<String, String> lowerKeyMetadata = Maps.newHashMap(); for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) { String key = entry.getKey().toLowerCase(); if (!systemMetadata.contains(key)) lowerKeyMetadata.put(key, entry.getValue()); } to.setUserMetadata(lowerKeyMetadata); return to; } }
@Test public void testCorrectContentMetadataName() throws SecurityException, NoSuchMethodException { AtmosObject blob = BLOB_FACTORY.create(null); blob.getContentMetadata().setName("foo"); assertEquals(fn.apply(blob), "foo"); }
private static void verifyMetadata(String metadataValue, AtmosObject getBlob) { assertEquals(getBlob.getContentMetadata().getContentLength(), Long.valueOf(16)); assert getBlob.getContentMetadata().getContentType().startsWith("text/plain"); assertEquals(getBlob.getUserMetadata().getMetadata().get("Metadata"), metadataValue); SystemMetadata md = getBlob.getSystemMetadata(); assertEquals(md.getSize(), 16); assert md.getGroupID() != null; assertEquals(md.getHardLinkCount(), 1); assert md.getInceptionTime() != null; assert md.getLastAccessTime() != null; assert md.getLastMetadataModification() != null; assert md.getLastUserDataModification() != null; assert md.getObjectID() != null; assertEquals(md.getObjectName(), "object"); assert md.getPolicyName() != null; assertEquals(md.getType(), FileType.REGULAR); assert md.getUserID() != null; }
@Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AtmosObject, "this binder is only valid for AtmosObject!"); checkNotNull(request, "request"); AtmosObject object = AtmosObject.class.cast(input); checkNotNull(object.getPayload(), "object payload"); checkArgument(object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); byte[] contentMD5 = object.getContentMetadata().getContentMD5(); if (contentMD5 != null) { request = (R) request.toBuilder() .addHeader(AtmosHeaders.CHECKSUM, "MD5/0/" + BaseEncoding.base16().encode(contentMD5)) .build(); } return metaBinder.bindToRequest(request, object.getUserMetadata()); } }
/** * First, calls {@link ParseSystemAndUserMetadataFromHeaders}. * * Then, sets the object size based on the Content-Length header and adds the content to the * {@link AtmosObject} result. * * @throws org.jclouds.http.HttpException */ public AtmosObject apply(HttpResponse from) { checkNotNull(from, "http response"); AtmosObject object = objectProvider.create(systemMetadataParser.apply(from), userMetadataParser.apply(from)); object.getContentMetadata().setName(object.getSystemMetadata().getObjectName()); object.getContentMetadata().setPath(path); object.getContentMetadata().setUri(uri); object.getAllHeaders().putAll(from.getHeaders()); object.setPayload(from.getPayload()); object.getContentMetadata().setContentLength(attemptToParseSizeAndRangeFromHeaders(from)); return object; }
public MutableBlobMetadata apply(AtmosObject from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.setId(from.getSystemMetadata().getObjectID()); to.setLastModified(from.getSystemMetadata().getLastUserDataModification()); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setName(objectName.apply(from)); to.setUri(from.getContentMetadata().getUri()); to.setContainer(Iterables.get(Splitter.on('/').split(from.getContentMetadata().getPath()), 0)); if (from.getAllHeaders().containsEntry("x-emc-groupacl", "other=READ")) to.setPublicUri(shareUrl.apply(from.getContentMetadata().getPath())); if (from.getSystemMetadata().getType() == FileType.DIRECTORY) { to.setType(StorageType.FOLDER); } else { to.setType(StorageType.BLOB); } Map<String, String> lowerKeyMetadata = Maps.newHashMap(); for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) { String key = entry.getKey().toLowerCase(); if (!systemMetadata.contains(key)) lowerKeyMetadata.put(key, entry.getValue()); } to.setUserMetadata(lowerKeyMetadata); to.setSize(from.getContentMetadata().getContentLength()); return to; } }
public MutableBlobMetadata apply(AtmosObject from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.setId(from.getSystemMetadata().getObjectID()); to.setLastModified(from.getSystemMetadata().getLastUserDataModification()); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setName(objectName.apply(from)); to.setUri(from.getContentMetadata().getUri()); to.setContainer(Iterables.get(Splitter.on('/').split(from.getContentMetadata().getPath()),0)); if (from.getAllHeaders().containsEntry("x-emc-groupacl", "other=READ")) to.setPublicUri(shareUrl.apply(from.getContentMetadata().getPath())); if (from.getSystemMetadata().getType() == FileType.DIRECTORY) { to.setType(StorageType.FOLDER); } else { to.setType(StorageType.BLOB); } Map<String, String> lowerKeyMetadata = Maps.newHashMap(); for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) { String key = entry.getKey().toLowerCase(); if (!systemMetadata.contains(key)) lowerKeyMetadata.put(key, entry.getValue()); } to.setUserMetadata(lowerKeyMetadata); return to; } }
@Test public void testCorrectContentMetadataName() throws SecurityException, NoSuchMethodException { AtmosObject blob = BLOB_FACTORY.create(null); blob.getContentMetadata().setName("foo"); assertEquals(fn.apply(blob), "foo"); }
private static void verifyMetadata(String metadataValue, AtmosObject getBlob) { assertEquals(getBlob.getContentMetadata().getContentLength(), Long.valueOf(16)); assert getBlob.getContentMetadata().getContentType().startsWith("text/plain"); assertEquals(getBlob.getUserMetadata().getMetadata().get("Metadata"), metadataValue); SystemMetadata md = getBlob.getSystemMetadata(); assertEquals(md.getSize(), 16); assert md.getGroupID() != null; assertEquals(md.getHardLinkCount(), 1); assert md.getInceptionTime() != null; assert md.getLastAccessTime() != null; assert md.getLastMetadataModification() != null; assert md.getLastUserDataModification() != null; assert md.getObjectID() != null; assertEquals(md.getObjectName(), "object"); assert md.getPolicyName() != null; assertEquals(md.getType(), FileType.REGULAR); assert md.getUserID() != null; try { Strings2.toStringAndClose(URI.create( "http://accesspoint.emccis.com/rest/objects/" + getBlob.getSystemMetadata().getObjectID()).toURL() .openStream()); fail("shouldn't have worked, since it is private"); } catch (IOException e) { } }
@Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AtmosObject, "this binder is only valid for AtmosObject!"); checkNotNull(request, "request"); AtmosObject object = AtmosObject.class.cast(input); checkNotNull(object.getPayload(), "object payload"); checkArgument(object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); byte[] contentMD5 = object.getContentMetadata().getContentMD5(); if (contentMD5 != null) { request = (R) request.toBuilder() .addHeader(AtmosHeaders.CHECKSUM, "MD5/0/" + BaseEncoding.base16().encode(contentMD5)) .build(); } return metaBinder.bindToRequest(request, object.getUserMetadata()); } }
/** * First, calls {@link ParseSystemAndUserMetadataFromHeaders}. * * Then, sets the object size based on the Content-Length header and adds the content to the * {@link AtmosObject} result. * * @throws org.jclouds.http.HttpException */ public AtmosObject apply(HttpResponse from) { checkNotNull(from, "http response"); AtmosObject object = objectProvider.create(systemMetadataParser.apply(from), userMetadataParser.apply(from)); object.getContentMetadata().setName(object.getSystemMetadata().getObjectName()); object.getContentMetadata().setPath(path); object.getContentMetadata().setUri(uri); object.getAllHeaders().putAll(from.getHeaders()); object.setPayload(from.getPayload()); object.getContentMetadata().setContentLength(attemptToParseSizeAndRangeFromHeaders(from)); return object; }