Search in sources :

Example 61 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 62 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class SchedulerStateRecoverHelperTest method createJob.

private InternalJob createJob(String workflowDescriptor, JobStatus jobStatus) throws JobCreationException, KeyException {
    Job job = JOB_FACTORY.createJob(this.getClass().getResource("/workflow/descriptors/" + workflowDescriptor).getPath());
    InternalJob internalJob = InternalJobFactory.createJob(job, null);
    internalJob.setStatus(jobStatus);
    internalJob.setOwner("toto");
    return internalJob;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) Job(org.ow2.proactive.scheduler.common.job.Job) InternalJob(org.ow2.proactive.scheduler.job.InternalJob)

Example 63 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class WorkflowSubmitter method submit.

/**
 * Submits a workflow to the scheduler (XML or archive).
 * It also creates a job visualization HTML file.
 *
 * @param workflowStream a workflow as input stream
 * @param variables variables to be replaced on submission
 * @param genericInfos generic informations to be replaced on submission
 * @return job ID of the job created for the specified workflow and associated variables.
 * @throws JobCreationRestException
 * @throws NotConnectedRestException
 * @throws PermissionRestException
 * @throws SubmissionClosedRestException
 */
public JobId submit(InputStream workflowStream, Map<String, String> variables, Map<String, String> genericInfos) throws NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, JobCreationRestException {
    try {
        long t0 = System.currentTimeMillis();
        Job job = createJobObject(workflowStream, variables, genericInfos);
        long t1 = System.currentTimeMillis();
        JobId jobId = scheduler.submit(job);
        long t2 = System.currentTimeMillis();
        // Create Job's SVG visualization file
        String visualization = job.getVisualization();
        File visualizationFile = new File(PortalConfiguration.jobIdToPath(jobId.value()) + ".html");
        long t3 = System.currentTimeMillis();
        Files.deleteIfExists(visualizationFile.toPath());
        if (visualization != null && !visualization.isEmpty()) {
            FileUtils.write(new File(visualizationFile.getAbsolutePath()), job.getVisualization(), Charset.forName(FILE_ENCODING));
        }
        long d1 = t1 - t0;
        long d2 = t2 - t1;
        long d3 = t3 - t2;
        logger.debug(String.format("timer;%d;%d;%d;%d", jobId.longValue(), d1, d2, d3));
        return jobId;
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (SubmissionClosedException e) {
        logger.warn("Could not submit job", e);
        throw new SubmissionClosedRestException(e);
    } catch (JobCreationException e) {
        logger.warn("Could not submit job", e);
        throw new JobCreationRestException(e);
    } catch (Exception e) {
        logger.warn("Unexpected error when submitting job", e);
        throw new JobCreationRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) 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) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) Job(org.ow2.proactive.scheduler.common.job.Job) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 64 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class TestStaxJobFactory method testJobCreationAttributeOrderDefinitionVariableXmlElement.

@Test
public void testJobCreationAttributeOrderDefinitionVariableXmlElement() throws URISyntaxException, JobCreationException {
    GlobalVariablesParser.setConfigurationPath(GlobalVariablesParserTest.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/globalvariables/global_variables_default.xml").toExternalForm());
    GlobalVariablesParser.getInstance().reloadFilters();
    Job job = factory.createJob(jobDescriptorAttrDefVariableXmlElement);
    Map<String, JobVariable> jobVariables = job.getVariables();
    assertEquals(2, jobVariables.size());
    JobVariable jobVariable = jobVariables.get("name1");
    assertNotNull(jobVariable);
    assertEquals("name1", jobVariable.getName());
    assertEquals("value1", jobVariable.getValue());
    assertEquals("model1", jobVariable.getModel());
    jobVariable = jobVariables.get("name2");
    assertNotNull(jobVariable);
    assertEquals("name2", jobVariable.getName());
    assertEquals("value2", jobVariable.getValue());
    assertEquals("model2", jobVariable.getModel());
}
Also used : Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) GlobalVariablesParserTest(org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesParserTest) Test(org.junit.Test)

Example 65 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class TestStaxJobFactory method testUnresolvedGenericInformation.

@Test
public void testUnresolvedGenericInformation() throws URISyntaxException, JobCreationException {
    TaskFlowJob job = (TaskFlowJob) factory.createJob(jobDescriptorWithUnresolvedGenericInfoAndVariables);
    Map<String, String> unresolvedGenericInformation = job.getUnresolvedGenericInformation();
    Map<String, String> genericInformation = job.getGenericInformation();
    assertEquals("${variable1}", unresolvedGenericInformation.get("info1"));
    assertEquals("value1", genericInformation.get("info1"));
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) GlobalVariablesParserTest(org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesParserTest) Test(org.junit.Test)

Aggregations

JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)51 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)30 FileNotFoundException (java.io.FileNotFoundException)29 XMLStreamException (javax.xml.stream.XMLStreamException)29 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 IOException (java.io.IOException)24 LinkedHashMap (java.util.LinkedHashMap)16 Job (org.ow2.proactive.scheduler.common.job.Job)16 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)12 HashMap (java.util.HashMap)11 Test (org.junit.Test)10 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)9 GlobalVariablesParserTest (org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesParserTest)9 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)8 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)8 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)8 ArrayList (java.util.ArrayList)7 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)7 Task (org.ow2.proactive.scheduler.common.task.Task)7