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

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

Introduction

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

Prototype


public String getState() 

Source Link

Document

The state of the task.

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 w w w . ja v a 2s . c  om*/
        }

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