use of org.ligoj.app.plugin.prov.model.ProvQuote 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.ProvQuote in project plugin-prov by ligoj.
the class ProvResource method getConfiguration.
/**
* Return the quote configuration from a validated subscription.
*
* @param subscription
* A visible subscription for the current principal.
* @return The configuration with computed data.
*/
public QuoteVo getConfiguration(final Subscription subscription) {
final QuoteVo vo = new QuoteVo();
final ProvQuote entity = repository.getCompute(subscription.getId());
DescribedBean.copy(entity, vo);
vo.copyAuditData(entity, toUser());
vo.setLocation(entity.getLocation());
vo.setInstances(entity.getInstances());
vo.setStorages(repository.getStorage(subscription.getId()));
vo.setUsage(entity.getUsage());
// Also copy the pre-computed cost
vo.setCost(toFloatingCost(entity));
return vo;
}
use of org.ligoj.app.plugin.prov.model.ProvQuote in project plugin-prov by ligoj.
the class ProvResource method getSusbcriptionStatus.
/**
* Return the quote status linked to given subscription.
*
* @param subscription
* The parent subscription identifier.
* @return The quote status (summary only) linked to given subscription.
*/
public QuoteLigthVo getSusbcriptionStatus(final int subscription) {
final QuoteLigthVo vo = new QuoteLigthVo();
final Object[] compute = repository.getComputeSummary(subscription).get(0);
final Object[] storage = repository.getStorageSummary(subscription).get(0);
final ProvQuote entity = (ProvQuote) compute[0];
DescribedBean.copy(entity, vo);
vo.setCost(toFloatingCost(entity));
vo.setNbInstances(((Long) compute[1]).intValue());
vo.setTotalCpu((Double) compute[2]);
vo.setTotalRam(((Long) compute[3]).intValue());
vo.setNbPublicAccess(((Long) compute[4]).intValue());
vo.setNbStorages(((Long) storage[1]).intValue());
vo.setTotalStorage(((Long) storage[2]).intValue());
vo.setLocation(entity.getLocation());
return vo;
}
use of org.ligoj.app.plugin.prov.model.ProvQuote 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.ProvQuote in project plugin-prov by ligoj.
the class ProvQuoteUsageResourceTest method deleteUnused.
@Test
public void deleteUnused() {
final ProvQuote quote = repository.findByName("quote1");
quote.setUsage(usageRepository.findByName("Full Time"));
em.persist(quote);
em.flush();
em.clear();
checkCost(resource.refresh(subscription), 3165.4, 5615.0, false);
Assertions.assertNotNull(usageRepository.findByName(subscription, "Dev"));
Assertions.assertEquals(2, usageRepository.findAllBy("name", "Dev").size());
// Delete the usage
// Check the cost is at 100%
checkUsage100AfterDelete(uResource.delete(subscription, "Dev"));
}
Aggregations