use of org.ow2.proactive.scripting.ScriptResult in project scheduling by ow2-proactive.
the class TestExecRemote method selectionScript.
private void selectionScript(HashSet<String> nodesUrls) throws Exception {
RMTHelper.log("Test 2 - Execute SelectionScript");
SelectionScript script = new SelectionScript(TestExecRemote.selectionScriptContent, "javascript");
List<ScriptResult<Boolean>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODE_URL.toString(), nodesUrls);
assertFalse("The results must not be empty", results.size() == 0);
for (ScriptResult<Boolean> res : results) {
assertTrue("The selection script must return true", res.getResult());
String output = res.getOutput();
assertTrue("The script output must contain the printed value", output.contains("true"));
}
}
use of org.ow2.proactive.scripting.ScriptResult in project scheduling by ow2-proactive.
the class TestExecRemote method processBuilderWithDSScript.
private void processBuilderWithDSScript(String miscDir, boolean isLinux, String valueToEcho, HashSet<String> nodesUrls) throws Exception {
File sFile = new File(miscDir + "processBuilderWithDS.groovy");
RMTHelper.log("Test 5 - Test " + sFile);
// Create test temporary file
File tempDir = tmpFolder.newFolder("testExecRemote");
String testFilename = "test.txt";
FileUtils.write(new File(tempDir, testFilename), valueToEcho);
// Generate the remote command execute in the remote localspace
DSHelper dsHelper = new DSHelper();
try {
// Start DS
String dsurl = dsHelper.startDS(tempDir.getAbsolutePath());
String[] cmd = (isLinux) ? new String[] { dsurl, "/bin/cat", testFilename } : new String[] { dsurl, "cmd.exe", "/c", "more", testFilename };
// Execute the script
SimpleScript script = new SimpleScript(sFile, cmd);
List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODE_URL.toString(), nodesUrls);
assertFalse("The results must not be empty", results.size() == 0);
for (ScriptResult<Object> res : results) {
Throwable exception = res.getException();
if (exception != null) {
RMTHelper.log("An exception occured while executing the script remotely:");
exception.printStackTrace(System.out);
}
String output = res.getOutput();
assertTrue("The script output must contains " + valueToEcho, output.contains(valueToEcho));
}
} finally {
dsHelper.stopDS();
}
}
use of org.ow2.proactive.scripting.ScriptResult in project scheduling by ow2-proactive.
the class TestExecRemote method simpleScript.
private void simpleScript(HashSet<String> nodesUrls) throws Exception {
RMTHelper.log("Test 1 - Execute SimpleScript");
SimpleScript script = new SimpleScript(TestExecRemote.erroneousSimpleScriptContent, "javascript");
List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODE_URL.toString(), nodesUrls);
assertFalse("The results must not be empty", results.size() == 0);
for (ScriptResult<Object> res : results) {
Throwable exception = res.getException();
assertNotNull("There should be an exception since the script is deliberately erroneous", exception);
}
}
use of org.ow2.proactive.scripting.ScriptResult in project scheduling by ow2-proactive.
the class InstallPackageCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
ScriptResult scriptResult;
Map<String, Object> schedulerProperties;
String packageDirPath;
try {
packageDirPath = retrievePackagePath();
schedulerProperties = retrieveSchedulerProperties(currentContext, scheduler);
addSessionIdToSchedulerProperties(currentContext, schedulerProperties);
scriptResult = executeScript(schedulerProperties, packageDirPath);
if (scriptResult.errorOccured()) {
logger.error("Failed to execute script: " + SCRIPT_PATH);
throw new InvalidScriptException("Failed to execute script: " + scriptResult.getException().getMessage(), scriptResult.getException());
} else {
writeLine(currentContext, "Package('%s') successfully installed in the catalog", SOURCE_PACKAGE);
}
} catch (Exception e) {
handleError(String.format("An error occurred while attempting to install package('%s') in the catalog", SOURCE_PACKAGE), e, currentContext);
}
}
use of org.ow2.proactive.scripting.ScriptResult in project scheduling by ow2-proactive.
the class InstallPackageCommand method executeScript.
private ScriptResult executeScript(Map<String, Object> schedulerProperties, String packageDirPath) throws InvalidScriptException {
ByteArrayOutputStream outputStream = null;
PrintStream printStream = null;
File scriptFile = new File(PASchedulerProperties.getAbsolutePath(SCRIPT_PATH));
String[] param = { packageDirPath };
ScriptResult scriptResult = null;
if (scriptFile.exists()) {
outputStream = new ByteArrayOutputStream();
printStream = new PrintStream(outputStream, true);
scriptResult = new SimpleScript(scriptFile, param).execute(schedulerProperties, printStream, printStream);
logger.info(outputStream.toString());
outputStream.reset();
} else {
logger.warn("Load package script " + scriptFile.getPath() + " not found");
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
// ignore
}
}
if (printStream != null) {
printStream.close();
}
return scriptResult;
}
Aggregations