Search in sources :

Example 1 with SdkClientException

use of com.amazonaws.SdkClientException in project heron by twitter.

the class S3Uploader method uploadPackage.

@Override
public URI uploadPackage() throws UploaderException {
    // Backup any existing files incase we need to undo this action
    if (s3Client.doesObjectExist(bucket, remoteFilePath)) {
        s3Client.copyObject(bucket, remoteFilePath, bucket, previousVersionFilePath);
    }
    // Attempt to write the topology package to s3
    try {
        s3Client.putObject(bucket, remoteFilePath, packageFileHandler);
    } catch (SdkClientException e) {
        throw new UploaderException(String.format("Error writing topology package to %s %s", bucket, remoteFilePath), e);
    }
    // Ask s3 for the url to the topology package we just uploaded
    final URL resourceUrl = s3Client.getUrl(bucket, remoteFilePath);
    LOG.log(Level.INFO, "Package URL: {0}", resourceUrl);
    // This will happen if the package does not actually exist in the place where we uploaded it to.
    if (resourceUrl == null) {
        throw new UploaderException(String.format("Resource not found for bucket %s and path %s", bucket, remoteFilePath));
    }
    try {
        return resourceUrl.toURI();
    } catch (URISyntaxException e) {
        throw new UploaderException(String.format("Could not convert URL %s to URI", resourceUrl), e);
    }
}
Also used : SdkClientException(com.amazonaws.SdkClientException) URISyntaxException(java.net.URISyntaxException) UploaderException(com.twitter.heron.spi.uploader.UploaderException) URL(java.net.URL)

Aggregations

SdkClientException (com.amazonaws.SdkClientException)1 UploaderException (com.twitter.heron.spi.uploader.UploaderException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1