Search in sources :

Example 6 with Spread

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

the class SpreadBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodSpreads")
public void testGoodSignatures(String str, int nbVMs) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Spread x = (Spread) b.build("namespace test; VM[1..10] : tiny;\n" + str).getConstraints().iterator().next();
    Assert.assertEquals(x.getInvolvedVMs().size(), nbVMs);
    Assert.assertEquals(x.isContinuous(), !str.startsWith(">>"));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Test(org.testng.annotations.Test)

Example 7 with Spread

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

the class SpreadConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    Model mo = new DefaultModel();
    Spread d = new Spread(new HashSet<>(Arrays.asList(mo.newVM(), mo.newVM())), false);
    Spread c = new Spread(new HashSet<>(Arrays.asList(mo.newVM(), mo.newVM())), true);
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new SpreadConverter());
    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) Spread(org.btrplace.model.constraint.Spread) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 8 with Spread

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

the class SpreadBuilder method buildConstraint.

@Override
public List<Spread> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
    if (checkConformance(t, args)) {
        @SuppressWarnings("unchecked") List<VM> vms = (List<VM>) params[0].transform(this, t, args.get(0));
        if (vms == null) {
            return Collections.emptyList();
        }
        Set<VM> s = new HashSet<>(vms);
        if (s.size() != vms.size()) {
            return Collections.emptyList();
        }
        return Collections.singletonList(new Spread(new HashSet<>(vms), true));
    }
    return Collections.emptyList();
}
Also used : Spread(org.btrplace.model.constraint.Spread) VM(org.btrplace.model.VM) List(java.util.List) HashSet(java.util.HashSet)

Example 9 with Spread

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

the class SpreadSplitterTest method simpleTest.

@Test
public void simpleTest() {
    SpreadSplitter splitter = new SpreadSplitter();
    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    m0.getMapping().addReadyVM(m0.newVM(1));
    Node n1 = m0.newNode();
    m0.getMapping().addOnlineNode(n1);
    m0.getMapping().addRunningVM(m0.newVM(2), n1);
    Model m1 = new DefaultModel();
    m1.getMapping().addReadyVM(m1.newVM(3));
    Node n2 = m1.newNode();
    Node n3 = m1.newNode();
    m1.getMapping().addOnlineNode(n2);
    m1.getMapping().addOnlineNode(n3);
    m1.getMapping().addSleepingVM(m1.newVM(4), n2);
    m1.getMapping().addRunningVM(m1.newVM(5), n3);
    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());
    TIntIntHashMap index = Instances.makeVMIndex(instances);
    // Only VMs in m0
    Spread spreadSingle = new Spread(m0.getMapping().getAllVMs());
    Assert.assertTrue(splitter.split(spreadSingle, null, instances, index, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(spreadSingle));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(spreadSingle));
    // All the VMs, test the split
    Spread spreadAmong = new Spread(all, false);
    Assert.assertTrue(splitter.split(spreadAmong, null, instances, index, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(new Spread(m0.getMapping().getAllVMs(), false)));
    Assert.assertTrue(instances.get(1).getSatConstraints().contains(new Spread(m1.getMapping().getAllVMs(), false)));
}
Also used : ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Spread(org.btrplace.model.constraint.Spread) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Spread (org.btrplace.model.constraint.Spread)9 Test (org.testng.annotations.Test)7 DefaultModel (org.btrplace.model.DefaultModel)6 Model (org.btrplace.model.Model)5 HashSet (java.util.HashSet)3 VM (org.btrplace.model.VM)3 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)3 Instance (org.btrplace.model.Instance)2 Node (org.btrplace.model.Node)2 MinMTTR (org.btrplace.model.constraint.MinMTTR)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Among (org.btrplace.model.constraint.Among)1 Fence (org.btrplace.model.constraint.Fence)1 MinMigrations (org.btrplace.model.constraint.MinMigrations)1 Offline (org.btrplace.model.constraint.Offline)1 RunningCapacity (org.btrplace.model.constraint.RunningCapacity)1