use of org.ligoj.app.plugin.prov.model.ProvStoragePrice 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);
}
use of org.ligoj.app.plugin.prov.model.ProvStoragePrice 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());
}
use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installStoragePrice.
/**
* Install a {@link ProvStoragePrice} from an {@link ManagedDisk} offer.
*
* @param context
* The update context.
* @param offer
* The current offer to install.
*/
private void installStoragePrice(final UpdateContext context, final Entry<String, ManagedDisk> offer) {
final ManagedDisk disk = offer.getValue();
final ProvStorageType type = installStorageType(context, offer.getKey(), disk);
final Map<ProvLocation, ProvStoragePrice> previousT = context.getPreviousStorages().computeIfAbsent(type, t -> new HashMap<>());
disk.getPrices().entrySet().stream().filter(p -> isEnabledRegion(p.getKey())).forEach(p -> installStoragePrice(context, previousT, context.getRegions().get(p.getKey()), type, p.getValue().getValue()));
}
use of org.ligoj.app.plugin.prov.model.ProvStoragePrice in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installStoragePrice.
/**
* Install or update a storage price.
*
* @param context
* The update context.
* @see <a href="https://azure.microsoft.com/en-us/pricing/details/managed-disks/"></a>
*/
private ProvStoragePrice installStoragePrice(final UpdateContext context, final Map<ProvLocation, ProvStoragePrice> regionPrices, final ProvLocation region, final ProvStorageType type, final double value) {
final ProvStoragePrice price = regionPrices.computeIfAbsent(region, r -> {
final ProvStoragePrice newPrice = new ProvStoragePrice();
newPrice.setType(type);
newPrice.setLocation(region);
return newPrice;
});
// Fixed cost
price.setCost(value);
if (!type.getName().startsWith("premium")) {
// Additional transaction based cost : $/10,000 transaction -> $/1,000,000 transaction
price.setCostTransaction(Optional.ofNullable(context.getTransactions().get(region.getName())).map(v -> round3Decimals(v.getValue() * 100)).orElse(0d));
}
spRepository.saveAndFlush(price);
return price;
}
Aggregations