Example usage for com.amazonaws.services.ec2.util S3UploadPolicy S3UploadPolicy

List of usage examples for com.amazonaws.services.ec2.util S3UploadPolicy S3UploadPolicy

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.util S3UploadPolicy S3UploadPolicy.

Prototype

public S3UploadPolicy(String awsAccessKeyId, String awsSecretKey, String bucketName, String prefix,
        int expireInMinutes) 

Source Link

Document

Creates a new S3 upload policy object from the specified parameters.

Usage

From source file:com.zotoh.cloudapi.aws.AMImage.java

License:Open Source License

@Override
public AsynchronousTask<String> imageVirtualMachineToStorage(String vmId, String name, String desc,
        String directory) throws CloudException, InternalException {
    tstEStrArg("directory", directory);
    tstEStrArg("name", name);
    tstEStrArg("instance-id", vmId);
    Properties props = _svc.getCloud().getContext().getCustomProperties();
    String uid = props.getProperty(P_ID);
    String pwd = props.getProperty(P_PWD);
    S3UploadPolicy p = new S3UploadPolicy(uid, pwd, directory, name, 60 * 12);
    S3Storage s3 = new S3Storage().withAWSAccessKeyId(uid).withBucket(directory).withPrefix(name)
            .withUploadPolicy(p.getPolicyString()).withUploadPolicySignature(p.getPolicySignature());
    BundleInstanceResult res = _svc.getCloud().getEC2().bundleInstance(
            new BundleInstanceRequest().withInstanceId(vmId).withStorage(new Storage().withS3(s3)));
    BundleTask t = res == null ? null : res.getBundleTask();
    final String bid = t == null ? null : t.getBundleId();
    if (isEmpty(bid)) {
        throw new CloudException("Bundle Id is empty");
    }//  ww w  .ja  v  a  2s. c  om
    final AsynchronousTask<String> task = new AsynchronousTask<String>();
    final String manifest = (directory + "/" + name + ".manifest.xml");
    asyncExec(new Runnable() {
        public void run() {
            try {
                waitForBundle(bid, manifest, task);
            } catch (Throwable t) {
                task.complete(t);
            }
        }
    });
    return task;
}