use of org.ligoj.app.plugin.prov.model.ProvStorageType 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.ProvStorageType 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.ProvStorageType 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.ProvStorageType 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.ProvStorageType in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installStorageType.
/**
* Install or update a storage type.
*/
private ProvStorageType installStorageType(final UpdateContext context, String name, ManagedDisk disk) {
final boolean isSnapshot = name.endsWith("snapshot");
final ProvStorageType type = context.getStorageTypes().computeIfAbsent(isSnapshot ? name : name.replace("standard-", "").replace("premium-", ""), n -> {
final ProvStorageType newType = new ProvStorageType();
newType.setNode(context.getNode());
newType.setName(n);
return newType;
});
// Merge storage type statistics
if (context.getStorageTypesMerged().add(type.getName())) {
final boolean isPremium = name.startsWith("premium");
final boolean isStandard = name.startsWith("standard");
if (isSnapshot) {
type.setLatency(Rate.WORST);
type.setMinimal(0);
type.setOptimized(ProvStorageOptimized.DURABILITY);
type.setIops(0);
type.setThroughput(0);
} else {
// Complete data
// Source :
// https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disk-scalability-targets
type.setLatency(isPremium ? Rate.BEST : Rate.MEDIUM);
type.setMinimal(disk.getSize());
type.setMaximal(disk.getSize());
type.setOptimized(isPremium ? ProvStorageOptimized.IOPS : null);
type.setInstanceCompatible(true);
type.setIops(isStandard && disk.getIops() == 0 ? 500 : disk.getIops());
type.setThroughput(isStandard && disk.getThroughput() == 0 ? 60 : disk.getThroughput());
}
stRepository.saveAndFlush(type);
}
return type;
}
Aggregations