Search in sources :

Example 1 with DescribeApplicationVersionsResult

use of com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationVersionsResult in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ArtifactProcessing method createOrGetApplicationVersion.

/**
 * Create the application version if it does not already exist.
 * @param versionLabel
 * @param fileURl
 * @throws IOException
 */
public ApplicationVersionDescription createOrGetApplicationVersion(String appPrfix) throws IOException {
    String s3Path = config.getVersionPath(appPrfix);
    final String versionLabel = config.getVersionLabel(appPrfix);
    String fileURL = config.getArtifactoryUrl(appPrfix);
    // First determine if this version already exists
    log.debug(String.format("Creating version: %1$s using: %2$s ", versionLabel, fileURL));
    DescribeApplicationVersionsResult results = beanstalkClient.describeApplicationVersions(new DescribeApplicationVersionsRequest().withApplicationName(config.getElasticBeanstalkApplicationName()).withVersionLabels(versionLabel));
    if (results.getApplicationVersions().size() < 1) {
        log.debug(String.format("Version: %1$s does not already existing so it will be created...", versionLabel));
        // first download the file
        // Download the artifacts
        File temp = null;
        String key = s3Path + versionLabel;
        try {
            // First download the file from Artifactory
            temp = downloadFile(fileURL);
            // Now upload it to s3.
            final long start = System.currentTimeMillis();
            ;
            log.debug("Starting to upload file " + fileURL + " to S3...");
            PutObjectResult putResult = s3Client.putObject(new PutObjectRequest(config.getStackConfigS3BucketName(), key, temp).withProgressListener(new ProgressListener() {

                private volatile long lastUpdate = start;

                public void progressChanged(ProgressEvent progressEvent) {
                    // The progress data they give use never seems to change so we just show the elase time.
                    long now = System.currentTimeMillis();
                    long lastUpdateElapase = now - lastUpdate;
                    long totalElapse = now - start;
                    if (lastUpdateElapase > 2 * 1000) {
                        // Log the event
                        log.debug(String.format("Uploading %1$s to S3. Elapse time: %2$tM:%2$tS:%2$tL ", versionLabel, totalElapse));
                        lastUpdate = now;
                    }
                }
            }));
        } finally {
            if (temp != null) {
                temp.delete();
            }
        // Clean up the file
        }
        // The S3 Location for this file.
        S3Location location = new S3Location(config.getStackConfigS3BucketName(), key);
        // we need to create this version
        beanstalkClient.createApplicationVersion(new CreateApplicationVersionRequest().withApplicationName(config.getElasticBeanstalkApplicationName()).withAutoCreateApplication(false).withSourceBundle(location).withVersionLabel(versionLabel));
        // Describe the version
        results = beanstalkClient.describeApplicationVersions(new DescribeApplicationVersionsRequest().withApplicationName(config.getElasticBeanstalkApplicationName()).withVersionLabels(versionLabel));
    } else {
        log.debug(String.format("Version: %1$s already exists.", versionLabel));
    }
    return results.getApplicationVersions().get(0);
}
Also used : DescribeApplicationVersionsRequest(com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationVersionsRequest) ProgressListener(com.amazonaws.services.s3.model.ProgressListener) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) DescribeApplicationVersionsResult(com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationVersionsResult) CreateApplicationVersionRequest(com.amazonaws.services.elasticbeanstalk.model.CreateApplicationVersionRequest) ProgressEvent(com.amazonaws.services.s3.model.ProgressEvent) File(java.io.File) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) S3Location(com.amazonaws.services.elasticbeanstalk.model.S3Location)

Aggregations

CreateApplicationVersionRequest (com.amazonaws.services.elasticbeanstalk.model.CreateApplicationVersionRequest)1 DescribeApplicationVersionsRequest (com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationVersionsRequest)1 DescribeApplicationVersionsResult (com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationVersionsResult)1 S3Location (com.amazonaws.services.elasticbeanstalk.model.S3Location)1 ProgressEvent (com.amazonaws.services.s3.model.ProgressEvent)1 ProgressListener (com.amazonaws.services.s3.model.ProgressListener)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)1 File (java.io.File)1