use of org.ow2.proactive.scheduler.task.context.TaskContext 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.task.context.TaskContext in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method failingFlowScript.
@Test
public void failingFlowScript() throws Exception {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setControlFlowScript(FlowScript.createReplicateFlowScript(""));
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("hello", taskOutput.output());
assertNotEquals("", taskOutput.error());
assertNotNull(result.getException());
}
use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.
the class TaskContextVariableExtractor method getScopeVariables.
/**
* Return all variables in scope of a given taskContext.
*
* @param taskContext task context container.
* @return Map containing all variables resolved.
*/
public Map<String, Serializable> getScopeVariables(TaskContext taskContext) {
Map<String, Serializable> variables = new HashMap<>();
Map<String, Serializable> inherited = new HashMap<>();
Map<String, Serializable> dictionary = new HashMap<>();
try {
inherited.putAll(extractSystemVariables(taskContext, ""));
inherited.putAll(extractJobVariables(taskContext));
inherited.putAll(extractInheritedVariables(taskContext));
for (TaskVariable taskVariable : taskContext.getInitializer().getTaskVariables().values()) {
if (!taskVariable.isJobInherited()) {
// add non inherited variables
variables.put(taskVariable.getName(), taskVariable.getValue());
} else if (!inherited.containsKey(taskVariable.getName())) {
// but if the variable is inherited
// replace by the inherited value if exists
variables.put(taskVariable.getName(), taskVariable.getValue());
}
}
dictionary = extractAllVariables(taskContext, null, "");
} catch (IOException | ClassNotFoundException e) {
logger.error(ERROR_READING_VARIABLES, e);
}
return VariableSubstitutor.resolveVariables(variables, dictionary);
}
use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.
the class ForkEnvironmentScriptExecutor method executeForkEnvironmentScript.
/**
* Executes a fork environment script.
*
* @param context The task context to execute the script in.
* @param outputSink Standard output sink.
* @param errorSink Error output sink.
* @return Returns a ScriptResult.
* @throws Exception
*/
public ScriptResult executeForkEnvironmentScript(TaskContext context, PrintStream outputSink, PrintStream errorSink) throws Exception {
VariablesMap variables = new VariablesMap();
variables.setInheritedMap(taskContextVariableExtractor.getAllNonTaskVariables(context));
variables.setScopeMap(taskContextVariableExtractor.getScopeVariables(context));
Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager.extractThirdPartyCredentials(context);
ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
Script<?> script = context.getInitializer().getForkEnvironment().getEnvScript();
SchedulerNodeClient schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(context);
RemoteSpace userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(context, schedulerNodeClient, IDataSpaceClient.Dataspace.USER);
RemoteSpace globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(context, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL);
forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, context, variables, thirdPartyCredentials, schedulerNodeClient, userSpaceClient, globalSpaceClient, Collections.<String, String>emptyMap());
forkedTaskVariablesManager.replaceScriptParameters(script, thirdPartyCredentials, variables, errorSink);
ScriptResult scriptResult = scriptHandler.handle(script, outputSink, errorSink);
if (scriptResult.errorOccured()) {
throw new Exception("Failed to execute fork environment script", scriptResult.getException());
}
return scriptResult;
}
use of org.ow2.proactive.scheduler.task.context.TaskContext in project scheduling by ow2-proactive.
the class ForkedProcessBuilderCreator method createForkedProcessBuilder.
/**
* Creates a process builder for a given task context.
*
* @param context The task context to execute.
* @param serializedContext The task context saved to disk.
* @param outputSink Standard output sink.
* @param errorSink Error sink.
* @param workingDir The working directory to execute the process in.
* @return Returns a process builder, ready to execute.
* @throws Exception
*/
public OSProcessBuilder createForkedProcessBuilder(TaskContext context, File serializedContext, PrintStream outputSink, PrintStream errorSink, File workingDir) throws Exception {
String nativeScriptPath = context.getSchedulerHome();
OSProcessBuilder processBuilder = getOsProcessBuilder(context, workingDir, nativeScriptPath);
ScriptResult forkEnvironmentScriptResult = executeForkEnvironmentScriptAndExtractVariables(context, outputSink, errorSink, processBuilder);
processBuilder.command().addAll(forkedJvmTaskExecutionCommandCreator.createForkedJvmTaskExecutionCommand(context, forkEnvironmentScriptResult, serializedContext.getAbsolutePath()));
processBuilder = processBuilder.directory(workingDir);
return processBuilder;
}
Aggregations