Search in sources :

Example 1 with UpdatedCost

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

Aggregations

QuoteInstanceEditionVo (org.ligoj.app.plugin.prov.QuoteInstanceEditionVo)1 QuoteInstanceLookup (org.ligoj.app.plugin.prov.QuoteInstanceLookup)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 ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)1 ProvStorageType (org.ligoj.app.plugin.prov.model.ProvStorageType)1