You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Ignasi Barrera <no...@github.com> on 2013/06/27 12:19:07 UTC

[jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Refactored asynchronous tasks to be generic, and created a concrete task class for each existing task type.
This way, all operations will produce a typed task, and operating with it will be easier. This will also allow to get the results produced by the task.
You can merge this Pull Request by running:

  git pull https://github.com/nacx/jclouds-labs 146-task-result

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

  https://github.com/jclouds/jclouds-labs/pull/9

-- Commit Summary --

  * JCLOUDS-146: Refactored asynchronous tasks in Abiquo

-- File Changes --

    M abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java (3)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java (18)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java (66)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java (4)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java (16)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java (88)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java (27)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Volume.java (9)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java (1)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java (1)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java (1)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java (1)
    M abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java (51)
    A abiquo/src/main/java/org/jclouds/abiquo/domain/task/ConversionTask.java (44)
    A abiquo/src/main/java/org/jclouds/abiquo/domain/task/VirtualMachineTask.java (44)
    A abiquo/src/main/java/org/jclouds/abiquo/domain/task/VirtualMachineTemplateTask.java (44)
    M abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java (22)
    M abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java (1)
    M abiquo/src/main/java/org/jclouds/abiquo/monitor/AsyncTaskMonitor.java (8)
    M abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java (4)
    M abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java (8)
    M abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java (18)
    M abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java (2)
    M abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveTest.java (6)
    M abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveApiTest.java (5)
    M abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveTest.java (14)
    M abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java (20)
    M abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java (10)
    M abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java (4)
    A abiquo/src/test/java/org/jclouds/abiquo/features/CloudApiExpectTest.java (78)
    M abiquo/src/test/java/org/jclouds/abiquo/features/CloudApiTest.java (1)
    M abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureApiExpectTest.java (2)
    M abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitorTest.java (7)
    A abiquo/src/test/resources/payloads/vm-accepted-request.xml (4)
    A abiquo/src/test/resources/payloads/vm-snapshot.xml (4)

-- Patch Links --

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


Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
> @@ -14,6 +14,7 @@
>   * See the License for the specific language governing permissions and
>   * limitations under the License.
>   */
> +

No. Will remove.

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Andrew Phillips <no...@github.com>.
> @@ -14,6 +14,7 @@
>   * See the License for the specific language governing permissions and
>   * limitations under the License.
>   */
> +

Intended?

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
@demobox I rebased to the latest master after the cleanup. It should be ready to be reviewed again!

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-labs #159](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs/159/) 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/pull/9#issuecomment-20402271

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Andrew Phillips <no...@github.com>.
>              return Arrays.asList(states).contains(task.getState());
>           }
>        };
>     }
> +
> +   public static Predicate<AsyncTask<?, ?>> type(final TaskType... types) {
> +      checkNotNull(types, "types must be defined");
> +
> +      return new Predicate<AsyncTask<?, ?>>() {
> +         @Override
> +         public boolean apply(final AsyncTask<?, ?> task) {
> +            return Arrays.asList(types).contains(task.getType());

Do this conversion once rather than every time the predicate is applied, e.g.
```
checkNotNull(...);
final List<Type> typeList = Arrays.asList(types);
...
  return typeList.contains...
```
?

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
> +    * 
> +    * @param context
> +    *           The API context.
> +    * @param dto
> +    *           The dto used to generate the domain object.
> +    * @return The task domain object.
> +    */
> +   protected static AsyncTask<?, ?> newTask(final ApiContext<AbiquoApi> context, final TaskDto dto) {
> +      // Can be null in untrackable tasks
> +      if (dto == null) {
> +         return null;
> +      }
> +
> +      Class<? extends AsyncTask<?, ?>> taskClass = null;
> +
> +      switch (dto.getType().getOwnerType()) {

If I understand what you mean, I think it is not possible. The task representation (in XML) does not contain a type. In the Abiquo API, there is only a generic Task type, which has an owner (not an api user, but an entity; the task owner is the entity that "has" that task: virtual machines can have tasks, images can have tasks too, etc), and depending on that owner, the task may produce a result of a type or another (the task may produce a VirtualMachine, an Image, and so on).
This purpose of this method is to fill that gap, and provide, in jclouds, a concrete class type for each Task, and I'm doing that by looking at the owner of the task definition.

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

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

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-labs #158](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs/158/) 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/pull/9#issuecomment-20401851

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
Closed #9.

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

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

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-labs #141](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs/141/) 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/pull/9#issuecomment-20109953

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
Merged

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Andrew Phillips <no...@github.com>.
> Let's do things right!

Coolio! Thanks, @nacx !

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

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

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
Closed #9.

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Andrew Phillips <no...@github.com>.
> +    * 
> +    * @param context
> +    *           The API context.
> +    * @param dto
> +    *           The dto used to generate the domain object.
> +    * @return The task domain object.
> +    */
> +   protected static AsyncTask<?, ?> newTask(final ApiContext<AbiquoApi> context, final TaskDto dto) {
> +      // Can be null in untrackable tasks
> +      if (dto == null) {
> +         return null;
> +      }
> +
> +      Class<? extends AsyncTask<?, ?>> taskClass = null;
> +
> +      switch (dto.getType().getOwnerType()) {

I'm guessing the Type object shouldn't know anything different class types? Otherwise, could this be simplified to a dto.getType().getTaskClass() call?

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
>              return Arrays.asList(states).contains(task.getState());
>           }
>        };
>     }
> +
> +   public static Predicate<AsyncTask<?, ?>> type(final TaskType... types) {
> +      checkNotNull(types, "types must be defined");
> +
> +      return new Predicate<AsyncTask<?, ?>>() {
> +         @Override
> +         public boolean apply(final AsyncTask<?, ?> task) {
> +            return Arrays.asList(types).contains(task.getType());

Indeed. I'll re-check all similar predicates.

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
@demobox, I've just created [JCLOUDS-156](https://issues.apache.org/jira/browse/JCLOUDS-156). There are several predicates like this one in Abiquo that should be remove, since they are trivial and provide no value. I'll close  this PR for the moment, cleanup the provider, and reopen it again once the improvement is done.
Let's do things right!

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

Re: [jclouds-labs] JCLOUDS-146: Refactored asynchronous tasks in Abiquo (#9)

Posted by Ignasi Barrera <no...@github.com>.
Reopened #9.

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