Search in sources :

Example 1 with ProvQuoteFunction

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

the class ProvQuoteFunctionResourceTest method checkFunction.

private void checkFunction(final QuoteFunctionLookup lookup) {
    // Check the instance result
    final var pi = lookup.getPrice();
    Assertions.assertNotNull(pi.getId());
    Assertions.assertEquals("function2", pi.getType().getName());
    Assertions.assertEquals(1, pi.getType().getCpu());
    Assertions.assertEquals(2000, pi.getType().getRam());
    Assertions.assertEquals("FUNCTION3", pi.getCode());
    Assertions.assertFalse(pi.getTerm().isEphemeral());
    Assertions.assertEquals(168.0, pi.getCost(), DELTA);
    Assertions.assertEquals(2034.0, pi.getCostPeriod(), DELTA);
    Assertions.assertEquals("on-demand1", pi.getTerm().getName());
    Assertions.assertEquals(168.0, lookup.getCost(), DELTA);
    Assertions.assertTrue(pi.toString().contains("name=on-demand1"), pi.toString());
    // Coverage only
    Assertions.assertTrue(lookup.toString().contains("name=on-demand1"));
    new ProvQuoteFunction().setStorages(null);
    Assertions.assertNotNull(qfResource.getItRepository());
}
Also used : ProvQuoteFunction(org.ligoj.app.plugin.prov.model.ProvQuoteFunction)

Example 2 with ProvQuoteFunction

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

the class ProvBudgetResource method pack.

private double pack(final ProvBudget budget, final Map<Double, AbstractQuoteVm<?>> packToQr, final Map<AbstractQuoteVm<?>, FloatingPrice<?>> prices, final List<ProvQuoteInstance> validatedQi, final List<ProvQuoteDatabase> validatedQb, final List<ProvQuoteContainer> validatedQc, final List<ProvQuoteFunction> validatedQf, final Map<ResourceType, Map<Integer, FloatingCost>> costs) {
    if (packToQr.isEmpty()) {
        return 0d;
    }
    // At least one initial cost is implied, use bin packing strategy
    final var packStart = System.currentTimeMillis();
    final var packer = new LinearBinPacker();
    final var bins = packer.packAll(packToQr.entrySet().stream().sorted(priceOrder(prices)).map(Entry::getKey).collect(Collectors.toList()), new ArrayList<>(List.of(new LinearBin(budget.getRemainingBudget()))), new ArrayList<>(List.of(Double.MAX_VALUE)));
    final var bin = bins.get(0);
    bin.getPieces().stream().map(packToQr::get).forEach(i -> {
        if (i.getResourceType() == ResourceType.INSTANCE) {
            validatedQi.add((ProvQuoteInstance) i);
        } else if (i.getResourceType() == ResourceType.DATABASE) {
            validatedQb.add((ProvQuoteDatabase) i);
        } else if (i.getResourceType() == ResourceType.CONTAINER) {
            validatedQc.add((ProvQuoteContainer) i);
        } else {
            validatedQf.add((ProvQuoteFunction) i);
        }
    });
    logLean(b -> {
        log.info("Packing result: {}", b.get(0).getPieces().stream().map(packToQr::get).map(i -> i.getName() + CODE + i.getPrice().getCode() + ")").collect(Collectors.toList()));
        log.info("Packing result: {}", b);
    }, bins);
    logPack(packStart, packToQr, budget);
    var init = bin.getTotal();
    if (bins.size() > 1) {
        // Extra bin needs to make a new pass
        budget.setRemainingBudget(FloatingCost.round(budget.getRemainingBudget() - bin.getTotal()));
        final List<ProvQuoteInstance> subQi = newSubPack(packToQr, bins, ResourceType.INSTANCE);
        final List<ProvQuoteDatabase> subQb = newSubPack(packToQr, bins, ResourceType.DATABASE);
        final List<ProvQuoteContainer> subQc = newSubPack(packToQr, bins, ResourceType.CONTAINER);
        final List<ProvQuoteFunction> subQf = newSubPack(packToQr, bins, ResourceType.FUNCTION);
        init += leanRecursive(budget, subQi, subQb, subQc, subQf, costs);
    } else {
    // Pack is completed
    }
    return init;
}
Also used : ProvQuoteFunction(org.ligoj.app.plugin.prov.model.ProvQuoteFunction) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) ProvQuoteDatabase(org.ligoj.app.plugin.prov.model.ProvQuoteDatabase) ProvQuoteContainer(org.ligoj.app.plugin.prov.model.ProvQuoteContainer) Entry(java.util.Map.Entry) LinearBinPacker(net.jnellis.binpack.LinearBinPacker) LinearBin(net.jnellis.binpack.LinearBin)

Aggregations

ProvQuoteFunction (org.ligoj.app.plugin.prov.model.ProvQuoteFunction)2 Entry (java.util.Map.Entry)1 LinearBin (net.jnellis.binpack.LinearBin)1 LinearBinPacker (net.jnellis.binpack.LinearBinPacker)1 ProvQuoteContainer (org.ligoj.app.plugin.prov.model.ProvQuoteContainer)1 ProvQuoteDatabase (org.ligoj.app.plugin.prov.model.ProvQuoteDatabase)1 ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)1