Search in sources :

Example 1 with ProvStorageOptimized

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

the class ProvQuoteStorageResource method lookup.

private List<QuoteStorageLoopup> lookup(final ProvQuote configuration, final int size, final Rate latency, final Integer instance, final ProvStorageOptimized optimized, final String location) {
    // Get the attached node and check the security on this subscription
    final String node = configuration.getSubscription().getNode().getRefined().getId();
    final ProvQuoteInstance qi = checkInstance(node, instance);
    // The the right location from instance first, then the request one
    String iLocation = Optional.ofNullable(qi).map(qiResource::getLocation).map(ProvLocation::getName).orElse(location);
    iLocation = ObjectUtils.defaultIfNull(iLocation, configuration.getLocation().getName());
    if (location != null && !location.equals(iLocation)) {
        // Not compatible locations
        return Collections.emptyList();
    }
    return spRepository.findLowestPrice(node, size, latency, instance, optimized, iLocation, PageRequest.of(0, 10)).stream().map(spx -> (ProvStoragePrice) spx[0]).map(sp -> newPrice(sp, size, getCost(sp, size))).collect(Collectors.toList());
}
Also used : ProvStorageType(org.ligoj.app.plugin.prov.model.ProvStorageType) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) ProvQuoteStorage(org.ligoj.app.plugin.prov.model.ProvQuoteStorage) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) Function(java.util.function.Function) ValidationJsonException(org.ligoj.bootstrap.core.validation.ValidationJsonException) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ServicePluginLocator(org.ligoj.app.resource.ServicePluginLocator) Consumes(javax.ws.rs.Consumes) ProvLocation(org.ligoj.app.plugin.prov.model.ProvLocation) ObjectUtils(org.apache.commons.lang3.ObjectUtils) DataTableAttributes(org.ligoj.bootstrap.core.json.datatable.DataTableAttributes) Service(org.springframework.stereotype.Service) ProvStorageTypeRepository(org.ligoj.app.plugin.prov.dao.ProvStorageTypeRepository) DefaultValue(javax.ws.rs.DefaultValue) Rate(org.ligoj.app.plugin.prov.model.Rate) DescribedBean(org.ligoj.bootstrap.core.DescribedBean) DELETE(javax.ws.rs.DELETE) INamableBean(org.ligoj.bootstrap.core.INamableBean) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Transactional(javax.transaction.Transactional) ProvQuoteInstanceRepository(org.ligoj.app.plugin.prov.dao.ProvQuoteInstanceRepository) PageRequest(org.springframework.data.domain.PageRequest) Collectors(java.util.stream.Collectors) ProvInstancePrice(org.ligoj.app.plugin.prov.model.ProvInstancePrice) ProvQuoteStorageRepository(org.ligoj.app.plugin.prov.dao.ProvQuoteStorageRepository) List(java.util.List) Optional(java.util.Optional) PUT(javax.ws.rs.PUT) ProvQuote(org.ligoj.app.plugin.prov.model.ProvQuote) ProvStoragePrice(org.ligoj.app.plugin.prov.model.ProvStoragePrice) UriInfo(javax.ws.rs.core.UriInfo) TableItem(org.ligoj.bootstrap.core.json.TableItem) Collections(java.util.Collections) ProvStorageOptimized(org.ligoj.app.plugin.prov.model.ProvStorageOptimized) ProvStoragePriceRepository(org.ligoj.app.plugin.prov.dao.ProvStoragePriceRepository) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance)

Aggregations

Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Transactional (javax.transaction.Transactional)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 DefaultValue (javax.ws.rs.DefaultValue)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 QueryParam (javax.ws.rs.QueryParam)1 Context (javax.ws.rs.core.Context)1 MediaType (javax.ws.rs.core.MediaType)1 UriInfo (javax.ws.rs.core.UriInfo)1 ObjectUtils (org.apache.commons.lang3.ObjectUtils)1