You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Ilya Kulakov <no...@github.com> on 2013/11/27 20:28:52 UTC

[jclouds-labs] Cloudsigma2 subscription calc fix (#41)

I&#39;ll squash commits after we consider PR is ready to be merged.

We&#39;ve not fixed tests yet, so they&#39;ll fail for now if you don&#39;t have any IP subscriptions. Will fix that in the next few days.
You can merge this Pull Request by running:

  git pull https://github.com/cloudsigma/jclouds-labs cloudsigma2-subscription-calc-fix

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

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

-- Commit Summary --

  * Add CalcSubscription domain method
  * Change listSubscriptionsCalculator() to calculateSubscriptions() method
  * Add SubscriptionCalculator domain object
  * Add subscription calculator expect &amp; live tests

-- File Changes --

    M cloudsigma2/src/main/java/org/jclouds/cloudsigma2/CloudSigma2Api.java (25)
    A cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/CalcSubscription.java (249)
    A cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/SubscriptionCalculator.java (75)
    M cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/internal/ParseSubscriptions.java (22)
    M cloudsigma2/src/test/java/org/jclouds/cloudsigma2/CloudSigma2ApiExpectTest.java (80)
    M cloudsigma2/src/test/java/org/jclouds/cloudsigma2/CloudSigma2ApiLiveTest.java (61)
    A cloudsigma2/src/test/resources/subscriptioncalculator-request.json (1)
    A cloudsigma2/src/test/resources/subscriptioncalculator.json (35)

-- Patch Links --

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ilya Kulakov <no...@github.com>.
@nacx It could be an issue with out tests: we're adding resource that are not exist. @shevchenator is looking into that.

Meanwhile, I think server should respond with an error message in this case. What do you say, @gcbirzan?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +import java.util.Date;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class CalcSubscription {
> +
> +   public static class Builder {
> +      private String amount;
> +      private double discountAmount;
> +      private double discountPercent;
> +      private Date endTime;
> +      private String period;
> +      private double price;
> +      private SubscriptionResource resource;
> +      private Date startTime;

Ordering? Have `startTime` and `endTime` together?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
And the fix: https://github.com/jclouds/jclouds-labs/pull/46

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

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

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

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

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
> +   private final Date startTime;
> +
> +   @ConstructorProperties({
> +         "amount", "discount_amount", "discount_percent", "end_time", "period", "price"
> +         ,"resource", "start_time", "status", "subscribed_object", "uuid"
> +   })
> +   public CalcSubscription(String amount, double discountAmount, double discountPercent, Date endTime, String period
> +         , double price, SubscriptionResource resource, Date startTime) {
> +      this.amount = amount;
> +      this.discountAmount = discountAmount;
> +      this.discountPercent = discountPercent;
> +      this.endTime = endTime;
> +      this.period = period;
> +      this.price = price;
> +      this.resource = resource;
> +      this.startTime = startTime;

Add a `checkNotNull` check for the mandatory fields and annotate the optional ones with `@Nullable`.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
Thanks! It looks good to me. @demobox what do you say?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
> +   @Named("discount_amount")
> +   private final double discountAmount;
> +   @Named("discount_percent")
> +   private final double discountPercent;
> +   @Named("end_time")
> +   private final Date endTime;
> +   private final String period;
> +   private final double price;
> +   private final SubscriptionResource resource;
> +   @Named("start_time")
> +   private final Date startTime;
> +
> +   @ConstructorProperties({
> +         "amount", "discount_amount", "discount_percent", "end_time", "period", "price"
> +         ,"resource", "start_time", "status", "subscribed_object", "uuid"
> +   })

Values here do not match the constructor arguments.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
Thanks for the cleanup, @shevchenator - looks good to me!

@nacx: whenever you're ready, I'd say squash'n'rebase and then good to merge..?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by BuildHive <no...@github.com>.
[jclouds ยป jclouds-labs #641](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs/641/) 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/41#issuecomment-29550094

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ilya Kulakov <no...@github.com>.
@nacx What do you say?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by gcbirzan <no...@github.com>.
I know nothing about the jclouds implementation of tags, but if you could give a dump of the json/xml sent/received during that test, I can check if it's a problem on our side.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> + */
> +package org.jclouds.cloudsigma2.domain;
> +
> +import javax.inject.Named;
> +import java.beans.ConstructorProperties;
> +import java.util.Date;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class CalcSubscription {
> +
> +   public static class Builder {
> +      private String amount;
> +      private double discountAmount;
> +      private double discountPercent;

Also, is there some link between `discountAmount` and `discountPercent`? E.g. should
```
amount * discountPercent = discountAmount
```
or some other invariant be true? In that case, should we validate this, or can we keep only two of the three and calculate the third?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
Given @Kentzo comment and your feedback I'm pretty sure the tests are not properly configured: the resource being attached is a Drive, and having a deeper look at the tests (as test execution order is random), it is possible that the test that deletes the drive is executed between the "createTag" and "editTag" test. That could explain the failure.

I'll refactor the tests to make sure all resources that are reused between tests are deleted at the end, and see if that fixes the issue.

Thanks for the feedback!

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> @demobox what do you say?

Only a couple of minor comments, which could also be ignored if we are in a hurry. One other point about formatting: I noticed
```
lotsOfArgs
   , anotherArg
```
with the comma on the **new** line in a few places. I think jclouds generally uses:
```
lotsOfArgs,
   anotherArg
```
instead.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
Merged! Thank you all!

Although I'm closing this PR, feel free to add comments here regarding the edit tag test, just to have the context.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by gcbirzan <no...@github.com>.
Ah. I know!

The magic smoke is leaking from places. But, yes. That would explain it, and apparently we have a ticket for this, but it doesn't have a high priority so it'll be fixed after new year's.

The way the drive deletion works is that we put drive in a special state, called deleting, when you delete them. We then filter them out from responses, until the deletion actually happens (which generally doesn't take very long, but we throttle it so it can take several minutes. Problem solved by not filtering them out of responses... Except that when you try to attach it to a guest or put it in a tag, the status of the drive isn't checked, so the operation succeeds (for guests, it'll fail when you try to start it), but you just cannot see the resource.

Sorry for the confusion (took me a while to realise what's happening since I was doing the test manually, with a non-existent resource, instead of a deleting one.)

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> + */
> +package org.jclouds.cloudsigma2.domain;
> +
> +import javax.inject.Named;
> +import java.beans.ConstructorProperties;
> +import java.util.Date;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class CalcSubscription {
> +
> +   public static class Builder {
> +      private String amount;
> +      private double discountAmount;
> +      private double discountPercent;

> All these values are from the server.

Fair enough. Thanks for explaining, @Kentzo!

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> @@ -944,25 +947,13 @@ IPInfo editIP(@PathParam("uuid") String uuid
>     /**
>      * This is identical to the listSubscriptions(), except that subscriptions are not actually bought.
>      *
> -    * @return list of subscriptions that are not actually bought.
> +    * @return List of subscriptions that are not actually bought.

Is this correct? The signature of the method now says that we're returning a SubscriptionCalculator?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +   @Named("discount_percent")
> +   private final double discountPercent;
> +   @Named("end_time")
> +   private final Date endTime;
> +   private final String period;
> +   private final double price;
> +   private final SubscriptionResource resource;
> +   @Named("start_time")
> +   private final Date startTime;
> +
> +   @ConstructorProperties({
> +         "amount", "discount_amount", "discount_percent", "end_time", "period", "price"
> +         ,"resource", "start_time", "status", "subscribed_object", "uuid"
> +   })
> +   public CalcSubscription(String amount, double discountAmount, double discountPercent, Date endTime, String period
> +         , double price, SubscriptionResource resource, Date startTime) {

Formatting: move `,` to the end of the previous line?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ilya Kulakov <no...@github.com>.
> + */
> +package org.jclouds.cloudsigma2.domain;
> +
> +import javax.inject.Named;
> +import java.beans.ConstructorProperties;
> +import java.util.Date;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class CalcSubscription {
> +
> +   public static class Builder {
> +      private String amount;
> +      private double discountAmount;
> +      private double discountPercent;

@demobox 
All these values are from the server. We should pass them as is, without validation/transfomration, because they represent some business logic about rounding costs.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> @@ -679,6 +700,10 @@ private void checkProfileInfo(ProfileInfo newProfileInfo, ProfileInfo createdPro
>        assertEquals(newProfileInfo.getLastName(), createdProfileInfo.getLastName());
>        assertEquals(newProfileInfo.getTown(), createdProfileInfo.getTown());
>     }
> +
> +   private void checkCalcSubscription(CalcSubscription actual, CalcSubscription expected) {
> +      assertEquals(actual.getResource(), expected.getResource());
> +   }

If we're only doing one check here, inline this method?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ilya Kulakov <no...@github.com>.
@nacx :dart:

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +         this.resource = resource;
> +         return this;
> +      }
> +
> +      /**
> +       * @param startTime Start time of subscription
> +       * @return Subscription Binder
> +       */
> +      public Builder startTime(Date startTime) {
> +         this.startTime = startTime;
> +         return this;
> +      }
> +
> +      public CalcSubscription build() {
> +         return new CalcSubscription(amount, discountAmount, discountPercent, endTime, period, price, resource
> +               , startTime);

Formatting: move `,` to the end of the previous line?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

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

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
> + */
> +public class CalcSubscription {
> +
> +   public static class Builder {
> +      private String amount;
> +      private double discountAmount;
> +      private double discountPercent;
> +      private Date endTime;
> +      private String period;
> +      private double price;
> +      private SubscriptionResource resource;
> +      private Date startTime;
> +
> +      /**
> +       * @param amount
> +       * @return Subscription Binder

Should be Subscription "Builder"

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +import javax.inject.Named;
> +import java.beans.ConstructorProperties;
> +import java.util.Date;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class CalcSubscription {
> +
> +   public static class Builder {
> +      private String amount;
> +      private double discountAmount;
> +      private double discountPercent;
> +      private Date endTime;
> +      private String period;
> +      private double price;

Difference, if any, between `price` and `amount`?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +import javax.inject.Named;
> +import java.beans.ConstructorProperties;
> +import java.util.List;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class SubscriptionCalculator {
> +   private final double price;
> +   @Named("objects")
> +   private final List<CalcSubscription> subscriptions;
> +
> +   @ConstructorProperties({"price", "objects"})
> +   public SubscriptionCalculator(double price, List<CalcSubscription> subscriptions) {
> +      this.price = price;
> +      this.subscriptions = subscriptions;

If not nullable, add `checkNotNull` checks?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +   @Named("discount_amount")
> +   private final Double discountAmount;
> +   @Named("discount_percent")
> +   private final Double discountPercent;
> +   private final String period;
> +   private final Double price;
> +   private final SubscriptionResource resource;
> +   @Named("start_time")
> +   private final Date startTime;
> +   @Named("end_time")
> +   private final Date endTime;
> +
> +   @ConstructorProperties({
> +         "amount", "discount_amount", "discount_percent", "period", "price", "resource", "start_time", "end_time"
> +   })
> +   public CalcSubscription(@Nullable Double amount, @Nullable Double discountAmount, @Nullable  Double discountPercent,

[minor] Two spaces in `@Nullable  Double`

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by gcbirzan <no...@github.com>.
Sorry for the late response, some urgent stuff came up. 

There is an error, albeit misleading, when doing that, it says you do not have TAG permission on that resource.

I've also tried this several times, looked at our acceptance tests, they all do the same and it works. The only thing I can do is take a look at the logs at the time when you run the tests, but I doubt there'll be anything useful in there as CRUD operations that don't affect your infrastructure (i.e. not drives and snapshots) don't log much in case of success.

In a version we're deploying soon (though, probably not before new year's) we'll have the ability to track requests better and if you want, I can spin up such an instance on my machine for you test on, in a few days.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ilya Kulakov <no...@github.com>.
@nacx what's the number of JIRA issue?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
> +               .resource(SubscriptionResource.IP)
> +               .endTime(new SimpleDateFormatDateService().iso8601SecondsDateParse("2013-12-27T12:00:00+00:00"))
> +               .build()
> +            , new CalcSubscription.Builder()
> +            .resource(SubscriptionResource.VLAN)
> +            .endTime(new SimpleDateFormatDateService().iso8601SecondsDateParse("2013-12-27T12:00:00+00:00"))
> +            .build()
> +            , new CalcSubscription.Builder()
> +            .resource(SubscriptionResource.VLAN)
> +            .endTime(new SimpleDateFormatDateService().iso8601SecondsDateParse("2013-12-27T12:00:00+00:00"))
> +            .build()
> +      ));
> +
> +      assertNotNull(subscriptionCalculator);
> +      for (CalcSubscription subscription : subscriptionCalculator.getSubscriptions()) {
> +         assertNotNull(subscription);

Assert also that, at least, the `price` field has the expected value? Just to make sure deserialization works as expected (and to give a bit more meaning to the test).

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +import java.util.List;
> +
> +import static com.google.common.base.Preconditions.checkNotNull;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class SubscriptionCalculator {
> +   private final double price;
> +   @Named("objects")
> +   private final List<CalcSubscription> subscriptions;
> +
> +   @ConstructorProperties({"price", "objects"})
> +   public SubscriptionCalculator(double price, List<CalcSubscription> subscriptions) {
> +      this.price = checkNotNull(price);
> +      this.subscriptions = checkNotNull(subscriptions);

`checkNotNull(price, "price");` and `checkNotNull(subscriptions, "subscriptions");`

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
> + * limitations under the License.
> + */
> +package org.jclouds.cloudsigma2.domain;
> +
> +import javax.inject.Named;
> +import java.beans.ConstructorProperties;
> +import java.util.Date;
> +
> +/**
> + * @author Vladimir Shevchenko
> + */
> +public class CalcSubscription {
> +
> +   public static class Builder {
> +      private String amount;
> +      private double discountAmount;

Why is `amount` a String and `discountAmount` a double? Could we expose something more consistent in the builder/getters?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> This is not just the test failing, but the equals method not being properly implemented. Could you kindly fix that?

Good catch, @nacx!

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +   private final Date endTime;
> +
> +   @ConstructorProperties({
> +         "amount", "discount_amount", "discount_percent", "period", "price", "resource", "start_time", "end_time"
> +   })
> +   public CalcSubscription(@Nullable Double amount, @Nullable Double discountAmount, @Nullable  Double discountPercent,
> +                           @Nullable String period, @Nullable Double price, SubscriptionResource resource,
> +                           @Nullable Date startTime, @Nullable Date endTime) {
> +      checkArgument(!(endTime == null && period == null),
> +            "Subscription period should be configured with endTime or period");
> +      this.amount = amount;
> +      this.discountAmount = discountAmount;
> +      this.discountPercent = discountPercent;
> +      this.period = period;
> +      this.price = price;
> +      this.resource = checkNotNull(resource);

`checkNotNull(resource, "resource");`

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
> +   private final Date startTime;
> +
> +   @ConstructorProperties({
> +         "amount", "discount_amount", "discount_percent", "end_time", "period", "price"
> +         ,"resource", "start_time", "status", "subscribed_object", "uuid"
> +   })
> +   public CalcSubscription(String amount, double discountAmount, double discountPercent, Date endTime, String period
> +         , double price, SubscriptionResource resource, Date startTime) {
> +      this.amount = amount;
> +      this.discountAmount = discountAmount;
> +      this.discountPercent = discountPercent;
> +      this.endTime = endTime;
> +      this.period = period;
> +      this.price = price;
> +      this.resource = resource;
> +      this.startTime = startTime;

I assume they should be exclusive, right? In that case, something like this should properly validate the fields:
```java
checkArgument(endTime == null ^ period == null, "Subscription period should be configured with endTime or period");
```

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
Live tests for the subscription calculator have been fixed, so for me it is good to merge (I'll do later today).

@Kentzo, @shevchenator, There is still a live test failing (not related to this PR, and not a merge stopper, though):

    Failed tests:   testEditTag(org.jclouds.cloudsigma2.CloudSigma2LasVegasLiveTest): expected [0] but found [1]
    Tests run: 50, Failures: 1, Errors: 0, Skipped: 1
    
    testEditTag(org.jclouds.cloudsigma2.CloudSigma2LasVegasLiveTest)  Time elapsed: 0.698 sec  <<< FAILURE!
    java.lang.AssertionError: expected [0] but found [1]
	at org.testng.Assert.fail(Assert.java:94)
	at org.testng.Assert.failNotEquals(Assert.java:494)
	at org.testng.Assert.assertEquals(Assert.java:123)
	at org.testng.Assert.assertEquals(Assert.java:370)
	at org.testng.Assert.assertEquals(Assert.java:380)
	at org.jclouds.cloudsigma2.CloudSigma2ApiLiveTest.checkTag(CloudSigma2ApiLiveTest.java:692)
	at org.jclouds.cloudsigma2.CloudSigma2ApiLiveTest.testEditTag(CloudSigma2ApiLiveTest.java:530)

It was already failing before:

>It fails in [this line](https://github.com/jclouds/jclouds-labs/blob/master/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/CloudSigma2ApiLiveTest.java#L663). Is it possible that the tag edition does not properly handle the resource modification? Or is it something to fix in the live test itself?

Do you have any clue if it is something wrong in the test itself, or in the API/backend?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
Thanks for the fix, @Kentzo and @shevchenator! Could you run the live tests and post the results here, in a Gist or Pastie? Or would you have time to run the live tests again, @nacx?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
It is not related to this, but after I re-enabled the live tests for the tags, I get always the same failure:

    Failed tests:   testEditTag(org.jclouds.cloudsigma2.CloudSigma2LasVegasLiveTest): expected [0] but found [1]

It fails in [this line](https://github.com/jclouds/jclouds-labs/blob/master/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/CloudSigma2ApiLiveTest.java#L663). Is it possible that the tag edition does not properly handle the resource modification? Or is it something to fix in the live test itself?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Vladimir Shevchenko <no...@github.com>.
> +   private final Date startTime;
> +
> +   @ConstructorProperties({
> +         "amount", "discount_amount", "discount_percent", "end_time", "period", "price"
> +         ,"resource", "start_time", "status", "subscribed_object", "uuid"
> +   })
> +   public CalcSubscription(String amount, double discountAmount, double discountPercent, Date endTime, String period
> +         , double price, SubscriptionResource resource, Date startTime) {
> +      this.amount = amount;
> +      this.discountAmount = discountAmount;
> +      this.discountPercent = discountPercent;
> +      this.endTime = endTime;
> +      this.period = period;
> +      this.price = price;
> +      this.resource = resource;
> +      this.startTime = startTime;

@nacx users can specify subscription period with ```endTime``` or ```period``` what is the way to properly handle these cases?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +   @Override
> +   public int hashCode() {
> +      int result;
> +      long temp;
> +      temp = Double.doubleToLongBits(price);
> +      result = (int) (temp ^ (temp >>> 32));
> +      result = 31 * result + (subscriptions != null ? subscriptions.hashCode() : 0);
> +      return result;
> +   }
> +
> +   @Override
> +   public String toString() {
> +      return "SubscriptionCalculator{" +
> +            "price=" + price +
> +            ", subscriptions=" + subscriptions +
> +            "} " + super.toString();

Why the `super.toString()`?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
>  import org.jclouds.cloudsigma2.domain.Tag;
>  import org.jclouds.cloudsigma2.domain.TagResource;
>  import org.jclouds.cloudsigma2.domain.Transaction;
>  import org.jclouds.cloudsigma2.domain.VLANInfo;
>  import org.testng.annotations.Test;
>  
> -import com.google.common.base.Function;
> -import com.google.common.collect.FluentIterable;
> -import com.google.common.collect.ImmutableList;
> +import java.math.BigInteger;
> +import java.util.Date;
> +import java.util.HashMap;
> +import java.util.List;
> +import java.util.Map;
> +
> +import static com.google.common.base.Predicates.in;
> +import static com.google.common.collect.Iterables.any;
> +import static com.google.common.collect.Iterables.transform;
> +import static org.testng.Assert.*;

Avoid using wildcard imports.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
Thanks @Kentzo !

I've executed the live tests and the calculator one throws a NPE. It is not about the test itself, but something that is wrong in the domain object definition (and we didn't find in previous reviews).

When performing [this assertion](https://github.com/cloudsigma/jclouds-labs/blob/cloudsigma2-subscription-calc-fix/cloudsigma2/src/test/java/org/jclouds/cloudsigma2/CloudSigma2ApiLiveTest.java#L621), the NPE is thrown. The problem is in [this implementation of the equals method](https://github.com/cloudsigma/jclouds-labs/blob/cloudsigma2-subscription-calc-fix/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/CalcSubscription.java#L213-L216) in the `CalcSubscription` object. As you'll see, all those parameters are declared as a `Double` (the object) and are `@Nullable`. However, the `Double.compare` method expects `double` arguments (the primitive types). This means that if those values are actually `null`, that method will throw a NPE when trying to unbox their value.

This is not just the test failing, but the `equals` method not being properly implemented. Could you kindly fix that?
Thanks!

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
+1. Squash + rebase + include the JIRA issue in the commit message.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> +      CloudSigma2Api api = requestSendsResponse(
> +            postBuilder()
> +            .endpoint(endpoint + "subscriptioncalculator/")
> +            .payload(payloadFromResourceWithContentType("/subscriptioncalculator-request.json"
> +                  , MediaType.APPLICATION_JSON))
> +            .build()
> +            , responseBuilder()
> +            .payload(payloadFromResourceWithContentType("/subscriptioncalculator.json", MediaType.APPLICATION_JSON))
> +            .build()
> +      );
> +
> +      SubscriptionCalculator subscriptionCalculator = api.calculateSubscriptions(subscriptionsToCalculate);
> +
> +      assertNotNull(subscriptionCalculator);
> +      for (int i = 0; i < subscriptionsToCalculate.size(); i++) {
> +         checkCalcSubscription(subscriptionCalculator.getSubscriptions().get(i) , subscriptionsToCalculate.get(i));

[minor] Space in `get(i) ,`

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

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

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
> We've not fixed tests yet, so they'll fail for now if you don't have any IP subscriptions. Will fix that in the next few days.

NP! That can be addressed in a different PR. I've just run the live tests and they pass now :)


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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Andrew Phillips <no...@github.com>.
> @@ -587,9 +588,29 @@ public void testGetSubscription() throws Exception {
>     }
>  
>     @Test
> -   public void testListSubscriptionsCalculator() throws Exception {
> -      for (Subscription subscription : api.listSubscriptionsCalculator().concat()) {
> -         assertNotNull(subscription);
> +   public void testCalculateSubscriptions() throws Exception {
> +      long month = (long) 30 * 24 * 3600 * 1000;

Rename to `monthInMillis` or something more descriptive?

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

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

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
https://issues.apache.org/jira/browse/JCLOUDS-390

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ignasi Barrera <no...@github.com>.
Thanks @gcbirzan!

The following are the request/response bodies for the create and edit tag requests.

You'll see that the edit tag request provides, in the resources list, the UUID of a resource that was already associated (if that is the correct word) with the tag in the create operation, but the response seems to not return that resource (only an empty resource list), and that is what is making the test fail.

Do you know if there is something that should be fixed in jclouds or could it be a server-side issue? Any feedback is very welcome!

**Create tag request**

    { "meta" : {  },
      "name" : "Cloudsigma2 Test tag",
      "resources" : [ "a390641e-265f-405f-8b23-e85e11fb960f" ]
    }

**Create tag response**

    { "objects" : [ { "meta" : {  },
            "name" : "Cloudsigma2 Test tag",
            "owner" : { "resource_uri" : "/api/2.0/user/e4daa70a-0d5b-4f75-a93c-b7ab9d229875/",
                "uuid" : "e4daa70a-0d5b-4f75-a93c-b7ab9d229875"
              },
            "resource_uri" : "/api/2.0/tags/1dd3ff35-1d47-4d88-b043-b88aaf24d495/",
            "resources" : [ { "owner" : { "resource_uri" : "/api/2.0/user/e4daa70a-0d5b-4f75-a93c-b7ab9d229875/",
                      "uuid" : "e4daa70a-0d5b-4f75-a93c-b7ab9d229875"
                    },
                  "res_type" : "drives",
                  "resource_uri" : "/api/2.0/drives/a390641e-265f-405f-8b23-e85e11fb960f/",
                  "uuid" : "a390641e-265f-405f-8b23-e85e11fb960f"
                } ],
            "uuid" : "1dd3ff35-1d47-4d88-b043-b88aaf24d495"
          } ] }

**Edit tag request**

    { "meta" : { "description" : "test tag" },
      "name" : "Edited tag",
      "resources" : [ "a390641e-265f-405f-8b23-e85e11fb960f" ]
    }

**Edit tag response**

    { "meta" : { "description" : "test tag" },
      "name" : "Edited tag",
      "owner" : { "resource_uri" : "/api/2.0/user/e4daa70a-0d5b-4f75-a93c-b7ab9d229875/",
          "uuid" : "e4daa70a-0d5b-4f75-a93c-b7ab9d229875"
        },
      "resource_uri" : "/api/2.0/tags/1dd3ff35-1d47-4d88-b043-b88aaf24d495/",
      "resources" : [  ],
      "uuid" : "1dd3ff35-1d47-4d88-b043-b88aaf24d495"
    }

**Get tag info response after the edit operation**

    { "meta" : { "description" : "test tag" },
      "name" : "Edited tag",
      "owner" : { "resource_uri" : "/api/2.0/user/e4daa70a-0d5b-4f75-a93c-b7ab9d229875/",
          "uuid" : "e4daa70a-0d5b-4f75-a93c-b7ab9d229875"
        },
      "resource_uri" : "/api/2.0/tags/1dd3ff35-1d47-4d88-b043-b88aaf24d495/",
      "resources" : [  ],
      "uuid" : "1dd3ff35-1d47-4d88-b043-b88aaf24d495"
    }

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

Posted by Ilya Kulakov <no...@github.com>.
@nacx That's the question to ask @gcbirzan.

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

Re: [jclouds-labs] Cloudsigma2 subscription calc fix (#41)

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

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