Search in sources :

Example 11 with ScriptResult

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

Example 12 with ScriptResult

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

Example 13 with ScriptResult

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

Example 14 with ScriptResult

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);
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) IOException(java.io.IOException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 15 with ScriptResult

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

Aggregations

ScriptResult (org.ow2.proactive.scripting.ScriptResult)18 SelectionScript (org.ow2.proactive.scripting.SelectionScript)10 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)8 Test (org.junit.Test)7 SimpleScript (org.ow2.proactive.scripting.SimpleScript)7 SelectionManager (org.ow2.proactive.resourcemanager.selection.SelectionManager)6 SelectionManagerTest (org.ow2.proactive.resourcemanager.selection.SelectionManagerTest)6 File (java.io.File)5 Serializable (java.io.Serializable)4 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)4 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)4 IOException (java.io.IOException)3 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 LoginException (javax.security.auth.login.LoginException)2 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)2 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)2