Search in sources :

Example 11 with BtrpSet

use of org.btrplace.btrpsl.element.BtrpSet in project scheduler by btrplace.

the class ImportStatement method go.

@Override
@SuppressWarnings("squid:S1166")
public BtrpOperand go(BtrPlaceTree parent) {
    String id = scriptId();
    List<Script> res;
    try {
        res = includes.getScripts(id);
        script.getDependencies().addAll(res);
    } catch (ScriptBuilderException e) {
        int nb = e.getErrorReporter().getErrors().size();
        return ignoreError(Integer.toString(nb) + " error(s) imported through '" + id + "'");
    }
    if (res.isEmpty()) {
        return ignoreError(getChild(0).getToken(), "Unable to locate '" + id + "'");
    }
    if (id.endsWith(".*")) {
        // Prepare the global variable.
        BtrpSet global = new BtrpSet(1, BtrpOperand.Type.VM);
        global.setLabel("$".concat(id.substring(0, id.length() - 2)));
        if (global.size() > 0 && !symTable.declareImmutable(global.label(), global)) {
            return ignoreError("Unable to add variable '" + global.label() + "'");
        }
    }
    for (Script v : res) {
        for (BtrpOperand op : v.getImportables(script.id())) {
            String fqn = v.fullyQualifiedSymbolName(op.label());
            if (!symTable.declareImmutable(fqn, op)) {
                return ignoreError("Unable to import '" + fqn + "': already declared");
            }
        }
    }
    return IgnorableOperand.getInstance();
}
Also used : Script(org.btrplace.btrpsl.Script) BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) ScriptBuilderException(org.btrplace.btrpsl.ScriptBuilderException) BtrpSet(org.btrplace.btrpsl.element.BtrpSet)

Example 12 with BtrpSet

use of org.btrplace.btrpsl.element.BtrpSet in project scheduler by btrplace.

the class NameSpaceStatement method go.

@Override
public BtrpOperand go(BtrPlaceTree parent) {
    StringBuilder fqdn = new StringBuilder();
    for (int i = 0; i < getChildCount(); i++) {
        fqdn.append(getChild(i));
        if (i != getChildCount() - 1) {
            fqdn.append('.');
        }
    }
    String id = fqdn.toString();
    script.setFullyQualifiedName(id);
    // $me is immutable and contains all the VMs.
    BtrpSet me = new BtrpSet(1, BtrpOperand.Type.VM);
    me.setLabel(SymbolsTable.ME);
    symbols.declareImmutable(me.label(), me);
    errors.updateNamespace();
    return IgnorableOperand.getInstance();
}
Also used : BtrpSet(org.btrplace.btrpsl.element.BtrpSet)

Example 13 with BtrpSet

use of org.btrplace.btrpsl.element.BtrpSet in project scheduler by btrplace.

the class ScriptBuilderTest method testLargeRange.

public void testLargeRange() throws ScriptBuilderException {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Script v = b.build("namespace foo; @N[1..500] : defaultNode;\n$all = @N[251..500]; export $all to *;");
    BtrpSet out = (BtrpSet) v.getImportable("$all");
    Assert.assertEquals(out.size(), 250);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpSet(org.btrplace.btrpsl.element.BtrpSet)

Aggregations

BtrpSet (org.btrplace.btrpsl.element.BtrpSet)13 BtrpOperand (org.btrplace.btrpsl.element.BtrpOperand)8 DefaultModel (org.btrplace.model.DefaultModel)4 BtrpString (org.btrplace.btrpsl.element.BtrpString)3 File (java.io.File)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ArrayList (java.util.ArrayList)1 Script (org.btrplace.btrpsl.Script)1 ScriptBuilderException (org.btrplace.btrpsl.ScriptBuilderException)1 BtrpNumber (org.btrplace.btrpsl.element.BtrpNumber)1 DefaultBtrpOperand (org.btrplace.btrpsl.element.DefaultBtrpOperand)1