use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class TestExecRemote method scriptOnNodeSource.
private void scriptOnNodeSource(String nsName, HashSet<String> nodesUrls) throws Exception {
RMTHelper.log("Test 6 - Execute script on a specified nodesource name");
SimpleScript script = new SimpleScript(TestExecRemote.simpleScriptContent, "javascript");
HashSet<String> targets = new HashSet<>(1);
targets.add(nsName);
List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODESOURCE_NAME.toString(), targets);
assertEquals("The size of result list must equal to size of nodesource", nodesUrls.size(), results.size());
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);
}
assertNull("No exception must occur", exception);
}
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class TestExecRemote method scriptOnHost.
private void scriptOnHost(String hostname) throws Exception {
RMTHelper.log("Test 7 - Execute script with hostname as target");
SimpleScript script = new SimpleScript(TestExecRemote.simpleScriptContent, "javascript");
HashSet<String> targets = new HashSet<>(1);
targets.add(hostname);
List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.HOSTNAME.toString(), targets);
assertEquals("The size of result list must equal to 1, if a hostname is specified a single node must be " + "selected", results.size(), 1);
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);
}
assertNull("No exception must occur", exception);
}
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class TestExecRemote method action.
@Test
public void action() throws Exception {
final String miscDir = System.getProperty("pa.rm.home") + File.separator + "samples" + File.separator + "scripts" + File.separator + "misc" + File.separator;
boolean isLinux = OperatingSystem.getOperatingSystem().equals(OperatingSystem.unix);
final String valueToEcho = "111";
String nsName = "TestExecRemote";
rmHelper.createNodeSource(nsName);
RMInitialState state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
String hostname = state.getNodeEvents().get(0).getHostName();
HashSet<String> nodesUrls = new HashSet<>();
for (RMNodeEvent ne : state.getNodeEvents()) {
nodesUrls.add(ne.getNodeUrl());
}
simpleScript(nodesUrls);
selectionScript(nodesUrls);
processBuilderScript(miscDir, isLinux, valueToEcho, nodesUrls);
processBuilderWithDSScript(miscDir, isLinux, valueToEcho, nodesUrls);
scriptOnNodeSource(nsName, nodesUrls);
scriptOnHost(hostname);
}
use of org.ow2.proactive.scripting.SimpleScript 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.SimpleScript 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);
}
}
Aggregations