Search in sources :

Example 1 with ProvInstanceType

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());
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 2 with ProvInstanceType

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"));
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) ProvInstancePriceTerm(org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 3 with ProvInstanceType

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);
    });
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) Arrays(java.util.Arrays) ClassPathResource(org.springframework.core.io.ClassPathResource) HashMap(java.util.HashMap) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) ProvTenancy(org.ligoj.app.plugin.prov.model.ProvTenancy) ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) Service(org.springframework.stereotype.Service) Map(java.util.Map) Rate(org.ligoj.app.plugin.prov.model.Rate) CurlProcessor(org.ligoj.app.resource.plugin.CurlProcessor) TypeReference(com.fasterxml.jackson.core.type.TypeReference) INamableBean(org.ligoj.bootstrap.core.INamableBean) Node(org.ligoj.app.model.Node) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) VmOs(org.ligoj.app.plugin.prov.model.VmOs) Slf4j(lombok.extern.slf4j.Slf4j) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) ProvInstancePriceTerm(org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm) Optional(java.util.Optional) ProvAzurePluginResource(org.ligoj.app.plugin.prov.azure.ProvAzurePluginResource) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) AbstractImportCatalogResource(org.ligoj.app.plugin.prov.in.AbstractImportCatalogResource) ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) ProvStorageOptimized(org.ligoj.app.plugin.prov.model.ProvStorageOptimized) VmOs(org.ligoj.app.plugin.prov.model.VmOs) ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvInstancePriceTerm(org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm)

Example 4 with ProvInstanceType

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;
}
Also used : ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) Rate(org.ligoj.app.plugin.prov.model.Rate)

Example 5 with ProvInstanceType

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());
}
Also used : ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) QuoteVo(org.ligoj.app.plugin.prov.QuoteVo) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvInstancePriceTerm(org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm) QuoteInstanceLookup(org.ligoj.app.plugin.prov.QuoteInstanceLookup) Test(org.junit.jupiter.api.Test) AbstractServerTest(org.ligoj.app.AbstractServerTest)

Aggregations

ProvInstanceType (org.ligoj.app.plugin.prov.model.ProvInstanceType)5 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)4 Test (org.junit.jupiter.api.Test)3 ProvInstancePriceTerm (org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm)3 ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)3 ProvStorageType (org.ligoj.app.plugin.prov.model.ProvStorageType)3 AbstractAppTest (org.ligoj.app.AbstractAppTest)2 ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)2 ProvQuoteStorage (org.ligoj.app.plugin.prov.model.ProvQuoteStorage)2 Rate (org.ligoj.app.plugin.prov.model.Rate)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1