Java Code Examples for com.amazonaws.services.s3.model.ObjectMetadata#getUserMetaDataOf()

The following examples show how to use com.amazonaws.services.s3.model.ObjectMetadata#getUserMetaDataOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: COSAPIClient.java    From stocator with Apache License 2.0 6 votes vote down vote up
private FileStatus getFileStatusKeyBased(String key, Path path) throws AmazonS3Exception {
  LOG.trace("internal method - get file status by key {}, path {}", key, path);
  FileStatus cachedFS = memoryCache.getFileStatus(path.toString());
  if (cachedFS != null) {
    return cachedFS;
  }
  ObjectMetadata meta = mClient.getObjectMetadata(mBucket, key);
  String sparkOrigin = meta.getUserMetaDataOf("data-origin");
  boolean stocatorCreated = false;
  if (sparkOrigin != null) {
    String tmp = (String) sparkOrigin;
    if (tmp.equals("stocator")) {
      stocatorCreated = true;
    }
  }
  mCachedSparkOriginated.put(key, Boolean.valueOf(stocatorCreated));
  FileStatus fs = createFileStatus(meta.getContentLength(), key, meta.getLastModified(), path);
  LOG.trace("getFileStatusKeyBased: key {} fs.path {}", key, fs.getPath());
  memoryCache.putFileStatus(path.toString(), fs);
  return fs;
}
 
Example 2
Source File: COSAPIClient.java    From stocator with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if container/object exists and verifies that it contains
 * Data-Origin=stocator metadata If so, object was created by Spark.
 *
 * @param objectKey the key of the object
 * @return boolean if object was created by Spark
 */
private boolean isStocatorOrigin(String objectKey) {
  LOG.debug("isStocatorOrigin: for {}", objectKey);
  if (objectKey.endsWith("/")) {
    objectKey = objectKey.substring(0, objectKey.length() - 1);
  }

  if (mCachedSparkOriginated.containsKey(objectKey)) {
    boolean res = mCachedSparkOriginated.get(objectKey).booleanValue();
    LOG.debug("isStocatorOrigin: found cached for stocator origin for {}. Status {}", objectKey,
        res);
    return res;
  }
  String key = getRealKey(objectKey);
  Boolean sparkOriginated = Boolean.FALSE;
  ObjectMetadata objMetadata = getObjectMetadata(key);
  if (objMetadata != null) {
    Object sparkOrigin = objMetadata.getUserMetaDataOf("data-origin");
    if (sparkOrigin != null) {
      String tmp = (String) sparkOrigin;
      if (tmp.equals("stocator")) {
        sparkOriginated = Boolean.TRUE;
      }
    }
  }
  mCachedSparkOriginated.put(key, sparkOriginated);
  LOG.debug("isStocatorOrigin: stocator origin for {} is {} non cached. Update cache", key,
      sparkOriginated.booleanValue());
  return sparkOriginated.booleanValue();
}