use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.
the class SchedulerFrontend method insertJobSignals.
private JobInfo insertJobSignals(JobInfo jobInfo) {
String jobid = jobInfo.getJobId().value();
if (checkJobPermissionMethod(jobid, "addJobSignal")) {
try {
TaskId taskId = createFakeTaskId(jobInfo.getJobId().value());
if (publicStore.channelExists(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobid)) {
Set<Map.Entry<String, Serializable>> signalEntries = publicStore.entrySet(SIGNAL_ORIGINATOR, taskId, signalsChannel + jobid);
Set<String> signalsToBeAdded = signalEntries.stream().map(entry -> entry.getKey()).collect(Collectors.toSet());
List<Signal> signalList = signalEntries.stream().map(entry -> (Signal) entry.getValue()).collect(Collectors.toList());
Map<String, Map<String, JobVariable>> detailedSignalsToBeAdded = new LinkedHashMap<>();
signalList.forEach(signal -> {
Map<String, JobVariable> variableMap = new LinkedHashMap<>();
if (signal.getInputVariables() != null) {
signal.getInputVariables().forEach(jobVariable -> variableMap.put(jobVariable.getName(), jobVariable));
}
detailedSignalsToBeAdded.put(signal.getName(), variableMap);
});
Set<String> jobSignals = jobInfo.getSignals();
Map<String, Map<String, JobVariable>> jobDetailedSignals = jobInfo.getDetailedSignals();
if (signalsToBeAdded != null && !signalsToBeAdded.isEmpty()) {
jobSignals.addAll(signalsToBeAdded);
jobInfo.setSignals(jobSignals);
}
if (detailedSignalsToBeAdded != null && !detailedSignalsToBeAdded.isEmpty()) {
jobDetailedSignals.putAll(detailedSignalsToBeAdded);
jobInfo.setDetailedSignals(jobDetailedSignals);
}
}
} catch (InvalidChannelException e) {
logger.warn("Could not retrieve the signals of the job " + jobid);
}
}
return jobInfo;
}
use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.
the class TerminationData method getStringSerializableMap.
public VariablesMap getStringSerializableMap(SchedulingService service, TaskTerminationData taskToTerminate) throws Exception {
VariablesMap variablesMap = new VariablesMap();
RunningTaskData taskData = taskToTerminate.taskData;
TaskResultImpl taskResult = taskToTerminate.taskResult;
InternalJob internalJob = taskToTerminate.internalJob;
if (taskToTerminate.terminationStatus == ABORTED || taskResult == null) {
List<InternalTask> iDependences = taskData.getTask().getIDependences();
if (iDependences != null) {
taskData.getTask().updateParentTasksResults(service);
getResultsFromListOfTaskResults(variablesMap.getInheritedMap(), taskData.getTask().getParentTasksResults());
} else {
if (internalJob != null) {
for (Map.Entry<String, JobVariable> jobVariableEntry : internalJob.getVariables().entrySet()) {
variablesMap.getInheritedMap().put(jobVariableEntry.getKey(), jobVariableEntry.getValue().getValue());
}
}
}
variablesMap.getInheritedMap().put(SchedulerVars.PA_TASK_SUCCESS.toString(), Boolean.toString(false));
} else if (taskResult.hadException()) {
variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, false));
} else {
variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, true));
}
variablesMap.setScopeMap(getNonInheritedScopeVariables(variablesMap.getInheritedMap(), taskData.getTask().getScopeVariables(), taskData.getTask().getVariables()));
return variablesMap;
}
use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.
the class JobData method toInternalJob.
InternalJob toInternalJob() {
JobId jobIdInstance = new JobIdImpl(getId(), getJobName());
JobInfoImpl jobInfo = createJobInfo(jobIdInstance);
InternalJob internalJob = new InternalTaskFlowJob();
internalJob.setCredentials(getCredentials());
internalJob.setJobInfo(jobInfo);
internalJob.setParentId(getParentId());
internalJob.setGenericInformation(getGenericInformation());
internalJob.setVariables(variablesToJobVariables());
internalJob.setProjectName(getProjectName());
internalJob.setOwner(getOwner());
internalJob.setDescription(getDescription());
internalJob.setInputSpace(getInputSpace());
internalJob.setOutputSpace(getOutputSpace());
internalJob.setGlobalSpace(getGlobalSpace());
internalJob.setUserSpace(getGlobalSpace());
internalJob.setMaxNumberOfExecution(getMaxNumberOfExecution());
internalJob.setOnTaskError(OnTaskError.getInstance(this.onTaskErrorString));
if (getTaskRetryDelay() != null) {
internalJob.setTaskRetryDelay(getTaskRetryDelay());
}
internalJob.setScheduledTimeForRemoval(getScheduledTimeForRemoval());
try {
internalJob.setResultMap(SerializationUtil.deserializeVariableMap(getResultMap()));
} catch (IOException | ClassNotFoundException e) {
logger.error("error when serializing result map variables " + e);
}
List<JobContent> jobContentList = getJobContent();
if (jobContentList != null && jobContentList.size() > 0) {
internalJob.setJobContent(jobContentList.get(0).getInitJobContent());
if (internalJob.getJobContent() != null) {
GlobalVariablesData globalVariablesData = GlobalVariablesParser.getInstance().getVariablesFor(internalJob.getJobContent());
Map<String, JobVariable> globalVariables = new LinkedHashMap<>();
Map<String, JobVariable> configuredGlobalVariables = globalVariablesData.getVariables();
for (String variableName : configuredGlobalVariables.keySet()) {
if (internalJob.getVariables().containsKey(variableName)) {
globalVariables.put(variableName, internalJob.getVariables().get(variableName));
} else {
globalVariables.put(variableName, configuredGlobalVariables.get(variableName));
}
}
internalJob.setGlobalVariables(globalVariables);
Map<String, String> globalGenericInfo = new LinkedHashMap<>();
Map<String, String> configuredGlobalGenericInfo = globalVariablesData.getGenericInformation();
for (String giName : configuredGlobalGenericInfo.keySet()) {
if (internalJob.getGenericInformation().containsKey(giName)) {
globalGenericInfo.put(giName, internalJob.getGenericInformation().get(giName));
} else {
globalGenericInfo.put(giName, configuredGlobalGenericInfo.get(giName));
}
}
internalJob.setGlobalGenericInformation(globalGenericInfo);
}
}
return internalJob;
}
use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.
the class JobData method jobDataVariableToTaskVariable.
private static JobVariable jobDataVariableToTaskVariable(JobDataVariable jobDataVariable) {
if (jobDataVariable == null) {
return null;
}
JobVariable jobVariable = new JobVariable();
jobVariable.setModel(jobDataVariable.getModel());
jobVariable.setValue(jobDataVariable.getValue());
jobVariable.setName(jobDataVariable.getName());
jobVariable.setDescription(jobDataVariable.getDescription());
jobVariable.setGroup(jobDataVariable.getGroup());
jobVariable.setAdvanced(jobDataVariable.getAdvanced());
return jobVariable;
}
use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.
the class TaskResultCreatorTest method testThatJobVariablesAreUsedIfTaskHasNoParents.
@Test
public void testThatJobVariablesAreUsedIfTaskHasNoParents() throws UnknownTaskException {
TaskResultCreator taskResultCreator = new TaskResultCreator();
SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenThrow(new DatabaseManagerException());
InternalJob mockedInternalJob = this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTaskWithoutParent());
Map<String, JobVariable> fakeVariableMap = new HashMap<>();
fakeVariableMap.put("TestVar", new JobVariable("TestVar", "h234"));
when(mockedInternalJob.getVariables()).thenReturn(fakeVariableMap);
Map<String, String> fakeReplacementVariableMap = new HashMap<>();
fakeReplacementVariableMap.put("TestVar", "h234");
when(mockedInternalJob.getVariablesAsReplacementMap()).thenReturn(fakeReplacementVariableMap);
TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, mockedInternalJob, this.getMockedInternalTask());
verify(mockedInternalJob, atLeastOnce()).getVariablesAsReplacementMap();
assertThat(new String(taskResult.getPropagatedVariables().get("TestVar")), is("h234"));
}
Aggregations