/** * 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 Blob apply(AtmosObject from) { if (from == null) return null; Blob blob = blobFactory.create(object2BlobMd.apply(from)); blob.setPayload(checkNotNull(from.getPayload(), "payload: " + from)); HttpUtils.copy(from.getContentMetadata(), blob.getPayload().getContentMetadata()); blob.setAllHeaders(from.getAllHeaders()); return blob; } }
@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()); } }
@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"); return metaBinder.bindToRequest(request, object.getUserMetadata()); } }
@Override public String apply(Object input) { checkArgument(checkNotNull(input, "input") instanceof AtmosObject, "this function is only valid for AtmosObjects!"); AtmosObject object = AtmosObject.class.cast(input); return checkNotNull(object.getContentMetadata().getName() != null ? object.getContentMetadata().getName() : object.getSystemMetadata().getObjectName(), "objectName"); }
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; } }
public AtmosObject apply(Blob from) { if (from == null) return null; AtmosObject object = blobMd2Object.apply(from.getMetadata()); object.setPayload(checkNotNull(from.getPayload(), "payload: " + from)); object.setAllHeaders(from.getAllHeaders()); return object; } }
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 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; }
/** * {@inheritDoc} */ @Override public int compareTo(AtmosObject o) { if (getContentMetadata().getName() == null) return -1; return (this == o) ? 0 : getContentMetadata().getName().compareTo(o.getContentMetadata().getName()); }
public void testGood() { AtmosObject object = injector.getInstance(AtmosObject.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); object.setPayload(payload); object.getUserMetadata().getListableMetadata().put("apple", "bear"); object.getUserMetadata().getListableMetadata().put("sushi", "king"); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build(); request = binder.bindToRequest(request, object); assertEquals(request.getFirstHeaderOrNull("x-emc-listable-meta"), "apple=bear,sushi=king"); }
protected void retryAndCheckSystemMetadataAndPutIfPresentReplaceStrategy(AtmosObject object) throws Exception { int failures = 0; while (true) { try { checkSystemMetadataAndPutIfPresentReplaceStrategy(object); break; } catch (ExecutionException e1) {// bug if (!(e1.getCause() instanceof KeyAlreadyExistsException)) throw e1; else failures++; } } if (failures > 0) System.err.printf("%d failures create/replacing %s%n", failures, object.getPayload() instanceof InputStreamPayload ? "stream" : "string"); }
private void alwaysDeleteFirstReplaceStrategy(AtmosObject object) throws Exception { deleteConfirmed(privateDirectory + "/" + object.getContentMetadata().getName()); long time = System.currentTimeMillis(); try { getApi().createFile(privateDirectory, object); System.err.printf("%s %s; %dms%n", "created", object.getPayload() instanceof InputStreamPayload ? "stream" : "string", System.currentTimeMillis() - time); } catch (Exception e) { String message = Throwables.getRootCause(e).getMessage(); System.err.printf("failure %s %s; %dms: [%s]%n", "creating", object.getPayload() instanceof InputStreamPayload ? "stream" : "string", System.currentTimeMillis() - time, message); throw e; } }
@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 void run() { try { AtmosObject object = future.get(); checkNotNull(object.getSystemMetadata(), object + " has no content metadata"); if (object.getSystemMetadata().getContentMD5() != null) { if (Arrays.equals(toSearch, object.getSystemMetadata().getContentMD5())) { queue.put(true); } } else { logger.debug("object %s has no content md5", object.getSystemMetadata().getObjectID()); } } catch (InterruptedException e) { Throwables.propagate(e); } catch (ExecutionException e) { Throwables.propagate(e); } } }, userExecutor);
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullContentLengthIllegal() { AtmosObject object = injector.getInstance(AtmosObject.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(null); object.setPayload(payload); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build(); binder.bindToRequest(request, object); }
public UserMetadata apply(BlobMetadata from) { return blob2ObjectInfo.apply(from).getUserMetadata(); } }, userExecutor);
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; } }
@Override public String apply(Object input) { checkArgument(checkNotNull(input, "input") instanceof AtmosObject, "this function is only valid for AtmosObjects!"); AtmosObject object = AtmosObject.class.cast(input); return checkNotNull(object.getContentMetadata().getName() != null ? object.getContentMetadata().getName() : object.getSystemMetadata().getObjectName(), "objectName"); }
public AtmosObject apply(Blob from) { if (from == null) return null; AtmosObject object = blobMd2Object.apply(from.getMetadata()); object.setPayload(checkNotNull(from.getPayload(), "payload: " + from)); object.setAllHeaders(from.getAllHeaders()); return object; } }