public void uploadSnapshot(
     File snapshotFile, SnapshotProgressCallback callback, String snapshotKey, String snapshotId)
     throws EucalyptusCloudException {
   try {
     s3Client.getS3Client().listObjects(StorageProperties.SNAPSHOT_BUCKET);
   } catch (Exception ex) {
     try {
       // if (!s3Client.getS3Client().doesBucketExist(StorageProperties.SNAPSHOT_BUCKET)) {
       s3Client.getS3Client().createBucket(StorageProperties.SNAPSHOT_BUCKET);
       // }
     } catch (Exception e) {
       LOG.error("Snapshot upload failed. Unable to create bucket: snapshots", e);
       throw new EucalyptusCloudException(e);
     }
   }
   try {
     ObjectMetadata metadata = new ObjectMetadata();
     metadata.setContentLength(snapshotFile.length());
     // FIXME: need to set MD5
     s3Client
         .getS3Client()
         .putObject(
             StorageProperties.SNAPSHOT_BUCKET,
             snapshotKey,
             new FileInputStreamWithCallback(snapshotFile, callback),
             metadata);
   } catch (Exception ex) {
     LOG.error("Snapshot " + snapshotId + " upload failed to: " + snapshotKey, ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public void deleteSnapshot(String snapshotLocation, String snapshotId)
     throws EucalyptusCloudException {
   try {
     s3Client.getS3Client().deleteObject(StorageProperties.SNAPSHOT_BUCKET, snapshotLocation);
   } catch (Exception ex) {
     LOG.error("Snapshot delete failed for: " + snapshotId, ex);
     throw new EucalyptusCloudException(ex);
   }
   try {
     s3Client.getS3Client().deleteBucket(StorageProperties.SNAPSHOT_BUCKET);
   } catch (Exception ex) {
     LOG.error("Snapshot bucket delete failed for: " + StorageProperties.SNAPSHOT_BUCKET, ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public void deleteSnapshot(String bucket, String key) throws EucalyptusCloudException {
   refreshOsgURI();
   try {
     s3Client.getS3Client().deleteObject(bucket, key);
   } catch (Exception ex) {
     LOG.error("Failed to delete snapshot file with key " + key, ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public void createBucket(String bucket) throws EucalyptusCloudException {
   refreshOsgURI();
   try {
     s3Client.getS3Client().createBucket(bucket);
   } catch (Exception ex) {
     LOG.error("Failed to create bucket: " + bucket, ex);
     throw new EucalyptusCloudException("Failed to create bucket: " + bucket, ex);
   }
 }
 public long getSnapshotSize(String bucket, String key) throws EucalyptusCloudException {
   refreshOsgURI();
   try {
     ObjectMetadata snapshotMetadata = s3Client.getS3Client().getObjectMetadata(bucket, key);
     return snapshotMetadata.getContentLength();
   } catch (Exception ex) {
     LOG.error("Snapshot download failed for: ", ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public Boolean checkSnapshotExists(String bucket, String key) throws EucalyptusCloudException {
   refreshOsgURI();
   try {
     s3Client.getS3Client().getObjectMetadata(bucket, key);
     return Boolean.TRUE;
   } catch (AmazonServiceException aex) {
     // May be key off on error code for objectnotfound?
     return Boolean.FALSE;
   } catch (Exception ex) {
     LOG.error("Snapshot download failed for: ", ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public void cancelSnapshotUpload(String snapshotId, String bucket, String key)
     throws EucalyptusCloudException {
   refreshOsgURI();
   try {
     if (checkSnapshotExists(bucket, key)) {
       deleteSnapshot(bucket, key);
     } else {
       new SnapshotUploader(snapshotId, bucket, key, s3Client.getS3Client()).cancelUpload();
     }
   } catch (Exception ex) {
     LOG.debug("Failed to cancel upload for snapshot " + snapshotId, ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public void downloadSnapshot(
     String snapshotBucket, String snapshotLocation, File tmpCompressedFile)
     throws EucalyptusCloudException {
   GetObjectRequest getObjectRequest = new GetObjectRequest(snapshotBucket, snapshotLocation);
   try {
     long startTime = System.currentTimeMillis();
     s3Client.getS3Client().getObject(getObjectRequest, tmpCompressedFile);
     LOG.info(
         "Snapshot "
             + snapshotBucket
             + "/"
             + snapshotLocation
             + " download took "
             + Long.toString(System.currentTimeMillis() - startTime)
             + "ms");
   } catch (Exception ex) {
     LOG.error("Snapshot download failed for: " + snapshotLocation, ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public void downloadSnapshot(String bucket, String key, File snapshotFile)
     throws EucalyptusCloudException {
   refreshOsgURI();
   GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
   try {
     long startTime = System.currentTimeMillis();
     s3Client.getS3Client().getObject(getObjectRequest, snapshotFile);
     LOG.info(
         "Snapshot "
             + bucket
             + "/"
             + key
             + " download took "
             + Long.toString(System.currentTimeMillis() - startTime)
             + "ms");
   } catch (Exception ex) {
     LOG.error("Snapshot download failed for: " + key, ex);
     throw new EucalyptusCloudException(ex);
   }
 }
 public void uploadSnapshot(String snapshotId, String bucket, String key, String snapshotFileName)
     throws EucalyptusCloudException {
   refreshOsgURI();
   new SnapshotUploader(snapshotId, bucket, key, snapshotFileName, s3Client.getS3Client())
       .upload();
 }