use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method forkEnvironment.
@Test
public void forkEnvironment() 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.addSystemEnvironmentVariable("envVar", "envValue");
forkEnvironment.addJVMArgument("-DjvmArg=jvmValue");
initializer.setForkEnvironment(forkEnvironment);
taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println System.getenv('envVar'); " + "println System.getProperty('jvmArg'); " + "println new File('.').getCanonicalPath()", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals(String.format("envValue%njvmValue%n%s%n", new File(workingDir, ".").getCanonicalPath()), taskOutput.output());
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method forkEnvironment_WithVariables.
@Test
public void forkEnvironment_WithVariables() 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)));
initializer.setJobVariables(Collections.singletonMap("aVar", new JobVariable("aVar", "aValue")));
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.addSystemEnvironmentVariable("envVar", "$aVar");
forkEnvironment.addJVMArgument("-DjvmArg=$aVar");
initializer.setForkEnvironment(forkEnvironment);
taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println System.getenv('envVar'); " + "println System.getProperty('jvmArg'); " + "println new File('.').getCanonicalPath()", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals(String.format("aValue%naValue%n%s%n", new File(workingDir, ".").getCanonicalPath()), taskOutput.output());
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class TaskData method createTaskData.
static TaskData createTaskData(JobData jobRuntimeData, InternalScriptTask task) {
TaskData taskData = new TaskData();
TaskData.DBTaskId taskId = new DBTaskId();
taskId.setJobId(jobRuntimeData.getId());
taskId.setTaskId(task.getTaskInfo().getTaskId().longValue());
taskData.setId(taskId);
taskData.setDescription(task.getDescription());
taskData.setTag(task.getTag());
taskData.setParallelEnvironment(task.getParallelEnvironment());
taskData.setFlowBlock(task.getFlowBlock());
taskData.setRestartMode(task.getRestartTaskOnError());
taskData.setPreciousLogs(task.isPreciousLogs());
taskData.setPreciousResult(task.isPreciousResult());
taskData.setRunAsMe(task.isRunAsMe());
taskData.setWallTime(task.getWallTime());
taskData.setOnTaskErrorString(task.getOnTaskErrorProperty().getValue());
taskData.setMaxNumberOfExecution(task.getMaxNumberOfExecution());
taskData.setJobData(jobRuntimeData);
taskData.setNumberOfExecutionOnFailureLeft(PASchedulerProperties.NUMBER_OF_EXECUTION_ON_FAILURE.getValueAsInt());
taskData.setNumberOfExecutionLeft(task.getMaxNumberOfExecution());
taskData.setGenericInformation(task.getGenericInformation());
HashMap<String, TaskDataVariable> variables = new HashMap<>();
for (Map.Entry<String, TaskVariable> entry : task.getVariables().entrySet()) {
variables.put(entry.getKey(), TaskDataVariable.create(entry.getKey(), entry.getValue(), taskData));
}
taskData.setVariables(variables);
// set the scheduledTime if the START_AT property exists
Map<String, String> genericInfos = taskData.getGenericInformation();
if (genericInfos != null && genericInfos.containsKey(CommonAttribute.GENERIC_INFO_START_AT_KEY)) {
long scheduledTime = ISO8601DateUtil.toDate(genericInfos.get(CommonAttribute.GENERIC_INFO_START_AT_KEY)).getTime();
taskData.setScheduledTime(scheduledTime);
task.setScheduledTime(scheduledTime);
}
taskData.updateMutableAttributes(task);
if (task.getSelectionScripts() != null) {
List<SelectionScriptData> scripts = new ArrayList<>(task.getSelectionScripts().size());
for (SelectionScript selectionScript : task.getSelectionScripts()) {
scripts.add(SelectionScriptData.createForSelectionScript(selectionScript, taskData));
}
taskData.setSelectionScripts(scripts);
}
if (task.getExecutableContainer() != null) {
taskData.setScript(ScriptData.createForScript(((ScriptExecutableContainer) task.getExecutableContainer()).getScript(), taskData));
}
if (task.getPreScript() != null) {
taskData.setPreScript(ScriptData.createForScript(task.getPreScript(), taskData));
}
if (task.getPostScript() != null) {
taskData.setPostScript(ScriptData.createForScript(task.getPostScript(), taskData));
}
if (task.getCleaningScript() != null) {
taskData.setCleanScript(ScriptData.createForScript(task.getCleaningScript(), taskData));
}
if (task.getFlowScript() != null) {
taskData.setFlowScript(ScriptData.createForFlowScript(task.getFlowScript(), taskData));
}
List<SelectorData> selectorsData = new ArrayList<>();
if (task.getInputFilesList() != null) {
for (InputSelector selector : task.getInputFilesList()) {
selectorsData.add(SelectorData.createForInputSelector(selector, taskData));
}
}
if (task.getOutputFilesList() != null) {
for (OutputSelector selector : task.getOutputFilesList()) {
selectorsData.add(SelectorData.createForOutputSelector(selector, taskData));
}
}
taskData.setDataspaceSelectors(selectorsData);
ForkEnvironment forkEnvironment = task.getForkEnvironment();
if (forkEnvironment != null) {
taskData.setAdditionalClasspath(forkEnvironment.getAdditionalClasspath());
taskData.setJavaHome(forkEnvironment.getJavaHome());
taskData.setJvmArguments(forkEnvironment.getJVMArguments());
taskData.setWorkingDir(forkEnvironment.getWorkingDir());
if (forkEnvironment.getEnvScript() != null) {
taskData.setEnvScript(ScriptData.createForScript(forkEnvironment.getEnvScript(), taskData));
}
Map<String, String> systemEnvironment = forkEnvironment.getSystemEnvironment();
if (systemEnvironment != null) {
List<EnvironmentModifierData> envModifiers = new ArrayList<>(systemEnvironment.size());
for (Map.Entry<String, String> entry : systemEnvironment.entrySet()) {
envModifiers.add(EnvironmentModifierData.create(new PropertyModifier(entry.getKey(), entry.getValue()), taskData));
}
taskData.setEnvModifiers(envModifiers);
}
}
taskData.initTaskType(task);
return taskData;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class TaskData method createForkEnvironment.
public ForkEnvironment createForkEnvironment() throws InvalidScriptException {
ForkEnvironment forkEnv = new ForkEnvironment();
forkEnv.setJavaHome(javaHome);
forkEnv.setWorkingDir(workingDir);
List<String> additionalClasspath = getAdditionalClasspath();
if (additionalClasspath != null) {
for (String classpath : additionalClasspath) {
forkEnv.addAdditionalClasspath(classpath);
}
}
List<String> jvmArguments = getJvmArguments();
if (jvmArguments != null) {
for (String jvmArg : jvmArguments) {
forkEnv.addJVMArgument(jvmArg);
}
}
List<EnvironmentModifierData> envModifiers = getEnvModifiers();
if (envModifiers != null) {
for (EnvironmentModifierData envModifier : envModifiers) {
forkEnv.addSystemEnvironmentVariable(envModifier.getName(), envModifier.getValue());
}
}
if (envScript != null) {
forkEnv.setEnvScript(envScript.createSimpleScript());
}
return forkEnv;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class TestKillTaskWhileExecutingScripts method forkedJavaTaskKillEndlessJavaExecutable.
public void forkedJavaTaskKillEndlessJavaExecutable() throws Throwable {
log("Test : killing an Endless Java Executable ...");
String tname = "forkedJavaTaskKillEndlessJavaExecutable";
// pre script interruption
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_" + tname);
JavaTask task1 = new JavaTask();
task1.setName(tname);
task1.setExecutableClassName(EndlessExecutable.class.getName());
task1.setForkEnvironment(new ForkEnvironment());
job.addTask(task1);
submitAndCheckJob(job, tname);
}
Aggregations