Search in sources :

Example 16 with ProvQuoteInstance

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

the class ProvResourceTest method findConfiguredNotFound.

@Test
public void findConfiguredNotFound() {
    final ProvQuoteInstance qi = qiRepository.findByName("server1");
    Assertions.assertThrows(EntityNotFoundException.class, () -> {
        resource.findConfigured(qiRepository, qi.getId(), 0).getName();
    });
}
Also used : ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 17 with ProvQuoteInstance

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

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

the class ProvResourceTest method getKey.

@Test
public void getKey() {
    Assertions.assertEquals("service:prov", resource.getKey());
    // Only there for coverage of associations required by JPA
    new ProvQuote().setStorages(null);
    new ProvQuote().getStorages();
    new ProvQuote().setInstances(null);
    new ProvQuoteInstance().setStorages(null);
    Rate.valueOf(Rate.GOOD.name());
    ProvStorageOptimized.valueOf(ProvStorageOptimized.IOPS.name());
    VmOs.valueOf(VmOs.LINUX.name());
    ProvTenancy.valueOf(ProvTenancy.DEDICATED.name());
}
Also used : ProvQuote(org.ligoj.app.plugin.prov.model.ProvQuote) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 19 with ProvQuoteInstance

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

ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)19 Test (org.junit.jupiter.api.Test)15 AbstractAppTest (org.ligoj.app.AbstractAppTest)14 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)5 ProvQuote (org.ligoj.app.plugin.prov.model.ProvQuote)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ProvQuoteStorage (org.ligoj.app.plugin.prov.model.ProvQuoteStorage)4 ProvInstanceType (org.ligoj.app.plugin.prov.model.ProvInstanceType)3 ProvLocation (org.ligoj.app.plugin.prov.model.ProvLocation)3 ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)3 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Transactional (javax.transaction.Transactional)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2