List of usage examples for com.amazonaws.services.s3.model ObjectMetadata ObjectMetadata
public ObjectMetadata()
From source file:com.netflix.exhibitor.core.backup.s3.MockS3Client.java
License:Apache License
@Override public synchronized PutObjectResult putObject(PutObjectRequest request) throws Exception { Map<String, String> userData = Maps.newHashMap(); userData.put(BYTES_HEADER, Integer.toString(uploadedBytes.size())); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteStreams.copy(request.getInputStream(), out); byte[] bytes = out.toByteArray(); uploadedBytes.add(bytes);/*w ww.ja v a 2 s . c om*/ byte[] md5bytes = S3Utils.md5(bytes, out.size()); S3Object object = new S3Object(); object.setKey(request.getKey()); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.setUserMetadata(userData); object.setObjectMetadata(metadata); uploads.put(request.getKey(), object); PutObjectResult result = new PutObjectResult(); result.setETag(S3Utils.toHex(md5bytes)); return result; }
From source file:com.netflix.exhibitor.core.config.s3.S3PseudoLock.java
License:Apache License
@Override protected void createFile(String key, byte[] contents) throws Exception { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(contents.length); PutObjectRequest request = new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), metadata); client.putObject(request);/*from www . ja va 2s . c o m*/ }
From source file:com.netflix.exhibitor.core.s3.S3Utils.java
License:Apache License
public static ObjectMetadata simpleUploadFile(S3Client client, byte[] bytes, String bucket, String key) throws Exception { byte[] md5 = md5(bytes, bytes.length); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.setLastModified(new Date()); metadata.setContentMD5(S3Utils.toBase64(md5)); PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, new ByteArrayInputStream(bytes), metadata);/*from w w w . j a v a 2 s .c o m*/ PutObjectResult putObjectResult = client.putObject(putObjectRequest); if (!putObjectResult.getETag().equals(S3Utils.toHex(md5))) { throw new Exception("Unable to match MD5 for config"); } return metadata; }
From source file:com.netflix.hollow.example.producer.infrastructure.S3Publisher.java
License:Apache License
@Override public void publishSnapshot(File snapshotFile, long stateVersion) { String objectName = getS3ObjectName(blobNamespace, "snapshot", stateVersion); ObjectMetadata metadata = new ObjectMetadata(); metadata.addUserMetadata("to_state", String.valueOf(stateVersion)); metadata.setHeader("Content-Length", snapshotFile.length()); uploadFile(snapshotFile, objectName, metadata); /// now we update the snapshot index updateSnapshotIndex(stateVersion);/*from ww w. ja v a 2 s. c o m*/ }
From source file:com.netflix.hollow.example.producer.infrastructure.S3Publisher.java
License:Apache License
@Override public void publishDelta(File deltaFile, long previousVersion, long currentVersion) { String objectName = getS3ObjectName(blobNamespace, "delta", previousVersion); ObjectMetadata metadata = new ObjectMetadata(); metadata.addUserMetadata("from_state", String.valueOf(previousVersion)); metadata.addUserMetadata("to_state", String.valueOf(currentVersion)); metadata.setHeader("Content-Length", deltaFile.length()); uploadFile(deltaFile, objectName, metadata); }
From source file:com.netflix.hollow.example.producer.infrastructure.S3Publisher.java
License:Apache License
@Override public void publishReverseDelta(File reverseDeltaFile, long previousVersion, long currentVersion) { String objectName = getS3ObjectName(blobNamespace, "reversedelta", currentVersion); ObjectMetadata metadata = new ObjectMetadata(); metadata.addUserMetadata("from_state", String.valueOf(currentVersion)); metadata.addUserMetadata("to_state", String.valueOf(previousVersion)); metadata.setHeader("Content-Length", reverseDeltaFile.length()); uploadFile(reverseDeltaFile, objectName, metadata); }
From source file:com.netflix.hollow.example.producer.infrastructure.S3Publisher.java
License:Apache License
/** * Write a list of all of the state versions to S3. * @param newVersion//from w w w . j av a2 s. c o m */ private synchronized void updateSnapshotIndex(Long newVersion) { /// insert the new version into the list int idx = Collections.binarySearch(snapshotIndex, newVersion); int insertionPoint = Math.abs(idx) - 1; snapshotIndex.add(insertionPoint, newVersion); /// build a binary representation of the list -- gap encoded variable-length integers byte[] idxBytes = buidGapEncodedVarIntSnapshotIndex(); /// indicate the Content-Length ObjectMetadata metadata = new ObjectMetadata(); metadata.setHeader("Content-Length", (long) idxBytes.length); /// upload the new file content. try (InputStream is = new ByteArrayInputStream(idxBytes)) { Upload upload = s3TransferManager.upload(bucketName, getSnapshotIndexObjectName(blobNamespace), is, metadata); upload.waitForCompletion(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.netflix.ice.basic.BasicS3ApplicationGroupService.java
License:Apache License
public boolean saveApplicationGroup(ApplicationGroup appgroup) { Map<String, ApplicationGroup> appgroups = getApplicationGroups(); appgroups.put(appgroup.name, appgroup); try {/* ww w.j a v a 2s . c om*/ String json = getJson(appgroups); s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups", IOUtils.toInputStream(json), new ObjectMetadata()); s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "copy_appgroups", IOUtils.toInputStream(json), new ObjectMetadata()); BasicS3ApplicationGroupService.logger.info("saved appgroup " + appgroup); return true; } catch (JSONException e) { logger.error("Error saving appgroup " + appgroup, e); return false; } }
From source file:com.netflix.ice.basic.BasicS3ApplicationGroupService.java
License:Apache License
public boolean deleteApplicationGroup(String name) { Map<String, ApplicationGroup> appgroups = getApplicationGroups(); ApplicationGroup appgroup = appgroups.remove(name); try {//from www.j a va 2s. c o m String json = getJson(appgroups); s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups", new ByteArrayInputStream(json.getBytes()), new ObjectMetadata()); BasicS3ApplicationGroupService.logger.info("delete appgroup " + name + " " + appgroup); return true; } catch (JSONException e) { logger.error("Error deleting appgroup " + appgroup, e); return false; } }
From source file:com.netflix.ice.processor.BillingFileProcessor.java
License:Apache License
private void updateLastMillis(long millis, String filename) { AmazonS3Client s3Client = AwsUtils.getAmazonS3Client(); s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + filename, IOUtils.toInputStream(millis + ""), new ObjectMetadata()); }