Search in sources :

Example 6 with ProvStorageType

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

the class ProvAzurePriceImportResourceTest method checkStorage.

private ProvQuoteStorage checkStorage(final ProvQuoteStorage storage) {
    Assertions.assertEquals(1.536d, storage.getCost(), DELTA);
    Assertions.assertEquals(5, storage.getSize(), DELTA);
    Assertions.assertNotNull(storage.getQuoteInstance());
    final ProvStorageType type = storage.getPrice().getType();
    Assertions.assertEquals("s4", type.getName());
    Assertions.assertEquals(500, type.getIops());
    Assertions.assertEquals(60, type.getThroughput());
    Assertions.assertEquals(Rate.MEDIUM, type.getLatency());
    Assertions.assertEquals(0.05, storage.getPrice().getCostTransaction(), DELTA);
    Assertions.assertEquals(32, type.getMinimal());
    Assertions.assertEquals(32, type.getMaximal().intValue());
    return storage;
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType)

Example 7 with ProvStorageType

use of org.ligoj.app.plugin.prov.model.ProvStorageType 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 8 with ProvStorageType

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

the class ProvQuoteStorageResource method saveOrUpdate.

/**
 * Save or update the storage inside a quote.
 *
 * @param entity
 *            The storage entity to update.
 * @param vo
 *            The new quote storage data to persist.
 * @return The formal entity.
 */
private UpdatedCost saveOrUpdate(final ProvQuoteStorage entity, final QuoteStorageEditionVo vo) {
    DescribedBean.copy(vo, entity);
    // Check the associations
    final int subscription = vo.getSubscription();
    final ProvQuote quote = getQuoteFromSubscription(subscription);
    final String node = quote.getSubscription().getNode().getRefined().getId();
    entity.setConfiguration(quote);
    entity.setLocation(resource.findLocation(node, vo.getLocation()));
    entity.setPrice(findByTypeName(subscription, vo.getType(), vo.getLocation(), quote));
    entity.setInstanceCompatible(vo.getInstanceCompatible());
    entity.setLatency(vo.getLatency());
    entity.setOptimized(vo.getOptimized());
    entity.setSize(vo.getSize());
    entity.setQuoteInstance(checkInstance(node, vo.getQuoteInstance()));
    // Check the storage requirements to validate the linked price
    final ProvStorageType type = entity.getPrice().getType();
    if (!lookup(quote, entity.getSize(), entity.getLatency(), vo.getQuoteInstance(), entity.getOptimized(), vo.getLocation()).stream().map(qs -> qs.getPrice().getType()).anyMatch(type::equals)) {
        // The related storage type does not match these requirements
        throw new ValidationJsonException("type", "type-incompatible-requirements", type.getName());
    }
    // Save and update the costs
    final UpdatedCost cost = refreshCost(entity);
    Optional.ofNullable(entity.getQuoteInstance()).ifPresent(q -> cost.setRelatedCosts(Collections.singletonMap(q.getId(), qiResource.updateCost(q))));
    return cost;
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) ProvQuote(org.ligoj.app.plugin.prov.model.ProvQuote) ValidationJsonException(org.ligoj.bootstrap.core.validation.ValidationJsonException)

Example 9 with ProvStorageType

use of org.ligoj.app.plugin.prov.model.ProvStorageType 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)

Aggregations

ProvStorageType (org.ligoj.app.plugin.prov.model.ProvStorageType)9 ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)6 Test (org.junit.jupiter.api.Test)3 AbstractAppTest (org.ligoj.app.AbstractAppTest)3 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)3 ProvInstanceType (org.ligoj.app.plugin.prov.model.ProvInstanceType)3 ProvInstancePriceTerm (org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm)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 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1