Added pricing api

This commit is contained in:
Ignasi Barrera 2012-09-25 16:28:51 +02:00
parent 68e44df1f6
commit 8939700db4
35 changed files with 2866 additions and 71 deletions

View File

@ -15,7 +15,7 @@
<packaging>bundle</packaging>
<properties>
<abiquo.version>2.1.0</abiquo.version>
<abiquo.version>2.1.1</abiquo.version>
<test.abiquo.endpoint>http://localhost/api</test.abiquo.endpoint>
<test.abiquo.identity>FIXME</test.abiquo.identity>
<test.abiquo.credential>FIXME</test.abiquo.credential>

View File

@ -89,7 +89,8 @@ public class AbiquoRestClientModule extends RestClientModule<AbiquoApi, AbiquoAs
.put(CloudApi.class, CloudAsyncApi.class) //
.put(VirtualMachineTemplateApi.class, VirtualMachineTemplateAsyncApi.class) //
.put(TaskApi.class, TaskAsyncApi.class) //
.put(EventApi.class, EventAsyncApi.class).put(PricingApi.class, PricingAsyncApi.class) //
.put(EventApi.class, EventAsyncApi.class) //
.put(PricingApi.class, PricingAsyncApi.class) //
.build();
public AbiquoRestClientModule()

View File

@ -24,8 +24,8 @@ import static com.google.common.collect.Iterables.filter;
import java.util.List;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions;
import org.jclouds.abiquo.domain.enterprise.Enterprise;
@ -295,6 +295,16 @@ public class VirtualAppliance extends DomainWrapper<VirtualApplianceDto>
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<AbiquoApi, AbiquoAsyncApi> context,

View File

@ -434,7 +434,7 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper<VirtualDatacenter
return wrap(context, VirtualMachineTemplate.class, templates.getCollection());
}
public List<VirtualMachineTemplate> listAvailableTempaltes(
public List<VirtualMachineTemplate> listAvailableTemplates(
final Predicate<VirtualMachineTemplate> filter)
{
return Lists.newLinkedList(filter(listAvailableTemplates(), filter));

View File

@ -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<VirtualMachineTemplate
return taskRef == null ? null : getTask(taskRef);
}
public CostCode getCostCode()
{
Integer costcodeId = target.getIdFromLink(ParentLinkName.COST_CODE);
CostCodeDto costcode = context.getApi().getPricingApi().getCostCode(costcodeId);
return wrap(context, CostCode.class, costcode);
}
// Delegate methods
public int getCpuRequired()
{
return target.getCpuRequired();

View File

@ -0,0 +1,199 @@
/**
* 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.util.List;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.rest.RestContext;
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.google.common.collect.Lists;
/**
* A cost code is a kind of label where concrete prices can be assigned.
* <p>
* 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.
* <p>
* 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<CostCodeDto>
{
private List<CostCodePrice> defaultPrices;
/**
* Constructor to be used only by the builder. This resource cannot be created.
*/
private CostCode(final RestContext<AbiquoApi, AbiquoAsyncApi> 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<AbiquoApi, AbiquoAsyncApi> context)
{
return new Builder(context);
}
public static class Builder
{
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
private String name;
private String description;
private List<CostCodePrice> defaultPrices = Lists.newArrayList();
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> 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<CostCodePrice> 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<CostCodePrice> getDefaultPrices()
{
return defaultPrices;
}
public void setDefaultPrices(final List<CostCodePrice> defaultPrices)
{
this.defaultPrices = defaultPrices;
}
@Override
public String toString()
{
return "CostCode [id=" + getId() + ", name=" + getName() + ", description="
+ getDescription() + "]";
}
}

View File

@ -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<CostCodeCurrencyDto>
{
protected CostCodeCurrency(final RestContext<AbiquoApi, AbiquoAsyncApi> 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() + "]";
}
}

View File

@ -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 + "]";
}
}

View File

@ -31,10 +31,7 @@ import com.abiquo.server.core.pricing.CurrencyDto;
*
* @author Ignasi Barrera
* @author Susana Acedo
* @see API: <a href="http://community.abiquo.com/display/ABI20/Currency+Resource">
* http://community.abiquo.com/display/ABI20/Currency+Resource</a>
*/
public class Currency extends DomainWrapper<CurrencyDto>
{
@ -48,35 +45,17 @@ public class Currency extends DomainWrapper<CurrencyDto>
// Domain operations
/**
* @see API: <a href=
* "http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-Deleteacurrency"
* > http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-
* Deleteacurrency</a>
*/
public void delete()
{
context.getApi().getPricingApi().deleteCurrency(target);
target = null;
}
/**
* @see API: <a href=
* "http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-Createacurrency"
* > http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-
* Createacurrency</a>
*/
public void save()
{
target = context.getApi().getPricingApi().createCurrency(target);
}
/**
* @see API: <a href=
* "http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-Updateanexistingcurrency"
* > http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-
* Updateanexistingcurrency</a>
*/
public void update()
{
target = context.getApi().getPricingApi().updateCurrency(target);
@ -187,5 +166,4 @@ public class Currency extends DomainWrapper<CurrencyDto>
return "Currency [id=" + getId() + ", name=" + getName() + ", symbol=" + getSymbol()
+ ", digits=" + getDigits() + "]";
}
}

View File

@ -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<PricingCostCodeDto>
{
private CostCode costcode;
private PricingTemplate pricingTemplate;
protected PricingCostCode(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
final PricingCostCodeDto target)
{
super(context, target);
}
// Builder
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
final PricingTemplate pricingtemplate, final CostCode costcode)
{
return new Builder(context, pricingtemplate, costcode);
}
public static class Builder
{
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
private Integer id;
private PricingTemplate pricingTemplate;
private CostCode costcode;
private BigDecimal price;
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> 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() + "]";
}
}

View File

@ -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}.
* <p>
* 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<PricingTemplateDto>
{
/** 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<AbiquoApi, AbiquoAsyncApi> 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<AbiquoApi, AbiquoAsyncApi> context,
final Currency currency)
{
return new Builder(context, currency);
}
public static class Builder
{
private RestContext<AbiquoApi, AbiquoAsyncApi> 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<AbiquoApi, AbiquoAsyncApi> 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()
+ "]";
}
}

View File

@ -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<PricingTierDto>
{
private Tier tier;
private PricingTemplate pricingTemplate;
protected PricingTier(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
final PricingTierDto target)
{
super(context, target);
}
// Builder
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
final PricingTemplate pricingtemplate, final Tier tier)
{
return new Builder(context, pricingtemplate, tier);
}
public static class Builder
{
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
private Integer id;
private PricingTemplate pricingTemplate;
private Tier tier;
private BigDecimal price;
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> 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() + "]";
}
}

View File

@ -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 <code>String</code> representation of the price of the virtual appliance.
*/
String getVirtualAppliancePrice(VirtualApplianceDto virtualAppliance);
/*********************** Virtual Machine ***********************/
/**

View File

@ -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<String> getVirtualAppliancePrice(
@EndpointLink("price") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance);
/*********************** Virtual Machine ***********************/
/**

View File

@ -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: <a href="http://community.abiquo.com/display/ABI20/API+Reference">
* http://community.abiquo.com/display/ABI20/API+Reference</a>
* @see API: <a href="http://community.abiquo.com/display/ABI20/APIReference">
* http://community.abiquo.com/display/ABI20/APIReference</a>
* @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);
}

View File

@ -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: <a href="http://community.abiquo.com/display/ABI20/API+Reference">
* http://community.abiquo.com/display/ABI20/API+Reference</a>
* @see API: <a href="http://community.abiquo.com/display/ABI20/APIReference">
* http://community.abiquo.com/display/ABI20/APIReference</a>
* @see PricingAsyncApi
* @author Ignasi Barrera
* @author Susana Acedo
@ -105,4 +115,203 @@ public interface PricingAsyncApi
ListenableFuture<Void> deleteCurrency(
@EndpointLink("edit") @BinderParam(BindToPath.class) CurrencyDto currency);
/*********************** CostCode ********************** */
/**
* @see PricingApi#listCostCodes()
*/
@GET
@Path("/costcodes")
@Consumes(CostCodesDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
ListenableFuture<CostCodesDto> listCostCodes();
/**
* @see PricingApi#getCostCode(Integer)
*/
@GET
@Path("/costcodes/{costcode}")
@Consumes(CostCodeDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<CostCodeDto> getCostCode(@PathParam("costcode") Integer costcodeId);
/**
* @see PricingApi#createCostCode(CostCodeDto)
*/
@POST
@Path("/costcodes")
@Produces(CostCodeDto.BASE_MEDIA_TYPE)
@Consumes(CostCodeDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
ListenableFuture<CostCodeDto> createCostCode(
@BinderParam(BindToXMLPayload.class) CostCodeDto costcode);
/**
* @see PricingApi#updateCostCode(CostCodeDto)
*/
@PUT
@Produces(CostCodeDto.BASE_MEDIA_TYPE)
@Consumes(CostCodeDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
ListenableFuture<CostCodeDto> updateCostCode(
@EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) CostCodeDto costcode);
/**
* @see PricingApi#deleteCostCode(CostCodeDto)
*/
@DELETE
ListenableFuture<Void> deleteCostCode(
@EndpointLink("edit") @BinderParam(BindToPath.class) CostCodeDto costcode);
/*********************** PricingTemplate ********************** */
/**
* @see PricingApi#listPricingTemplates()
*/
@GET
@Path("/pricingtemplates")
@Consumes(PricingTemplatesDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
ListenableFuture<PricingTemplatesDto> listPricingTemplates();
/**
* @see PricingApi#getPricingTemplate(Integer)
*/
@GET
@Path("/pricingtemplates/{pricingtemplate}")
@Consumes(PricingTemplateDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<PricingTemplateDto> getPricingTemplate(
@PathParam("pricingtemplate") Integer pricingTemplateId);
/**
* @see PricingApi#createPricingTemplate(PricingTemplateDto)
*/
@POST
@Path("/pricingtemplates")
@Produces(PricingTemplateDto.BASE_MEDIA_TYPE)
@Consumes(PricingTemplateDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
ListenableFuture<PricingTemplateDto> createPricingTemplate(
@BinderParam(BindToXMLPayload.class) PricingTemplateDto pricingtemplate);
/**
* @see PricingApi#updatePricingTemplate(PricingTemplateDto)
*/
@PUT
@Produces(PricingTemplateDto.BASE_MEDIA_TYPE)
@Consumes(PricingTemplateDto.BASE_MEDIA_TYPE)
@JAXBResponseParser
ListenableFuture<PricingTemplateDto> updatePricingTemplate(
@EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingTemplateDto pricingtemplate);
/**
* @see PricingApi#deletePricingTemplate(PricingTemplateDto)
*/
@DELETE
ListenableFuture<Void> 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<CostCodeCurrenciesDto> 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<CostCodeCurrenciesDto> 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<PricingCostCodesDto> 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<PricingCostCodeDto> 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<PricingCostCodeDto> 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<PricingTiersDto> 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<PricingTierDto> 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<PricingTierDto> updatePricingTier(
@EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingTierDto pricingtier,
@PathParam("pricingtemplate") Integer pricingTemplateId,
@PathParam("tier") Integer pricingTierId);
}

View File

@ -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 <code>null</code> if none is found.
*/
Currency findCurrency(final Predicate<Currency> filter);
/*********************** CostCode ***********************/
/**
* Get the list of costcodes.
*/
Iterable<CostCode> listCostCodes();
/**
* Get the list of costcodes matching the given filter.
*/
Iterable<CostCode> listCostCodes(final Predicate<CostCode> filter);
/**
* Get the first costcodes that matches the given filter or <code>null</code> if none is found.
*/
CostCode findCostCode(final Predicate<CostCode> filter);
/*********************** PricingTemplate ***********************/
/**
* Get the list of pricingtemplates.
*/
public Iterable<PricingTemplate> listPricingTemplates();
/**
* Get the list of pricingtemplates matching the given filter.
*/
public Iterable<PricingTemplate> listPricingTemplates(final Predicate<PricingTemplate> filter);
/**
* Get the first pricingtemplates that matches the given filter or <code>null</code> if none is
* found.
*/
public PricingTemplate findPricingTemplate(final Predicate<PricingTemplate> filter);
/*********************** CostCodeCurrency ***********************/
/**
* Get a cost code currency
*/
public Iterable<CostCodeCurrency> getCostCodeCurrencies(Integer costcodeid, Integer currencyid);
/*********************** PricingCostCode ***********************/
/**
* Get pricing cost codes
*/
public Collection<PricingCostCode> getPricingCostCodes(Integer pricingTemplateId);
/**
* Get a pricing cost code
*/
PricingCostCode getPricingCostCode(Integer pricingTemplateId, Integer pricingCostCodeId);
/*********************** PricingTier ***********************/
/**
* Get pricing tiers
*/
Collection<PricingTier> getPricingTiers(Integer pricingTemplateId);
/**
* Get a pricing tier
*/
PricingTier getPricingTier(Integer pricingTemplateId, Integer pricingTierId);
}

View File

@ -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<AbiquoApi, AbiquoAsyncApi> 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<CostCode> listCostCodes()
{
return listCostCodes.execute();
}
@Override
public Iterable<CostCode> listCostCodes(final Predicate<CostCode> filter)
{
return listCostCodes.execute(filter);
}
@Override
public CostCode findCostCode(final Predicate<CostCode> filter)
{
return Iterables.getFirst(listCostCodes(filter), null);
}
/*********************** PricingTemplate ********************** */
@Override
public Iterable<PricingTemplate> listPricingTemplates()
{
return listPricingTemplates.execute();
}
@Override
public Iterable<PricingTemplate> listPricingTemplates(final Predicate<PricingTemplate> filter)
{
return listPricingTemplates.execute(filter);
}
@Override
public PricingTemplate findPricingTemplate(final Predicate<PricingTemplate> filter)
{
return Iterables.getFirst(listPricingTemplates(filter), null);
}
/*********************** CostCodeCurrency ********************** */
@Override
public Iterable<CostCodeCurrency> 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<PricingCostCode> 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<PricingTier> 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);
}
}

View File

@ -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<VirtualAppliance> state(final VirtualApplianceState... states)
{
checkNotNull(states, "states must be defined");
return new Predicate<VirtualAppliance>()
{
@Override
public boolean apply(final VirtualAppliance virtualAppliance)
{
return Arrays.asList(states).contains(virtualAppliance.getState());
}
};
}
}

View File

@ -91,4 +91,28 @@ public class VirtualMachineTemplatePredicates
}
};
}
public static Predicate<VirtualMachineTemplate> isShared()
{
return new Predicate<VirtualMachineTemplate>()
{
@Override
public boolean apply(final VirtualMachineTemplate input)
{
return input.unwrap().isShared();
}
};
}
public static Predicate<VirtualMachineTemplate> isInstance()
{
return new Predicate<VirtualMachineTemplate>()
{
@Override
public boolean apply(final VirtualMachineTemplate input)
{
return input.unwrap().searchLink("master") != null;
}
};
}
}

View File

@ -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<Volume> state(final VolumeState... states)
{
checkNotNull(states, "states must be defined");
return new Predicate<Volume>()
{
@Override
public boolean apply(final Volume volume)
{
return Arrays.asList(states).contains(VolumeState.valueOf(volume.getState()));
}
};
}
}

View File

@ -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<Currency> name(final String... names)
public static Predicate<Currency> currency(final String... names)
{
checkNotNull(names, "names must be defined");
@ -49,4 +51,31 @@ public class CurrencyPredicates
};
}
public static Predicate<CostCode> costCode(final String... names)
{
checkNotNull(names, "names must be defined");
return new Predicate<CostCode>()
{
@Override
public boolean apply(final CostCode costcode)
{
return Arrays.asList(names).contains(costcode.getName());
}
};
}
public static Predicate<PricingTemplate> pricingTemplate(final String... names)
{
checkNotNull(names, "names must be defined");
return new Predicate<PricingTemplate>()
{
@Override
public boolean apply(final PricingTemplate pricingTemplate)
{
return Arrays.asList(names).contains(pricingTemplate.getName());
}
};
}
}

View File

@ -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<CostCode>
{
}

View File

@ -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<PricingTemplate>
{
}

View File

@ -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<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListCostCodesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context)
{
this.context = context;
}
@Override
public Iterable<CostCode> execute()
{
CostCodesDto result = context.getApi().getPricingApi().listCostCodes();
return wrap(context, CostCode.class, result.getCollection());
}
@Override
public Iterable<CostCode> execute(final Predicate<CostCode> selector)
{
return filter(execute(), selector);
}
}

View File

@ -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<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListPricingTemplatesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context)
{
this.context = context;
}
@Override
public Iterable<PricingTemplate> execute()
{
PricingTemplatesDto result = context.getApi().getPricingApi().listPricingTemplates();
return wrap(context, PricingTemplate.class, result.getCollection());
}
@Override
public Iterable<PricingTemplate> execute(final Predicate<PricingTemplate> selector)
{
return filter(execute(), selector);
}
}

View File

@ -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("<error>0</error>");
buffer.append("<highDisponibility>0</highDisponibility>");
buffer.append("<id>1</id>");

View File

@ -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("<currency>");
buffer.append("<symbol>¥</symbol>");
buffer.append("<symbol>DUMMY</symbol>");
buffer.append("<digits>3</digits>");
buffer.append("<name>yuan</name>");
buffer.append("</currency>");
@ -69,7 +77,7 @@ public class PricingResources
StringBuffer buffer = new StringBuffer();
buffer.append("<currency>");
buffer.append(link("/config/currencies/1", "edit"));
buffer.append("<symbol>¥</symbol>");
buffer.append("<symbol>DUMMY</symbol>");
buffer.append("<digits>3</digits>");
buffer.append("<id>1</id>");
buffer.append("<name>yuan</name>");
@ -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("<costCode>");
buffer.append("<name>cost code</name>");
buffer.append("<description>description</description>");
buffer.append("</costCode>");
return buffer.toString();
}
public static String costcodePutPayload()
{
StringBuffer buffer = new StringBuffer();
buffer.append("<costCode>");
buffer.append(link("/config/costcodes/1", "edit"));
buffer.append("<description>description</description>");
buffer.append("<id>1</id>");
buffer.append("<name>cost code</name>");
buffer.append("</costCode>");
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("<pricingTemplate>");
buffer.append("<name>pricing template</name>");
buffer.append("<description>pt_description</description>");
buffer.append("<hdGB>0</hdGB>");
buffer.append("<standingChargePeriod>0</standingChargePeriod>");
buffer.append("<vlan>0</vlan>");
buffer.append("<chargingPeriod>1</chargingPeriod>");
buffer.append("<minimumChargePeriod>0</minimumChargePeriod>");
buffer.append("<showChangesBefore>true</showChangesBefore>");
buffer.append("<showMinimumCharge>false</showMinimumCharge>");
buffer.append("<minimumCharge>2</minimumCharge>");
buffer.append("<memoryGB>0</memoryGB>");
buffer.append("<publicIp>0</publicIp>");
buffer.append("<vcpu>0</vcpu>");
buffer.append("<memoryMB>0</memoryMB>");
buffer.append("<defaultTemplate>true</defaultTemplate>");
buffer.append("<link href='http://localhost/api/config/currencies/1' rel='currency'/>");
buffer.append("</pricingTemplate>");
return buffer.toString();
}
public static String pricingtemplatePutPayload()
{
StringBuffer buffer = new StringBuffer();
buffer.append("<pricingTemplate>");
buffer.append("<name>pricing template</name>");
buffer.append("<description>pt_description</description>");
buffer.append("<hdGB>0</hdGB>");
buffer.append("<standingChargePeriod>0</standingChargePeriod>");
buffer.append("<vlan>0</vlan>");
buffer.append("<chargingPeriod>1</chargingPeriod>");
buffer.append("<minimumChargePeriod>0</minimumChargePeriod>");
buffer.append("<showChangesBefore>true</showChangesBefore>");
buffer.append("<showMinimumCharge>false</showMinimumCharge>");
buffer.append("<minimumCharge>2</minimumCharge>");
buffer.append("<memoryGB>0</memoryGB>");
buffer.append("<publicIp>0</publicIp>");
buffer.append("<vcpu>0</vcpu>");
buffer.append("<memoryMB>0</memoryMB>");
buffer.append("<defaultTemplate>true</defaultTemplate>");
buffer.append("<link href='http://localhost/api/config/currencies/1' rel='currency'/>");
buffer.append("<id>1</id>");
buffer.append(link("/config/pricingtemplates/1", "edit"));
buffer.append("</pricingTemplate>");
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("<costCodeCurrencies>");
buffer.append("<costCodeCurrency>");
buffer.append("<price>300</price>");
buffer
.append("<link href='http://localhost/api/config/costcodes/1/currencies' rel='edit'/>");
buffer.append("<link href='http://localhost/api/config/currencies/1' rel='currency'/>");
buffer.append("</costCodeCurrency>");
buffer.append("</costCodeCurrencies>");
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("<pricingCostCode>");
buffer.append("<link href='http://localhost/api/config/costcodes/1' rel='costcode'/>");
buffer
.append("<link href='http://localhost/api/config/pricingtemplates/1' rel='pricingtemplate'/>");
buffer.append("<price>400</price>");
buffer.append("<id>1</id>");
buffer.append(link("/config/pricingtemplates/1/costcodes/1", "edit"));
buffer.append("</pricingCostCode>");
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("<pricingTier>");
buffer
.append("<link href='http://localhost/api/admin/datacenters/1/storage/tiers/2' rel='tier'/>");
buffer
.append("<link href='http://localhost/api/config/pricingtemplates/1' rel='pricingtemplate'/>");
buffer.append("<price>600</price>");
buffer.append("<id>1</id>");
buffer.append(link("/config/pricingtemplates/1/tiers/2", "edit"));
buffer.append("</pricingTier>");
return buffer.toString();
}
}

View File

@ -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");
}
}
}

View File

@ -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<CostCodePrice> 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<CostCodePrice>();
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<CostCodeCurrency> costcodecurrencies =
env.context.getPricingService().getCostCodeCurrencies(costcode2.getId(),
currency.getId());
for (CostCodeCurrency costcodecurrency : costcodecurrencies)
{
assertEquals(costcodecurrency.getPrice().compareTo(new BigDecimal(100)), 0);
}
costcode2.delete();
}
}

View File

@ -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());

View File

@ -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<Currency> 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<PricingCostCode> 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<PricingTier> pricingTiers =
env.context.getPricingService().getPricingTiers(pricingTemplate.getId());
assertEquals(pricingTiers.size(), 4);
assertNotNull(pricingTiers);
for (PricingTier pt : pricingTiers)
{
assertEquals(pt.getPrice().compareTo(zero), 0);
}
}
}

View File

@ -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<CloudAsyncApi>
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,

View File

@ -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<PricingAsyncApi>
{
/*********************** Currency ***********************/
public void testListCurrencies() throws SecurityException, NoSuchMethodException, IOException
@ -80,7 +88,6 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest<PricingAsyncApi>
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<PricingAsyncApi>
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<PricingAsyncApi>
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<RestAnnotationProcessor<PricingAsyncApi>> createTypeLiteral()
{
@ -142,4 +338,172 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest<PricingAsyncApi>
{
};
}
/*********************** 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);
}
}

View File

@ -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