Search in sources :

Example 6 with ProvStoragePrice

use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov-azure by ligoj.

the class ProvAzurePriceImportResourceTest method installAndConfigure.

/**
 * Install and check
 */
private QuoteVo installAndConfigure() throws IOException, Exception {
    resource.install();
    em.flush();
    em.clear();
    Assertions.assertEquals(0, provResource.getConfiguration(subscription).getCost().getMin(), DELTA);
    // Request an instance that would not be a Spot
    final QuoteInstanceLookup lookup = qiResource.lookup(subscription, 8, 26000, true, VmOs.LINUX, "ds4v2", false, null, "36month");
    final QuoteInstanceEditionVo ivo = new QuoteInstanceEditionVo();
    ivo.setCpu(1d);
    ivo.setRam(1);
    ivo.setPrice(lookup.getPrice().getId());
    ivo.setName("server1");
    ivo.setSubscription(subscription);
    final UpdatedCost createInstance = qiResource.create(ivo);
    Assertions.assertTrue(createInstance.getTotalCost().getMin() > 1);
    final int instance = createInstance.getId();
    em.flush();
    em.clear();
    // Lookup & add STANDARD storage to this instance
    // ---------------------------------
    QuoteStorageLoopup slookup = qsResource.lookup(subscription, 5, Rate.LOW, instance, null, null).get(0);
    Assertions.assertEquals(1.536, slookup.getCost(), DELTA);
    // Check price & type
    ProvStoragePrice price = slookup.getPrice();
    ProvStorageType type = price.getType();
    Assertions.assertEquals("s4", type.getName());
    Assertions.assertEquals(Rate.MEDIUM, type.getLatency());
    Assertions.assertNull(type.getOptimized());
    Assertions.assertEquals("europe-north", price.getLocation().getName());
    Assertions.assertEquals("North Europe", price.getLocation().getDescription());
    QuoteStorageEditionVo svo = new QuoteStorageEditionVo();
    svo.setQuoteInstance(instance);
    svo.setSize(5);
    svo.setType(type.getName());
    svo.setName("sda1");
    svo.setSubscription(subscription);
    UpdatedCost newStorage = qsResource.create(svo);
    Assertions.assertTrue(newStorage.getTotalCost().getMin() > 100);
    Assertions.assertEquals(1.536, newStorage.getResourceCost().getMin(), DELTA);
    // Lookup & add PREMIUM storage to this quote
    // ---------------------------------
    slookup = qsResource.lookup(subscription, 1, Rate.LOW, null, ProvStorageOptimized.IOPS, null).get(0);
    Assertions.assertEquals(5.28, slookup.getCost(), DELTA);
    // Check price & type
    price = slookup.getPrice();
    type = price.getType();
    Assertions.assertEquals("p4", type.getName());
    Assertions.assertEquals(120, type.getIops());
    Assertions.assertEquals(25, type.getThroughput());
    Assertions.assertEquals(Rate.BEST, type.getLatency());
    Assertions.assertEquals(ProvStorageOptimized.IOPS, type.getOptimized());
    Assertions.assertEquals("europe-north", price.getLocation().getName());
    Assertions.assertEquals("North Europe", price.getLocation().getDescription());
    svo = new QuoteStorageEditionVo();
    svo.setOptimized(ProvStorageOptimized.IOPS);
    svo.setSize(1);
    svo.setType(type.getName());
    svo.setName("sda2");
    svo.setSubscription(subscription);
    newStorage = qsResource.create(svo);
    Assertions.assertTrue(newStorage.getTotalCost().getMin() > 100);
    Assertions.assertEquals(5.28, newStorage.getResourceCost().getMin(), DELTA);
    return provResource.getConfiguration(subscription);
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) UpdatedCost(org.ligoj.app.plugin.prov.UpdatedCost) QuoteStorageLoopup(org.ligoj.app.plugin.prov.QuoteStorageLoopup) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) QuoteInstanceEditionVo(org.ligoj.app.plugin.prov.QuoteInstanceEditionVo) QuoteInstanceLookup(org.ligoj.app.plugin.prov.QuoteInstanceLookup) QuoteStorageEditionVo(org.ligoj.app.plugin.prov.QuoteStorageEditionVo)

Example 7 with ProvStoragePrice

use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov by ligoj.

the class ProvResourceTest method updateLocationDifferentQILocation.

/**
 * Update the location of the quote, impact all instances, but no one use the default location. Cost still updated.
 */
@Test
public void updateLocationDifferentQILocation() {
    final ProvLocation location = locationRepository.findByName("region-1");
    final ProvLocation location4 = locationRepository.findByName("region-4");
    // Change the required location of all quote instance
    qiRepository.findAll().forEach(ip -> ip.setLocation(location));
    // Make sure there is no more world wild prices
    em.createQuery("FROM ProvInstancePrice WHERE location.name=:location", ProvInstancePrice.class).setParameter("location", "region-1").getResultList().forEach(ip -> ip.setLocation(location4));
    em.createQuery("FROM ProvStoragePrice WHERE location.name=:location", ProvStoragePrice.class).setParameter("location", "region-1").getResultList().forEach(ip -> ip.setLocation(location4));
    em.createQuery("FROM ProvQuoteInstance WHERE location.name=:location", ProvQuoteInstance.class).setParameter("location", "region-1").getResultList().forEach(ip -> ip.setLocation(location4));
    em.flush();
    em.clear();
    // New cost based on region-4
    final QuoteEditionVo quote = new QuoteEditionVo();
    quote.setName("name1");
    quote.setDescription("description1");
    quote.setLocation("region-4");
    final FloatingCost cost = resource.update(subscription, quote);
    checkCost(cost, 3165.4, 5615.0, false);
    final ProvQuote quote2 = repository.findByNameExpected("name1");
    Assertions.assertEquals("description1", quote2.getDescription());
    Assertions.assertEquals("region-4", quote2.getLocation().getName());
}
Also used : ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) ProvQuote(org.ligoj.app.plugin.prov.model.ProvQuote) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 8 with ProvStoragePrice

use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov-azure by ligoj.

the class ProvAzurePriceImportResource method installStoragePrice.

/**
 * Install a {@link ProvStoragePrice} from an {@link ManagedDisk} offer.
 *
 * @param context
 *            The update context.
 * @param offer
 *            The current offer to install.
 */
private void installStoragePrice(final UpdateContext context, final Entry<String, ManagedDisk> offer) {
    final ManagedDisk disk = offer.getValue();
    final ProvStorageType type = installStorageType(context, offer.getKey(), disk);
    final Map<ProvLocation, ProvStoragePrice> previousT = context.getPreviousStorages().computeIfAbsent(type, t -> new HashMap<>());
    disk.getPrices().entrySet().stream().filter(p -> isEnabledRegion(p.getKey())).forEach(p -> installStoragePrice(context, previousT, context.getRegions().get(p.getKey()), type, p.getValue().getValue()));
}
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) ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice)

Example 9 with ProvStoragePrice

use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov-azure by ligoj.

the class ProvAzurePriceImportResource method installStoragePrice.

/**
 * Install or update a storage price.
 *
 * @param context
 *            The update context.
 * @see <a href="https://azure.microsoft.com/en-us/pricing/details/managed-disks/"></a>
 */
private ProvStoragePrice installStoragePrice(final UpdateContext context, final Map<ProvLocation, ProvStoragePrice> regionPrices, final ProvLocation region, final ProvStorageType type, final double value) {
    final ProvStoragePrice price = regionPrices.computeIfAbsent(region, r -> {
        final ProvStoragePrice newPrice = new ProvStoragePrice();
        newPrice.setType(type);
        newPrice.setLocation(region);
        return newPrice;
    });
    // Fixed cost
    price.setCost(value);
    if (!type.getName().startsWith("premium")) {
        // Additional transaction based cost : $/10,000 transaction -> $/1,000,000 transaction
        price.setCostTransaction(Optional.ofNullable(context.getTransactions().get(region.getName())).map(v -> round3Decimals(v.getValue() * 100)).orElse(0d));
    }
    spRepository.saveAndFlush(price);
    return price;
}
Also used : ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice)

Aggregations

ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)9 ProvStorageType (org.ligoj.app.plugin.prov.model.ProvStorageType)7 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)5 Test (org.junit.jupiter.api.Test)4 AbstractAppTest (org.ligoj.app.AbstractAppTest)4 ProvInstanceType (org.ligoj.app.plugin.prov.model.ProvInstanceType)3 ProvLocation (org.ligoj.app.plugin.prov.model.ProvLocation)3 ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)3 List (java.util.List)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 ProvInstancePriceTerm (org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm)2 ProvQuote (org.ligoj.app.plugin.prov.model.ProvQuote)2 ProvQuoteStorage (org.ligoj.app.plugin.prov.model.ProvQuoteStorage)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 Collections (java.util.Collections)1