use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class ValidationUtil method validateJob.
public JobValidationData validateJob(String jobFilePath, Map<String, String> jobVariables) {
JobValidationData data = new JobValidationData();
try {
JobFactory factory = JobFactory.getFactory();
Job job = factory.createJob(jobFilePath, jobVariables);
if (job instanceof TaskFlowJob) {
validateJob((TaskFlowJob) job, data);
fillUpdatedVariables((TaskFlowJob) job, data);
} else {
data.setValid(true);
}
} catch (JobCreationException e) {
data.setTaskName(e.getTaskName());
data.setErrorMessage(e.getMessage());
data.setStackTrace(getStackTrace(e));
}
return data;
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class SchedulerClient method submit.
@Override
public JobId submit(Job job) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
JobIdData jobIdData = null;
try {
InputStream is = (new Job2XMLTransformer()).jobToxml((TaskFlowJob) job);
jobIdData = restApiClient().submitXml(sid, is);
} catch (Exception e) {
throwNCEOrPEOrSCEOrJCE(e);
}
return jobId(jobIdData);
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class AbstractSmartProxy method submit.
/**
* Submits a job to the scheduler and handle data transfer via the SmartProxy
*
* @param job job to submit
* @param localInputFolderPath path to the local directory containing input files
* @param pushUrl url of the dataspace server used to push input files to
* @param localOutputFolderPath path to the local directory which will contain output files
* @param pullUrl url of the dataspace server used to pull output files from
* @param isolateTaskOutputs if set to true, output files from each tasks will be isolated from each other in the dataspace server (to prevent overlapping)
* @param automaticTransfer if set to true, output files will be automatically transferred from the dataspace server to the local machine as soon as the task is finished.
* If set to false, the files will not be automatically transferred and a call to pullData must be done to transfer files
* @return the new job id
* @throws Exception
* @throws SubmissionClosedException
* @throws JobCreationException
*/
public JobId submit(TaskFlowJob job, String localInputFolderPath, String pushUrl, String localOutputFolderPath, String pullUrl, boolean isolateTaskOutputs, boolean automaticTransfer) throws Exception, SubmissionClosedException, JobCreationException {
checkInitialized();
if (isNullOrEmpty(pushUrl)) {
pushUrl = getLocalUserSpace();
}
if (isNullOrEmpty(pullUrl)) {
pullUrl = getLocalUserSpace();
}
String newFolderName = createNewFolderName();
String pushUrlUpdate = prepareJobInput(job, localInputFolderPath, pushUrl, newFolderName);
String pullUrlUpdate = prepareJobOutput(job, localOutputFolderPath, pullUrl, newFolderName, isolateTaskOutputs);
uploadInputfiles(job, localInputFolderPath);
JobId id = null;
try {
id = submit(job);
} catch (Exception e) {
log.error("Error while submitting job", e);
try {
removeJobIO(job, pushUrl, pullUrl, newFolderName);
} catch (Exception e2) {
log.error("Error while removing job IO", e2);
}
propagateIfInstanceOf(e, NotConnectedException.class);
propagateIfInstanceOf(e, PermissionException.class);
propagateIfInstanceOf(e, SubmissionClosedException.class);
propagateIfInstanceOf(e, JobCreationException.class);
propagateIfInstanceOf(e, RuntimeException.class);
propagate(e);
}
HashMap<String, AwaitedTask> awaitedTaskMap = new HashMap<>();
for (Task t : job.getTasks()) {
awaitedTaskMap.put(t.getName(), new AwaitedTask(t.getName(), t.getOutputFilesList()));
}
AwaitedJob awaitedJob = new AwaitedJob(id.toString(), localInputFolderPath, job.getInputSpace(), pushUrlUpdate, localOutputFolderPath, job.getOutputSpace(), pullUrlUpdate, isolateTaskOutputs, automaticTransfer, awaitedTaskMap);
jobTracker.putAwaitedJob(id.toString(), awaitedJob);
return id;
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class InternalJobFactory method createJob.
/**
* Create an internalTaskFlow job with the given task flow job (user)
*
* @param userJob the user job that will be used to create the internal job.
* @return the created internal job.
* @throws JobCreationException an exception if the factory cannot create the given job.
*/
private static InternalJob createJob(TaskFlowJob userJob) throws JobCreationException {
if (userJob.getTasks().size() == 0) {
logger.info("Job '" + userJob.getName() + "' must contain tasks !");
throw new JobCreationException("This job must contains tasks !");
}
// validate taskflow
List<FlowChecker.Block> blocks = new ArrayList<>();
FlowError err = FlowChecker.validate(userJob, blocks);
if (err != null) {
String e = "";
e += "Invalid taskflow: " + err.getMessage() + "; context: " + err.getTask();
logger.error(e);
throw new JobCreationException(e, err);
}
InternalJob job = new InternalTaskFlowJob();
// keep an initial job content
job.setTaskFlowJob(userJob);
Map<Task, InternalTask> tasksList = new LinkedHashMap<>();
boolean hasPreciousResult = false;
for (Task t : userJob.getTasks()) {
tasksList.put(t, createTask(userJob, job, t));
if (!hasPreciousResult) {
hasPreciousResult = t.isPreciousResult();
}
}
for (Entry<Task, InternalTask> entry : tasksList.entrySet()) {
if (entry.getKey().getDependencesList() != null) {
for (Task t : entry.getKey().getDependencesList()) {
entry.getValue().addDependence(tasksList.get(t));
}
}
job.addTask(entry.getValue());
}
// tag matching blocks in InternalTasks
for (InternalTask it : tasksList.values()) {
for (FlowChecker.Block block : blocks) {
if (it.getName().equals(block.start.element.getName())) {
it.setMatchingBlock(block.end.element.getName());
}
if (it.getName().equals(block.end.element.getName())) {
it.setMatchingBlock(block.start.element.getName());
}
}
}
// create if/else/join weak dependencies
for (InternalTask it : tasksList.values()) {
// it performs an IF action
if (it.getFlowScript() != null && it.getFlowScript().getActionType().equals(FlowActionType.IF.toString())) {
String ifBranch = it.getFlowScript().getActionTarget();
String elseBranch = it.getFlowScript().getActionTargetElse();
String join = it.getFlowScript().getActionContinuation();
List<InternalTask> joinedBranches = new ArrayList<>();
// find the ifBranch task
for (InternalTask it2 : tasksList.values()) {
if (it2.getName().equals(ifBranch)) {
it2.setIfBranch(it);
String match = it2.getMatchingBlock();
// find its matching block task
if (match == null) {
// no match: single task
joinedBranches.add(it2);
} else {
for (InternalTask it3 : tasksList.values()) {
if (it3.getName().equals(match)) {
joinedBranches.add(it3);
break;
}
}
}
break;
}
}
// find the elseBranch task
for (InternalTask it2 : tasksList.values()) {
if (it2.getName().equals(elseBranch)) {
it2.setIfBranch(it);
String match = it2.getMatchingBlock();
// find its matching block task
if (match == null) {
// no match: single task
joinedBranches.add(it2);
} else {
for (InternalTask it3 : tasksList.values()) {
if (it3.getName().equals(match)) {
joinedBranches.add(it3);
break;
}
}
}
break;
}
}
// find the joinBranch task
for (InternalTask it2 : tasksList.values()) {
if (it2.getName().equals(join)) {
it2.setJoinedBranches(joinedBranches);
}
}
}
}
return job;
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class InternalJobFactory method createTask.
private static InternalTask createTask(Job userJob, InternalJob internalJob, ScriptTask task) throws JobCreationException {
InternalTask scriptTask;
if (isForkingTask()) {
scriptTask = new InternalForkedScriptTask(new ScriptExecutableContainer(task.getScript()), internalJob);
configureRunAsMe(task);
} else {
scriptTask = new InternalScriptTask(new ScriptExecutableContainer(task.getScript()), internalJob);
}
// set task common properties
try {
setTaskCommonProperties(userJob, task, scriptTask);
} catch (Exception e) {
throw new JobCreationException(e);
}
return scriptTask;
}
Aggregations