use of org.ligoj.app.plugin.prov.model.ProvInstanceType 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.ProvInstanceType 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.ProvInstanceType in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installInstancesTerm.
private void installInstancesTerm(final UpdateContext context, final ProvInstancePriceTerm term, final ProvInstancePriceTerm termLow, Entry<String, AzureVmPrice> azPrice) {
final String[] parts = StringUtils.split(azPrice.getKey(), '-');
final VmOs os = VmOs.valueOf(parts[0].replace("redhat", "RHEL").replace("sles", "SUSE").toUpperCase());
// Basic, Low Priority, Standard
final String tier = parts[2];
final boolean isBasic = "basic".equals(tier);
final AzureVmPrice azType = azPrice.getValue();
// Get the right term : "lowpriority" within "PayGo" or the current term
final ProvInstancePriceTerm termU = tier.equals("lowpriority") ? termLow : term;
final String globalCode = termU.getName() + "-" + azPrice.getKey();
final ProvInstanceType type = installInstancePriceType(context, parts, isBasic, azType);
// Iterate over regions enabling this instance type
azType.getPrices().entrySet().stream().filter(pl -> isEnabledRegion(pl.getKey())).forEach(pl -> {
final ProvInstancePrice price = installInstancePrice(context, termU, os, globalCode, type, pl.getKey());
// Update the cost
price.setCost(round3Decimals(pl.getValue().getValue() * 24 * 30.5));
price.setCostPeriod(pl.getValue().getValue());
ipRepository.save(price);
});
}
use of org.ligoj.app.plugin.prov.model.ProvInstanceType in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installInstancePriceType.
private ProvInstanceType installInstancePriceType(final UpdateContext context, final String[] parts, final boolean isBasic, final AzureVmPrice azType) {
final ProvInstanceType type = context.getInstanceTypes().computeIfAbsent(parts[1], name -> {
// New instance type (not update mode)
final ProvInstanceType newType = new ProvInstanceType();
newType.setNode(context.getNode());
newType.setName(name);
return newType;
});
// Merge as needed
if (context.getInstanceTypesMerged().add(type.getName())) {
type.setCpu((double) azType.getCores());
type.setRam((int) azType.getRam() * 1024);
type.setDescription("series:" + azType.getSeries() + ", disk:" + azType.getDiskSize() + "GiB");
type.setConstant(!"B".equals(azType.getSeries()));
// Rating
final Rate rate = isBasic ? Rate.LOW : Rate.GOOD;
type.setCpuRate(isBasic ? Rate.LOW : getRate("cpu", type.getName()));
type.setRamRate(rate);
type.setNetworkRate(getRate("network", type.getName()));
type.setStorageRate(rate);
itRepository.saveAndFlush(type);
}
return type;
}
use of org.ligoj.app.plugin.prov.model.ProvInstanceType in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResourceTest method installOffLine.
@Test
public void installOffLine() throws Exception {
// Install a new configuration
final QuoteVo quote = install();
// Check the whole quote
final ProvQuoteInstance instance = check(quote, 157.096, 150.28d);
// Check the spot
final QuoteInstanceLookup lookup = qiResource.lookup(instance.getConfiguration().getSubscription().getId(), 2, 1741, true, VmOs.LINUX, null, true, null, null);
Assertions.assertEquals(150.28, lookup.getCost(), DELTA);
Assertions.assertEquals(150.28, lookup.getPrice().getCost(), DELTA);
Assertions.assertEquals("base-three-year", lookup.getPrice().getTerm().getName());
Assertions.assertFalse(lookup.getPrice().getTerm().isEphemeral());
Assertions.assertEquals("ds4v2", lookup.getPrice().getType().getName());
Assertions.assertEquals(10, ipRepository.countBy("term.name", "base-three-year"));
Assertions.assertEquals("europe-north", lookup.getPrice().getLocation().getName());
Assertions.assertEquals("North Europe", lookup.getPrice().getLocation().getDescription());
checkImportStatus();
// Install again to check the update without change
resetImportTask();
resource.install();
provResource.updateCost(subscription);
check(provResource.getConfiguration(subscription), 157.096d, 150.28d);
checkImportStatus();
// Now, change a price within the remote catalog
// Point to another catalog with different prices
configuration.saveOrUpdate(ProvAzurePriceImportResource.CONF_API_PRICES, "http://localhost:" + MOCK_PORT + "/v2");
// Install the new catalog, update occurs
resetImportTask();
resource.install();
provResource.updateCost(subscription);
// Check the new price
final QuoteVo newQuote = provResource.getConfiguration(subscription);
Assertions.assertEquals(171.837d, newQuote.getCost().getMin(), DELTA);
// Storage price is updated
final ProvQuoteStorage storage = newQuote.getStorages().get(0);
Assertions.assertEquals(1.537d, storage.getCost(), DELTA);
Assertions.assertEquals(5, storage.getSize(), DELTA);
// Compute price is updated
final ProvQuoteInstance instance2 = newQuote.getInstances().get(0);
Assertions.assertEquals(164.92d, instance2.getCost(), DELTA);
ProvInstancePrice price = instance2.getPrice();
Assertions.assertNull(price.getInitialCost());
Assertions.assertEquals(VmOs.LINUX, price.getOs());
Assertions.assertEquals(ProvTenancy.SHARED, price.getTenancy());
Assertions.assertEquals(164.92d, price.getCost(), DELTA);
final ProvInstancePriceTerm priceType = price.getTerm();
Assertions.assertEquals("base-three-year", priceType.getName());
Assertions.assertFalse(priceType.isEphemeral());
Assertions.assertEquals(36, priceType.getPeriod());
ProvInstanceType type = price.getType();
Assertions.assertEquals("ds4v2", type.getName());
Assertions.assertEquals("series:Dsv2, disk:56GiB", type.getDescription());
// Check rating of "ds4v2"
Assertions.assertEquals(Rate.GOOD, type.getRamRate());
Assertions.assertEquals(Rate.GOOD, type.getCpuRate());
Assertions.assertEquals(Rate.MEDIUM, type.getNetworkRate());
Assertions.assertEquals(Rate.GOOD, type.getStorageRate());
// Check rating of "f1"
type = itRepository.findByName("f1");
Assertions.assertEquals(Rate.GOOD, type.getRamRate());
Assertions.assertEquals(Rate.MEDIUM, type.getCpuRate());
Assertions.assertEquals(Rate.MEDIUM, type.getNetworkRate());
Assertions.assertEquals(Rate.GOOD, type.getStorageRate());
Assertions.assertEquals("series:F, disk:16GiB", type.getDescription());
// Check rating of "ds15v2" (dedicated)
price = iptRepository.findBy("type.name", "ds15v2");
Assertions.assertEquals(ProvTenancy.DEDICATED, price.getTenancy());
// Check status
checkImportStatus();
// Check some prices
final ProvInstancePrice price2 = ipRepository.findBy("code", "europe-west-lowpriority-windows-a1-lowpriority");
final ProvInstancePriceTerm term = price2.getTerm();
Assertions.assertEquals("lowpriority", term.getName());
Assertions.assertEquals(0, term.getPeriod());
Assertions.assertEquals("europe-west", price2.getLocation().getName());
Assertions.assertEquals(VmOs.WINDOWS, price2.getOs());
Assertions.assertTrue(term.isEphemeral());
}
Aggregations