use of org.ligoj.app.plugin.prov.model.ProvStoragePrice 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.ProvStoragePrice in project plugin-prov by ligoj.
the class ProvQuoteStorageResourceTest method refresh.
@Test
public void refresh() {
// Create with constraints
final QuoteStorageEditionVo vo = new QuoteStorageEditionVo();
vo.setSubscription(subscription);
vo.setName("server-new");
vo.setType("storage1");
vo.setOptimized(null);
vo.setInstanceCompatible(true);
vo.setLatency(Rate.GOOD);
vo.setQuoteInstance(qiRepository.findByNameExpected("server2").getId());
vo.setSize(512);
final UpdatedCost cost = qsResource.create(vo);
checkCost(cost.getResourceCost(), 107.52, 107.52, false);
// No change
checkCost(qsResource.refresh(qsRepository.findOneExpected(cost.getId())), 107.52, 107.52, false);
Assertions.assertEquals("storage1", qsRepository.findOneExpected(cost.getId()).getPrice().getType().getName());
Assertions.assertEquals(true, qsRepository.findOneExpected(cost.getId()).getInstanceCompatible());
// Change some constraints
vo.setLatency(Rate.WORST);
vo.setInstanceCompatible(false);
vo.setQuoteInstance(null);
vo.setId(cost.getId());
// Cost is the same since the type still match the constraints
checkCost(qsResource.update(vo).getResourceCost(), 107.52, 107.52, false);
// The cost changed since a best type matches to the constraints
checkCost(qsResource.refresh(qsRepository.findOneExpected(cost.getId())), 77.8, 77.8, false);
Assertions.assertEquals("storage2", qsRepository.findOneExpected(cost.getId()).getPrice().getType().getName());
// Change the price of "storage3" to make it as cheap as "storage2"
final ProvStoragePrice price3 = spRepository.findBy("type.name", "storage3");
price3.setCost(1);
spRepository.saveAndFlush(price3);
// Also, change the latency of "storage3" to "GOOD" class
final ProvStorageType type3 = stRepository.findByName("storage3");
type3.setLatency(Rate.GOOD);
stRepository.saveAndFlush(type3);
// Even if "storage2" and "storage3" have identical prices and match to
// the
// requirements, "storage3" offers a lowest latency.
checkCost(qsResource.refresh(qsRepository.findOneExpected(cost.getId())), 77.8, 77.8, false);
Assertions.assertEquals("storage3", qsRepository.findOneExpected(cost.getId()).getPrice().getType().getName());
}
use of org.ligoj.app.plugin.prov.model.ProvStoragePrice 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"));
}
use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov by ligoj.
the class ProvQuoteStorageResourceTest method assertCSP.
private QuoteStorageLoopup assertCSP(final QuoteStorageLoopup price) {
final ProvStoragePrice sp = price.getPrice();
final ProvStorageType st = sp.getType();
Assertions.assertNotNull(sp.getId());
Assertions.assertNotNull(st.getId());
Assertions.assertEquals("storage1", st.getName());
return price;
}
use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov by ligoj.
the class ProvQuoteStorageResource method lookup.
private List<QuoteStorageLoopup> lookup(final ProvQuote configuration, final int size, final Rate latency, final Integer instance, final ProvStorageOptimized optimized, final String location) {
// Get the attached node and check the security on this subscription
final String node = configuration.getSubscription().getNode().getRefined().getId();
final ProvQuoteInstance qi = checkInstance(node, instance);
// The the right location from instance first, then the request one
String iLocation = Optional.ofNullable(qi).map(qiResource::getLocation).map(ProvLocation::getName).orElse(location);
iLocation = ObjectUtils.defaultIfNull(iLocation, configuration.getLocation().getName());
if (location != null && !location.equals(iLocation)) {
// Not compatible locations
return Collections.emptyList();
}
return spRepository.findLowestPrice(node, size, latency, instance, optimized, iLocation, PageRequest.of(0, 10)).stream().map(spx -> (ProvStoragePrice) spx[0]).map(sp -> newPrice(sp, size, getCost(sp, size))).collect(Collectors.toList());
}
Aggregations