use of com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationVersionsRequest 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);
}
Aggregations