use of org.ligoj.app.plugin.prov.model.ProvInstancePrice in project plugin-prov by ligoj.
the class ProvResourceTest method getConfiguration.
@Test
public void getConfiguration() {
QuoteVo vo = resource.getConfiguration(subscription);
Assertions.assertEquals("quote1", vo.getName());
Assertions.assertEquals("quoteD1", vo.getDescription());
checkCost(vo.getCost(), 4704.758, 7154.358, false);
checkCost(resource.updateCost(subscription), 4704.758, 7154.358, false);
vo = resource.getConfiguration(subscription);
checkCost(vo.getCost(), 4704.758, 7154.358, false);
Assertions.assertNotNull(vo.getId());
Assertions.assertNotNull(vo.getCreatedBy());
Assertions.assertNotNull(vo.getCreatedDate());
Assertions.assertNotNull(vo.getLastModifiedBy());
Assertions.assertNotNull(vo.getLastModifiedDate());
Assertions.assertEquals("region-1", vo.getLocation().getName());
// Check compute
final List<ProvQuoteInstance> instances = vo.getInstances();
Assertions.assertEquals(7, instances.size());
final ProvQuoteInstance quoteInstance = instances.get(0);
Assertions.assertNotNull(quoteInstance.getId());
Assertions.assertEquals("server1", quoteInstance.getName());
Assertions.assertEquals("serverD1", quoteInstance.getDescription());
Assertions.assertTrue(quoteInstance.getConstant());
Assertions.assertEquals(InternetAccess.PUBLIC, quoteInstance.getInternet());
Assertions.assertEquals(10.1, quoteInstance.getMaxVariableCost(), DELTA);
Assertions.assertEquals(2, quoteInstance.getMinQuantity().intValue());
Assertions.assertEquals(10, quoteInstance.getMaxQuantity().intValue());
final ProvInstancePrice price = quoteInstance.getPrice();
Assertions.assertEquals(146.4, price.getCost(), DELTA);
Assertions.assertEquals(146.4, price.getCostPeriod(), DELTA);
Assertions.assertEquals(VmOs.LINUX, price.getOs());
Assertions.assertNotNull(price.getTerm().getId());
Assertions.assertFalse(price.getTerm().isEphemeral());
Assertions.assertFalse(price.getTerm().isVariable());
Assertions.assertEquals(0, price.getTerm().getPeriod());
Assertions.assertEquals("on-demand1", price.getTerm().getName());
Assertions.assertEquals("15 minutes fragment", price.getTerm().getDescription());
final ProvInstanceType instance = price.getType();
Assertions.assertNotNull(instance.getId().intValue());
Assertions.assertEquals("instance1", instance.getName());
Assertions.assertEquals("instanceD1", instance.getDescription());
Assertions.assertEquals(0.5, instance.getCpu(), 0.0001);
Assertions.assertEquals(2000, instance.getRam().intValue());
Assertions.assertTrue(instance.getConstant());
// No minimal for this instance price
Assertions.assertNull(instances.get(1).getMaxVariableCost());
Assertions.assertEquals(1, instances.get(3).getMinQuantity().intValue());
Assertions.assertEquals(1, instances.get(3).getMaxQuantity().intValue());
// Check the constant CPU requirement
Assertions.assertTrue(instances.get(0).getConstant());
Assertions.assertNull(instances.get(1).getConstant());
Assertions.assertFalse(instances.get(3).getConstant());
// Check the network requirement
Assertions.assertEquals(InternetAccess.PUBLIC, instances.get(0).getInternet());
Assertions.assertEquals(InternetAccess.PRIVATE, instances.get(1).getInternet());
Assertions.assertEquals(InternetAccess.PRIVATE_NAT, instances.get(2).getInternet());
// Check storage
final List<ProvQuoteStorage> storages = vo.getStorages();
Assertions.assertEquals(4, storages.size());
final ProvQuoteStorage quoteStorage = storages.get(0);
Assertions.assertNotNull(quoteStorage.getId());
Assertions.assertEquals("server1-root", quoteStorage.getName());
Assertions.assertEquals("server1-rootD", quoteStorage.getDescription());
Assertions.assertEquals(20, quoteStorage.getSize().intValue());
Assertions.assertEquals(8.4, quoteStorage.getCost(), DELTA);
// = 8.4 * 5
Assertions.assertEquals(42, quoteStorage.getMaxCost(), DELTA);
Assertions.assertNotNull(quoteStorage.getQuoteInstance());
final ProvStoragePrice storage = quoteStorage.getPrice();
final ProvStorageType storageType = storage.getType();
Assertions.assertNotNull(storage.getId());
Assertions.assertEquals(0.21, storage.getCostGb(), DELTA);
Assertions.assertEquals(0, storage.getCost(), DELTA);
Assertions.assertEquals("storage1", storageType.getName());
Assertions.assertEquals("storageD1", storageType.getDescription());
Assertions.assertEquals(200, storageType.getIops());
Assertions.assertEquals(60, storageType.getThroughput());
Assertions.assertEquals(0, storage.getCostTransaction(), DELTA);
Assertions.assertEquals(Rate.GOOD, storageType.getLatency());
Assertions.assertEquals(ProvStorageOptimized.IOPS, storageType.getOptimized());
// Not attached storage
Assertions.assertNull(storages.get(3).getQuoteInstance());
// Check the small transactional cost
Assertions.assertEquals(0.000000072, storages.get(1).getPrice().getCostTransaction(), 0.000000001);
// Check the related instance and price for the next comparison
Assertions.assertEquals("instance1", instances.get(0).getPrice().getType().getName());
Assertions.assertEquals("instance1", instances.get(1).getPrice().getType().getName());
Assertions.assertEquals("instance1", instances.get(2).getPrice().getType().getName());
Assertions.assertEquals("instance3", instances.get(3).getPrice().getType().getName());
Assertions.assertEquals("instance5", instances.get(4).getPrice().getType().getName());
Assertions.assertEquals("instance10", instances.get(5).getPrice().getType().getName());
Assertions.assertEquals("dynamic", instances.get(6).getPrice().getType().getName());
Assertions.assertEquals("on-demand1", instances.get(0).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand2", instances.get(1).getPrice().getTerm().getName());
Assertions.assertEquals("1y", instances.get(2).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand1", instances.get(3).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand2", instances.get(4).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand1", instances.get(5).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand1", instances.get(6).getPrice().getTerm().getName());
// Optimize the configuration
checkCost(resource.refresh(subscription), 3165.4, 5615.0, false);
final QuoteVo vo2 = resource.getConfiguration(subscription);
Assertions.assertEquals("quote1", vo2.getName());
Assertions.assertEquals(vo2.getId(), vo.getId());
// Check the new instances
final List<ProvQuoteInstance> instances2 = vo2.getInstances();
Assertions.assertEquals(7, instances2.size());
// Same instance
Assertions.assertEquals("instance1", instances2.get(0).getPrice().getType().getName());
Assertions.assertEquals("dynamic", instances2.get(5).getPrice().getType().getName());
Assertions.assertEquals("dynamic", instances2.get(4).getPrice().getType().getName());
// Fixed instance types for the same constraints
Assertions.assertEquals("instance2", instances2.get(1).getPrice().getType().getName());
Assertions.assertEquals("instance2", instances2.get(2).getPrice().getType().getName());
Assertions.assertEquals("instance2", instances2.get(3).getPrice().getType().getName());
Assertions.assertEquals("dynamic", instances2.get(6).getPrice().getType().getName());
// Check the contracts are the same but for 2
Assertions.assertEquals("on-demand1", instances2.get(0).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand2", instances2.get(1).getPrice().getTerm().getName());
// Updated
Assertions.assertEquals("on-demand1", instances2.get(2).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand1", instances2.get(3).getPrice().getTerm().getName());
// Updated
Assertions.assertEquals("on-demand1", instances2.get(4).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand1", instances2.get(5).getPrice().getTerm().getName());
Assertions.assertEquals("on-demand1", instances2.get(6).getPrice().getTerm().getName());
// No associated usage for this use case
Assertions.assertNull(vo.getUsage());
}
use of org.ligoj.app.plugin.prov.model.ProvInstancePrice in project plugin-prov by ligoj.
the class ProvQuoteInstanceResourceTest method assertPrice.
private void assertPrice(final QuoteInstanceLookup lookup, final String code, final String instance, final double cost, final String term) {
// Check the custom instance
final ProvInstancePrice pi = lookup.getPrice();
Assertions.assertEquals(code, pi.getCode());
Assertions.assertEquals(instance, pi.getType().getName());
Assertions.assertEquals(term, pi.getTerm().getName());
Assertions.assertEquals(cost, lookup.getCost(), DELTA);
}
use of org.ligoj.app.plugin.prov.model.ProvInstancePrice in project plugin-prov by ligoj.
the class ProvQuoteInstanceResourceTest method lookupInstanceOnlyCustom.
/**
* Too much requirements for an instance
*/
@Test
public void lookupInstanceOnlyCustom() {
final QuoteInstanceLookup lookup = qiResource.lookup(subscription, 999, 0, null, VmOs.LINUX, null, true, null, "Full Time 12 month");
// Check the custom instance
final ProvInstancePrice pi = lookup.getPrice();
Assertions.assertNotNull(pi.getId());
Assertions.assertEquals("dynamic", pi.getType().getName());
Assertions.assertEquals(0, pi.getType().getCpu().intValue());
Assertions.assertEquals(0, pi.getType().getRam().intValue());
Assertions.assertTrue(pi.getType().getConstant());
Assertions.assertEquals(0, pi.getCost(), DELTA);
Assertions.assertEquals(VmOs.LINUX, pi.getOs());
Assertions.assertEquals("on-demand1", pi.getTerm().getName());
Assertions.assertTrue(pi.getType().isCustom());
Assertions.assertEquals(242590.846, lookup.getCost(), DELTA);
}
use of org.ligoj.app.plugin.prov.model.ProvInstancePrice in project plugin-prov by ligoj.
the class ProvQuoteInstanceResourceTest method checkInstance.
private void checkInstance(final QuoteInstanceLookup lookup) {
// Check the instance result
final ProvInstancePrice pi = lookup.getPrice();
Assertions.assertNotNull(pi.getId());
Assertions.assertEquals("instance2", pi.getType().getName());
Assertions.assertEquals(1, pi.getType().getCpu().intValue());
Assertions.assertEquals(2000, pi.getType().getRam().intValue());
Assertions.assertEquals("C11", pi.getCode());
Assertions.assertFalse(pi.getTerm().isEphemeral());
Assertions.assertEquals(102.48, pi.getCost(), DELTA);
Assertions.assertEquals(1229.76, pi.getCostPeriod(), DELTA);
Assertions.assertEquals(VmOs.LINUX, pi.getOs());
Assertions.assertEquals("1y", pi.getTerm().getName());
Assertions.assertEquals(102.48, lookup.getCost(), DELTA);
}
use of org.ligoj.app.plugin.prov.model.ProvInstancePrice in project plugin-prov by ligoj.
the class ProvResourceTest method testToString.
@Test
public void testToString() {
final QuoteInstanceLookup computedInstancePrice = new QuoteInstanceLookup();
computedInstancePrice.setCost(1.23);
final ProvInstancePrice ip = new ProvInstancePrice();
final ProvInstancePriceTerm type = new ProvInstancePriceTerm();
type.setName("type1");
ip.setTerm(type);
final ProvInstanceType instance = new ProvInstanceType();
instance.setName("instance1");
ip.setType(instance);
computedInstancePrice.setPrice(ip);
Assertions.assertTrue(computedInstancePrice.toString().contains("cost=1.23"));
Assertions.assertTrue(computedInstancePrice.toString().contains("name=instance1"));
final QuoteStorageLoopup computedStoragePrice = new QuoteStorageLoopup();
computedStoragePrice.setCost(1.23);
final ProvStoragePrice sp = new ProvStoragePrice();
final ProvStorageType stype = new ProvStorageType();
stype.setName("type1");
sp.setType(stype);
computedStoragePrice.setPrice(sp);
Assertions.assertTrue(computedStoragePrice.toString().contains("cost=1.23"));
Assertions.assertTrue(computedStoragePrice.toString().contains("name=type1"));
}
Aggregations