You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jclouds.apache.org by Roman Coedo <no...@github.com> on 2014/07/26 08:14:54 UTC

[jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

The polling strategy interface for job operations
and a simple implementation class have been added.
This implementation waits an initial time and then
polls at regular intervals.
You can merge this Pull Request by running:

  git pull https://github.com/rcoedo/jclouds-labs-aws blobstoreup

Or you can view, comment on it, or merge it online at:

  https://github.com/jclouds/jclouds-labs-aws/pull/44

-- Commit Summary --

  * JCLOUDS-457: Add polling strategy

-- File Changes --

    M glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java (7)
    M glacier/src/main/java/org/jclouds/glacier/blobstore/config/GlacierBlobStoreContextModule.java (3)
    A glacier/src/main/java/org/jclouds/glacier/blobstore/strategy/PollingStrategy.java (21)
    A glacier/src/main/java/org/jclouds/glacier/blobstore/strategy/internal/BasePollingStrategy.java (76)
    M glacier/src/test/java/org/jclouds/glacier/GlacierClientLongLiveTest.java (12)

-- Patch Links --

https://github.com/jclouds/jclouds-labs-aws/pull/44.patch
https://github.com/jclouds/jclouds-labs-aws/pull/44.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Roman Coedo <no...@github.com>.
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {
> +      Thread.sleep(initialWait);
> +      while (inProgress(job, vault)) {
> +         Thread.sleep(timeBetweenPolls);

Seems right! thanks @demobox

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15733544

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Roman Coedo <no...@github.com>.
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {
> +      Thread.sleep(initialWait);
> +      while (inProgress(job, vault)) {
> +         Thread.sleep(timeBetweenPolls);

It seemed correct to me allowing interruption. Also, if the user works with the provider instead of the abstraction and uses the PollingStrategy, they can handle the interruption as they please.

Any thoughts about this @andrewgaul ?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15728156

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-labs-aws-pull-requests #97](https://jclouds.ci.cloudbees.com/job/jclouds-labs-aws-pull-requests/97/) SUCCESS
This pull request looks good

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44#issuecomment-50224869

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Gaul <no...@github.com>.
Pushed to master as 3bc840e6794fa7cc5a62c5bc4632911ed44d45b0.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44#issuecomment-50231294

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {
> +      Thread.sleep(initialWait);
> +      while (inProgress(job, vault)) {
> +         Thread.sleep(timeBetweenPolls);

Is there any specific reason to allow interruption here (given the long potential runtime of Glacier, perhaps yes)? Otherwise, consider [`sleepUninterruptibly`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/Uninterruptibles.html#sleepUninterruptibly%28long,%20java.util.concurrent.TimeUnit%29)?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15726002

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> @@ -112,11 +111,8 @@ public void testListJobs() {
>  
>     @Test(groups = {"live", "livelong", "longtest"}, dependsOnMethods = {"testInitiateJob", "testDescribeJob", "testListJobs"})
>     public void testWaitForSucceed() throws InterruptedException {
> -      Thread.sleep(INITIAL_WAIT);
> -      while (api.describeJob(VAULT_NAME, archiveRetrievalJob).getStatusCode() == JobStatus.IN_PROGRESS ||
> -            api.describeJob(VAULT_NAME, inventoryRetrievalJob).getStatusCode() == JobStatus.IN_PROGRESS) {
> -         Thread.sleep(TIME_BETWEEN_POLLS);
> -      }
> +      new BasePollingStrategy(api).waitForSuccess(VAULT_NAME, archiveRetrievalJob);

This will wait for **three hours**? Does it make sense to have a live test like that?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15726059

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   private final long timeBetweenPolls;
> +
> +   public BasePollingStrategy(long initialWait, long timeBetweenPolls, GlacierClient client) {
> +      this.initialWait = initialWait;
> +      this.timeBetweenPolls = timeBetweenPolls;
> +      this.client = checkNotNull(client, "client");
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);

`describeJob` is [not documented](https://github.com/jclouds/jclouds-labs-aws/blob/master/glacier/src/main/java/org/jclouds/glacier/GlacierClient.java#L248) as returning `null`. Can it? If so, update the Javadoc to explain that?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15725982

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Roman Coedo <no...@github.com>.
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {
> +      Thread.sleep(initialWait);
> +      while (inProgress(job, vault)) {
> +         Thread.sleep(timeBetweenPolls);

Do you think I should do this in the javadoc, or maybe in the readme/getting started guide?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15729458

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> +      this.initialWait = initialWait;
> +      this.timeBetweenPolls = timeBetweenPolls;
> +      this.client = checkNotNull(client, "client");
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {

More of a style question, but is there any reason not to inline this method? It's pretty short and seems to be called from one place only?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15726023

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Gaul <no...@github.com>.
Closed #44.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44#event-145906721

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {
> +      Thread.sleep(initialWait);
> +      while (inProgress(job, vault)) {
> +         Thread.sleep(timeBetweenPolls);

> Do you think I should do this in the javadoc, or maybe in the readme/getting started guide?

I would say the Javadoc should simply say "this method can be long-running and can be interrupted" for those methods where that is appropriate.

The Getting Started Guide should describe the provider in general, and also explain that the operations are long-running and can be interrupted. It could say something like "see the Javadoc to find out which methods can be interrupted", and perhaps give an example of how that could be done.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15733330

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {
> +      Thread.sleep(initialWait);
> +      while (inProgress(job, vault)) {
> +         Thread.sleep(timeBetweenPolls);
> +      }
> +   }
> +
> +   private boolean succeeded(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.SUCCEEDED);

See comment about `describeJob` above

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15726005

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> +import org.jclouds.glacier.GlacierClient;
> +import org.jclouds.glacier.blobstore.strategy.PollingStrategy;
> +import org.jclouds.glacier.domain.JobMetadata;
> +import org.jclouds.glacier.domain.JobStatus;
> +
> +import com.google.inject.Inject;
> +
> +public class BasePollingStrategy implements PollingStrategy {
> +   public static final long DEFAULT_INITIAL_WAIT = TimeUnit.HOURS.toMillis(3);
> +   public static final long DEFAULT_TIME_BETWEEN_POLLS = TimeUnit.MINUTES.toMillis(15);
> +
> +   private final GlacierClient client;
> +   private final long initialWait;
> +   private final long timeBetweenPolls;
> +
> +   public BasePollingStrategy(long initialWait, long timeBetweenPolls, GlacierClient client) {

[minor] Change the order to match the overloaded constructor and field declarations, i.e. `(client, initialWait, timeBetweenPolls)`?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15725952

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {
> +      Thread.sleep(initialWait);
> +      while (inProgress(job, vault)) {
> +         Thread.sleep(timeBetweenPolls);

> It seemed correct to me allowing interruption

Given the time these operations can take, that makes sense to me too. But from what I recall we catch `InterruptedException` in GlacierBlobstore and rethrow as a RuntimeException, so we don't really give you that much "nice" control as a user.

In any case, would it make sense to document (probably on GlacierBlobstore) that it is "safe" to interrupt the long-running operations, and giving a code example (in the Javadocs or jclouds-examples) showing how to do that..?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15729405

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Roman Coedo <no...@github.com>.
> +      this.initialWait = initialWait;
> +      this.timeBetweenPolls = timeBetweenPolls;
> +      this.client = checkNotNull(client, "client");
> +   }
> +
> +   @Inject
> +   public BasePollingStrategy(GlacierClient client) {
> +      this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
> +   }
> +
> +   private boolean inProgress(String job, String vault) {
> +      JobMetadata jobMetadata = client.describeJob(vault, job);
> +      return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
> +   }
> +
> +   private void waitForJob(String job, String vault) throws InterruptedException {

Just clarity, but I can inline it too.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15728167

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by BuildHive <no...@github.com>.
[jclouds ยป jclouds-labs-aws #1196](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs-aws/1196/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44#issuecomment-50224834

Re: [jclouds-labs-aws] JCLOUDS-457: Add polling strategy (#44)

Posted by Roman Coedo <no...@github.com>.
> @@ -112,11 +111,8 @@ public void testListJobs() {
>  
>     @Test(groups = {"live", "livelong", "longtest"}, dependsOnMethods = {"testInitiateJob", "testDescribeJob", "testListJobs"})
>     public void testWaitForSucceed() throws InterruptedException {
> -      Thread.sleep(INITIAL_WAIT);
> -      while (api.describeJob(VAULT_NAME, archiveRetrievalJob).getStatusCode() == JobStatus.IN_PROGRESS ||
> -            api.describeJob(VAULT_NAME, inventoryRetrievalJob).getStatusCode() == JobStatus.IN_PROGRESS) {
> -         Thread.sleep(TIME_BETWEEN_POLLS);
> -      }
> +      new BasePollingStrategy(api).waitForSuccess(VAULT_NAME, archiveRetrievalJob);

It does, that test is part of the long test group and has its own test profile.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/44/files#r15728170