diff --git a/labs/abiquo/pom.xml b/labs/abiquo/pom.xml index 12acaadc04..88bd3fa62d 100644 --- a/labs/abiquo/pom.xml +++ b/labs/abiquo/pom.xml @@ -15,7 +15,7 @@ bundle - 2.1.0 + 2.1.1 http://localhost/api FIXME FIXME diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java index 274a55c83e..abe9785ed3 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java @@ -89,7 +89,8 @@ public class AbiquoRestClientModule extends RestClientModule return getTasks(response); } + /** + * Returns a String message with the price info of the virtual appliance. + * + * @return The price of the virtual appliance + */ + public String getPrice() + { + return context.getApi().getCloudApi().getVirtualAppliancePrice(target); + } + // Builder public static Builder builder(final RestContext context, diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java index b95c59112c..af9363bab8 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java @@ -434,7 +434,7 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper listAvailableTempaltes( + public List listAvailableTemplates( final Predicate filter) { return Lists.newLinkedList(filter(listAvailableTemplates(), filter)); diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java index d7df2d7043..924f28a9f5 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java @@ -32,6 +32,7 @@ import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.domain.DomainWrapper; import org.jclouds.abiquo.domain.cloud.options.ConversionOptions; import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.domain.config.CostCode; import org.jclouds.abiquo.domain.enterprise.Enterprise; import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.abiquo.domain.infrastructure.Tier; @@ -53,6 +54,7 @@ import com.abiquo.server.core.appslibrary.ConversionsDto; import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; import com.abiquo.server.core.appslibrary.VirtualMachineTemplatePersistentDto; import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.abiquo.server.core.pricing.CostCodeDto; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -317,7 +319,15 @@ public class VirtualMachineTemplate extends DomainWrapper + * Cloud administrators can create several cost codes and assign a price to each one, to have a + * flexible way to configure custom billings for each resource. + *

+ * Cost codes can be assigned to {@link VirtualMachineTemplate}s and other resources to provide + * pricing information about them. + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +public class CostCode extends DomainWrapper +{ + + private List defaultPrices; + + /** + * Constructor to be used only by the builder. This resource cannot be created. + */ + private CostCode(final RestContext context, final CostCodeDto target) + { + super(context, target); + } + + // Domain operations + + public void delete() + { + context.getApi().getPricingApi().deleteCostCode(target); + target = null; + } + + public void save() + { + target = context.getApi().getPricingApi().createCostCode(target); + + if (defaultPrices != null && !defaultPrices.isEmpty()) + { + CostCodeCurrenciesDto costcodecurrencies = new CostCodeCurrenciesDto(); + for (CostCodePrice ccp : defaultPrices) + { + CostCodeCurrencyDto costcodecurrency = new CostCodeCurrencyDto(); + Currency currency = ccp.getCurrency(); + + costcodecurrency.addLink(new RESTLink("currency", currency.unwrap().getEditLink() + .getHref())); + costcodecurrency.setPrice(ccp.getPrice()); + costcodecurrencies.add(costcodecurrency); + } + context.getApi().getPricingApi().updateCostCodeCurrencies(getId(), costcodecurrencies); + } + + } + + public void update() + { + target = context.getApi().getPricingApi().updateCostCode(target); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder + { + private RestContext context; + + private String name; + + private String description; + + private List defaultPrices = Lists.newArrayList(); + + public Builder(final RestContext context) + { + super(); + this.context = context; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder description(final String description) + { + this.description = description; + return this; + } + + public Builder defaultPrices(final List prices) + { + this.defaultPrices.addAll(prices); + return this; + } + + public CostCode build() + { + CostCodeDto dto = new CostCodeDto(); + dto.setName(name); + dto.setDescription(description); + CostCode costcode = new CostCode(context, dto); + costcode.setDefaultPrices(defaultPrices); + return costcode; + } + + public static Builder fromCostCode(final CostCode in) + { + Builder builder = + CostCode.builder(in.context).name(in.getName()).description(in.getDescription()) + .defaultPrices(in.getDefaultPrices()); + return builder; + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public void setName(final String name) + { + target.setName(name); + } + + public String getDescription() + { + return target.getDescription(); + } + + public void setDescription(final String description) + { + target.setDescription(description); + } + + public List getDefaultPrices() + { + return defaultPrices; + } + + public void setDefaultPrices(final List defaultPrices) + { + this.defaultPrices = defaultPrices; + } + + @Override + public String toString() + { + return "CostCode [id=" + getId() + ", name=" + getName() + ", description=" + + getDescription() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java new file mode 100644 index 0000000000..66492a0df3 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.abiquo.domain.config; + +import java.math.BigDecimal; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.pricing.CostCodeCurrencyDto; + +public class CostCodeCurrency extends DomainWrapper +{ + + protected CostCodeCurrency(final RestContext context, + final CostCodeCurrencyDto target) + { + super(context, target); + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public BigDecimal getPrice() + { + return target.getPrice(); + } + + @Override + public String toString() + { + return "CostCodeCurrency [id=" + getId() + ", price=" + getPrice() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java new file mode 100644 index 0000000000..b2caf5bdbe --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.abiquo.domain.config; + +import java.math.BigDecimal; + +/** + * Gives a price to a {@link CostCode}. + * + * @author Susana Acedo + */ +public class CostCodePrice +{ + private Currency currency; + + private BigDecimal price; + + public CostCodePrice(final Currency currency, final BigDecimal price) + { + super(); + this.currency = currency; + this.price = price; + } + + public Currency getCurrency() + { + return currency; + } + + public void setCurrency(final Currency currency) + { + this.currency = currency; + } + + public BigDecimal getPrice() + { + return price; + } + + public void setPrice(final BigDecimal price) + { + this.price = price; + } + + @Override + public String toString() + { + return "CostCodePrice [currency=" + currency + ", price=" + price + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java index d1fdb9835b..691a93562a 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java @@ -31,10 +31,7 @@ import com.abiquo.server.core.pricing.CurrencyDto; * * @author Ignasi Barrera * @author Susana Acedo - * @see API: - * http://community.abiquo.com/display/ABI20/Currency+Resource */ - public class Currency extends DomainWrapper { @@ -48,35 +45,17 @@ public class Currency extends DomainWrapper // Domain operations - /** - * @see API: http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource- - * Deleteacurrency - */ public void delete() { context.getApi().getPricingApi().deleteCurrency(target); target = null; } - /** - * @see API: http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource- - * Createacurrency - */ public void save() { target = context.getApi().getPricingApi().createCurrency(target); } - /** - * @see API: http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource- - * Updateanexistingcurrency - */ public void update() { target = context.getApi().getPricingApi().updateCurrency(target); @@ -187,5 +166,4 @@ public class Currency extends DomainWrapper return "Currency [id=" + getId() + ", name=" + getName() + ", symbol=" + getSymbol() + ", digits=" + getDigits() + "]"; } - } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java new file mode 100644 index 0000000000..ff0d1b5123 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java @@ -0,0 +1,130 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.abiquo.domain.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.math.BigDecimal; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.pricing.PricingCostCodeDto; + +/** + * Associates a {@link CostCode} with a pricing template. + * + * @author Susana Acedo + */ +public class PricingCostCode extends DomainWrapper +{ + private CostCode costcode; + + private PricingTemplate pricingTemplate; + + protected PricingCostCode(final RestContext context, + final PricingCostCodeDto target) + { + super(context, target); + } + + // Builder + + public static Builder builder(final RestContext context, + final PricingTemplate pricingtemplate, final CostCode costcode) + { + return new Builder(context, pricingtemplate, costcode); + } + + public static class Builder + { + private RestContext context; + + private Integer id; + + private PricingTemplate pricingTemplate; + + private CostCode costcode; + + private BigDecimal price; + + public Builder(final RestContext context, + final PricingTemplate pricingTemplate, final CostCode costcode) + { + super(); + this.pricingTemplate = + checkNotNull(pricingTemplate, ValidationErrors.NULL_RESOURCE + + PricingTemplate.class); + this.costcode = checkNotNull(costcode, ValidationErrors.NULL_RESOURCE + CostCode.class); + this.context = context; + } + + public Builder price(final BigDecimal price) + { + this.price = price; + return this; + } + + public PricingCostCode build() + { + PricingCostCodeDto dto = new PricingCostCodeDto(); + dto.setId(id); + dto.setPrice(price); + + RESTLink link = costcode.unwrap().searchLink("edit"); + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + dto.addLink(new RESTLink("costcode", link.getHref())); + + PricingCostCode pricingcostcode = new PricingCostCode(context, dto); + pricingcostcode.pricingTemplate = pricingTemplate; + pricingcostcode.costcode = costcode; + + return pricingcostcode; + } + + public static Builder fromPricingCostCode(final PricingCostCode in) + { + return PricingCostCode.builder(in.context, in.pricingTemplate, in.costcode).price( + in.getPrice()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public BigDecimal getPrice() + { + return target.getPrice(); + } + + @Override + public String toString() + { + return "PricingCostCode [id=" + getId() + ", price=" + getPrice() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTemplate.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTemplate.java new file mode 100644 index 0000000000..379724417c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTemplate.java @@ -0,0 +1,443 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.math.BigDecimal; +import java.util.Date; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.PricingPeriod; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.pricing.PricingTemplateDto; + +/** + * A pricing template is a complete pricing schema that can be assigned to an {@link Enterprise}. + *

+ * This pricing schema will provide detailed billing information for each resource consumed by the + * users of the enterprise. + * + * @author Ignasi Barrera + * @author Susana Acedo + */ + +public class PricingTemplate extends DomainWrapper +{ + + /** The currency used by the pricing template. */ + protected Currency currency; + + /** + * Constructor to be used only by the builder. This resource cannot be created. + */ + private PricingTemplate(final RestContext context, + final PricingTemplateDto target) + { + super(context, target); + } + + // Domain operations + + public void delete() + { + context.getApi().getPricingApi().deletePricingTemplate(target); + target = null; + } + + public void save() + { + target = context.getApi().getPricingApi().createPricingTemplate(target); + } + + public void update() + { + target = context.getApi().getPricingApi().updatePricingTemplate(target); + } + + // Builder + + public static Builder builder(final RestContext context, + final Currency currency) + { + return new Builder(context, currency); + } + + public static class Builder + { + private RestContext context; + + private Currency currency; + + private String name; + + private String description; + + private BigDecimal hdGB; + + private BigDecimal standingChargePeriod; + + private BigDecimal vlan; + + private PricingPeriod chargingPeriod; + + private BigDecimal minimumChargePeriod; + + private boolean showChangesBefore; + + private boolean showMinimumCharge; + + private PricingPeriod minimumCharge; + + private BigDecimal publicIp; + + private BigDecimal vcpu; + + private BigDecimal memoryGB; + + private boolean defaultTemplate; + + private Date lastUpdate; + + public Builder(final RestContext context, final Currency currency) + { + super(); + this.currency = checkNotNull(currency, ValidationErrors.NULL_RESOURCE + Currency.class); + this.context = context; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder description(final String description) + { + this.description = description; + return this; + } + + public Builder hdGB(final BigDecimal hdGB) + { + this.hdGB = hdGB; + return this; + } + + public Builder standingChargePeriod(final BigDecimal standingChargePeriod) + { + this.standingChargePeriod = standingChargePeriod; + return this; + } + + public Builder chargingPeriod(final PricingPeriod chargingPeriod) + { + this.chargingPeriod = chargingPeriod; + return this; + } + + public Builder vlan(final BigDecimal vlan) + { + this.vlan = vlan; + return this; + } + + public Builder minimumChargePeriod(final BigDecimal minimumChargePeriod) + { + this.minimumChargePeriod = minimumChargePeriod; + return this; + } + + public Builder minimumCharge(final PricingPeriod minimumCharge) + { + this.minimumCharge = minimumCharge; + return this; + } + + public Builder showChangesBefore(final boolean showChangesBefore) + { + this.showChangesBefore = showChangesBefore; + return this; + } + + public Builder showMinimumCharge(final boolean showMinimumCharge) + { + this.showMinimumCharge = showMinimumCharge; + return this; + } + + public Builder publicIp(final BigDecimal publicIp) + { + this.publicIp = publicIp; + return this; + } + + public Builder vcpu(final BigDecimal vcpu) + { + this.vcpu = vcpu; + return this; + } + + public Builder memoryGB(final BigDecimal memoryGB) + { + this.memoryGB = memoryGB; + return this; + } + + public Builder defaultTemplate(final boolean defaultTemplate) + { + this.defaultTemplate = defaultTemplate; + return this; + } + + public Builder lastUpdate(final Date lastUpdate) + { + this.lastUpdate = lastUpdate; + return this; + } + + public Builder currency(final Currency currency) + { + this.currency = checkNotNull(currency, ValidationErrors.NULL_RESOURCE + Currency.class); + return this; + } + + public PricingTemplate build() + { + PricingTemplateDto dto = new PricingTemplateDto(); + dto.setName(name); + dto.setDescription(description); + dto.setHdGB(hdGB); + dto.setStandingChargePeriod(standingChargePeriod); + dto.setVlan(vlan); + dto.setChargingPeriod(chargingPeriod.ordinal()); + dto.setMinimumCharge(minimumCharge.ordinal()); + dto.setMinimumChargePeriod(minimumChargePeriod); + dto.setShowChangesBefore(showChangesBefore); + dto.setShowMinimumCharge(showMinimumCharge); + dto.setPublicIp(publicIp); + dto.setVcpu(vcpu); + dto.setMemoryGB(memoryGB); + dto.setDefaultTemplate(defaultTemplate); + dto.setLastUpdate(lastUpdate); + + RESTLink link = currency.unwrap().searchLink("edit"); + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + dto.addLink(new RESTLink("currency", link.getHref())); + + PricingTemplate pricingTemplate = new PricingTemplate(context, dto); + pricingTemplate.currency = currency; + + return pricingTemplate; + } + + public static Builder fromPricingTemplate(final PricingTemplate in) + { + Builder builder = + PricingTemplate.builder(in.context, in.currency).name(in.getName()) + .description(in.getDescription()).hdGB(in.getHdGB()) + .standingChargePeriod(in.getStandingChargePeriod()).vcpu(in.getVlan()) + .chargingPeriod(in.getChargingPeriod()).minimumCharge(in.getMinimumCharge()) + .minimumChargePeriod(in.getMinimumChargePeriod()) + .showChangesBefore(in.isShowChangesBefore()) + .showMinimumCharge(in.isShowMinimumCharge()).publicIp(in.getPublicIp()) + .vcpu(in.getVcpu()).memoryGB(in.getMemoryGB()) + .defaultTemplate(in.isDefaultTemplate()).lastUpdate(in.getLastUpdate()); + return builder; + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public void setName(final String name) + { + target.setName(name); + } + + public String getDescription() + { + return target.getDescription(); + } + + public void setDescription(final String description) + { + target.setDescription(description); + } + + public BigDecimal getHdGB() + { + return target.getHdGB(); + } + + public void setHdGB(final BigDecimal hdGB) + { + target.setHdGB(hdGB); + } + + public BigDecimal getStandingChargePeriod() + { + return target.getStandingChargePeriod(); + } + + public void setStandingChargePeriod(final BigDecimal standingChargePeriod) + { + target.setStandingChargePeriod(standingChargePeriod); + } + + public BigDecimal getVlan() + { + return target.getVlan(); + } + + public void setVlan(final BigDecimal vlan) + { + target.getVlan(); + } + + public BigDecimal getMinimumChargePeriod() + { + return target.getMinimumChargePeriod(); + } + + public void setMinimumChargePeriod(final BigDecimal minimumChargePeriod) + { + target.setMinimumChargePeriod(minimumChargePeriod); + } + + public boolean isShowChangesBefore() + { + return target.isShowChangesBefore(); + } + + public void setShowChangesBefore(final boolean showChangesBefore) + { + target.setShowChangesBefore(showChangesBefore); + } + + public boolean isShowMinimumCharge() + { + return target.isShowMinimumCharge(); + } + + public void setShowMinimumCharge(final boolean showMinimumCharge) + { + target.setShowMinimumCharge(showMinimumCharge); + } + + public PricingPeriod getMinimumCharge() + { + return PricingPeriod.fromId(target.getMinimumCharge()); + } + + public void setMinimumCharge(final PricingPeriod minimumCharge) + { + target.setMinimumCharge(minimumCharge.ordinal()); + } + + public PricingPeriod getChargingPeriod() + { + return PricingPeriod.fromId(target.getChargingPeriod()); + } + + public void setChargingPeriod(final PricingPeriod chargingPeriod) + { + target.setChargingPeriod(chargingPeriod.ordinal()); + } + + public BigDecimal getPublicIp() + { + return target.getPublicIp(); + } + + public void setPublicIp(final BigDecimal publicIp) + { + target.setPublicIp(publicIp); + } + + public BigDecimal getVcpu() + { + return target.getVcpu(); + } + + public void setVcpu(final BigDecimal vcpu) + { + target.setVcpu(vcpu); + } + + public BigDecimal getMemoryGB() + { + return target.getMemoryGB(); + } + + public void setMemoryGB(final BigDecimal memoryGB) + { + target.setMemoryGB(memoryGB); + } + + public boolean isDefaultTemplate() + { + return target.isDefaultTemplate(); + } + + public void setDefaultTemplate(final boolean defaultTemplate) + { + target.setDefaultTemplate(defaultTemplate); + } + + public Date getLastUpdate() + { + return target.getLastUpdate(); + } + + public void setLastUpdate(final Date lastUpdate) + { + target.setLastUpdate(lastUpdate); + } + + @Override + public String toString() + { + return "PricingTemplate [id=" + getId() + ", name=" + getName() + ", description=" + + getDescription() + ", hdGB =" + getHdGB() + ", standingChargePeriod =" + + getStandingChargePeriod() + ", vlan = " + getVlan() + ", chargingPeriod =" + + getChargingPeriod() + ", minimumChargePeriod=" + getMinimumChargePeriod() + + ", showChangesBefore =" + isShowChangesBefore() + ", showMinimumCharge= " + + isShowMinimumCharge() + ", minimumCharge = " + getMinimumCharge() + ", publicIp = " + + getPublicIp() + ", vcpu =" + getVcpu() + ", memoryGB= " + getMemoryGB() + + ", defaultTemplate= " + isDefaultTemplate() + ", lastUpdate = " + getLastUpdate() + + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java new file mode 100644 index 0000000000..36a4612bb1 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java @@ -0,0 +1,130 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.abiquo.domain.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.math.BigDecimal; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.pricing.PricingTierDto; + +/** + * Associates an storage {@link Tier} with a {@link PricingTemplate}. + * + * @author Susana Acedo + */ +public class PricingTier extends DomainWrapper +{ + private Tier tier; + + private PricingTemplate pricingTemplate; + + protected PricingTier(final RestContext context, + final PricingTierDto target) + { + super(context, target); + } + + // Builder + + public static Builder builder(final RestContext context, + final PricingTemplate pricingtemplate, final Tier tier) + { + return new Builder(context, pricingtemplate, tier); + } + + public static class Builder + { + private RestContext context; + + private Integer id; + + private PricingTemplate pricingTemplate; + + private Tier tier; + + private BigDecimal price; + + public Builder(final RestContext context, + final PricingTemplate pricingTemplate, final Tier tier) + { + super(); + this.pricingTemplate = + checkNotNull(pricingTemplate, ValidationErrors.NULL_RESOURCE + + PricingTemplate.class); + this.tier = checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Tier.class); + this.context = context; + } + + public Builder price(final BigDecimal price) + { + this.price = price; + return this; + } + + public PricingTier build() + { + PricingTierDto dto = new PricingTierDto(); + dto.setId(id); + dto.setPrice(price); + + RESTLink link = tier.unwrap().searchLink("edit"); + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + dto.addLink(new RESTLink("tier", link.getHref())); + + PricingTier pricingTier = new PricingTier(context, dto); + pricingTier.pricingTemplate = pricingTemplate; + pricingTier.tier = tier; + + return pricingTier; + } + + public static Builder fromPricingTier(final PricingTier in) + { + return PricingTier.builder(in.context, in.pricingTemplate, in.tier) + .price(in.getPrice()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public BigDecimal getPrice() + { + return target.getPrice(); + } + + @Override + public String toString() + { + return "PricingTier [id=" + getId() + ", price=" + getPrice() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java index e6ef57ff24..2d01dcb640 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java @@ -359,6 +359,14 @@ public interface CloudApi */ VirtualApplianceStateDto getVirtualApplianceState(VirtualApplianceDto virtualAppliance); + /** + * Gets the price of the given virtual appliance. + * + * @param virtualAppliance The virtual appliance to get the price of. + * @return A String representation of the price of the virtual appliance. + */ + String getVirtualAppliancePrice(VirtualApplianceDto virtualAppliance); + /*********************** Virtual Machine ***********************/ /** diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java index ce59a8b99c..3c3772c9fa 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java @@ -28,6 +28,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; import org.jclouds.abiquo.binders.AppendToPath; import org.jclouds.abiquo.binders.BindToPath; @@ -55,6 +56,7 @@ import org.jclouds.abiquo.http.filters.AbiquoAuthentication; import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; @@ -431,6 +433,15 @@ public interface CloudAsyncApi @EndpointLink("undeploy") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance, @BinderParam(BindToXMLPayload.class) VirtualMachineTaskDto task); + /** + * @see CloudApi#getVirtualAppliancePrice(VirtualApplianceDto) + */ + @GET + @Consumes(MediaType.TEXT_PLAIN) + @ResponseParser(ReturnStringIf2xx.class) + ListenableFuture getVirtualAppliancePrice( + @EndpointLink("price") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance); + /*********************** Virtual Machine ***********************/ /** diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java index 989153bd36..1d33510aa6 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java @@ -22,14 +22,23 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; +import com.abiquo.server.core.pricing.CostCodeDto; +import com.abiquo.server.core.pricing.CostCodesDto; import com.abiquo.server.core.pricing.CurrenciesDto; import com.abiquo.server.core.pricing.CurrencyDto; +import com.abiquo.server.core.pricing.PricingCostCodeDto; +import com.abiquo.server.core.pricing.PricingCostCodesDto; +import com.abiquo.server.core.pricing.PricingTemplateDto; +import com.abiquo.server.core.pricing.PricingTemplatesDto; +import com.abiquo.server.core.pricing.PricingTierDto; +import com.abiquo.server.core.pricing.PricingTiersDto; /** * Provides synchronous access to Abiquo Pricing API. * - * @see API: - * http://community.abiquo.com/display/ABI20/API+Reference + * @see API: + * http://community.abiquo.com/display/ABI20/APIReference * @see PricingAsyncApi * @author Ignasi Barrera * @author Susana Acedo @@ -77,4 +86,157 @@ public interface PricingApi * @param currency The currency to delete */ void deleteCurrency(final CurrencyDto currency); + + /*********************** CostCode ********************** */ + + /** + * List all costcodes + * + * @return The list of costcodes + */ + CostCodesDto listCostCodes(); + + /** + * Get the given costcode + * + * @param costcodeId The id of the costcode + * @return The costcode + */ + CostCodeDto getCostCode(Integer costcodeId); + + /** + * Create a new costcode + * + * @param costcode The costcode to be created. + * @return The created costcode. + */ + CostCodeDto createCostCode(CostCodeDto costcode); + + /** + * Updates an existing costcode + * + * @param costcode The new attributes for the costcode + * @return The updated costcode + */ + CostCodeDto updateCostCode(CostCodeDto costcode); + + /** + * Deletes an existing costcode + * + * @param currency The costcode to delete + */ + void deleteCostCode(CostCodeDto costcode); + + /*********************** PricingTemplate ********************** */ + + /** + * List all pricingtemplates + * + * @return The list of pricingtemplates + */ + PricingTemplatesDto listPricingTemplates(); + + /** + * Get the given pricingtemplate + * + * @param pricingTemplateId The id of the pricingtemplate + * @return The pricingtemplate + */ + PricingTemplateDto getPricingTemplate(Integer pricingTemplateId); + + /** + * Create a new pricing template + * + * @param pricingtemplate The pricingtemplate to be created + * @return The created pricingtemplate + */ + PricingTemplateDto createPricingTemplate(PricingTemplateDto pricingtemplate); + + /** + * Updates an existing pricing template + * + * @param pricingtemplate The new attributes for the pricingtemplate + * @return The updated pricingtemplate + */ + PricingTemplateDto updatePricingTemplate(PricingTemplateDto pricingtemplate); + + /** + * Deletes an existing pricingtemplate + * + * @param pricingtemplate The pricingtemplate to delete + */ + void deletePricingTemplate(PricingTemplateDto pricingtemplate); + + /*********************** CostCodeCurrency ********************** */ + + /** + * Get the given costcodecurrency + * + * @param costcodecurrencyId The id of the costcodecurrency + * @return The costcodecurrency + */ + CostCodeCurrenciesDto getCostCodeCurrencies(Integer costcodeId, Integer currencyId); + + /** + * Updates cost code currencies + * + * @param costcodeCurrency The new attributes for the costcodecurrencies + * @return The updated costcodecurrencies + */ + CostCodeCurrenciesDto updateCostCodeCurrencies(Integer costcodeId, + CostCodeCurrenciesDto costcodeCurrencies); + + /*********************** PricingTemplateCostCode ********************** */ + + /** + * Get the pricing cost codes for a pricing template + * + * @param pricingTemplateId + * @return pricingcostcodes + */ + PricingCostCodesDto getPricingCostCodes(Integer pricingTemplateId); + + /** + * Get the given pricing cost code + * + * @param pricingCostCodeId the id of the pricing cost code + * @return The pricingcostcode + */ + PricingCostCodeDto getPricingCostCode(Integer pricingTemplateId, Integer pricingCostCodeId); + + /** + * Updates an existing pricingcostcode + * + * @param costcodeCurrency The new attributes for the pricingcostcode + * @return The updated pricingcostcode + */ + PricingCostCodeDto updatePricingCostCode(PricingCostCodeDto pricingCostCode, + Integer pricingTemplateId, Integer pricingCostCodeId); + + /*********************** PricingTemplateTier ********************** */ + + /** + * Get the pricing tiers for a pricing template + * + * @param pricingTemplateId + * @return pricingtiers + */ + PricingTiersDto getPricingTiers(Integer pricingTemplateId); + + /** + * Get the given pricing tier + * + * @param pricingTierId The id of the pricing tier + * @return The pricingtier + */ + PricingTierDto getPricingTier(Integer pricingTemplateId, Integer pricingTierId); + + /** + * Updates an existing pricing tier + * + * @param costcodeCurrency The new attributes for the pricing tier + * @return The updated pricing tier + */ + PricingTierDto updatePricingTier(PricingTierDto pricingTier, Integer pricingTemplateId, + Integer pricingTierId); } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java index 34dacbeec1..688b7749fa 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java @@ -26,6 +26,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import org.jclouds.abiquo.binders.BindToPath; import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; @@ -39,15 +40,24 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; +import com.abiquo.server.core.pricing.CostCodeDto; +import com.abiquo.server.core.pricing.CostCodesDto; import com.abiquo.server.core.pricing.CurrenciesDto; import com.abiquo.server.core.pricing.CurrencyDto; +import com.abiquo.server.core.pricing.PricingCostCodeDto; +import com.abiquo.server.core.pricing.PricingCostCodesDto; +import com.abiquo.server.core.pricing.PricingTemplateDto; +import com.abiquo.server.core.pricing.PricingTemplatesDto; +import com.abiquo.server.core.pricing.PricingTierDto; +import com.abiquo.server.core.pricing.PricingTiersDto; import com.google.common.util.concurrent.ListenableFuture; /** * Provides synchronous access to Abiquo Pricing API. * - * @see API: - * http://community.abiquo.com/display/ABI20/API+Reference + * @see API: + * http://community.abiquo.com/display/ABI20/APIReference * @see PricingAsyncApi * @author Ignasi Barrera * @author Susana Acedo @@ -105,4 +115,203 @@ public interface PricingAsyncApi ListenableFuture deleteCurrency( @EndpointLink("edit") @BinderParam(BindToPath.class) CurrencyDto currency); + /*********************** CostCode ********************** */ + + /** + * @see PricingApi#listCostCodes() + */ + @GET + @Path("/costcodes") + @Consumes(CostCodesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listCostCodes(); + + /** + * @see PricingApi#getCostCode(Integer) + */ + @GET + @Path("/costcodes/{costcode}") + @Consumes(CostCodeDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getCostCode(@PathParam("costcode") Integer costcodeId); + + /** + * @see PricingApi#createCostCode(CostCodeDto) + */ + @POST + @Path("/costcodes") + @Produces(CostCodeDto.BASE_MEDIA_TYPE) + @Consumes(CostCodeDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createCostCode( + @BinderParam(BindToXMLPayload.class) CostCodeDto costcode); + + /** + * @see PricingApi#updateCostCode(CostCodeDto) + */ + @PUT + @Produces(CostCodeDto.BASE_MEDIA_TYPE) + @Consumes(CostCodeDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateCostCode( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) CostCodeDto costcode); + + /** + * @see PricingApi#deleteCostCode(CostCodeDto) + */ + @DELETE + ListenableFuture deleteCostCode( + @EndpointLink("edit") @BinderParam(BindToPath.class) CostCodeDto costcode); + + /*********************** PricingTemplate ********************** */ + + /** + * @see PricingApi#listPricingTemplates() + */ + @GET + @Path("/pricingtemplates") + @Consumes(PricingTemplatesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPricingTemplates(); + + /** + * @see PricingApi#getPricingTemplate(Integer) + */ + @GET + @Path("/pricingtemplates/{pricingtemplate}") + @Consumes(PricingTemplateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getPricingTemplate( + @PathParam("pricingtemplate") Integer pricingTemplateId); + + /** + * @see PricingApi#createPricingTemplate(PricingTemplateDto) + */ + @POST + @Path("/pricingtemplates") + @Produces(PricingTemplateDto.BASE_MEDIA_TYPE) + @Consumes(PricingTemplateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createPricingTemplate( + @BinderParam(BindToXMLPayload.class) PricingTemplateDto pricingtemplate); + + /** + * @see PricingApi#updatePricingTemplate(PricingTemplateDto) + */ + @PUT + @Produces(PricingTemplateDto.BASE_MEDIA_TYPE) + @Consumes(PricingTemplateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updatePricingTemplate( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingTemplateDto pricingtemplate); + + /** + * @see PricingApi#deletePricingTemplate(PricingTemplateDto) + */ + @DELETE + ListenableFuture deletePricingTemplate( + @EndpointLink("edit") @BinderParam(BindToPath.class) PricingTemplateDto pricingtemplate); + + /*********************** CostCodeCurrency ********************** */ + + /** + * @see PricingApi#getCostCodeCurrency(Integer) + */ + @GET + @Path("/costcodes/{costcode}/currencies") + @Consumes(CostCodeCurrenciesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getCostCodeCurrencies( + @PathParam("costcode") Integer costcodeId, @QueryParam("idCurrency") Integer currencyId); + + /** + * @see PricingApi#updateCostCodeCurrencies(CostCodeCurrenciesDto) + */ + @PUT + @Path("/costcodes/{costcode}/currencies") + @Produces(CostCodeCurrenciesDto.BASE_MEDIA_TYPE) + @Consumes(CostCodeCurrenciesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateCostCodeCurrencies( + @PathParam("costcode") Integer costcodeId, + @BinderParam(BindToXMLPayload.class) CostCodeCurrenciesDto costcodecurrencies); + + /*********************** PricingCostCode ********************** */ + + /** + * @see PricingApi#getPricingCostCodes(Integer) + */ + @GET + @Path("/pricingtemplates/{pricingtemplate}/costcodes") + @Consumes(PricingCostCodesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getPricingCostCodes( + @PathParam("pricingtemplate") Integer pricingTemplateId); + + /** + * @see PricingApi#getPricingCostCode(Integer) + */ + @GET + @Path("/pricingtemplates/{pricingtemplate}/costcodes/{costcode}") + @Consumes(PricingCostCodeDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getPricingCostCode( + @PathParam("pricingtemplate") Integer pricingTemplateId, + @PathParam("costcode") Integer pricingCostcodeId); + + /** + * @see PricingApi#updatePricingCostCode(PricingCostCodeDto) + */ + @PUT + @Path("/pricingtemplates/{pricingtemplate}/costcodes/{costcode}") + @Produces(PricingCostCodeDto.BASE_MEDIA_TYPE) + @Consumes(PricingCostCodeDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updatePricingCostCode( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingCostCodeDto pricingcostcode, + @PathParam("pricingtemplate") Integer pricingTemplateId, + @PathParam("costcode") Integer pricingCostcodeId); + + /*********************** PricingTier ********************** */ + + /** + * @see PricingApi#getPricingTiers(Integer) + */ + @GET + @Path("/pricingtemplates/{pricingtemplate}/tiers") + @Consumes(PricingTiersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getPricingTiers( + @PathParam("pricingtemplate") Integer pricingTemplateId); + + /** + * @see PricingApi#getPricingTier(Integer) + */ + @GET + @Path("/pricingtemplates/{pricingtemplate}/tiers/{tier}") + @Consumes(PricingTierDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getPricingTier( + @PathParam("pricingtemplate") Integer pricingTemplateId, + @PathParam("tier") Integer pricingTierId); + + /** + * @see PricingApi#updatePricingTier(PricingTierDto) + */ + @PUT + @Path("/pricingtemplates/{pricingtemplate}/tiers/{tier}") + @Produces(PricingTierDto.BASE_MEDIA_TYPE) + @Consumes(PricingTierDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updatePricingTier( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingTierDto pricingtier, + @PathParam("pricingtemplate") Integer pricingTemplateId, + @PathParam("tier") Integer pricingTierId); } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java index 442200787e..51347b198a 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java @@ -19,7 +19,14 @@ package org.jclouds.abiquo.features.services; +import java.util.Collection; + +import org.jclouds.abiquo.domain.config.CostCode; +import org.jclouds.abiquo.domain.config.CostCodeCurrency; import org.jclouds.abiquo.domain.config.Currency; +import org.jclouds.abiquo.domain.config.PricingCostCode; +import org.jclouds.abiquo.domain.config.PricingTemplate; +import org.jclouds.abiquo.domain.config.PricingTier; import org.jclouds.abiquo.internal.BasePricingService; import com.google.common.base.Predicate; @@ -51,4 +58,71 @@ public interface PricingService * Get the first currencies that matches the given filter or null if none is found. */ Currency findCurrency(final Predicate filter); + + /*********************** CostCode ***********************/ + + /** + * Get the list of costcodes. + */ + Iterable listCostCodes(); + + /** + * Get the list of costcodes matching the given filter. + */ + Iterable listCostCodes(final Predicate filter); + + /** + * Get the first costcodes that matches the given filter or null if none is found. + */ + CostCode findCostCode(final Predicate filter); + + /*********************** PricingTemplate ***********************/ + + /** + * Get the list of pricingtemplates. + */ + public Iterable listPricingTemplates(); + + /** + * Get the list of pricingtemplates matching the given filter. + */ + public Iterable listPricingTemplates(final Predicate filter); + + /** + * Get the first pricingtemplates that matches the given filter or null if none is + * found. + */ + public PricingTemplate findPricingTemplate(final Predicate filter); + + /*********************** CostCodeCurrency ***********************/ + + /** + * Get a cost code currency + */ + public Iterable getCostCodeCurrencies(Integer costcodeid, Integer currencyid); + + /*********************** PricingCostCode ***********************/ + + /** + * Get pricing cost codes + */ + public Collection getPricingCostCodes(Integer pricingTemplateId); + + /** + * Get a pricing cost code + */ + PricingCostCode getPricingCostCode(Integer pricingTemplateId, Integer pricingCostCodeId); + + /*********************** PricingTier ***********************/ + + /** + * Get pricing tiers + */ + Collection getPricingTiers(Integer pricingTemplateId); + + /** + * Get a pricing tier + */ + PricingTier getPricingTier(Integer pricingTemplateId, Integer pricingTierId); + } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java index c879374a7f..0dc034be78 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java @@ -20,17 +20,32 @@ package org.jclouds.abiquo.internal; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import java.util.Collection; import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.abiquo.AbiquoApi; import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.config.CostCode; +import org.jclouds.abiquo.domain.config.CostCodeCurrency; import org.jclouds.abiquo.domain.config.Currency; +import org.jclouds.abiquo.domain.config.PricingCostCode; +import org.jclouds.abiquo.domain.config.PricingTemplate; +import org.jclouds.abiquo.domain.config.PricingTier; import org.jclouds.abiquo.features.services.PricingService; +import org.jclouds.abiquo.strategy.config.ListCostCodes; import org.jclouds.abiquo.strategy.config.ListCurrencies; +import org.jclouds.abiquo.strategy.config.ListPricingTemplates; import org.jclouds.rest.RestContext; +import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; +import com.abiquo.server.core.pricing.PricingCostCodeDto; +import com.abiquo.server.core.pricing.PricingCostCodesDto; +import com.abiquo.server.core.pricing.PricingTierDto; +import com.abiquo.server.core.pricing.PricingTiersDto; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; @@ -50,12 +65,21 @@ public class BasePricingService implements PricingService @VisibleForTesting protected final ListCurrencies listCurrencies; + @VisibleForTesting + protected final ListCostCodes listCostCodes; + + @VisibleForTesting + protected final ListPricingTemplates listPricingTemplates; + @Inject protected BasePricingService(final RestContext context, - final ListCurrencies listCurrencies) + final ListCurrencies listCurrencies, final ListCostCodes listCostCodes, + final ListPricingTemplates listPricingTemplates) { this.context = checkNotNull(context, "context"); this.listCurrencies = checkNotNull(listCurrencies, "listCurrencies"); + this.listCostCodes = checkNotNull(listCostCodes, "listCostCodes"); + this.listPricingTemplates = checkNotNull(listPricingTemplates, "listPricingTemplates"); } /*********************** Currency ********************** */ @@ -77,4 +101,93 @@ public class BasePricingService implements PricingService { return Iterables.getFirst(listCurrencies(filter), null); } + + /*********************** CostCode ********************** */ + + @Override + public Iterable listCostCodes() + { + return listCostCodes.execute(); + } + + @Override + public Iterable listCostCodes(final Predicate filter) + { + return listCostCodes.execute(filter); + } + + @Override + public CostCode findCostCode(final Predicate filter) + { + return Iterables.getFirst(listCostCodes(filter), null); + } + + /*********************** PricingTemplate ********************** */ + + @Override + public Iterable listPricingTemplates() + { + return listPricingTemplates.execute(); + } + + @Override + public Iterable listPricingTemplates(final Predicate filter) + { + return listPricingTemplates.execute(filter); + } + + @Override + public PricingTemplate findPricingTemplate(final Predicate filter) + { + return Iterables.getFirst(listPricingTemplates(filter), null); + } + + /*********************** CostCodeCurrency ********************** */ + + @Override + public Iterable getCostCodeCurrencies(final Integer costcodeId, + final Integer currencyId) + { + CostCodeCurrenciesDto result = + context.getApi().getPricingApi().getCostCodeCurrencies(costcodeId, currencyId); + return wrap(context, CostCodeCurrency.class, result.getCollection()); + } + + /*********************** Pricing Cost Code ********************** */ + + @Override + public Collection getPricingCostCodes(final Integer pricingTemplateId) + { + PricingCostCodesDto result = + context.getApi().getPricingApi().getPricingCostCodes(pricingTemplateId); + return wrap(context, PricingCostCode.class, result.getCollection()); + } + + @Override + public PricingCostCode getPricingCostCode(final Integer pricingTemplateId, + final Integer pricingCostCodeId) + { + PricingCostCodeDto pricingcostcode = + context.getApi().getPricingApi() + .getPricingCostCode(pricingTemplateId, pricingCostCodeId); + return wrap(context, PricingCostCode.class, pricingcostcode); + } + + /*********************** Pricing Tier********************** */ + + @Override + public Collection getPricingTiers(final Integer pricingTemplateId) + { + PricingTiersDto result = + context.getApi().getPricingApi().getPricingTiers(pricingTemplateId); + return wrap(context, PricingTier.class, result.getCollection()); + } + + @Override + public PricingTier getPricingTier(final Integer pricingTemplateId, final Integer pricingTierId) + { + PricingTierDto pricingtier = + context.getApi().getPricingApi().getPricingTier(pricingTemplateId, pricingTierId); + return wrap(context, PricingTier.class, pricingtier); + } } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java index 426f2f77d9..22b2f53d7c 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java @@ -25,6 +25,7 @@ import java.util.Arrays; import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import com.abiquo.server.core.cloud.VirtualApplianceState; import com.google.common.base.Predicate; /** @@ -47,4 +48,18 @@ public class VirtualAppliancePredicates } }; } + + public static Predicate state(final VirtualApplianceState... states) + { + checkNotNull(states, "states must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualAppliance virtualAppliance) + { + return Arrays.asList(states).contains(virtualAppliance.getState()); + } + }; + } } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java index a90c54e274..be3c372a0d 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java @@ -91,4 +91,28 @@ public class VirtualMachineTemplatePredicates } }; } + + public static Predicate isShared() + { + return new Predicate() + { + @Override + public boolean apply(final VirtualMachineTemplate input) + { + return input.unwrap().isShared(); + } + }; + } + + public static Predicate isInstance() + { + return new Predicate() + { + @Override + public boolean apply(final VirtualMachineTemplate input) + { + return input.unwrap().searchLink("master") != null; + } + }; + } } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java index b85ef9f428..afebcb6004 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java @@ -25,6 +25,7 @@ import java.util.Arrays; import org.jclouds.abiquo.domain.cloud.Volume; +import com.abiquo.model.enumerator.VolumeState; import com.google.common.base.Predicate; import com.google.common.base.Predicates; @@ -86,4 +87,18 @@ public class VolumePredicates { return Predicates.not(greaterThan(sizeInMb)); } + + public static Predicate state(final VolumeState... states) + { + checkNotNull(states, "states must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Volume volume) + { + return Arrays.asList(states).contains(VolumeState.valueOf(volume.getState())); + } + }; + } } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CurrencyPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PricingPredicates.java similarity index 57% rename from labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CurrencyPredicates.java rename to labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PricingPredicates.java index 4261dfb014..29b2a78807 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CurrencyPredicates.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PricingPredicates.java @@ -23,19 +23,21 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Arrays; +import org.jclouds.abiquo.domain.config.CostCode; import org.jclouds.abiquo.domain.config.Currency; +import org.jclouds.abiquo.domain.config.PricingTemplate; import com.google.common.base.Predicate; /** - * Container for {@link Currency} filters. + * Container for pricing related filters. * * @author Ignasi Barrera * @author Susana Acedo */ -public class CurrencyPredicates +public class PricingPredicates { - public static Predicate name(final String... names) + public static Predicate currency(final String... names) { checkNotNull(names, "names must be defined"); @@ -49,4 +51,31 @@ public class CurrencyPredicates }; } + public static Predicate costCode(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final CostCode costcode) + { + return Arrays.asList(names).contains(costcode.getName()); + } + }; + } + + public static Predicate pricingTemplate(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final PricingTemplate pricingTemplate) + { + return Arrays.asList(names).contains(pricingTemplate.getName()); + } + }; + } } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCostCodes.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCostCodes.java new file mode 100644 index 0000000000..e1f83c5243 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCostCodes.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config; + +import org.jclouds.abiquo.domain.config.CostCode; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.config.internal.ListCostCodesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List cost codes + * + * @author Susana Acedo + */ +@ImplementedBy(ListCostCodesImpl.class) +public interface ListCostCodes extends ListRootEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListPricingTemplates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListPricingTemplates.java new file mode 100644 index 0000000000..8415bda36f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListPricingTemplates.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config; + +import org.jclouds.abiquo.domain.config.PricingTemplate; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.config.internal.ListPricingTemplatesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List pricing templates + * + * @author Susana Acedo + */ +@ImplementedBy(ListPricingTemplatesImpl.class) +public interface ListPricingTemplates extends ListRootEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCostCodesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCostCodesImpl.java new file mode 100644 index 0000000000..1a5a1c14b7 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCostCodesImpl.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.config.CostCode; +import org.jclouds.abiquo.strategy.config.ListCostCodes; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.pricing.CostCodesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List cost codes + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +@Singleton +public class ListCostCodesImpl implements ListCostCodes +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListCostCodesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + CostCodesDto result = context.getApi().getPricingApi().listCostCodes(); + return wrap(context, CostCode.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPricingTemplatesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPricingTemplatesImpl.java new file mode 100644 index 0000000000..6f5b33032c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPricingTemplatesImpl.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.config.PricingTemplate; +import org.jclouds.abiquo.strategy.config.ListPricingTemplates; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.pricing.PricingTemplatesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List pricing templates + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +@Singleton +public class ListPricingTemplatesImpl implements ListPricingTemplates +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListPricingTemplatesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + PricingTemplatesDto result = context.getApi().getPricingApi().listPricingTemplates(); + return wrap(context, PricingTemplate.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java index b605f9f164..f742124716 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java @@ -117,6 +117,8 @@ public class CloudResources "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/action/undeploy")); virtualAppliance.addLink(new RESTLink("virtualmachines", "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines")); + virtualAppliance.addLink(new RESTLink("price", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/action/price")); return virtualAppliance; } @@ -369,6 +371,8 @@ public class CloudResources "undeploy")); buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines", "virtualmachines")); + buffer + .append(link("/cloud/virtualdatacenters/1/virtualappliances/1/action/price", "price")); buffer.append("0"); buffer.append("0"); buffer.append("1"); diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java index f694aa5a51..bbca9da2cb 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java @@ -21,8 +21,16 @@ package org.jclouds.abiquo.domain; import static org.jclouds.abiquo.domain.DomainUtils.link; +import java.math.BigDecimal; + import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; +import com.abiquo.server.core.pricing.CostCodeCurrencyDto; +import com.abiquo.server.core.pricing.CostCodeDto; import com.abiquo.server.core.pricing.CurrencyDto; +import com.abiquo.server.core.pricing.PricingCostCodeDto; +import com.abiquo.server.core.pricing.PricingTemplateDto; +import com.abiquo.server.core.pricing.PricingTierDto; /** * Enterprise domain utilities. @@ -37,7 +45,7 @@ public class PricingResources { CurrencyDto currency = new CurrencyDto(); currency.setName("yuan"); - currency.setSymbol("¥"); + currency.setSymbol("DUMMY"); currency.setDigits(3); return currency; } @@ -46,7 +54,7 @@ public class PricingResources { CurrencyDto currency = new CurrencyDto(); currency.setName("yuan"); - currency.setSymbol("¥"); + currency.setSymbol("DUMMY"); currency.setDigits(3); currency.setId(1); currency.addLink(new RESTLink("edit", "http://localhost/api/config/currencies/1")); @@ -57,7 +65,7 @@ public class PricingResources { StringBuffer buffer = new StringBuffer(); buffer.append(""); - buffer.append("¥"); + buffer.append("DUMMY"); buffer.append("3"); buffer.append("yuan"); buffer.append(""); @@ -69,7 +77,7 @@ public class PricingResources StringBuffer buffer = new StringBuffer(); buffer.append(""); buffer.append(link("/config/currencies/1", "edit")); - buffer.append("¥"); + buffer.append("DUMMY"); buffer.append("3"); buffer.append("1"); buffer.append("yuan"); @@ -77,4 +85,226 @@ public class PricingResources return buffer.toString(); } + public static Object costcodePost() + { + CostCodeDto costcode = new CostCodeDto(); + costcode.setName("cost code"); + costcode.setDescription("description"); + return costcode; + } + + public static Object costcodePut() + { + CostCodeDto costcode = new CostCodeDto(); + costcode.setName("cost code"); + costcode.setDescription("description"); + costcode.setId(1); + costcode.addLink(new RESTLink("edit", "http://localhost/api/config/costcodes/1")); + return costcode; + } + + public static String costcodePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("cost code"); + buffer.append("description"); + buffer.append(""); + return buffer.toString(); + } + + public static String costcodePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/config/costcodes/1", "edit")); + buffer.append("description"); + buffer.append("1"); + buffer.append("cost code"); + buffer.append(""); + return buffer.toString(); + } + + public static Object pricingtemplatePost() + { + PricingTemplateDto pricingtemplate = new PricingTemplateDto(); + pricingtemplate.setName("pricing template"); + pricingtemplate.setDescription("pt_description"); + pricingtemplate.setHdGB(new BigDecimal(0)); + pricingtemplate.setStandingChargePeriod(new BigDecimal(0)); + pricingtemplate.setVlan(new BigDecimal(0)); + pricingtemplate.setChargingPeriod(1); + pricingtemplate.setMinimumChargePeriod(new BigDecimal(0)); + pricingtemplate.setShowChangesBefore(true); + pricingtemplate.setShowMinimumCharge(false); + pricingtemplate.setMinimumCharge(2); + pricingtemplate.setPublicIp(new BigDecimal(0)); + pricingtemplate.setVcpu(new BigDecimal(0)); + pricingtemplate.setMemoryGB(new BigDecimal(0)); + pricingtemplate.setDefaultTemplate(true); + pricingtemplate + .addLink(new RESTLink("currency", "http://localhost/api/config/currencies/1")); + return pricingtemplate; + } + + public static Object pricingtemplatePut() + { + PricingTemplateDto pricingtemplate = new PricingTemplateDto(); + pricingtemplate.setName("pricing template"); + pricingtemplate.setDescription("pt_description"); + pricingtemplate.setHdGB(new BigDecimal(0)); + pricingtemplate.setStandingChargePeriod(new BigDecimal(0)); + pricingtemplate.setVlan(new BigDecimal(0)); + pricingtemplate.setChargingPeriod(1); + pricingtemplate.setMinimumChargePeriod(new BigDecimal(0)); + pricingtemplate.setShowChangesBefore(true); + pricingtemplate.setShowMinimumCharge(false); + pricingtemplate.setMinimumCharge(2); + pricingtemplate.setPublicIp(new BigDecimal(0)); + pricingtemplate.setVcpu(new BigDecimal(0)); + pricingtemplate.setMemoryGB(new BigDecimal(0)); + pricingtemplate.setDefaultTemplate(true); + pricingtemplate + .addLink(new RESTLink("currency", "http://localhost/api/config/currencies/1")); + pricingtemplate.setId(1); + pricingtemplate.addLink(new RESTLink("edit", + "http://localhost/api/config/pricingtemplates/1")); + return pricingtemplate; + } + + public static String pricingtemplatePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("pricing template"); + buffer.append("pt_description"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("1"); + buffer.append("0"); + buffer.append("true"); + buffer.append("false"); + buffer.append("2"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("true"); + buffer.append(""); + buffer.append(""); + return buffer.toString(); + } + + public static String pricingtemplatePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("pricing template"); + buffer.append("pt_description"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("1"); + buffer.append("0"); + buffer.append("true"); + buffer.append("false"); + buffer.append("2"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("true"); + buffer.append(""); + buffer.append("1"); + buffer.append(link("/config/pricingtemplates/1", "edit")); + buffer.append(""); + return buffer.toString(); + } + + public static Object costcodecurrencyPut() + { + CostCodeCurrencyDto costcodecurrency = new CostCodeCurrencyDto(); + costcodecurrency.addLink(new RESTLink("edit", + "http://localhost/api/config/costcodes/1/currencies")); + costcodecurrency.addLink(new RESTLink("currency", + "http://localhost/api/config/currencies/1")); + costcodecurrency.setPrice(new BigDecimal("300")); + CostCodeCurrenciesDto costcodecurrencies = new CostCodeCurrenciesDto(); + costcodecurrencies.add(costcodecurrency); + return costcodecurrencies; + } + + public static String costcodecurrencyPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(""); + buffer.append("300"); + buffer + .append(""); + buffer.append(""); + buffer.append(""); + + buffer.append(""); + return buffer.toString(); + } + + public static Object pricingCostcodePut() + { + PricingCostCodeDto pricingcostcode = new PricingCostCodeDto(); + pricingcostcode.setId(1); + pricingcostcode.setPrice(new BigDecimal("400")); + pricingcostcode + .addLink(new RESTLink("costcode", "http://localhost/api/config/costcodes/1")); + pricingcostcode.addLink(new RESTLink("pricingtemplate", + "http://localhost/api/config/pricingtemplates/1")); + pricingcostcode.addLink(new RESTLink("edit", + "http://localhost/api/config/pricingtemplates/1/costcodes/1")); + return pricingcostcode; + } + + public static String pricingCostCodePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(""); + buffer + .append(""); + buffer.append("400"); + buffer.append("1"); + buffer.append(link("/config/pricingtemplates/1/costcodes/1", "edit")); + buffer.append(""); + return buffer.toString(); + } + + public static Object pricingTierPut() + { + PricingTierDto pricingtier = new PricingTierDto(); + pricingtier.setId(1); + pricingtier.setPrice(new BigDecimal("600")); + pricingtier.addLink(new RESTLink("tier", + "http://localhost/api/admin/datacenters/1/storage/tiers/2")); + pricingtier.addLink(new RESTLink("pricingtemplate", + "http://localhost/api/config/pricingtemplates/1")); + pricingtier.addLink(new RESTLink("edit", + "http://localhost/api/config/pricingtemplates/1/tiers/2")); + return pricingtier; + } + + public static String pricingTierPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer + .append(""); + buffer + .append(""); + buffer.append("600"); + buffer.append("1"); + buffer.append(link("/config/pricingtemplates/1/tiers/2", "edit")); + buffer.append(""); + return buffer.toString(); + } + } diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java index 9a372a4b8e..98884bf3ef 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java @@ -23,8 +23,11 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.SkipException; import org.testng.annotations.Test; +import com.abiquo.model.enumerator.HypervisorType; + /** * Live integration tests for the {@link HardDisk} domain class. * @@ -37,6 +40,8 @@ public class HardDiskLiveApiTest extends BaseAbiquoApiLiveApiTest public void createHardDisk() { + skipIfUnsupported(); + hardDisk = HardDisk.builder(env.context.getApiContext(), env.virtualDatacenter).sizeInMb(64L) .build(); @@ -51,6 +56,8 @@ public class HardDiskLiveApiTest extends BaseAbiquoApiLiveApiTest @Test(dependsOnMethods = "createHardDisk") public void deleteHardDisk() { + skipIfUnsupported(); + HardDisk hd = env.virtualDatacenter.getHardDisk(hardDisk.getId()); assertNotNull(hd); @@ -59,4 +66,11 @@ public class HardDiskLiveApiTest extends BaseAbiquoApiLiveApiTest assertNull(env.virtualDatacenter.getHardDisk(id)); } + protected static void skipIfUnsupported() + { + if (!env.machine.getType().equals(HypervisorType.VMX_04)) + { + throw new SkipException("Cannot perform this test because hard disk actions are not available for this hypervisor"); + } + } } diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CostCodeLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CostCodeLiveApiTest.java new file mode 100644 index 0000000000..df6220a450 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CostCodeLiveApiTest.java @@ -0,0 +1,142 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.config.PricingPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link CostCode} domain class. + * + * @author Susana Acedo + */ +@Test(groups = "api", testName = "CostCodeLiveApiTest") +public class CostCodeLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private CostCode costcode; + + private Currency currency; + + private CostCodePrice costcodeprice; + + private List defaultPrices; + + @BeforeClass + public void setupCostCode() + { + currency = + Currency.builder(env.context.getApiContext()).name(PREFIX + "test-currency") + .symbol("test-$").digits(2).build(); + currency.save(); + + costcode = + CostCode.builder(env.context.getApiContext()).name(PREFIX + "test-costcode") + .description("description").build(); + + costcode.save(); + } + + @AfterClass + public void tearDownCostCode() + { + currency.delete(); + costcode.delete(); + } + + public void testCreateRepeated() + { + CostCode repeated = CostCode.Builder.fromCostCode(costcode).build(); + + try + { + repeated.save(); + fail("Should not be able to create costcodes with the same name"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "COSTCODE-2"); + } + } + + public void testUpdate() + { + costcode.setName(PREFIX + "costcode-updated"); + costcode.update(); + + CostCode apiCostCode = + env.context.getPricingService().findCostCode( + PricingPredicates.costCode(PREFIX + "costcode-updated")); + + assertNotNull(apiCostCode); + assertEquals(PREFIX + "costcode-updated", apiCostCode.getName()); + + } + + public void testCreateCostCodewithDefaultPrices() + { + CostCode costcode2 = + CostCode.builder(env.context.getApiContext()).name(PREFIX + "ccdefaultprice") + .description("description").build(); + + costcodeprice = new CostCodePrice(currency, new BigDecimal(100)); + this.defaultPrices = new ArrayList(); + defaultPrices.add(costcodeprice); + costcode2.setDefaultPrices(defaultPrices); + // When a cost code is created it is also created a costcodecurrency with price 0 and after + // that if a list of prices(CostCodePrice) has been sent this costcode is updated with the + // new price + costcode2.save(); + + // check that costcode has been created + CostCode apiCostCode = + env.context.getPricingService().findCostCode( + PricingPredicates.costCode(PREFIX + "ccdefaultprice")); + + assertNotNull(apiCostCode); + assertEquals(PREFIX + "ccdefaultprice", apiCostCode.getName()); + + // check that the price has been modified in the + Iterable costcodecurrencies = + env.context.getPricingService().getCostCodeCurrencies(costcode2.getId(), + currency.getId()); + for (CostCodeCurrency costcodecurrency : costcodecurrencies) + { + assertEquals(costcodecurrency.getPrice().compareTo(new BigDecimal(100)), 0); + } + + costcode2.delete(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java index 4e0bd132a4..c7b6b1f573 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java @@ -24,7 +24,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.predicates.config.CurrencyPredicates; +import org.jclouds.abiquo.predicates.config.PricingPredicates; import org.testng.annotations.Test; /** @@ -44,7 +44,7 @@ public class CurrencyLiveApiTest extends BaseAbiquoApiLiveApiTest Currency apiCurrency = env.context.getPricingService().findCurrency( - CurrencyPredicates.name(PREFIX + "test-currency")); + PricingPredicates.currency(PREFIX + "test-currency")); assertNotNull(apiCurrency); assertEquals(currency.getName(), apiCurrency.getName()); @@ -65,7 +65,7 @@ public class CurrencyLiveApiTest extends BaseAbiquoApiLiveApiTest Currency apiCurrency = env.context.getPricingService().findCurrency( - CurrencyPredicates.name(PREFIX + "t-currency-upd")); + PricingPredicates.currency(PREFIX + "t-currency-upd")); assertNotNull(apiCurrency); assertEquals(PREFIX + "t-currency-upd", apiCurrency.getName()); diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/PricingTemplateLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/PricingTemplateLiveApiTest.java new file mode 100644 index 0000000000..026f5153fd --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/PricingTemplateLiveApiTest.java @@ -0,0 +1,146 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.math.BigDecimal; +import java.util.Collection; +import java.util.Date; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.config.PricingPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.PricingPeriod; + +/** + * Live integration tests for the {@link PricingTemplate} domain class. + * + * @author Susana Acedo + */ +@Test(groups = "api", testName = "PricingTemplateLiveApiTest") +public class PricingTemplateLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private PricingTemplate pricingTemplate; + + private Currency currency; + + private CostCode costcode; + + private BigDecimal zero = new BigDecimal(0); + + @BeforeClass + public void setupPricingTemplate() + { + Iterable currencies = env.context.getPricingService().listCurrencies(); + currency = currencies.iterator().next(); + + costcode = + CostCode.builder(env.context.getApiContext()).name(PREFIX + "test-costcode") + .description("description").build(); + + costcode.save(); + + pricingTemplate = + PricingTemplate.builder(env.context.getApiContext(), currency).name("pricing_template") + .description("description").hdGB(zero).standingChargePeriod(zero).vlan(zero) + .chargingPeriod(PricingPeriod.MONTH).minimumChargePeriod(zero) + .showChangesBefore(true).showMinimumCharge(false).minimumCharge(PricingPeriod.WEEK) + .publicIp(zero).vcpu(zero).memoryGB(zero).defaultTemplate(true) + .lastUpdate(new Date()).build(); + + pricingTemplate.save(); + } + + @AfterClass + public void tearDownPricingTemplate() + { + pricingTemplate.delete(); + costcode.delete(); + } + + public void testCreateRepeated() + { + PricingTemplate repeated = + PricingTemplate.Builder.fromPricingTemplate(pricingTemplate).build(); + + try + { + repeated.save(); + fail("Should not be able to create pricingtemplates with the same name"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "PRICINGTEMPLATE-2"); + } + } + + public void testUpdate() + { + pricingTemplate.setName(PREFIX + "pt-updated"); + pricingTemplate.update(); + + PricingTemplate apiPricingTemplate = + env.context.getPricingService().findPricingTemplate( + PricingPredicates.pricingTemplate(PREFIX + "pt-updated")); + + assertNotNull(apiPricingTemplate); + assertEquals(PREFIX + "pt-updated", apiPricingTemplate.getName()); + + } + + // when a pricing template is created, pricing cost codes for each existent cost code are also + // created with price 0 + public void getPricingCostCodes() + { + Collection pricingCostCodes = + env.context.getPricingService().getPricingCostCodes(pricingTemplate.getId()); + assertEquals(pricingCostCodes.size(), 1); + assertNotNull(pricingCostCodes); + for (PricingCostCode pc : pricingCostCodes) + { + assertEquals(pc.getPrice().compareTo(zero), 0); + } + } + + // when a pricing template is created, pricing tiers are also created with price 0 + public void getPricingTiers() + { + Collection pricingTiers = + + env.context.getPricingService().getPricingTiers(pricingTemplate.getId()); + assertEquals(pricingTiers.size(), 4); + assertNotNull(pricingTiers); + for (PricingTier pt : pricingTiers) + { + assertEquals(pt.getPrice().compareTo(zero), 0); + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java index 873be24fd5..13fc5b93bd 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java @@ -24,6 +24,8 @@ import static org.jclouds.abiquo.domain.DomainUtils.withHeader; import java.io.IOException; import java.lang.reflect.Method; +import javax.ws.rs.core.MediaType; + import org.jclouds.abiquo.domain.CloudResources; import org.jclouds.abiquo.domain.EnterpriseResources; import org.jclouds.abiquo.domain.InfrastructureResources; @@ -38,6 +40,7 @@ import org.jclouds.abiquo.functions.ReturnTaskReferenceOrNull; import org.jclouds.abiquo.functions.cloud.ReturnMovedVolume; import org.jclouds.http.functions.ParseXMLWithJAXB; import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -806,6 +809,26 @@ public class CloudAsyncApiTest extends BaseAbiquoAsyncApiTest checkFilters(request); } + public void testGetVirtualAppliancePrice() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getVirtualAppliancePrice", VirtualApplianceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/action/price HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MediaType.TEXT_PLAIN + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReturnStringIf2xx.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + /*********************** Virtual Machine ***********************/ public void testListVirtualMachines() throws SecurityException, NoSuchMethodException, diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java index 3e0f6a01f2..aea1dc5ce1 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java @@ -32,8 +32,17 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; +import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; +import com.abiquo.server.core.pricing.CostCodeDto; +import com.abiquo.server.core.pricing.CostCodesDto; import com.abiquo.server.core.pricing.CurrenciesDto; import com.abiquo.server.core.pricing.CurrencyDto; +import com.abiquo.server.core.pricing.PricingCostCodeDto; +import com.abiquo.server.core.pricing.PricingCostCodesDto; +import com.abiquo.server.core.pricing.PricingTemplateDto; +import com.abiquo.server.core.pricing.PricingTemplatesDto; +import com.abiquo.server.core.pricing.PricingTierDto; +import com.abiquo.server.core.pricing.PricingTiersDto; import com.google.inject.TypeLiteral; /** @@ -45,7 +54,6 @@ import com.google.inject.TypeLiteral; @Test(groups = "unit", singleThreaded = true, testName = "PricingAsyncApiTest") public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest { - /*********************** Currency ***********************/ public void testListCurrencies() throws SecurityException, NoSuchMethodException, IOException @@ -80,7 +88,6 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest checkFilters(request); } - @Test(enabled = false) //TODO: fails public void testCreateCurrency() throws SecurityException, NoSuchMethodException, IOException { Method method = PricingAsyncApi.class.getMethod("createCurrency", CurrencyDto.class); @@ -98,8 +105,7 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest checkFilters(request); } - - @Test(enabled = false) //TODO: fails + public void testUpdateCurrency() throws SecurityException, NoSuchMethodException, IOException { Method method = PricingAsyncApi.class.getMethod("updateCurrency", CurrencyDto.class); @@ -135,6 +141,196 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest checkFilters(request); } + /*********************** Cost Code ***********************/ + + public void testListCostCodes() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("listCostCodes"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/config/costcodes HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CostCodesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetCostCode() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("getCostCode", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/config/costcodes/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateCostCode() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("createCostCode", CostCodeDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.costcodePost()); + + assertRequestLineEquals(request, "POST http://localhost/api/config/costcodes HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.costcodePostPayload()), + CostCodeDto.class, CostCodeDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateCostCode() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("updateCostCode", CostCodeDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.costcodePut()); + + assertRequestLineEquals(request, "PUT http://localhost/api/config/costcodes/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.costcodePutPayload()), + CostCodeDto.class, CostCodeDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteCostCode() throws SecurityException, NoSuchMethodException + { + Method method = PricingAsyncApi.class.getMethod("deleteCostCode", CostCodeDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.costcodePut()); + + assertRequestLineEquals(request, "DELETE http://localhost/api/config/costcodes/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Pricing Template ***********************/ + + public void testListPricingTemplates() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = PricingAsyncApi.class.getMethod("listPricingTemplates"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/pricingtemplates HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplatesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetPricingTemplate() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = PricingAsyncApi.class.getMethod("getPricingTemplate", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/pricingtemplates/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreatePricingTemplate() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + PricingAsyncApi.class.getMethod("createPricingTemplate", PricingTemplateDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.pricingtemplatePost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/config/pricingtemplates HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.pricingtemplatePostPayload()), + PricingTemplateDto.class, PricingTemplateDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdatePricingTemplate() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + PricingAsyncApi.class.getMethod("updatePricingTemplate", PricingTemplateDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.pricingtemplatePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/config/pricingtemplates/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.pricingtemplatePutPayload()), + PricingTemplateDto.class, PricingTemplateDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeletePricingTemplate() throws SecurityException, NoSuchMethodException + { + Method method = + PricingAsyncApi.class.getMethod("deletePricingTemplate", PricingTemplateDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.pricingtemplatePut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/config/pricingtemplates/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + @Override protected TypeLiteral> createTypeLiteral() { @@ -142,4 +338,172 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest { }; } + + /*********************** Cost Code Currency ***********************/ + + public void testGetCostCodeCurrencies() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + PricingAsyncApi.class.getMethod("getCostCodeCurrencies", Integer.class, Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/costcodes/1/currencies?idCurrency=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeCurrenciesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateCostCodeCurrencies() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + PricingAsyncApi.class.getMethod("updateCostCodeCurrencies", Integer.class, + CostCodeCurrenciesDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, 1, PricingResources.costcodecurrencyPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/config/costcodes/1/currencies HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeCurrenciesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.costcodecurrencyPutPayload()), + CostCodeCurrenciesDto.class, CostCodeCurrenciesDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Pricing Cost Code ***********************/ + + public void testGetPricingCostCodes() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = PricingAsyncApi.class.getMethod("getPricingCostCodes", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/pricingtemplates/1/costcodes HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingCostCodesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetPricingCostCode() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + PricingAsyncApi.class.getMethod("getPricingCostCode", Integer.class, Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/pricingtemplates/1/costcodes/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingCostCodeDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdatePricingCostCode() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + PricingAsyncApi.class.getMethod("updatePricingCostCode", PricingCostCodeDto.class, + Integer.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.pricingCostcodePut(), 1, 1); + + assertRequestLineEquals(request, + "PUT http://localhost/api/config/pricingtemplates/1/costcodes/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingCostCodeDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.pricingCostCodePutPayload()), + PricingCostCodeDto.class, PricingCostCodeDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Pricing Tier ***************************/ + + public void testGetPricingTiers() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("getPricingTiers", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/pricingtemplates/1/tiers HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingTiersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetPricingTier() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + PricingAsyncApi.class.getMethod("getPricingTier", Integer.class, Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/pricingtemplates/1/tiers/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingTierDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdatePricingTier() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + PricingAsyncApi.class.getMethod("updatePricingTier", PricingTierDto.class, + Integer.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.pricingTierPut(), 1, 2); + + assertRequestLineEquals(request, + "PUT http://localhost/api/config/pricingtemplates/1/tiers/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PricingTierDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.pricingTierPutPayload()), + PricingTierDto.class, PricingTierDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } } diff --git a/labs/abiquo/src/test/resources/filters/filters_jenkins.properties b/labs/abiquo/src/test/resources/filters/filters_jenkins.properties deleted file mode 100644 index 071d53b99a..0000000000 --- a/labs/abiquo/src/test/resources/filters/filters_jenkins.properties +++ /dev/null @@ -1,26 +0,0 @@ -# Hypervisor configuration -# This is the Tarantino IT hypervisor. -# Should be replaced with a dedicated ESX asap! -#abiquo.hypervisor.pass=tarantino -#abiquo.hypervisor.address=10.60.1.132 -#abiquo.hypervisor.datastore=nfs-ds -abiquo.hypervisor.type=VMX_04 -abiquo.hypervisor.address=10.60.20.62 -abiquo.hypervisor.pass=temporal -abiquo.hypervisor.user=root -abiquo.hypervisor.vswitch=vSwitch0 -abiquo.hypervisor.datastore=datastore1 - - -# Storage configuration -abiquo.storage.type=NEXENTA -abiquo.storage.address=10.60.20.23 -abiquo.storage.user=admin -abiquo.storage.pass=nexenta -abiquo.storage.pool=abiquo - -# UCS Rack configuration -abiquo.ucs.address=10.60.1.45 -abiquo.ucs.port=80 -abiquo.ucs.pass=config -abiquo.ucs.user=config \ No newline at end of file