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));
}
}
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());
}
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());
}
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());
}
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;
}
Aggregations