Search in sources :

Example 1 with JobFactory

use of org.ow2.proactive.scheduler.common.job.factories.JobFactory in project scheduling by ow2-proactive.

the class ValidationUtil method validateJob.

public static JobValidationData validateJob(String jobFilePath, Map<String, String> jobVariables, Scheduler scheduler, SchedulerSpaceInterface space, String sessionId) {
    JobValidationData data = new JobValidationData();
    Job job = null;
    try {
        JobFactory factory = JobFactory.getFactory();
        job = factory.createJob(jobFilePath, jobVariables, null, scheduler, space, sessionId);
        if (job instanceof TaskFlowJob) {
            fillUpdatedVariables((TaskFlowJob) job, data);
            validateJob((TaskFlowJob) job, data);
        } else {
            data.setValid(true);
        }
    } catch (JobCreationException e) {
        data.setTaskName(e.getTaskName());
        setJobValidationDataErrorMessage(data, 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 2 with JobFactory

use of org.ow2.proactive.scheduler.common.job.factories.JobFactory 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 3 with JobFactory

use of org.ow2.proactive.scheduler.common.job.factories.JobFactory in project scheduling by ow2-proactive.

the class JobFactory method getFactory.

/**
 * Try to instantiate the known factories.
 * Return the created instance of the jobFactory.
 * As it may instantiate built'in factories, this method rarely fails but a RuntimeException is raised if
 * no factory can be found.
 * @param handleGlobalVariables if global variables should be handled by the job factory
 *
 * @return the instance of the jobFactory.
 */
public static JobFactory getFactory(boolean handleGlobalVariables) {
    JobFactory factory = null;
    for (String factoryInstance : CURRENT_IMPL) {
        try {
            ClassLoader cl = JobFactory.class.getClassLoader();
            Class c = cl.loadClass(factoryInstance);
            Constructor constructor = c.getConstructor(Boolean.TYPE);
            factory = (JobFactory) constructor.newInstance(handleGlobalVariables);
            break;
        } catch (ClassNotFoundException e) {
            logger.warn("Cannot instanciate this factory : " + factoryInstance, e);
        } catch (Exception e) {
            logger.warn("Error while instanciating this factory : " + factoryInstance, e);
        }
    }
    if (factory == null) {
        throw new RuntimeException("Cannot instanciate any factory ! (see WARN logs to know why)");
    }
    return factory;
}
Also used : Constructor(java.lang.reflect.Constructor) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException)

Example 4 with JobFactory

use of org.ow2.proactive.scheduler.common.job.factories.JobFactory in project scheduling by ow2-proactive.

the class JobFactory method getFactory.

/**
 * Try to instantiate the given factory.
 * Return the created instance of the jobFactory.
 * If the factory is not found or not created, a runtime exception is raised.
 * @param handleGlobalVariables if global variables should be handled by the job factory
 *
 * @return the instance of the required factory.
 */
public static JobFactory getFactory(String impl, boolean handleGlobalVariables) {
    if (impl == null) {
        return getFactory(handleGlobalVariables);
    }
    JobFactory factory;
    try {
        Class c = Class.forName(impl);
        Constructor constructor = c.getConstructor(Boolean.TYPE);
        factory = (JobFactory) constructor.newInstance(handleGlobalVariables);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Cannot instanciate this factory : " + impl, e);
    } catch (Exception e) {
        throw new RuntimeException("Error while instanciating this factory : " + impl, e);
    }
    return factory;
}
Also used : Constructor(java.lang.reflect.Constructor) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException)

Example 5 with JobFactory

use of org.ow2.proactive.scheduler.common.job.factories.JobFactory in project scheduling by ow2-proactive.

the class ValidationUtil method validateJob.

public static JobValidationData validateJob(InputStream jobInputStream, Map<String, String> jobVariables, Scheduler scheduler, SchedulerSpaceInterface space, String sessionId) {
    JobValidationData data = new JobValidationData();
    Job job = null;
    try {
        JobFactory factory = JobFactory.getFactory();
        job = factory.createJob(jobInputStream, jobVariables, null, scheduler, space, sessionId);
        if (job instanceof TaskFlowJob) {
            fillUpdatedVariables((TaskFlowJob) job, data);
            validateJob((TaskFlowJob) job, data);
        } else {
            data.setValid(true);
        }
    } catch (JobCreationException e) {
        data.setTaskName(e.getTaskName());
        setJobValidationDataErrorMessage(data, 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)

Aggregations

JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)5 Job (org.ow2.proactive.scheduler.common.job.Job)3 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 JobFactory (org.ow2.proactive.scheduler.common.job.factories.JobFactory)3 JobValidationData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData)3 Constructor (java.lang.reflect.Constructor)2 File (java.io.File)1 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1