Search in sources :

Example 1 with ResourceCapacity

use of org.btrplace.model.constraint.ResourceCapacity in project scheduler by btrplace.

the class ResourceCapacityBuilder method buildConstraint.

@Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
    if (!checkConformance(t, args)) {
        return Collections.emptyList();
    }
    @SuppressWarnings("unchecked") List<Node> ns = (List<Node>) params[0].transform(this, t, args.get(0));
    String rcId = (String) params[1].transform(this, t, args.get(1));
    BtrpNumber n = (BtrpNumber) args.get(2);
    if (!n.isInteger()) {
        t.ignoreError("Parameter '" + params[2].getName() + "' expects an integer");
        return Collections.emptyList();
    }
    int v = n.getIntValue();
    if (v < 0) {
        t.ignoreError("Parameter '" + params[2].getName() + "' expects a positive integer (" + v + " given)");
        return Collections.emptyList();
    }
    return ns != null ? Collections.singletonList(new ResourceCapacity(new HashSet<>(ns), rcId, v)) : Collections.emptyList();
}
Also used : ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) Node(org.btrplace.model.Node) List(java.util.List) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 2 with ResourceCapacity

use of org.btrplace.model.constraint.ResourceCapacity in project scheduler by btrplace.

the class CShareableResource method getMisPlacedVMs.

/**
 * {@inheritDoc}
 *
 * @param i the model to use to inspect the VMs.
 * @return the set of VMs that cannot have their associated {@link Preserve} constraint satisfy with regards
 * to a possible {@link Overbook} and single-node {@link ResourceCapacity} constraint.
 */
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    for (SatConstraint c : i.getSatConstraints()) {
        if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
            continue;
        }
        if (c instanceof Preserve) {
            VM v = c.getInvolvedVMs().iterator().next();
            wantedAmount.put(v, consumption(v, ((Preserve) c).getAmount()));
        } else if (c instanceof Overbook) {
            Node n = c.getInvolvedNodes().iterator().next();
            wantedRatios.put(n, ratio(n, ((Overbook) c).getRatio()));
        } else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
            Node n = c.getInvolvedNodes().iterator().next();
            wantedCapacity.put(n, capacity(n, ((ResourceCapacity) c).getAmount()));
        }
    }
    Mapping m = i.getModel().getMapping();
    Set<VM> candidates = new HashSet<>();
    for (Node n : m.getOnlineNodes()) {
        if (overloaded(m, n)) {
            candidates.addAll(m.getRunningVMs(n));
        }
    }
    return candidates;
}
Also used : ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) ResourceRelated(org.btrplace.model.view.ResourceRelated) SatConstraint(org.btrplace.model.constraint.SatConstraint) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Overbook(org.btrplace.model.constraint.Overbook) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) Preserve(org.btrplace.model.constraint.Preserve) HashSet(java.util.HashSet)

Example 3 with ResourceCapacity

use of org.btrplace.model.constraint.ResourceCapacity in project scheduler by btrplace.

the class ResourceCapacityConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new ResourceCapacityConverter());
    Model mo = new DefaultModel();
    ResourceCapacity d = new ResourceCapacity(new HashSet<>(Arrays.asList(mo.newNode(), mo.newNode(), mo.newNode())), "cpu", 5, false);
    ResourceCapacity c = new ResourceCapacity(new HashSet<>(Arrays.asList(mo.newNode(), mo.newNode())), "mem", 5, true);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 4 with ResourceCapacity

use of org.btrplace.model.constraint.ResourceCapacity in project scheduler by btrplace.

the class ResourceCapacityBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodResources")
public void testGoodSignatures(String str, int nbNodes, String rcId, int capa, boolean c) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    ResourceCapacity x = (ResourceCapacity) b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
    Assert.assertEquals(x.getResource(), rcId);
    Assert.assertEquals(x.getAmount(), capa);
    Assert.assertEquals(x.isContinuous(), c);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Test(org.testng.annotations.Test)

Aggregations

ResourceCapacity (org.btrplace.model.constraint.ResourceCapacity)4 DefaultModel (org.btrplace.model.DefaultModel)2 Node (org.btrplace.model.Node)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 Test (org.testng.annotations.Test)2 HashSet (java.util.HashSet)1 List (java.util.List)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 BtrpNumber (org.btrplace.btrpsl.element.BtrpNumber)1 Mapping (org.btrplace.model.Mapping)1 Model (org.btrplace.model.Model)1 VM (org.btrplace.model.VM)1 Overbook (org.btrplace.model.constraint.Overbook)1 Preserve (org.btrplace.model.constraint.Preserve)1 ResourceRelated (org.btrplace.model.view.ResourceRelated)1 MigrateVM (org.btrplace.plan.event.MigrateVM)1