List of usage examples for com.amazonaws.services.s3.model ObjectMetadata getLastModified
public Date getLastModified()
From source file:alluxio.underfs.s3a.S3AUnderFileSystem.java
License:Apache License
@Override public long getModificationTimeMs(String path) throws IOException { ObjectMetadata details = getObjectDetails(path); if (details != null) { return details.getLastModified().getTime(); } else {/* www.j a va 2s .c om*/ throw new FileNotFoundException(path); } }
From source file:com.emc.ecs.sync.model.object.S3SyncObject.java
License:Open Source License
protected SyncMetadata toSyncMeta(ObjectMetadata s3meta) { SyncMetadata meta = new SyncMetadata(); meta.setCacheControl(s3meta.getCacheControl()); meta.setContentDisposition(s3meta.getContentDisposition()); meta.setContentEncoding(s3meta.getContentEncoding()); if (s3meta.getContentMD5() != null) meta.setChecksum(new Checksum("MD5", s3meta.getContentMD5())); meta.setContentType(s3meta.getContentType()); meta.setHttpExpires(s3meta.getHttpExpiresDate()); meta.setExpirationDate(s3meta.getExpirationTime()); meta.setModificationTime(s3meta.getLastModified()); meta.setContentLength(s3meta.getContentLength()); meta.setUserMetadata(toMetaMap(s3meta.getUserMetadata())); return meta;//from w w w. j a va 2 s . co m }
From source file:com.emc.ecs.sync.target.S3Target.java
License:Open Source License
@Override public void filter(SyncObject obj) { try {/* w w w . jav a2 s .c om*/ // skip the root of the bucket since it obviously exists if ("".equals(rootKey + obj.getRelativePath())) { log.debug("Target is bucket root; skipping"); return; } // some sync objects lazy-load their metadata (i.e. AtmosSyncObject) // since this may be a timed operation, ensure it loads outside of other timed operations if (!(obj instanceof S3ObjectVersion) || !((S3ObjectVersion) obj).isDeleteMarker()) obj.getMetadata(); // Compute target key String targetKey = getTargetKey(obj); obj.setTargetIdentifier(AwsS3Util.fullPath(bucketName, targetKey)); if (includeVersions) { ListIterator<S3ObjectVersion> sourceVersions = s3Source.versionIterator((S3SyncObject) obj); ListIterator<S3ObjectVersion> targetVersions = versionIterator(obj); boolean newVersions = false, replaceVersions = false; if (force) { replaceVersions = true; } else { // special workaround for bug where objects are listed, but they have no versions if (sourceVersions.hasNext()) { // check count and etag/delete-marker to compare version chain while (sourceVersions.hasNext()) { S3ObjectVersion sourceVersion = sourceVersions.next(); if (targetVersions.hasNext()) { S3ObjectVersion targetVersion = targetVersions.next(); if (sourceVersion.isDeleteMarker()) { if (!targetVersion.isDeleteMarker()) replaceVersions = true; } else { if (targetVersion.isDeleteMarker()) replaceVersions = true; else if (!sourceVersion.getETag().equals(targetVersion.getETag())) replaceVersions = true; // different checksum } } else if (!replaceVersions) { // source has new versions, but existing target versions are ok newVersions = true; sourceVersions.previous(); // back up one putIntermediateVersions(sourceVersions, targetKey); // add any new intermediary versions (current is added below) } } if (targetVersions.hasNext()) replaceVersions = true; // target has more versions if (!newVersions && !replaceVersions) { log.info("Source and target versions are the same. Skipping {}", obj.getRelativePath()); return; } } } // something's off; must delete all versions of the object if (replaceVersions) { log.info( "[{}]: version history differs between source and target; re-placing target version history with that from source.", obj.getRelativePath()); // collect versions in target List<DeleteObjectsRequest.KeyVersion> deleteVersions = new ArrayList<>(); while (targetVersions.hasNext()) targetVersions.next(); // move cursor to end while (targetVersions.hasPrevious()) { // go in reverse order S3ObjectVersion version = targetVersions.previous(); deleteVersions.add(new DeleteObjectsRequest.KeyVersion(targetKey, version.getVersionId())); } // batch delete all versions in target log.debug("[{}]: deleting all versions in target", obj.getRelativePath()); s3.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(deleteVersions)); // replay version history in target while (sourceVersions.hasPrevious()) sourceVersions.previous(); // move cursor to beginning putIntermediateVersions(sourceVersions, targetKey); } } else { // normal sync (no versions) Date sourceLastModified = obj.getMetadata().getModificationTime(); long sourceSize = obj.getMetadata().getContentLength(); // Get target metadata. ObjectMetadata destMeta = null; try { destMeta = s3.getObjectMetadata(bucketName, targetKey); } catch (AmazonS3Exception e) { if (e.getStatusCode() != 404) throw new RuntimeException("Failed to check target key '" + targetKey + "' : " + e, e); } if (!force && obj.getFailureCount() == 0 && destMeta != null) { // Check overwrite Date destLastModified = destMeta.getLastModified(); long destSize = destMeta.getContentLength(); if (destLastModified.equals(sourceLastModified) && sourceSize == destSize) { log.info("Source and target the same. Skipping {}", obj.getRelativePath()); return; } if (destLastModified.after(sourceLastModified)) { log.info("Target newer than source. Skipping {}", obj.getRelativePath()); return; } } } // at this point we know we are going to write the object // Put [current object version] if (obj instanceof S3ObjectVersion && ((S3ObjectVersion) obj).isDeleteMarker()) { // object has version history, but is currently deleted log.debug("[{}]: deleting object in target to replicate delete marker in source.", obj.getRelativePath()); s3.deleteObject(bucketName, targetKey); } else { putObject(obj, targetKey); // if object has new metadata after the stream (i.e. encryption checksum), we must update S3 again if (obj.requiresPostStreamMetadataUpdate()) { log.debug("[{}]: updating metadata after sync as required", obj.getRelativePath()); CopyObjectRequest cReq = new CopyObjectRequest(bucketName, targetKey, bucketName, targetKey); cReq.setNewObjectMetadata(AwsS3Util.s3MetaFromSyncMeta(obj.getMetadata())); s3.copyObject(cReq); } } } catch (Exception e) { throw new RuntimeException("Failed to store object: " + e, e); } }
From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java
License:Open Source License
protected void populateResponseMetadata(final ObjectStorageDataResponseType reply, final ObjectMetadata metadata) { reply.setSize(metadata.getContentLength()); reply.setContentDisposition(metadata.getContentDisposition()); reply.setContentType(metadata.getContentType()); reply.setEtag(metadata.getETag());/*from w w w .ja va 2 s .co m*/ reply.setLastModified(metadata.getLastModified()); if (metadata.getUserMetadata() != null && metadata.getUserMetadata().size() > 0) { if (reply.getMetaData() == null) reply.setMetaData(new ArrayList<MetaDataEntry>()); for (String k : metadata.getUserMetadata().keySet()) { reply.getMetaData().add(new MetaDataEntry(k, metadata.getUserMetadata().get(k))); } } }
From source file:com.facebook.presto.hive.PrestoS3FileSystem.java
License:Apache License
private static long lastModifiedTime(ObjectMetadata metadata) { Date date = metadata.getLastModified(); return (date != null) ? date.getTime() : 0; }
From source file:com.github.wuic.nut.s3.S3NutDao.java
License:Open Source License
/** * {@inheritDoc}// www.ja v a 2s .c om */ @Override protected Long getLastUpdateTimestampFor(final String path) throws StreamException { try { // Connect if necessary connect(); log.info("Polling S3 nut '{}'", path); final ObjectMetadata objectMetadata = amazonS3Client.getObjectMetadata(bucketName, path); final String response = objectMetadata.getLastModified().toString(); log.info("Last modification response : {}", response); return objectMetadata.getLastModified().getTime(); } catch (AmazonClientException ase) { throw new StreamException(new IOException(ase)); } }
From source file:com.ibm.stocator.fs.cos.COSAPIClient.java
License:Apache License
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; }//from w w w.ja v a2s .com 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); memoryCache.putFileStatus(path.toString(), fs); return fs; }
From source file:com.jeet.s3.AmazonS3ClientWrapper.java
License:Open Source License
public Date getLastModified(String path) { try {//from ww w. ja v a 2 s . co m ObjectMetadata objectMetadata = s3Client.getObjectMetadata(Constants.BUCKET_NAME, path); return objectMetadata != null ? objectMetadata.getLastModified() : null; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.liferay.portal.store.s3.S3FileCacheImpl.java
License:Open Source License
@Override public File getCacheFile(S3Object s3Object, String fileName) throws IOException { StringBundler sb = new StringBundler(4); sb.append(getCacheDirName());/*from ww w . j a v a2 s. com*/ sb.append(DateUtil.getCurrentDate(_CACHE_DIR_PATTERN, LocaleUtil.getDefault())); sb.append(_s3KeyTransformer.getNormalizedFileName(fileName)); ObjectMetadata objectMetadata = s3Object.getObjectMetadata(); Date lastModifiedDate = objectMetadata.getLastModified(); sb.append(lastModifiedDate.getTime()); String cacheFileName = sb.toString(); File cacheFile = new File(cacheFileName); try (InputStream inputStream = s3Object.getObjectContent()) { if (cacheFile.exists() && (cacheFile.lastModified() >= lastModifiedDate.getTime())) { return cacheFile; } if (inputStream == null) { throw new IOException("S3 object input stream is null"); } File parentFile = cacheFile.getParentFile(); FileUtil.mkdirs(parentFile); try (OutputStream outputStream = new FileOutputStream(cacheFile)) { StreamUtil.transfer(inputStream, outputStream); } } return cacheFile; }
From source file:com.netflix.exhibitor.core.config.s3.S3ConfigProvider.java
License:Apache License
@Override public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception { {//from w ww. j a v a2 s. c om ObjectMetadata metadata = getConfigMetadata(); if (metadata != null) { Date lastModified = metadata.getLastModified(); if (lastModified.getTime() != compareVersion) { return null; // apparently there's no atomic way to do this with S3 so this will have to do } } } PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config); ByteArrayOutputStream out = new ByteArrayOutputStream(); propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor " + hostname); byte[] bytes = out.toByteArray(); ObjectMetadata metadata = S3Utils.simpleUploadFile(s3Client, bytes, arguments.getBucket(), arguments.getKey()); return new LoadedInstanceConfig(propertyBasedInstanceConfig, metadata.getLastModified().getTime()); }