use of org.ligoj.app.plugin.prov.model.VmOs in project plugin-prov by ligoj.
the class ProvQuoteInstanceResource method lookup.
private QuoteInstanceLookup lookup(final ProvQuote configuration, final double cpu, final int ram, final Boolean constant, final VmOs osName, final String type, final boolean ephemeral, final String location, final String usageName) {
final String node = configuration.getSubscription().getNode().getId();
final int subscription = configuration.getSubscription().getId();
// Resolve
final VmOs os = Optional.ofNullable(osName).map(VmOs::toPricingOs).orElse(null);
// Resolve the location to use
final String locationR = location == null ? configuration.getLocation().getName() : location;
// Compute the rate to use
final ProvUsage usage = usageName == null ? ObjectUtils.defaultIfNull(configuration.getUsage(), USAGE_DEFAULT) : resource.findConfiguredByName(usageRepository, usageName, subscription);
final double rate = usage.getRate() / 100d;
final int duration = usage.getDuration();
// Resolve the required instance type
final Integer typeId = type == null ? null : assertFound(itRepository.findByName(subscription, type), type).getId();
// Return only the first matching instance
// Template instance
final QuoteInstanceLookup template = ipRepository.findLowestPrice(node, cpu, ram, constant, os, typeId, ephemeral, locationR, rate, duration, PageRequest.of(0, 1)).stream().findFirst().map(ip -> newPrice((ProvInstancePrice) ip[0], (double) ip[2])).orElse(null);
// Custom instance
final QuoteInstanceLookup custom = ipRepository.findLowestCustomPrice(node, Math.ceil(cpu), Math.ceil(ram / 1024), constant, os, locationR, PageRequest.of(0, 1)).stream().findFirst().map(ip -> newPrice((ProvInstancePrice) ip[0], rate * (double) ip[1])).orElse(null);
// Select the best price term
if (template == null) {
return custom;
}
if (custom == null) {
return template;
}
return custom.getCost() < template.getCost() ? custom : template;
}
use of org.ligoj.app.plugin.prov.model.VmOs in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installInstancesTerm.
private void installInstancesTerm(final UpdateContext context, final ProvInstancePriceTerm term, final ProvInstancePriceTerm termLow, Entry<String, AzureVmPrice> azPrice) {
final String[] parts = StringUtils.split(azPrice.getKey(), '-');
final VmOs os = VmOs.valueOf(parts[0].replace("redhat", "RHEL").replace("sles", "SUSE").toUpperCase());
// Basic, Low Priority, Standard
final String tier = parts[2];
final boolean isBasic = "basic".equals(tier);
final AzureVmPrice azType = azPrice.getValue();
// Get the right term : "lowpriority" within "PayGo" or the current term
final ProvInstancePriceTerm termU = tier.equals("lowpriority") ? termLow : term;
final String globalCode = termU.getName() + "-" + azPrice.getKey();
final ProvInstanceType type = installInstancePriceType(context, parts, isBasic, azType);
// Iterate over regions enabling this instance type
azType.getPrices().entrySet().stream().filter(pl -> isEnabledRegion(pl.getKey())).forEach(pl -> {
final ProvInstancePrice price = installInstancePrice(context, termU, os, globalCode, type, pl.getKey());
// Update the cost
price.setCost(round3Decimals(pl.getValue().getValue() * 24 * 30.5));
price.setCostPeriod(pl.getValue().getValue());
ipRepository.save(price);
});
}
Aggregations