Example usage for com.amazonaws.services.ec2.model BundleTask getProgress

List of usage examples for com.amazonaws.services.ec2.model BundleTask getProgress

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model BundleTask getProgress.

Prototype


public String getProgress() 

Source Link

Document

The level of task completion, as a percent (for example, 20%).

Usage

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

License:Open Source License

private void waitForBundle(String bid, String manifest, AsynchronousTask<String> task) throws Exception {
    long failurePoint = -1L;
    while (!task.isComplete()) {
        DescribeBundleTasksResult res = _svc.getCloud().getEC2()
                .describeBundleTasks(new DescribeBundleTasksRequest().withBundleIds(bid));
        List<BundleTask> lst = res == null ? null : res.getBundleTasks();
        BundleTask t = isNil(lst) ? null : lst.get(0);
        if (t != null) {
            double bar = asDouble(t.getProgress(), 0.0);
            // pending | waiting-for-shutdown | storing | canceling | complete | failed                
            String s = t.getState();
            if ("pending".equals(s) || "waiting-for-shutdown".equals(s)) {
                task.setPercentComplete(0.0);
            } else if ("complete".equals(s)) {
                onBundleComplete(manifest, task);
            } else if ("bundling".equals(s)) {
                task.setPercentComplete(Math.min(50.0, bar / 2));
            } else if ("storing".equals(s)) {
                task.setPercentComplete(Math.min(100.0, 50.0 + bar / 2));
            } else if ("failed".equals(s)) {
                failurePoint = onBundleFailure(failurePoint, t, task);
            } else {
                task.setPercentComplete(0.0);
            }/*from ww  w  .j a va2 s  .c  om*/
        }

        if (!task.isComplete()) {
            safeThreadWait(1500);
        }
    }
}