Search in sources :

Example 1 with INamableBean

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);
}
Also used : Node(org.ligoj.app.model.Node) INamableBean(org.ligoj.bootstrap.core.INamableBean)

Example 2 with INamableBean

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));
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) Arrays(java.util.Arrays) ClassPathResource(org.springframework.core.io.ClassPathResource) HashMap(java.util.HashMap) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) ProvTenancy(org.ligoj.app.plugin.prov.model.ProvTenancy) ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) Service(org.springframework.stereotype.Service) Map(java.util.Map) Rate(org.ligoj.app.plugin.prov.model.Rate) CurlProcessor(org.ligoj.app.resource.plugin.CurlProcessor) TypeReference(com.fasterxml.jackson.core.type.TypeReference) INamableBean(org.ligoj.bootstrap.core.INamableBean) Node(org.ligoj.app.model.Node) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) VmOs(org.ligoj.app.plugin.prov.model.VmOs) Slf4j(lombok.extern.slf4j.Slf4j) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) ProvInstancePriceTerm(org.ligoj.app.plugin.prov.model.ProvInstancePriceTerm) Optional(java.util.Optional) ProvAzurePluginResource(org.ligoj.app.plugin.prov.azure.ProvAzurePluginResource) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) AbstractImportCatalogResource(org.ligoj.app.plugin.prov.in.AbstractImportCatalogResource) ProvInstanceType(org.ligoj.app.plugin.prov.model.ProvInstanceType) ProvStorageOptimized(org.ligoj.app.plugin.prov.model.ProvStorageOptimized) HashMap(java.util.HashMap) CurlProcessor(org.ligoj.app.resource.plugin.CurlProcessor) Node(org.ligoj.app.model.Node) INamableBean(org.ligoj.bootstrap.core.INamableBean)

Aggregations

Node (org.ligoj.app.model.Node)2 INamableBean (org.ligoj.bootstrap.core.INamableBean)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1 Slf4j (lombok.extern.slf4j.Slf4j)1 IOUtils (org.apache.commons.io.IOUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ProvAzurePluginResource (org.ligoj.app.plugin.prov.azure.ProvAzurePluginResource)1