@Override public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception { { 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()); }
private S3Object getConfigObject() throws Exception { try { S3Object object = s3Client.getObject(arguments.getBucket(), arguments.getKey()); if (object.getObjectMetadata().getContentLength() > 0) { return object; } } catch (AmazonS3Exception e) { if (!isNotFoundError(e)) { throw e; } } return null; }
private ObjectMetadata getConfigMetadata() throws Exception { try { ObjectMetadata metadata = s3Client.getObjectMetadata(arguments.getBucket(), arguments.getKey()); if (metadata.getContentLength() > 0) { return metadata; } } catch (AmazonS3Exception e) { if (!isNotFoundError(e)) { throw e; } } return null; }