Search in sources :

Example 6 with ProvQuoteStorage

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

the class ProvQuoteInstanceResourceTest method updateInstanceUnbound.

@Test
public void updateInstanceUnbound() {
    ProvQuoteStorage qs = qsRepository.findByNameExpected("server1-root");
    Assertions.assertFalse(qs.isUnboundCost());
    Assertions.assertEquals(8.4, qs.getCost(), DELTA);
    Assertions.assertEquals(42, qs.getMaxCost(), DELTA);
    // Check the cost of related storages of this instance
    final Map<Integer, FloatingCost> storagePrices = toStoragesFloatingCost("server1");
    Assertions.assertEquals(3, storagePrices.size());
    final QuoteInstanceEditionVo vo = new QuoteInstanceEditionVo();
    vo.setSubscription(subscription);
    vo.setId(qiRepository.findByNameExpected("server1").getId());
    vo.setPrice(ipRepository.findByExpected("code", "C1").getId());
    vo.setName("server1-bis");
    vo.setRam(2000);
    vo.setCpu(0.5);
    vo.setMinQuantity(1);
    vo.setMaxQuantity(null);
    UpdatedCost updatedCost = qiResource.update(vo);
    Assertions.assertEquals(updatedCost.getId(), vo.getId().intValue());
    // Check the exact new cost
    checkCost(updatedCost.getTotalCost(), 4398.558, 4398.558, true);
    checkCost(updatedCost.getResourceCost(), 146.4, 146.4, true);
    checkCost(subscription, 4398.558, 4398.558, true);
    // Check the related storage prices
    Assertions.assertEquals(3, updatedCost.getRelatedCosts().size());
    qs = qsRepository.findByNameExpected("server1-root");
    Assertions.assertEquals(4.2, updatedCost.getRelatedCosts().get(qs.getId()).getMin(), DELTA);
    Assertions.assertEquals(4.2, updatedCost.getRelatedCosts().get(qs.getId()).getMax(), DELTA);
    Assertions.assertTrue(updatedCost.getRelatedCosts().get(qs.getId()).isUnbound());
    Assertions.assertTrue(qs.isUnboundCost());
    Assertions.assertEquals(4.2, qs.getCost(), DELTA);
    Assertions.assertEquals(4.2, qs.getMaxCost(), DELTA);
    // Check the cost is the same
    vo.setMinQuantity(2);
    vo.setMaxQuantity(10);
    updatedCost = qiResource.update(vo);
    checkUpdatedCost();
}
Also used : ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 7 with ProvQuoteStorage

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

the class ProvQuoteStorageResourceTest method updateStorageDetachAttach.

@Test
public void updateStorageDetachAttach() {
    checkCost(subscription, 4704.758, 7154.358, false);
    // Make "server1" with unbound maximal quantities
    setUnboundInstance("server1");
    // Check the new cost corresponds to the minimal cost since there is
    // only
    // one unbound instance
    checkCost(subscription, 4704.758, 4704.758, true);
    // Detach "server1-root" storage from "server1"
    final QuoteStorageEditionVo vo = new QuoteStorageEditionVo();
    vo.setSubscription(subscription);
    vo.setId(qsRepository.findByNameExpected("server1-root").getId());
    vo.setName("server1-root-bis");
    vo.setType("storage1");
    vo.setSize(20);
    // Check the new cost is equals to :
    // NEW_TOTAL .. = OLD_TOTAL-(STORAGE.COST*(STORAGE.INSTANCE.MIN-1))
    // ............ = OLD_TOTAL-STORAGE.COST * (2 -1))
    // ............ = OLD_TOTAL-STORAGE.COST
    // STORAGE_COST = STORAGE_COST * STORAGE.INSTANCE.MIN
    // ............ = 4.2 * 1
    UpdatedCost cost = qsResource.update(vo);
    checkCost(cost.getTotalCost(), 4700.558, 4700.558, true);
    checkCost(cost.getResourceCost(), 4.2, 4.2, false);
    Assertions.assertEquals(0, cost.getRelatedCosts().size());
    // Check the exact new cost
    checkCost(subscription, 4700.558, 4700.558, true);
    final ProvQuoteStorage qs = qsRepository.findOneExpected(vo.getId());
    Assertions.assertEquals("server1-root-bis", qs.getName());
    Assertions.assertFalse(qs.isUnboundCost());
    // Attach back this storage to "server1
    vo.setQuoteInstance(qiRepository.findByNameExpected("server1").getId());
    cost = qsResource.update(vo);
    checkCost(cost.getTotalCost(), 4704.758, 4704.758, true);
    checkCost(cost.getResourceCost(), 8.4, 8.4, true);
    Assertions.assertEquals(1, cost.getRelatedCosts().size());
    checkCost(cost.getRelatedCosts().get(vo.getQuoteInstance()), 292.8, 292.8, true);
    checkCost(subscription, 4704.758, 4704.758, true);
    Assertions.assertTrue(qsRepository.findOneExpected(vo.getId()).isUnboundCost());
}
Also used : ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 8 with ProvQuoteStorage

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

the class ProvQuoteStorageResourceTest method updateStorageLimit.

@Test
public void updateStorageLimit() {
    final QuoteStorageEditionVo vo = new QuoteStorageEditionVo();
    vo.setSubscription(subscription);
    vo.setId(qsRepository.findByNameExpected("server1-root").getId());
    vo.setName("server1-root-bis");
    vo.setDescription("server1-root-bisD");
    // Change the storage type -> storage2 has a minimal to 512
    vo.setType("storage2");
    // Limit for this storage is 512
    vo.setSize(512);
    qsResource.update(vo);
    em.flush();
    em.clear();
    // Check the exact new cost
    checkCost(subscription, 4774.158, 7190.158, false);
    final ProvQuoteStorage storage = qsRepository.findOneExpected(vo.getId());
    Assertions.assertEquals("server1-root-bis", storage.getName());
    Assertions.assertEquals("server1-root-bisD", storage.getDescription());
    Assertions.assertEquals(512, storage.getSize().intValue());
    Assertions.assertEquals(vo.getType(), storage.getPrice().getType().getName());
    Assertions.assertEquals(77.8, storage.getCost(), DELTA);
}
Also used : ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 9 with ProvQuoteStorage

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

the class ProvQuoteStorageResourceTest method createStorageInstance.

@Test
public void createStorageInstance() {
    final QuoteStorageEditionVo vo = new QuoteStorageEditionVo();
    vo.setSubscription(subscription);
    vo.setName("server1-root-bis");
    vo.setType("storage1");
    vo.setQuoteInstance(qiRepository.findByNameExpected("server1").getId());
    vo.setSize(512);
    final UpdatedCost cost = qsResource.create(vo);
    checkCost(cost.getTotalCost(), 4919.798, 8229.558, false);
    checkCost(cost.getResourceCost(), 215.04, 1075.2, false);
    Assertions.assertEquals(1, cost.getRelatedCosts().size());
    checkCost(cost.getRelatedCosts().get(vo.getQuoteInstance()), 292.8, 1464.0, false);
    final int id = cost.getId();
    em.flush();
    em.clear();
    // Check the exact new cost
    checkCost(subscription, 4919.798, 8229.558, false);
    final ProvQuoteStorage storage = qsRepository.findOneExpected(id);
    Assertions.assertEquals("server1-root-bis", storage.getName());
    Assertions.assertEquals(512, storage.getSize().intValue());
    Assertions.assertEquals(vo.getType(), storage.getPrice().getType().getName());
    Assertions.assertEquals(215.04, storage.getCost(), DELTA);
    Assertions.assertFalse(storage.isUnboundCost());
}
Also used : ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 10 with ProvQuoteStorage

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

Test (org.junit.jupiter.api.Test)10 ProvQuoteStorage (org.ligoj.app.plugin.prov.model.ProvQuoteStorage)10 AbstractAppTest (org.ligoj.app.AbstractAppTest)9 ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)3 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)2 ProvInstanceType (org.ligoj.app.plugin.prov.model.ProvInstanceType)2 AbstractServerTest (org.ligoj.app.AbstractServerTest)1 QuoteInstanceLookup (org.ligoj.app.plugin.prov.QuoteInstanceLookup)1 QuoteVo (org.ligoj.app.plugin.prov.QuoteVo)1 ProvInstancePriceTerm (org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm)1 ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)1 ProvStorageType (org.ligoj.app.plugin.prov.model.ProvStorageType)1 ValidationJsonException (org.ligoj.bootstrap.core.validation.ValidationJsonException)1