Search in sources :

Example 1 with QuoteInstanceLookup

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

the class ProvAzurePriceImportResourceTest method installOnLine.

@Test
public void installOnLine() throws Exception {
    configuration.delete(ProvAzurePriceImportResource.CONF_API_PRICES);
    configuration.saveOrUpdate(ProvAzurePriceImportResource.CONF_REGIONS, "europe-north");
    // Check the reserved
    final QuoteVo quote = installAndConfigure();
    Assertions.assertTrue(quote.getCost().getMin() > 150);
    // Check the spot
    final QuoteInstanceLookup lookup = qiResource.lookup(subscription, 8, 26000, true, VmOs.LINUX, "ds4v2", false, null, "36month");
    Assertions.assertTrue(lookup.getCost() > 100d);
    final ProvInstancePrice instance2 = lookup.getPrice();
    Assertions.assertEquals("base-three-year", instance2.getTerm().getName());
    Assertions.assertEquals("ds4v2", instance2.getType().getName());
}
Also used : QuoteVo(org.ligoj.app.plugin.prov.QuoteVo) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) QuoteInstanceLookup(org.ligoj.app.plugin.prov.QuoteInstanceLookup) Test(org.junit.jupiter.api.Test) AbstractServerTest(org.ligoj.app.AbstractServerTest)

Example 2 with QuoteInstanceLookup

use of org.ligoj.app.plugin.prov.QuoteInstanceLookup 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 3 with QuoteInstanceLookup

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

QuoteInstanceLookup (org.ligoj.app.plugin.prov.QuoteInstanceLookup)3 Test (org.junit.jupiter.api.Test)2 AbstractServerTest (org.ligoj.app.AbstractServerTest)2 QuoteVo (org.ligoj.app.plugin.prov.QuoteVo)2 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)2 QuoteInstanceEditionVo (org.ligoj.app.plugin.prov.QuoteInstanceEditionVo)1 QuoteStorageEditionVo (org.ligoj.app.plugin.prov.QuoteStorageEditionVo)1 QuoteStorageLoopup (org.ligoj.app.plugin.prov.QuoteStorageLoopup)1 UpdatedCost (org.ligoj.app.plugin.prov.UpdatedCost)1 ProvInstancePriceTerm (org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm)1 ProvInstanceType (org.ligoj.app.plugin.prov.model.ProvInstanceType)1 ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)1 ProvQuoteStorage (org.ligoj.app.plugin.prov.model.ProvQuoteStorage)1 ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)1 ProvStorageType (org.ligoj.app.plugin.prov.model.ProvStorageType)1