use of org.btrplace.btrpsl.Script in project scheduler by btrplace.
the class DefaultTemplateFactoryTest method testTypingIssue.
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"})
public void testAccessibleWithStrict() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(mo));
tplf.register(new MockVMTemplate("mock1"));
Script scr = new Script();
tplf.check(scr, "mock1", null, new HashMap<String, String>());
Assert.assertEquals(mo.getAttributes().get(el.getElement(), "template"), "mock1");
} */
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"}, expectedExceptions = {ElementBuilderException.class})
public void testInaccessibleWithStrict() throws ElementBuilderException {
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(), new DefaultModel());
Script scr = new Script();
tplf.check(scr, "bar", , "foo", new HashMap<String, String>());
} */
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"})
public void testAccessibleWithoutStrict() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(), mo);
tplf.register(new MockVMTemplate("mock1"));
Script scr = new Script();
tplf.check(scr, "mock1", null, new HashMap<String, String>());
Assert.assertEquals(mo.getAttributes().get(el.getElement(), "template"), "mock1");
} */
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"})
public void testInaccessibleWithoutStrict() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(), mo);
Map<String, String> m = new HashMap<>();
m.put("migratable", null);
m.put("foo", "7.5");
m.put("bar", "1243");
m.put("template", "bar");
Script scr = new Script();
tplf.check(scr, "bar", null, m);
Assert.assertEquals(mo.getAttributes().get(el.getElement(), "template"), "bar");
Assert.assertEquals(el.getName(), "foo");
Assert.assertTrue(mo.getAttributes().getBoolean(el.getElement(), "migratable"));
Assert.assertEquals(mo.getAttributes().getInteger(el.getElement(), "bar").longValue(), 1243);
Assert.assertEquals(mo.getAttributes().getDouble(el.getElement(), "foo"), 7.5);
Assert.assertEquals(mo.getAttributes().getKeys(el.getElement()), m.keySet());
} */
@Test(expectedExceptions = { ElementBuilderException.class })
public void testTypingIssue() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(NamingService.newNodeNS(), NamingService.newVMNS(), mo);
tplf.register(new MockVMTemplate("mock1"));
Script scr = new Script();
tplf.check(scr, "mock1", mo.newNode(), new HashMap<>());
}
use of org.btrplace.btrpsl.Script in project scheduler by btrplace.
the class PathBasedIncludes method getScripts.
/**
* Get the script associated to a given identifier by browsing the given paths.
* The first script having a matching identifier is selected, whatever the parsing process result will be
*
* @param name the identifier of the script
* @return the script if found
* @throws org.btrplace.btrpsl.ScriptBuilderException if the builder was not able to parse the looked script
*/
@Override
public List<Script> getScripts(String name) throws ScriptBuilderException {
List<Script> scripts = new ArrayList<>();
if (!name.endsWith(".*")) {
String toSearch = name.replaceAll("\\.", File.separator) + Script.EXTENSION;
for (File path : paths) {
File f = new File(path.getPath() + File.separator + toSearch);
if (f.exists()) {
scripts.add(builder.build(f));
break;
}
}
} else {
// We need to consolidate the errors in allEx and rethrow it at the end if necessary
ScriptBuilderException allEx = null;
String base = name.substring(0, name.length() - 2).replaceAll("\\.", File.separator);
for (File path : paths) {
File f = new File(path.getPath() + File.separator + base);
File[] files = f.listFiles();
if (f.isDirectory() && files != null) {
for (File sf : files) {
if (sf.getName().endsWith(Script.EXTENSION)) {
try {
scripts.add(builder.build(sf));
} catch (ScriptBuilderException ex) {
if (allEx == null) {
allEx = ex;
} else {
allEx.getErrorReporter().getErrors().addAll(ex.getErrorReporter().getErrors());
}
}
}
}
}
}
if (allEx != null) {
throw allEx;
}
}
return scripts;
}
use of org.btrplace.btrpsl.Script 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();
}
Aggregations