use of org.ligoj.app.plugin.prov.model.ProvStorageType in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResourceTest method checkStorage.
private ProvQuoteStorage checkStorage(final ProvQuoteStorage storage) {
Assertions.assertEquals(1.536d, storage.getCost(), DELTA);
Assertions.assertEquals(5, storage.getSize(), DELTA);
Assertions.assertNotNull(storage.getQuoteInstance());
final ProvStorageType type = storage.getPrice().getType();
Assertions.assertEquals("s4", type.getName());
Assertions.assertEquals(500, type.getIops());
Assertions.assertEquals(60, type.getThroughput());
Assertions.assertEquals(Rate.MEDIUM, type.getLatency());
Assertions.assertEquals(0.05, storage.getPrice().getCostTransaction(), DELTA);
Assertions.assertEquals(32, type.getMinimal());
Assertions.assertEquals(32, type.getMaximal().intValue());
return storage;
}
use of org.ligoj.app.plugin.prov.model.ProvStorageType 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.ProvStorageType in project plugin-prov by ligoj.
the class ProvQuoteStorageResource method saveOrUpdate.
/**
* Save or update the storage inside a quote.
*
* @param entity
* The storage entity to update.
* @param vo
* The new quote storage data to persist.
* @return The formal entity.
*/
private UpdatedCost saveOrUpdate(final ProvQuoteStorage entity, final QuoteStorageEditionVo vo) {
DescribedBean.copy(vo, entity);
// Check the associations
final int subscription = vo.getSubscription();
final ProvQuote quote = getQuoteFromSubscription(subscription);
final String node = quote.getSubscription().getNode().getRefined().getId();
entity.setConfiguration(quote);
entity.setLocation(resource.findLocation(node, vo.getLocation()));
entity.setPrice(findByTypeName(subscription, vo.getType(), vo.getLocation(), quote));
entity.setInstanceCompatible(vo.getInstanceCompatible());
entity.setLatency(vo.getLatency());
entity.setOptimized(vo.getOptimized());
entity.setSize(vo.getSize());
entity.setQuoteInstance(checkInstance(node, vo.getQuoteInstance()));
// Check the storage requirements to validate the linked price
final ProvStorageType type = entity.getPrice().getType();
if (!lookup(quote, entity.getSize(), entity.getLatency(), vo.getQuoteInstance(), entity.getOptimized(), vo.getLocation()).stream().map(qs -> qs.getPrice().getType()).anyMatch(type::equals)) {
// The related storage type does not match these requirements
throw new ValidationJsonException("type", "type-incompatible-requirements", type.getName());
}
// Save and update the costs
final UpdatedCost cost = refreshCost(entity);
Optional.ofNullable(entity.getQuoteInstance()).ifPresent(q -> cost.setRelatedCosts(Collections.singletonMap(q.getId(), qiResource.updateCost(q))));
return cost;
}
use of org.ligoj.app.plugin.prov.model.ProvStorageType 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()));
}
Aggregations