Search in sources :

Example 6 with ProvLocation

use of org.ligoj.app.plugin.prov.model.ProvLocation in project plugin-prov by ligoj.

the class ProvResource method create.

@Override
public void create(final int subscription) throws Exception {
    // Add an empty quote
    final ProvQuote quote = new ProvQuote();
    quote.setSubscription(subscriptionRepository.findOne(subscription));
    // Associate a default name and description
    quote.setName(quote.getSubscription().getProject().getName());
    final Node provider = quote.getSubscription().getNode().getRefined();
    final List<ProvLocation> locations = locationRepository.findAllBy("node.id", provider.getId());
    if (locations.isEmpty()) {
        // No available location, need a catalog to continue
        throw new BusinessException(SERVICE_KEY + "-no-catalog", provider.getId(), provider.getName());
    }
    quote.setLocation(locations.get(0));
    quote.setDescription(quote.getSubscription().getProject().getPkey() + "-> " + provider.getName());
    repository.saveAndFlush(quote);
}
Also used : BusinessException(org.ligoj.bootstrap.core.resource.BusinessException) ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) ProvQuote(org.ligoj.app.plugin.prov.model.ProvQuote) Node(org.ligoj.app.model.Node)

Example 7 with ProvLocation

use of org.ligoj.app.plugin.prov.model.ProvLocation in project plugin-prov by ligoj.

the class ProvResourceTest method updateLocationDifferentQILocation.

/**
 * Update the location of the quote, impact all instances, but no one use the default location. Cost still updated.
 */
@Test
public void updateLocationDifferentQILocation() {
    final ProvLocation location = locationRepository.findByName("region-1");
    final ProvLocation location4 = locationRepository.findByName("region-4");
    // Change the required location of all quote instance
    qiRepository.findAll().forEach(ip -> ip.setLocation(location));
    // Make sure there is no more world wild prices
    em.createQuery("FROM ProvInstancePrice WHERE location.name=:location", ProvInstancePrice.class).setParameter("location", "region-1").getResultList().forEach(ip -> ip.setLocation(location4));
    em.createQuery("FROM ProvStoragePrice WHERE location.name=:location", ProvStoragePrice.class).setParameter("location", "region-1").getResultList().forEach(ip -> ip.setLocation(location4));
    em.createQuery("FROM ProvQuoteInstance WHERE location.name=:location", ProvQuoteInstance.class).setParameter("location", "region-1").getResultList().forEach(ip -> ip.setLocation(location4));
    em.flush();
    em.clear();
    // New cost based on region-4
    final QuoteEditionVo quote = new QuoteEditionVo();
    quote.setName("name1");
    quote.setDescription("description1");
    quote.setLocation("region-4");
    final FloatingCost cost = resource.update(subscription, quote);
    checkCost(cost, 3165.4, 5615.0, false);
    final ProvQuote quote2 = repository.findByNameExpected("name1");
    Assertions.assertEquals("description1", quote2.getDescription());
    Assertions.assertEquals("region-4", quote2.getLocation().getName());
}
Also used : ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) ProvQuote(org.ligoj.app.plugin.prov.model.ProvQuote) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 8 with ProvLocation

use of org.ligoj.app.plugin.prov.model.ProvLocation 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()));
}
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) ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice)

Aggregations

ProvLocation (org.ligoj.app.plugin.prov.model.ProvLocation)8 ProvQuote (org.ligoj.app.plugin.prov.model.ProvQuote)5 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)4 Optional (java.util.Optional)3 Function (java.util.function.Function)3 Test (org.junit.jupiter.api.Test)3 AbstractAppTest (org.ligoj.app.AbstractAppTest)3 ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)3 Service (org.springframework.stereotype.Service)3 IOException (java.io.IOException)2 Transactional (javax.transaction.Transactional)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 PathParam (javax.ws.rs.PathParam)2 Produces (javax.ws.rs.Produces)2