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);
}
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());
}
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()));
}
Aggregations