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;
}
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;
}
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());
}
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);
}
}
}
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);
}
}
Aggregations