Пример #1
0
  @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());
  }
Пример #2
0
 @Override
 public PseudoLock newPseudoLock() throws Exception {
   return new S3PseudoLock(
       s3Client,
       arguments.getBucket(),
       arguments.getLockArguments().getPrefix(),
       arguments.getLockArguments().getTimeoutMs(),
       arguments.getLockArguments().getPollingMs(),
       arguments.getLockArguments().getSettlingMs());
 }
Пример #3
0
 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;
 }
Пример #4
0
 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;
 }