Search in sources :

Example 41 with JobCreationException

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;
}
Also used : JobFactory(org.ow2.proactive.scheduler.common.job.factories.JobFactory) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobValidationData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData) Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob)

Example 42 with JobCreationException

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);
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) Job2XMLTransformer(org.ow2.proactive.scheduler.common.job.factories.Job2XMLTransformer) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)

Example 43 with JobCreationException

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;
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) Task(org.ow2.proactive.scheduler.common.task.Task) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) HashMap(java.util.HashMap) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) LoginException(javax.security.auth.login.LoginException) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 44 with JobCreationException

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;
}
Also used : FlowError(org.ow2.proactive.scheduler.common.job.factories.FlowError) Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) LinkedHashMap(java.util.LinkedHashMap) FlowChecker(org.ow2.proactive.scheduler.common.job.factories.FlowChecker)

Example 45 with JobCreationException

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;
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Aggregations

JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)37 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)21 FileNotFoundException (java.io.FileNotFoundException)20 XMLStreamException (javax.xml.stream.XMLStreamException)20 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)20 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)13 LinkedHashMap (java.util.LinkedHashMap)10 HashMap (java.util.HashMap)9 Job (org.ow2.proactive.scheduler.common.job.Job)9 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)7 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)6 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)6 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)6 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)6 File (java.io.File)5 IOException (java.io.IOException)5