use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance 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.ProvQuoteInstance in project plugin-prov by ligoj.
the class ProvQuoteStorageResourceTest method setUnboundInstance.
/**
* Change the given instance name from bound to unbound type.
*/
private ProvQuoteInstance setUnboundInstance(final String name) {
final ProvQuoteInstance quoteInstance = qiRepository.findByNameExpected(name);
// Precondition
Assertions.assertEquals(10, quoteInstance.getMaxQuantity().intValue());
Assertions.assertEquals(0, quoteInstance.getConfiguration().getUnboundCostCounter().intValue());
// Make the instance with unbound cost
quoteInstance.setMaxQuantity(null);
quoteInstance.getConfiguration().setUnboundCostCounter(1);
em.flush();
em.clear();
resource.updateCost(subscription);
em.flush();
return quoteInstance;
}
use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.
the class ProvQuoteInstanceResourceTest method uploadMaxQuantities.
@Test
public void uploadMaxQuantities() throws IOException {
qiResource.upload(subscription, new ByteArrayInputStream("ANY;0.5;500;LINUX;1;true;1;1;true".getBytes("UTF-8")), new String[] { "name", "cpu", "ram", "os", "disk", "constant", "minQuantity", "maxQuantity", "ephemeral" }, false, "Full Time 12 month", 1, "UTF-8");
final QuoteVo configuration = resource.getConfiguration(subscription);
Assertions.assertEquals(8, configuration.getInstances().size());
final ProvQuoteInstance qi = configuration.getInstances().get(7);
Assertions.assertEquals(1, qi.getMinQuantity().intValue());
Assertions.assertEquals(1, qi.getMaxQuantity().intValue());
Assertions.assertEquals(5, configuration.getStorages().size());
checkCost(configuration.getCost(), 4833.068, 7282.668, false);
final Map<Integer, FloatingCost> storagesFloatingCost = toStoragesFloatingCost("ANY");
Assertions.assertEquals(1, storagesFloatingCost.size());
checkCost(storagesFloatingCost.values().iterator().next(), 0.21, 0.21, false);
}
use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.
the class ProvQuoteInstanceResourceTest method updateInstance.
@Test
public void updateInstance() {
// Check the cost of related storages of this instance
final Map<Integer, FloatingCost> storagePrices = toStoragesFloatingCost("server1");
Assertions.assertEquals(3, storagePrices.size());
final QuoteInstanceEditionVo vo = new QuoteInstanceEditionVo();
vo.setSubscription(subscription);
vo.setId(qiRepository.findByNameExpected("server1").getId());
vo.setPrice(ipRepository.findByExpected("code", "C10").getId());
vo.setName("server1-bis");
vo.setRam(1024);
vo.setCpu(0.5);
vo.setMinQuantity(1);
vo.setMaxQuantity(20);
vo.setLocation("region-1");
vo.setUsage("Full Time");
final UpdatedCost updatedCost = qiResource.update(vo);
Assertions.assertEquals(updatedCost.getId(), vo.getId().intValue());
// Check the exact new cost
checkCost(updatedCost.getTotalCost(), 4460.778, 11460.758, false);
checkCost(updatedCost.getResourceCost(), 208.62, 4172.4, false);
checkCost(subscription, 4460.778, 11460.758, false);
// Check the related storage prices
Assertions.assertEquals(3, updatedCost.getRelatedCosts().size());
final ProvQuoteInstance instance = qiRepository.findOneExpected(vo.getId());
Assertions.assertEquals("server1-bis", instance.getName());
Assertions.assertEquals(1024, instance.getRam().intValue());
Assertions.assertEquals(0.5, instance.getCpu(), DELTA);
Assertions.assertEquals(208.62, instance.getCost(), DELTA);
Assertions.assertEquals(4172.4, instance.getMaxCost(), DELTA);
Assertions.assertEquals("region-1", instance.getLocation().getName());
// Change the usage of this instance to 50%
vo.setUsage("Dev");
final UpdatedCost updatedCost2 = qiResource.update(vo);
checkCost(updatedCost2.getTotalCost(), 4356.468, 9374.558, false);
checkCost(updatedCost2.getResourceCost(), 104.31, 2086.2, false);
// Change the region of this instance, storage is also
vo.setLocation("region-2");
}
use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.
the class ProvQuoteInstanceResourceTest method uploadUnBoundQuantities.
@Test
public void uploadUnBoundQuantities() throws IOException {
qiResource.upload(subscription, new ByteArrayInputStream("ANY;0.5;500;LINUX;1;true;1;0;true".getBytes("UTF-8")), new String[] { "name", "cpu", "ram", "os", "disk", "constant", "minQuantity", "maxQuantity", "ephemeral" }, false, "Full Time 12 month", 1, "UTF-8");
final QuoteVo configuration = resource.getConfiguration(subscription);
Assertions.assertEquals(8, configuration.getInstances().size());
final ProvQuoteInstance qi = configuration.getInstances().get(7);
Assertions.assertEquals(1, qi.getMinQuantity().intValue());
Assertions.assertNull(qi.getMaxQuantity());
Assertions.assertEquals(5, configuration.getStorages().size());
checkCost(configuration.getCost(), 4833.068, 7282.668, true);
final Map<Integer, FloatingCost> storagesFloatingCost = toStoragesFloatingCost("ANY");
Assertions.assertEquals(1, storagesFloatingCost.size());
checkCost(storagesFloatingCost.values().iterator().next(), 0.21, 0.21, true);
}
Aggregations