if (jobExecutionContext.getSecurityContext(AmazonSecurityContext.AMAZON_SECURITY_CONTEXT)
instanceof AmazonSecurityContext) {
this.amazonSecurityContext = (AmazonSecurityContext) jobExecutionContext.
getSecurityContext(AmazonSecurityContext.AMAZON_SECURITY_CONTEXT);
} else {
throw new GFacProviderException("Amazon Security Context is not set" + jobExecutionContext);
}
} else {
throw new GFacProviderException("Job Execution Context is null" + jobExecutionContext);
}
if (log.isDebugEnabled()) {
log.debug("ACCESS_KEY:" + amazonSecurityContext.getAccessKey());
log.debug("SECRET_KEY:" + amazonSecurityContext.getSecretKey());
log.debug("AMI_ID:" + amazonSecurityContext.getAmiId());
log.debug("INS_ID:" + amazonSecurityContext.getInstanceId());
log.debug("INS_TYPE:" + amazonSecurityContext.getInstanceType());
log.debug("USERNAME:" + amazonSecurityContext.getUserName());
}
saveApplicationJob(jobExecutionContext);
// job
/* Validation */
if (amazonSecurityContext.getAccessKey() == null || amazonSecurityContext.getAccessKey().isEmpty())
throw new GFacProviderException("EC2 Access Key is empty", jobExecutionContext);
if (amazonSecurityContext.getSecretKey() == null || amazonSecurityContext.getSecretKey().isEmpty())
throw new GFacProviderException("EC2 Secret Key is empty", jobExecutionContext);
if ((amazonSecurityContext.getAmiId() == null && amazonSecurityContext.getInstanceId() == null) ||
(amazonSecurityContext.getAmiId() != null && amazonSecurityContext.getAmiId().isEmpty()) ||
(amazonSecurityContext.getInstanceId() != null && amazonSecurityContext.getInstanceId().isEmpty()))
throw new GFacProviderException("EC2 AMI or Instance ID is empty", jobExecutionContext);
if (amazonSecurityContext.getUserName() == null || amazonSecurityContext.getUserName().isEmpty())
throw new GFacProviderException("EC2 Username is empty", jobExecutionContext);
/* Need to start EC2 instance before running it */
AWSCredentials credential =
new BasicAWSCredentials(amazonSecurityContext.getAccessKey(), amazonSecurityContext.getSecretKey());
AmazonEC2Client ec2client = new AmazonEC2Client(credential);