use of org.ligoj.bootstrap.core.INamableBean in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method install.
/**
* Install or update prices.
*
* @throws IOException
* When prices cannot be remotely read.
*/
public void install() throws IOException {
final UpdateContext context = new UpdateContext();
// Node is already persisted, install VM prices
final Node node = nodeRepository.findOneExpected(ProvAzurePluginResource.KEY);
context.setNode(node);
nextStep(node, "initialize", 1);
// The previously installed location cache. Key is the location AWS name
context.setRegions(locationRepository.findAllBy(BY_NODE, node.getId()).stream().collect(Collectors.toMap(INamableBean::getName, Function.identity())));
// Proceed to the install
installStoragePrices(context);
installComputePrices(context);
nextStep(node, "finalize", 0);
}
use of org.ligoj.bootstrap.core.INamableBean in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installStoragePrices.
/**
* Install storage prices from the JSON file provided by AWS.
*
* @param context
* The update context.
*/
private void installStoragePrices(final UpdateContext context) throws IOException {
final Node node = context.getNode();
log.info("Azure managed-disk prices...");
nextStep(node, "managed-disk-initialize", 1);
// The previously installed storage types cache. Key is the storage type
// name
context.setStorageTypes(stRepository.findAllBy(BY_NODE, node.getId()).stream().collect(Collectors.toMap(INamableBean::getName, Function.identity())));
context.setPreviousStorages(new HashMap<>());
spRepository.findAllBy("type.node.id", node.getId()).forEach(p -> {
context.getPreviousStorages().computeIfAbsent(p.getType(), t -> new HashMap<>()).put(p.getLocation(), p);
});
// Fetch the remote prices stream
nextStep(node, "managed-disk-retrieve-catalog", 1);
final String rawJson = StringUtils.defaultString(new CurlProcessor().get(getManagedDiskApi()), "{}");
final ManagedDisks prices = objectMapper.readValue(rawJson, ManagedDisks.class);
// Add region as needed
nextStep(node, "managed-disk-update-catalog", 1);
prices.getRegions().stream().filter(this::isEnabledRegion).forEach(r -> installRegion(context, r));
// Update or install storage price
final Map<String, ManagedDisk> offers = prices.getOffers();
context.setTransactions(offers.getOrDefault("transactions", new ManagedDisk()).getPrices());
offers.entrySet().stream().filter(p -> !"transactions".equals(p.getKey())).forEach(o -> installStoragePrice(context, o));
}
Aggregations