use of org.ligoj.app.plugin.prov.model.Rate in project plugin-prov by ligoj.
the class ProvQuoteStorageResource method lookup.
private List<QuoteStorageLoopup> lookup(final ProvQuote configuration, final int size, final Rate latency, final Integer instance, final ProvStorageOptimized optimized, final String location) {
// Get the attached node and check the security on this subscription
final String node = configuration.getSubscription().getNode().getRefined().getId();
final ProvQuoteInstance qi = checkInstance(node, instance);
// The the right location from instance first, then the request one
String iLocation = Optional.ofNullable(qi).map(qiResource::getLocation).map(ProvLocation::getName).orElse(location);
iLocation = ObjectUtils.defaultIfNull(iLocation, configuration.getLocation().getName());
if (location != null && !location.equals(iLocation)) {
// Not compatible locations
return Collections.emptyList();
}
return spRepository.findLowestPrice(node, size, latency, instance, optimized, iLocation, PageRequest.of(0, 10)).stream().map(spx -> (ProvStoragePrice) spx[0]).map(sp -> newPrice(sp, size, getCost(sp, size))).collect(Collectors.toList());
}
use of org.ligoj.app.plugin.prov.model.Rate in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installInstancePriceType.
private ProvInstanceType installInstancePriceType(final UpdateContext context, final String[] parts, final boolean isBasic, final AzureVmPrice azType) {
final ProvInstanceType type = context.getInstanceTypes().computeIfAbsent(parts[1], name -> {
// New instance type (not update mode)
final ProvInstanceType newType = new ProvInstanceType();
newType.setNode(context.getNode());
newType.setName(name);
return newType;
});
// Merge as needed
if (context.getInstanceTypesMerged().add(type.getName())) {
type.setCpu((double) azType.getCores());
type.setRam((int) azType.getRam() * 1024);
type.setDescription("series:" + azType.getSeries() + ", disk:" + azType.getDiskSize() + "GiB");
type.setConstant(!"B".equals(azType.getSeries()));
// Rating
final Rate rate = isBasic ? Rate.LOW : Rate.GOOD;
type.setCpuRate(isBasic ? Rate.LOW : getRate("cpu", type.getName()));
type.setRamRate(rate);
type.setNetworkRate(getRate("network", type.getName()));
type.setStorageRate(rate);
itRepository.saveAndFlush(type);
}
return type;
}
Aggregations