Search in sources :

Example 1 with SimpleScript

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);
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript) HashSet(java.util.HashSet)

Example 2 with SimpleScript

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);
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript) HashSet(java.util.HashSet)

Example 3 with SimpleScript

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);
}
Also used : RMInitialState(org.ow2.proactive.resourcemanager.common.event.RMInitialState) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 4 with SimpleScript

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();
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript) File(java.io.File)

Example 5 with SimpleScript

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);
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript)

Aggregations

SimpleScript (org.ow2.proactive.scripting.SimpleScript)99 TaskScript (org.ow2.proactive.scripting.TaskScript)78 Test (org.junit.Test)68 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)64 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)31 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)31 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)19 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 File (java.io.File)16 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)13 Serializable (java.io.Serializable)12 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)8 HashMap (java.util.HashMap)7 JobId (org.ow2.proactive.scheduler.common.job.JobId)7