Search in sources :

Example 1 with ProvQuoteStorage

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

the class ProvResourceTest method getConfiguration.

@Test
public void getConfiguration() {
    QuoteVo vo = resource.getConfiguration(subscription);
    Assertions.assertEquals("quote1", vo.getName());
    Assertions.assertEquals("quoteD1", vo.getDescription());
    checkCost(vo.getCost(), 4704.758, 7154.358, false);
    checkCost(resource.updateCost(subscription), 4704.758, 7154.358, false);
    vo = resource.getConfiguration(subscription);
    checkCost(vo.getCost(), 4704.758, 7154.358, false);
    Assertions.assertNotNull(vo.getId());
    Assertions.assertNotNull(vo.getCreatedBy());
    Assertions.assertNotNull(vo.getCreatedDate());
    Assertions.assertNotNull(vo.getLastModifiedBy());
    Assertions.assertNotNull(vo.getLastModifiedDate());
    Assertions.assertEquals("region-1", vo.getLocation().getName());
    // Check compute
    final List<ProvQuoteInstance> instances = vo.getInstances();
    Assertions.assertEquals(7, instances.size());
    final ProvQuoteInstance quoteInstance = instances.get(0);
    Assertions.assertNotNull(quoteInstance.getId());
    Assertions.assertEquals("server1", quoteInstance.getName());
    Assertions.assertEquals("serverD1", quoteInstance.getDescription());
    Assertions.assertTrue(quoteInstance.getConstant());
    Assertions.assertEquals(InternetAccess.PUBLIC, quoteInstance.getInternet());
    Assertions.assertEquals(10.1, quoteInstance.getMaxVariableCost(), DELTA);
    Assertions.assertEquals(2, quoteInstance.getMinQuantity().intValue());
    Assertions.assertEquals(10, quoteInstance.getMaxQuantity().intValue());
    final ProvInstancePrice price = quoteInstance.getPrice();
    Assertions.assertEquals(146.4, price.getCost(), DELTA);
    Assertions.assertEquals(146.4, price.getCostPeriod(), DELTA);
    Assertions.assertEquals(VmOs.LINUX, price.getOs());
    Assertions.assertNotNull(price.getTerm().getId());
    Assertions.assertFalse(price.getTerm().isEphemeral());
    Assertions.assertFalse(price.getTerm().isVariable());
    Assertions.assertEquals(0, price.getTerm().getPeriod());
    Assertions.assertEquals("on-demand1", price.getTerm().getName());
    Assertions.assertEquals("15 minutes fragment", price.getTerm().getDescription());
    final ProvInstanceType instance = price.getType();
    Assertions.assertNotNull(instance.getId().intValue());
    Assertions.assertEquals("instance1", instance.getName());
    Assertions.assertEquals("instanceD1", instance.getDescription());
    Assertions.assertEquals(0.5, instance.getCpu(), 0.0001);
    Assertions.assertEquals(2000, instance.getRam().intValue());
    Assertions.assertTrue(instance.getConstant());
    // No minimal for this instance price
    Assertions.assertNull(instances.get(1).getMaxVariableCost());
    Assertions.assertEquals(1, instances.get(3).getMinQuantity().intValue());
    Assertions.assertEquals(1, instances.get(3).getMaxQuantity().intValue());
    // Check the constant CPU requirement
    Assertions.assertTrue(instances.get(0).getConstant());
    Assertions.assertNull(instances.get(1).getConstant());
    Assertions.assertFalse(instances.get(3).getConstant());
    // Check the network requirement
    Assertions.assertEquals(InternetAccess.PUBLIC, instances.get(0).getInternet());
    Assertions.assertEquals(InternetAccess.PRIVATE, instances.get(1).getInternet());
    Assertions.assertEquals(InternetAccess.PRIVATE_NAT, instances.get(2).getInternet());
    // Check storage
    final List<ProvQuoteStorage> storages = vo.getStorages();
    Assertions.assertEquals(4, storages.size());
    final ProvQuoteStorage quoteStorage = storages.get(0);
    Assertions.assertNotNull(quoteStorage.getId());
    Assertions.assertEquals("server1-root", quoteStorage.getName());
    Assertions.assertEquals("server1-rootD", quoteStorage.getDescription());
    Assertions.assertEquals(20, quoteStorage.getSize().intValue());
    Assertions.assertEquals(8.4, quoteStorage.getCost(), DELTA);
    // = 8.4 * 5
    Assertions.assertEquals(42, quoteStorage.getMaxCost(), DELTA);
    Assertions.assertNotNull(quoteStorage.getQuoteInstance());
    final ProvStoragePrice storage = quoteStorage.getPrice();
    final ProvStorageType storageType = storage.getType();
    Assertions.assertNotNull(storage.getId());
    Assertions.assertEquals(0.21, storage.getCostGb(), DELTA);
    Assertions.assertEquals(0, storage.getCost(), DELTA);
    Assertions.assertEquals("storage1", storageType.getName());
    Assertions.assertEquals("storageD1", storageType.getDescription());
    Assertions.assertEquals(200, storageType.getIops());
    Assertions.assertEquals(60, storageType.getThroughput());
    Assertions.assertEquals(0, storage.getCostTransaction(), DELTA);
    Assertions.assertEquals(Rate.GOOD, storageType.getLatency());
    Assertions.assertEquals(ProvStorageOptimized.IOPS, storageType.getOptimized());
    // Not attached storage
    Assertions.assertNull(storages.get(3).getQuoteInstance());
    // Check the small transactional cost
    Assertions.assertEquals(0.000000072, storages.get(1).getPrice().getCostTransaction(), 0.000000001);
    // Check the related instance and price for the next comparison
    Assertions.assertEquals("instance1", instances.get(0).getPrice().getType().getName());
    Assertions.assertEquals("instance1", instances.get(1).getPrice().getType().getName());
    Assertions.assertEquals("instance1", instances.get(2).getPrice().getType().getName());
    Assertions.assertEquals("instance3", instances.get(3).getPrice().getType().getName());
    Assertions.assertEquals("instance5", instances.get(4).getPrice().getType().getName());
    Assertions.assertEquals("instance10", instances.get(5).getPrice().getType().getName());
    Assertions.assertEquals("dynamic", instances.get(6).getPrice().getType().getName());
    Assertions.assertEquals("on-demand1", instances.get(0).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand2", instances.get(1).getPrice().getTerm().getName());
    Assertions.assertEquals("1y", instances.get(2).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand1", instances.get(3).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand2", instances.get(4).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand1", instances.get(5).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand1", instances.get(6).getPrice().getTerm().getName());
    // Optimize the configuration
    checkCost(resource.refresh(subscription), 3165.4, 5615.0, false);
    final QuoteVo vo2 = resource.getConfiguration(subscription);
    Assertions.assertEquals("quote1", vo2.getName());
    Assertions.assertEquals(vo2.getId(), vo.getId());
    // Check the new instances
    final List<ProvQuoteInstance> instances2 = vo2.getInstances();
    Assertions.assertEquals(7, instances2.size());
    // Same instance
    Assertions.assertEquals("instance1", instances2.get(0).getPrice().getType().getName());
    Assertions.assertEquals("dynamic", instances2.get(5).getPrice().getType().getName());
    Assertions.assertEquals("dynamic", instances2.get(4).getPrice().getType().getName());
    // Fixed instance types for the same constraints
    Assertions.assertEquals("instance2", instances2.get(1).getPrice().getType().getName());
    Assertions.assertEquals("instance2", instances2.get(2).getPrice().getType().getName());
    Assertions.assertEquals("instance2", instances2.get(3).getPrice().getType().getName());
    Assertions.assertEquals("dynamic", instances2.get(6).getPrice().getType().getName());
    // Check the contracts are the same but for 2
    Assertions.assertEquals("on-demand1", instances2.get(0).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand2", instances2.get(1).getPrice().getTerm().getName());
    // Updated
    Assertions.assertEquals("on-demand1", instances2.get(2).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand1", instances2.get(3).getPrice().getTerm().getName());
    // Updated
    Assertions.assertEquals("on-demand1", instances2.get(4).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand1", instances2.get(5).getPrice().getTerm().getName());
    Assertions.assertEquals("on-demand1", instances2.get(6).getPrice().getTerm().getName());
    // No associated usage for this use case
    Assertions.assertNull(vo.getUsage());
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 2 with ProvQuoteStorage

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

the class ProvQuoteStorageResourceTest method createStorage.

@Test
public void createStorage() {
    final QuoteStorageEditionVo vo = new QuoteStorageEditionVo();
    vo.setSubscription(subscription);
    vo.setName("server1-root-ter");
    vo.setDescription("server1-root-terD");
    vo.setType("storage1");
    vo.setSize(256);
    final UpdatedCost cost = qsResource.create(vo);
    checkCost(cost.getTotalCost(), 4758.518, 7208.118, false);
    checkCost(cost.getResourceCost(), 53.76, 53.76, false);
    Assertions.assertEquals(0, cost.getRelatedCosts().size());
    final int id = cost.getId();
    em.flush();
    em.clear();
    // Check the exact new cost
    checkCost(subscription, 4758.518, 7208.118, false);
    final ProvQuoteStorage storage = qsRepository.findOneExpected(id);
    Assertions.assertEquals("server1-root-ter", storage.getName());
    Assertions.assertEquals("server1-root-terD", storage.getDescription());
    Assertions.assertEquals(256, storage.getSize().intValue());
    Assertions.assertEquals(vo.getType(), storage.getPrice().getType().getName());
    Assertions.assertEquals(53.76, 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 3 with ProvQuoteStorage

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

the class ProvQuoteInstanceResourceTest method updateInstanceLocationNoMatchStorage.

@Test
public void updateInstanceLocationNoMatchStorage() {
    // Add a storage only available in "region-1"
    final ProvQuoteStorage qs = new ProvQuoteStorage();
    qs.setPrice(spRepository.findBy("type.name", "storage4"));
    qs.setInstanceCompatible(true);
    qs.setLatency(Rate.BEST);
    qs.setQuoteInstance(qiRepository.findByName("server1"));
    qs.setName("qi-storage4");
    qs.setConfiguration(repository.findByName("quote1"));
    qs.setCost(0d);
    qs.setMaxCost(0d);
    qs.setSize(100);
    em.persist(qs);
    em.flush();
    // Check the cost
    checkCost(resource.refresh(subscription), 3469.4, 7135.0, false);
    // Everything identity but the region
    final QuoteInstanceEditionVo vo = new QuoteInstanceEditionVo();
    vo.setSubscription(subscription);
    vo.setId(qiRepository.findByNameExpected("server1").getId());
    vo.setPrice(ipRepository.findByExpected("code", "C1").getId());
    vo.setName("server1");
    vo.setRam(2000);
    vo.setCpu(0.5);
    vo.setMinQuantity(2);
    vo.setMaxQuantity(10);
    vo.setLocation("region-1");
    // No change
    checkCost(qiResource.update(vo).getTotalCost(), 3469.4, 7135.0, false);
    // "C1" -> "C7"
    checkCost(resource.refresh(subscription), 3447.44, 7025.2, false);
    vo.setPrice(ipRepository.findByExpected("code", "C7").getId());
    // No change
    checkCost(qiResource.update(vo).getTotalCost(), 3447.44, 7025.2, false);
    checkCost(resource.refresh(subscription), 3447.44, 7025.2, false);
    // Check the update failed because of "storage4"
    // "region-1" to "region-2"
    vo.setLocation("region-2");
    MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> qiResource.update(vo)), "storage", "no-match-storage");
}
Also used : ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) ValidationJsonException(org.ligoj.bootstrap.core.validation.ValidationJsonException) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 4 with ProvQuoteStorage

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

the class ProvQuoteStorageResourceTest method createStorageUnboundInstance.

@Test
public void createStorageUnboundInstance() {
    final ProvQuoteInstance quoteInstance = setUnboundInstance("server1");
    // Attach the new storage to this unbound instance
    final QuoteStorageEditionVo vo = new QuoteStorageEditionVo();
    vo.setSubscription(subscription);
    vo.setName("server1-root-bis");
    vo.setType("storage1");
    vo.setQuoteInstance(quoteInstance.getId());
    vo.setSize(512);
    final UpdatedCost cost = qsResource.create(vo);
    checkCost(cost.getTotalCost(), 4919.798, 4919.798, true);
    checkCost(cost.getResourceCost(), 215.04, 215.04, true);
    Assertions.assertEquals(1, cost.getRelatedCosts().size());
    checkCost(cost.getRelatedCosts().get(vo.getQuoteInstance()), 292.8, 292.8, true);
    final int id = cost.getId();
    em.flush();
    em.clear();
    // Check the exact new cost
    checkCost(subscription, 4919.798, 4919.798, true);
    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.assertTrue(storage.isUnboundCost());
}
Also used : ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 5 with ProvQuoteStorage

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

the class ProvQuoteStorageResourceTest method createStorageNoInstance.

/**
 * Attempt to attach a storage compatible to an instance but without an instance.
 */
@Test
public void createStorageNoInstance() {
    final QuoteStorageEditionVo vo = new QuoteStorageEditionVo();
    vo.setSubscription(subscription);
    vo.setName("storage3-root-bis");
    vo.setType("storage3");
    vo.setSize(1);
    final UpdatedCost cost = qsResource.create(vo);
    checkCost(cost.getTotalCost(), 4706.908, 7156.508, false);
    checkCost(cost.getResourceCost(), 2.15, 2.15, false);
    Assertions.assertEquals(0, cost.getRelatedCosts().size());
    final int id = cost.getId();
    em.flush();
    em.clear();
    // Check the exact new cost
    checkCost(subscription, 4706.908, 7156.508, false);
    final ProvQuoteStorage storage = qsRepository.findOneExpected(id);
    Assertions.assertEquals("storage3-root-bis", storage.getName());
    Assertions.assertEquals(1, storage.getSize().intValue());
    Assertions.assertEquals(vo.getType(), storage.getPrice().getType().getName());
    Assertions.assertEquals(2.15, 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)

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