Search in sources :

Example 26 with JobVariable

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

the class TaskResultCreatorTest method getMockedInternalJobTaskFlowType.

private InternalJob getMockedInternalJobTaskFlowType(JobDescriptorImpl mockedJobDescriptor) {
    InternalJob mockedInternalJob = mock(InternalJob.class);
    when(mockedInternalJob.getJobDescriptor()).thenReturn(mockedJobDescriptor);
    when(mockedInternalJob.getType()).thenReturn(JobType.TASKSFLOW);
    when(mockedInternalJob.getVariables()).thenReturn(new HashMap<String, JobVariable>());
    return mockedInternalJob;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 27 with JobVariable

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

the class SchedulerEfficiencyMetricsTest method createJob.

public static TaskFlowJob createJob(int taskNumber, int taskDuration) throws Exception {
    final TaskFlowJob job = new TaskFlowJob();
    job.setName(String.format("EP_%d_NO_MERGE_%dSEC", taskNumber, taskDuration));
    job.setOnTaskError(OnTaskError.CANCEL_JOB);
    job.getVariables().put(OPTIMAL_JOB_DURATION, new JobVariable(OPTIMAL_JOB_DURATION, String.valueOf(taskDuration)));
    for (int i = 0; i < taskNumber; i++) {
        ScriptTask task = new ScriptTask();
        task.setName("process_" + i);
        task.setScript(new TaskScript(new SimpleScript(String.format("Thread.sleep(%s)", taskDuration), "groovy")));
        job.addTask(task);
    }
    return job;
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 28 with JobVariable

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

the class SignalApiTest method testReadyForSignalWithVariables.

@Test
public void testReadyForSignalWithVariables() throws SignalApiException, InvalidChannelException {
    String signalName = "test_signal_1";
    JobVariable jobVariable1 = new JobVariable("name1", "value1");
    JobVariable jobVariable2 = new JobVariable("name2", "value2");
    List<JobVariable> jobVariables = new ArrayList<>();
    jobVariables.add(jobVariable1);
    jobVariables.add(jobVariable2);
    signalApi.readyForSignal(signalName, jobVariables);
    Assert.assertTrue(((Signal) synchronizationInternal.get(USER, TASK_ID, SIGNALS_CHANNEL + JOB_ID.value(), READY_PREFIX + signalName)).getName().equals(signalName));
    Assert.assertNotNull((synchronizationInternal.get(USER, TASK_ID, SIGNALS_CHANNEL + JOB_ID.value(), READY_PREFIX + signalName)));
    Assert.assertEquals(jobVariables, ((Signal) synchronizationInternal.get(USER, TASK_ID, SIGNALS_CHANNEL + JOB_ID.value(), READY_PREFIX + signalName)).getInputVariables());
}
Also used : JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 29 with JobVariable

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

the class DefaultModelJobValidatorServiceProvider method checkVariableFormat.

protected void checkVariableFormat(Task task, JobVariable variable, ModelValidatorContext context) throws JobValidationException {
    if (variable.getModel() != null && !variable.getModel().trim().isEmpty()) {
        String model = variable.getModel().trim();
        context.setVariableName(variable.getName());
        try {
            new ModelValidator(model).validate(variable.getValue(), context, variable.isHidden());
        } catch (Exception e) {
            throw new JobValidationException((task != null ? "Task '" + task.getName() + "': " : "") + "Variable '" + variable.getName() + "': Model " + variable.getModel() + ": " + e.getMessage(), e);
        }
    }
}
Also used : ModelValidator(org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.ModelValidator) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException)

Example 30 with JobVariable

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

the class SchedulerFrontend method validateJobSignal.

@Override
@ImmediateService
public List<JobVariable> validateJobSignal(String jobId, String signalName, Map<String, String> updatedVariables) throws NotConnectedException, UnknownJobException, PermissionException, SignalApiException, JobValidationException {
    if (updatedVariables == null || updatedVariables.isEmpty()) {
        return null;
    }
    String currentUser = frontendState.getCurrentUser();
    logger.debug("Request to validate signal " + signalName + " on job " + jobId + " received from " + currentUser);
    final JobId jobIdObject = JobIdImpl.makeJobId(jobId);
    frontendState.checkPermissions("addJobSignal", frontendState.getIdentifiedJob(jobIdObject), YOU_DO_NOT_HAVE_PERMISSION_TO_SEND_SIGNALS_TO_THIS_JOB);
    String readyPrefix = SignalApiImpl.READY_PREFIX;
    if (StringUtils.isBlank(signalName.trim())) {
        throw new SignalApiException("Empty signals are not allowed");
    }
    try {
        TaskId taskId = createFakeTaskId(jobId);
        publicStore.createChannelIfAbsent(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, true);
        Signal signal = (Signal) publicStore.get(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobId, readyPrefix + signalName);
        if (signal != null) {
            DefaultModelJobValidatorServiceProvider validatorServiceProvider = new DefaultModelJobValidatorServiceProvider();
            Map<String, Serializable> serializableUpdatedVariables = new LinkedHashMap<>();
            serializableUpdatedVariables.putAll(updatedVariables);
            validatorServiceProvider.validateVariables(signal.getInputVariables(), serializableUpdatedVariables, this, this);
            return signal.getInputVariables();
        } else {
            throw new SignalApiException("Signal not found");
        }
    } catch (InvalidChannelException e) {
        throw new SignalApiException("Could not read signals channel", e);
    } catch (IOException e) {
        throw new SignalApiException("Could not add signalName for the job " + jobId, e);
    }
}
Also used : InvalidChannelException(org.ow2.proactive.scheduler.synchronization.InvalidChannelException) Signal(org.ow2.proactive.scheduler.signal.Signal) DefaultModelJobValidatorServiceProvider(org.ow2.proactive.scheduler.common.job.factories.spi.model.DefaultModelJobValidatorServiceProvider) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) SignalApiException(org.ow2.proactive.scheduler.signal.SignalApiException) JobId(org.ow2.proactive.scheduler.common.job.JobId) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Aggregations

JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)51 Test (org.junit.Test)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)17 HashMap (java.util.HashMap)15 LinkedHashMap (java.util.LinkedHashMap)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 JobId (org.ow2.proactive.scheduler.common.job.JobId)8 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)7 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)6 Task (org.ow2.proactive.scheduler.common.task.Task)6 TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)6 IOException (java.io.IOException)5 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)5 SimpleScript (org.ow2.proactive.scripting.SimpleScript)5 TaskScript (org.ow2.proactive.scripting.TaskScript)5 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)4 SimpleJob (functionaltests.jobs.SimpleJob)4 FileNotFoundException (java.io.FileNotFoundException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)4