use of org.ow2.proactive.scheduler.common.task.ScriptTask in project scheduling by ow2-proactive.
the class SchedulerClientTest method nodeClientJob.
protected Job nodeClientJob(String groovyScript, String forkScript) throws Exception {
URL scriptURL = SchedulerClientTest.class.getResource(groovyScript);
URL forkScriptURL = SchedulerClientTest.class.getResource(forkScript);
TaskFlowJob job = new TaskFlowJob();
job.setName("NodeClientJob");
ScriptTask task = new ScriptTask();
task.setName("NodeClientTask");
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.setEnvScript(new SimpleScript(IOUtils.toString(forkScriptURL.toURI()), "groovy"));
task.setForkEnvironment(forkEnvironment);
task.setScript(new TaskScript(new SimpleScript(IOUtils.toString(scriptURL.toURI()), "groovy")));
// add CleanScript to test external APIs
task.setCleaningScript(new SimpleScript("" + "schedulerapi.connect();\n" + "print(\"SCHEDULERAPI_URI_LIST_NOT_NULL=\"+(schedulerapi.getGlobalSpaceURIs()!=null));\n" + "\n" + "userspaceapi.connect();\n" + "print(\"USERSPACE_FILE_LIST_NOT_NULL=\"+(userspaceapi.listFiles(\".\", \"*\")!=null));\n" + "\n" + "globalspaceapi.connect();\n" + "print(\"GLOBALSPACE_FILE_LIST_NOT_NULL=\"+(globalspaceapi.listFiles(\".\", \"*\")!=null));\n" + "print(\"TEST_CREDS=\"+(credentials.get(\"TEST_CREDS\")));\n", "js"));
job.addTask(task);
return job;
}
use of org.ow2.proactive.scheduler.common.task.ScriptTask in project scheduling by ow2-proactive.
the class DefaultModelJobValidatorServiceProviderTest method createJobWithTaskModelVariable.
private TaskFlowJob createJobWithTaskModelVariable(String value, String model) throws UserException {
TaskFlowJob job = new TaskFlowJob();
TaskVariable variable = new TaskVariable("VAR", value, model, false);
Task task = new ScriptTask();
task.setName("ModelTask");
task.setVariables(Collections.singletonMap(variable.getName(), variable));
job.addTask(task);
return job;
}
use of org.ow2.proactive.scheduler.common.task.ScriptTask in project scheduling by ow2-proactive.
the class JobComparator method isTaskEqual.
private boolean isTaskEqual(Task t1, Task t2) throws IOException, ClassNotFoundException {
if ((t1 == null) && (t2 == null))
return true;
if ((t1 == null) ^ (t2 == null)) {
stack.push("One of 2 tasks is null");
return false;
}
if (!isEqualCommonAttribute(t1, t2))
return false;
if (!t1.getName().equals(t2.getName())) {
stack.push("name");
return false;
}
if (!isEqualString(t1.getDescription(), t2.getDescription())) {
stack.push("description");
return false;
}
if (t1.getWallTime() != t2.getWallTime()) {
stack.push("walltime");
return false;
}
// ****** task dependencies ****
stack.push("task dependenices");
List<Task> dep1 = t1.getDependencesList();
List<Task> dep2 = t2.getDependencesList();
if (dep1 == null ^ dep2 == null) {
stack.push("one dependency list is empty");
return false;
}
if (dep1 != null) {
if (dep1.size() != dep2.size()) {
stack.push("sizes don't match");
return false;
}
// we only compare the names in the 2 dependencies lists
int dep1Size = dep1.size();
Set<String> names1 = new HashSet<String>(dep1Size);
Set<String> names2 = new HashSet<String>(dep1Size);
for (int k = 0; k < dep1Size; k++) {
names1.add(dep1.get(k).getName());
names2.add(dep2.get(k).getName());
}
if (!CollectionUtils.isEqualCollection(names1, names2)) {
return false;
}
}
// task dependencies
stack.pop();
// **** parallel environment ****
stack.push("parallel environment");
if (!isEqualParallelEnvironment(t1.getParallelEnvironment(), t2.getParallelEnvironment()))
return false;
// parallel env
stack.pop();
// input files
stack.push("input files");
if (!isEqualInputFiles(t1.getInputFilesList(), t2.getInputFilesList()))
return false;
stack.pop();
stack.push("output files");
if (!isEqualOutputFiles(t1.getOutputFilesList(), t2.getOutputFilesList()))
return false;
stack.pop();
// scripts
stack.push("pre script");
if (!isEqualScript(t1.getPreScript(), t2.getPreScript()))
return false;
stack.pop();
stack.push("post script");
if (!isEqualScript(t1.getPostScript(), t2.getPostScript()))
return false;
stack.pop();
stack.push("cleaning script");
if (!isEqualScript(t1.getCleaningScript(), t2.getCleaningScript()))
return false;
stack.pop();
stack.push("selection scripts");
List<SelectionScript> ss1 = t1.getSelectionScripts();
List<SelectionScript> ss2 = t2.getSelectionScripts();
if ((ss1 == null) ^ (ss2 == null)) {
stack.push("One of two lists of selection scripts is null");
return false;
}
if (ss1 != null) {
if (t1.getSelectionScripts().size() != t2.getSelectionScripts().size()) {
stack.push("lists size don't match");
return false;
}
for (int k = 0; k < t1.getSelectionScripts().size(); k++) {
if (!isEqualScript(t1.getSelectionScripts().get(k), t2.getSelectionScripts().get(k))) {
return false;
}
}
}
// select scripts
stack.pop();
// flow control
if (t1.getFlowBlock() != t2.getFlowBlock()) {
stack.push("flow block");
return false;
}
stack.push("flow control");
if (!isEqualFlowControl(t1.getFlowScript(), t2.getFlowScript()))
return false;
stack.pop();
// ***** task executable *****
if (!isEqualClass(t1.getClass(), t2.getClass())) {
stack.push("Executable types don't match");
return false;
}
if (t1 instanceof JavaTask) {
JavaTask jt1 = (JavaTask) t1;
JavaTask jt2 = (JavaTask) t2;
stack.push("arguments");
if (!isEqualMap(jt1.getArguments(), jt2.getArguments()))
return false;
stack.pop();
stack.push("executable class");
if (!isEqualString(jt1.getExecutableClassName(), jt2.getExecutableClassName()))
return false;
stack.pop();
stack.push("forked environemnt");
if (!isEqualForkedEnvironment(jt1.getForkEnvironment(), jt2.getForkEnvironment()))
return false;
stack.pop();
}
if (t1 instanceof NativeTask) {
NativeTask nt1 = (NativeTask) t1;
NativeTask nt2 = (NativeTask) t2;
String[] cl1 = nt1.getCommandLine();
String[] cl2 = nt2.getCommandLine();
if (cl1 == null ^ cl2 == null) {
return false;
} else if (cl1 != null) {
if (!CollectionUtils.isEqualCollection(Arrays.asList(cl1), Arrays.asList(cl2))) {
return false;
}
}
}
if (t1 instanceof ScriptTask) {
ScriptTask st1 = (ScriptTask) t1;
ScriptTask st2 = (ScriptTask) t2;
if (!isEqualScript(st1.getScript(), st2.getScript()))
return false;
}
return true;
}
use of org.ow2.proactive.scheduler.common.task.ScriptTask in project scheduling by ow2-proactive.
the class StaxJobFactory method displayJobInfo.
private void displayJobInfo(Job job) {
if (logger.isDebugEnabled()) {
logger.debug("type: " + job.getType());
logger.debug("name: " + job.getName());
logger.debug("description: " + job.getDescription());
logger.debug("projectName: " + job.getProjectName());
logger.debug("variables: " + job.getVariables());
logger.debug("priority: " + job.getPriority());
logger.debug("onTaskError: " + job.getOnTaskErrorProperty().getValue().toString());
logger.debug("restartTaskOnError: " + job.getRestartTaskOnError());
logger.debug("maxNumberOfExecution: " + job.getMaxNumberOfExecution());
logger.debug("inputSpace: " + job.getInputSpace());
logger.debug("outputSpace: " + job.getOutputSpace());
logger.debug("genericInformation: " + job.getGenericInformation());
logger.debug("TASKS ------------------------------------------------");
ArrayList<Task> tasks = new ArrayList<>();
switch(job.getType()) {
case TASKSFLOW:
tasks.addAll(((TaskFlowJob) job).getTasks());
break;
default:
break;
}
for (Task t : tasks) {
logger.debug("name: " + t.getName());
logger.debug("description: " + t.getDescription());
logger.debug("parallel: " + t.isParallel());
logger.debug("nbNodes: " + (t.getParallelEnvironment() == null ? "1" : t.getParallelEnvironment().getNodesNumber()));
logger.debug("onTaskError: " + t.getOnTaskErrorProperty().getValue().toString());
logger.debug("preciousResult: " + t.isPreciousResult());
logger.debug("preciousLogs: " + t.isPreciousLogs());
logger.debug("restartTaskOnError: " + t.getRestartTaskOnError());
logger.debug("maxNumberOfExecution: " + t.getMaxNumberOfExecution());
logger.debug("walltime: " + t.getWallTime());
logger.debug("selectionScripts: " + t.getSelectionScripts());
logger.debug("preScript: " + t.getPreScript());
logger.debug("postScript: " + t.getPostScript());
logger.debug("cleaningScript: " + t.getCleaningScript());
try {
logger.debug("inputFileList: length=" + t.getInputFilesList().size());
} catch (NullPointerException ignored) {
}
try {
logger.debug("outputFileList: length=" + t.getOutputFilesList().size());
} catch (NullPointerException ignored) {
}
if (t.getDependencesList() != null) {
String dep = "dependence: ";
for (Task tdep : t.getDependencesList()) {
dep += tdep.getName() + " ";
}
logger.debug(dep);
} else {
logger.debug("dependence: null");
}
logger.debug("genericInformation: " + t.getGenericInformation());
logger.debug("variables: " + t.getVariables());
if (t instanceof JavaTask) {
logger.debug("class: " + ((JavaTask) t).getExecutableClassName());
try {
logger.debug("args: " + ((JavaTask) t).getArguments());
} catch (Exception e) {
logger.debug("Cannot get args: " + e.getMessage(), e);
}
logger.debug("fork: " + ((JavaTask) t).isFork());
} else if (t instanceof NativeTask) {
logger.debug("commandLine: " + Arrays.toString(((NativeTask) t).getCommandLine()));
} else if (t instanceof ScriptTask) {
logger.debug("script: " + ((ScriptTask) t).getScript());
}
ForkEnvironment forkEnvironment = t.getForkEnvironment();
if (forkEnvironment != null) {
logger.debug("javaHome: " + forkEnvironment.getJavaHome());
logger.debug("systemEnvironment: " + forkEnvironment.getSystemEnvironment());
logger.debug("jvmArguments: " + forkEnvironment.getJVMArguments());
logger.debug("classpath: " + forkEnvironment.getAdditionalClasspath());
logger.debug("envScript: " + forkEnvironment.getEnvScript());
}
logger.debug("--------------------------------------------------");
}
}
}
use of org.ow2.proactive.scheduler.common.task.ScriptTask in project scheduling by ow2-proactive.
the class StaxJobFactory method createTask.
/**
* Fill the given task by the information that are at the given cursorTask.
* Leave the method with the cursor at the end of 'ELEMENT_TASK' tag.
*
* @param cursorTask the streamReader with the cursor on the 'ELEMENT_TASK' tag.
* @return The newly created task that can be any type.
*/
private Task createTask(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
int i = 0;
XMLTags currentTag = null;
String current = null;
String taskName = null;
try {
Task toReturn = null;
Task tmpTask = new Task() {
};
// parse job attributes and fill the temporary one
int attrLen = cursorTask.getAttributeCount();
for (i = 0; i < attrLen; i++) {
String attributeName = cursorTask.getAttributeLocalName(i);
String attributeValue = cursorTask.getAttributeValue(i);
if (XMLAttributes.COMMON_NAME.matches(attributeName)) {
tmpTask.setName(attributeValue);
taskName = attributeValue;
} else if (XMLAttributes.TASK_NB_NODES.matches(attributeName)) {
int numberOfNodesNeeded = Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job)));
tmpTask.setParallelEnvironment(new ParallelEnvironment(numberOfNodesNeeded));
} else if (XMLAttributes.COMMON_CANCEL_JOB_ON_ERROR.matches(attributeName)) {
handleCancelJobOnErrorAttribute(tmpTask, attributeValue);
} else if (XMLAttributes.COMMON_ON_TASK_ERROR.matches(attributeName)) {
tmpTask.setOnTaskError(OnTaskError.getInstance(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.COMMON_RESTART_TASK_ON_ERROR.matches(attributeName)) {
tmpTask.setRestartTaskOnError(RestartMode.getMode(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION.matches(attributeName)) {
tmpTask.setMaxNumberOfExecution(Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_PRECIOUS_RESULT.matches(attributeName)) {
tmpTask.setPreciousResult(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_PRECIOUS_LOGS.matches(attributeName)) {
tmpTask.setPreciousLogs(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_WALLTIME.matches(attributeName)) {
tmpTask.setWallTime(Tools.formatDate(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_RUN_AS_ME.matches(attributeName)) {
tmpTask.setRunAsMe(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
}
}
int eventType;
boolean shouldContinue = true;
while (shouldContinue && cursorTask.hasNext()) {
eventType = cursorTask.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
current = cursorTask.getLocalName();
currentTag = null;
if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
tmpTask.setGenericInformation(getGenericInformation(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.VARIABLES.matches(current)) {
Map<String, TaskVariable> taskVariablesMap = createTaskVariables(cursorTask, tmpTask.getVariablesOverriden(job));
tmpTask.setVariables(taskVariablesMap);
} else if (XMLTags.COMMON_DESCRIPTION.matches(current)) {
tmpTask.setDescription(getDescription(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.DS_INPUT_FILES.matches(current)) {
setIOFIles(cursorTask, XMLTags.DS_INPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
} else if (XMLTags.DS_OUTPUT_FILES.matches(current)) {
setIOFIles(cursorTask, XMLTags.DS_OUTPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
} else if (XMLTags.PARALLEL_ENV.matches(current)) {
tmpTask.setParallelEnvironment(createParallelEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_SELECTION.matches(current)) {
tmpTask.setSelectionScripts(createSelectionScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.FORK_ENVIRONMENT.matches(current)) {
tmpTask.setForkEnvironment(createForkEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_PRE.matches(current)) {
tmpTask.setPreScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_POST.matches(current)) {
tmpTask.setPostScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_CLEANING.matches(current)) {
tmpTask.setCleaningScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.FLOW.matches(current)) {
tmpTask.setFlowScript(createControlFlowScript(cursorTask, tmpTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.TASK_DEPENDENCES.matches(current)) {
currentTag = XMLTags.TASK_DEPENDENCES;
dependencies.putAll(createDependences(cursorTask, tmpTask));
} else if (XMLTags.JAVA_EXECUTABLE.matches(current)) {
toReturn = new JavaTask();
setJavaExecutable((JavaTask) toReturn, cursorTask, tmpTask.getVariablesOverriden(job));
} else if (XMLTags.NATIVE_EXECUTABLE.matches(current)) {
toReturn = new NativeTask();
setNativeExecutable((NativeTask) toReturn, cursorTask);
} else if (XMLTags.SCRIPT_EXECUTABLE.matches(current)) {
toReturn = new ScriptTask();
((ScriptTask) toReturn).setScript(new TaskScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job))));
}
break;
case XMLEvent.END_ELEMENT:
current = cursorTask.getLocalName();
if (XMLTags.TASK.matches(cursorTask.getLocalName())) {
shouldContinue = false;
}
break;
}
}
// fill the real task with common attribute if it is a new one
autoCopyfields(CommonAttribute.class, tmpTask, toReturn);
autoCopyfields(Task.class, tmpTask, toReturn);
if (toReturn != null) {
if (toReturn.getRestartTaskOnErrorProperty().isSet()) {
toReturn.setRestartTaskOnError(toReturn.getRestartTaskOnError());
}
if (toReturn.getMaxNumberOfExecutionProperty().isSet()) {
toReturn.setMaxNumberOfExecution(toReturn.getMaxNumberOfExecution());
}
}
return toReturn;
} catch (JobCreationException jce) {
jce.setTaskName(taskName);
if (currentTag != null) {
jce.pushTag(currentTag);
} else {
jce.pushTag(current);
}
throw jce;
} catch (Exception e) {
String attrtmp = null;
if (cursorTask.isStartElement() && cursorTask.getAttributeCount() > i) {
attrtmp = cursorTask.getAttributeLocalName(i);
}
if (currentTag != null) {
throw new JobCreationException(currentTag, attrtmp, e);
} else {
throw new JobCreationException(current, attrtmp, e);
}
}
}
Aggregations