Search in sources :

Example 76 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class JavaClassScriptEngine method eval.

@Override
public Object eval(String userExecutableClassName, ScriptContext context) throws ScriptException {
    try {
        JavaExecutable javaExecutable = getExecutable(userExecutableClassName);
        JavaStandaloneExecutableInitializer execInitializer = new JavaStandaloneExecutableInitializer();
        PrintStream output = new PrintStream(new WriterOutputStream(context.getWriter()), true);
        execInitializer.setOutputSink(output);
        PrintStream error = new PrintStream(new WriterOutputStream(context.getErrorWriter()), true);
        execInitializer.setErrorSink(error);
        Map<String, byte[]> propagatedVariables = null;
        if (context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME) != null) {
            propagatedVariables = SerializationUtil.serializeVariableMap(((VariablesMap) context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME)).getPropagatedVariables());
            execInitializer.setPropagatedVariables(propagatedVariables);
        } else {
            execInitializer.setPropagatedVariables(Collections.<String, byte[]>emptyMap());
        }
        if (context.getAttribute(Script.ARGUMENTS_NAME) != null) {
            execInitializer.setSerializedArguments((Map<String, byte[]>) ((Serializable[]) context.getAttribute(Script.ARGUMENTS_NAME))[0]);
        } else {
            execInitializer.setSerializedArguments(Collections.<String, byte[]>emptyMap());
        }
        if (context.getAttribute(SchedulerConstants.CREDENTIALS_VARIABLE) != null) {
            execInitializer.setThirdPartyCredentials((Map<String, String>) context.getAttribute(SchedulerConstants.CREDENTIALS_VARIABLE));
        } else {
            execInitializer.setThirdPartyCredentials(Collections.<String, String>emptyMap());
        }
        if (context.getAttribute(SchedulerConstants.MULTI_NODE_TASK_NODESURL_BINDING_NAME) != null) {
            List<String> nodesURLs = (List<String>) context.getAttribute(SchedulerConstants.MULTI_NODE_TASK_NODESURL_BINDING_NAME);
            execInitializer.setNodesURL(nodesURLs);
        } else {
            execInitializer.setNodesURL(Collections.<String>emptyList());
        }
        javaExecutable.internalInit(execInitializer, context);
        Serializable execute = javaExecutable.execute((TaskResult[]) context.getAttribute(SchedulerConstants.RESULTS_VARIABLE));
        if (propagatedVariables != null) {
            ((Map<String, Serializable>) context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME)).putAll(javaExecutable.getVariables());
        }
        output.close();
        error.close();
        return execute;
    } catch (Throwable e) {
        throw new ScriptException(new TaskException(getStackTraceAsString(e), e));
    }
}
Also used : PrintStream(java.io.PrintStream) Serializable(java.io.Serializable) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) JavaExecutable(org.ow2.proactive.scheduler.common.task.executable.JavaExecutable) ScriptException(javax.script.ScriptException) TaskException(org.ow2.proactive.scheduler.task.exceptions.TaskException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) List(java.util.List) JavaStandaloneExecutableInitializer(org.ow2.proactive.scheduler.common.task.executable.internal.JavaStandaloneExecutableInitializer) Map(java.util.Map) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap)

Example 77 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class ForkedTaskExecutorTest method forkEnvironment_failingEnvScript.

@Test
public void forkEnvironment_failingEnvScript() throws Exception {
    TestTaskOutput taskOutput = new TestTaskOutput();
    File workingDir = tmpFolder.newFolder();
    ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(workingDir);
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.setEnvScript(new SimpleScript("should fail execution", "groovy"));
    initializer.setForkEnvironment(forkEnvironment);
    TaskResultImpl taskResult = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertTrue(taskResult.hadException());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) File(java.io.File) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 78 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method result_from_parent_task.

@Test
public void result_from_parent_task() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    TaskResult[] previousTasksResults = { new TaskResultImpl(null, "aresult", null, 0) };
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(results[0]);", "groovy"))), initializer, previousTasksResults, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals("aresult", taskOutput.output());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 79 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method multiNodesURLsAreBounded.

@Test
public void multiNodesURLsAreBounded() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    ScriptExecutableContainer printNodesFileTask = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println nodesurl.size()", "groovy")));
    printNodesFileTask.setNodes(mockedNodeSet());
    TaskContext context = new TaskContext(printNodesFileTask, initializer, null, new NodeDataSpacesURIs(tmpFolder.newFolder().getAbsolutePath(), "", "", "", "", ""), "", "thisHost");
    TaskResultImpl taskResult = new InProcessTaskExecutor().execute(context, taskOutput.outputStream, taskOutput.error);
    assertTaskResultOk(taskResult);
    assertEquals(String.format("1%n"), taskOutput.output());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 80 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class MonteCarloAverage method execute.

/**
 * @see JavaExecutable#execute(org.ow2.proactive.scheduler.common.task.TaskResult[])
 */
@Override
public Serializable execute(TaskResult... results) throws Throwable {
    double avrg = 0;
    int count = 0;
    getOut().print("Parameters are: ");
    for (TaskResult res : results) {
        if (!res.hadException()) {
            getOut().print(res.value() + " ");
            avrg += ((Double) (res.value())).doubleValue();
            count++;
        }
    }
    Double result = new Double(avrg / count);
    getOut().println("Average is: " + result);
    return result;
}
Also used : TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult)

Aggregations

TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)99 Test (org.junit.Test)54 JobId (org.ow2.proactive.scheduler.common.job.JobId)38 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)28 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)25 SimpleScript (org.ow2.proactive.scripting.SimpleScript)25 File (java.io.File)24 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)23 TaskScript (org.ow2.proactive.scripting.TaskScript)23 HashMap (java.util.HashMap)22 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)22 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)18 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)17 GET (javax.ws.rs.GET)16 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 GZIP (org.jboss.resteasy.annotations.GZIP)16 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)14 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)12 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)12