use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.
the class SchedulerDBManager method saveSingleTaskDependencies.
private void saveSingleTaskDependencies(Session session, InternalTask task, TaskData taskRuntimeData) {
if (task.hasDependences()) {
List<DBTaskId> dependencies = new ArrayList<>(task.getDependences().size());
for (Task dependency : task.getDependences()) {
dependencies.add(taskId((InternalTask) dependency));
}
taskRuntimeData.setDependentTasks(dependencies);
} else {
taskRuntimeData.setDependentTasks(Collections.<DBTaskId>emptyList());
}
if (task.getIfBranch() != null) {
InternalTask ifBranch = task.getIfBranch();
taskRuntimeData.setIfBranch(getTaskReference(session, ifBranch));
} else {
taskRuntimeData.setIfBranch(null);
}
if (task.getJoinedBranches() != null && !task.getJoinedBranches().isEmpty()) {
List<DBTaskId> joinedBranches = new ArrayList<>(task.getJoinedBranches().size());
for (InternalTask joinedBranch : task.getJoinedBranches()) {
joinedBranches.add(taskId(joinedBranch));
}
taskRuntimeData.setJoinedBranches(joinedBranches);
} else {
taskRuntimeData.setJoinedBranches(Collections.<DBTaskId>emptyList());
}
}
use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.
the class SchedulerDBManager method toInternalTasks.
private Collection<InternalTask> toInternalTasks(boolean loadFullState, InternalJob internalJob, List<TaskData> taskRuntimeDataList) {
Map<DBTaskId, InternalTask> tasks = new HashMap<>(taskRuntimeDataList.size());
try {
for (TaskData taskData : taskRuntimeDataList) {
InternalTask internalTask = taskData.toInternalTask(internalJob, loadFullState);
if (loadFullState) {
internalTask.setParallelEnvironment(taskData.getParallelEnvironment());
internalTask.setGenericInformation(taskData.getGenericInformation());
for (SelectionScriptData scriptData : taskData.getSelectionScripts()) {
internalTask.addSelectionScript(scriptData.createSelectionScript());
}
if (taskData.getCleanScript() != null) {
internalTask.setCleaningScript(taskData.getCleanScript().createSimpleScript());
}
if (taskData.getPreScript() != null) {
internalTask.setPreScript(taskData.getPreScript().createSimpleScript());
}
if (taskData.getPostScript() != null) {
internalTask.setPostScript(taskData.getPostScript().createSimpleScript());
}
if (taskData.getFlowScript() != null) {
internalTask.setFlowScript(taskData.getFlowScript().createFlowScript());
}
for (SelectorData selectorData : taskData.getDataspaceSelectors()) {
if (selectorData.isInput()) {
InputSelector selector = selectorData.createInputSelector();
internalTask.addInputFiles(selector.getInputFiles(), selector.getMode());
} else {
OutputSelector selector = selectorData.createOutputSelector();
internalTask.addOutputFiles(selector.getOutputFiles(), selector.getMode());
}
}
}
tasks.put(taskData.getId(), internalTask);
}
} catch (InvalidScriptException e) {
throw new DatabaseManagerException("Failed to initialize loaded script", e);
}
for (TaskData taskData : taskRuntimeDataList) {
InternalTask internalTask = tasks.get(taskData.getId());
if (!taskData.getDependentTasks().isEmpty()) {
for (DBTaskId dependent : taskData.getDependentTasks()) {
internalTask.addDependence(tasks.get(dependent));
}
}
if (loadFullState) {
if (taskData.getIfBranch() != null) {
internalTask.setIfBranch(tasks.get(taskData.getIfBranch().getId()));
}
if (!taskData.getJoinedBranches().isEmpty()) {
List<InternalTask> branches = new ArrayList<>(taskData.getJoinedBranches().size());
for (DBTaskId joinedBranch : taskData.getJoinedBranches()) {
branches.add(tasks.get(joinedBranch));
}
internalTask.setJoinedBranches(branches);
}
internalTask.setName(internalTask.getName());
}
}
return tasks.values();
}
use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.
the class SchedulerDBManager method loadTaskResult.
@SuppressWarnings("unchecked")
private TaskResult loadTaskResult(Session session, TaskId taskId, int resultIndex) {
DBTaskId dbTaskId = taskId(taskId);
TaskData task = session.load(TaskData.class, dbTaskId);
Query query = session.getNamedQuery("loadTasksResultByTask").setParameter("task", task);
query.setMaxResults(1);
query.setFirstResult(resultIndex);
List<TaskResultData> results = (List<TaskResultData>) query.list();
if (results.isEmpty()) {
return null;
} else {
return results.get(0).toTaskResult(taskId);
}
}
use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.
the class SchedulerDBManager method loadJobResult.
@SuppressWarnings("unchecked")
private JobResultImpl loadJobResult(Session session, Query query, JobData job, JobId jobId) {
JobResultImpl jobResult = new JobResultImpl();
jobResult.setJobInfo(job.createJobInfo(jobId));
DBTaskId currentTaskId = null;
List<Object[]> resultList = (List<Object[]>) query.list();
if (resultList.isEmpty()) {
return jobResult;
}
int counter = 0;
for (Object[] result : resultList) {
TaskResultData resultData = (TaskResultData) result[0];
DBTaskId dbTaskId = (DBTaskId) result[1];
String taskName = (String) result[2];
Boolean preciousResult = (Boolean) result[3];
boolean nextTask = !dbTaskId.equals(currentTaskId);
if (nextTask) {
TaskId taskId = TaskIdImpl.createTaskId(jobId, taskName, dbTaskId.getTaskId());
jobResult.addTaskResult(taskName, resultData.toTaskResult(taskId), preciousResult);
currentTaskId = dbTaskId;
}
if (++counter % 100 == 0) {
session.clear();
}
}
return jobResult;
}
use of org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId in project scheduling by ow2-proactive.
the class TaskData method createTaskData.
static TaskData createTaskData(JobData jobRuntimeData, InternalScriptTask task) {
TaskData taskData = new TaskData();
TaskData.DBTaskId taskId = new DBTaskId();
taskId.setJobId(jobRuntimeData.getId());
taskId.setTaskId(task.getTaskInfo().getTaskId().longValue());
taskData.setId(taskId);
taskData.setDescription(task.getDescription());
taskData.setTag(task.getTag());
taskData.setParallelEnvironment(task.getParallelEnvironment());
taskData.setFlowBlock(task.getFlowBlock());
taskData.setRestartMode(task.getRestartTaskOnError());
taskData.setPreciousLogs(task.isPreciousLogs());
taskData.setPreciousResult(task.isPreciousResult());
taskData.setRunAsMe(task.isRunAsMe());
taskData.setWallTime(task.getWallTime());
taskData.setOnTaskErrorString(task.getOnTaskErrorProperty().getValue());
taskData.setMaxNumberOfExecution(task.getMaxNumberOfExecution());
taskData.setJobData(jobRuntimeData);
taskData.setNumberOfExecutionOnFailureLeft(PASchedulerProperties.NUMBER_OF_EXECUTION_ON_FAILURE.getValueAsInt());
taskData.setNumberOfExecutionLeft(task.getMaxNumberOfExecution());
taskData.setGenericInformation(task.getGenericInformation());
HashMap<String, TaskDataVariable> variables = new HashMap<>();
for (Map.Entry<String, TaskVariable> entry : task.getVariables().entrySet()) {
variables.put(entry.getKey(), TaskDataVariable.create(entry.getKey(), entry.getValue(), taskData));
}
taskData.setVariables(variables);
// set the scheduledTime if the START_AT property exists
Map<String, String> genericInfos = taskData.getGenericInformation();
if (genericInfos != null && genericInfos.containsKey(CommonAttribute.GENERIC_INFO_START_AT_KEY)) {
long scheduledTime = ISO8601DateUtil.toDate(genericInfos.get(CommonAttribute.GENERIC_INFO_START_AT_KEY)).getTime();
taskData.setScheduledTime(scheduledTime);
task.setScheduledTime(scheduledTime);
}
taskData.updateMutableAttributes(task);
if (task.getSelectionScripts() != null) {
List<SelectionScriptData> scripts = new ArrayList<>(task.getSelectionScripts().size());
for (SelectionScript selectionScript : task.getSelectionScripts()) {
scripts.add(SelectionScriptData.createForSelectionScript(selectionScript, taskData));
}
taskData.setSelectionScripts(scripts);
}
if (task.getExecutableContainer() != null) {
taskData.setScript(ScriptData.createForScript(((ScriptExecutableContainer) task.getExecutableContainer()).getScript(), taskData));
}
if (task.getPreScript() != null) {
taskData.setPreScript(ScriptData.createForScript(task.getPreScript(), taskData));
}
if (task.getPostScript() != null) {
taskData.setPostScript(ScriptData.createForScript(task.getPostScript(), taskData));
}
if (task.getCleaningScript() != null) {
taskData.setCleanScript(ScriptData.createForScript(task.getCleaningScript(), taskData));
}
if (task.getFlowScript() != null) {
taskData.setFlowScript(ScriptData.createForFlowScript(task.getFlowScript(), taskData));
}
List<SelectorData> selectorsData = new ArrayList<>();
if (task.getInputFilesList() != null) {
for (InputSelector selector : task.getInputFilesList()) {
selectorsData.add(SelectorData.createForInputSelector(selector, taskData));
}
}
if (task.getOutputFilesList() != null) {
for (OutputSelector selector : task.getOutputFilesList()) {
selectorsData.add(SelectorData.createForOutputSelector(selector, taskData));
}
}
taskData.setDataspaceSelectors(selectorsData);
ForkEnvironment forkEnvironment = task.getForkEnvironment();
if (forkEnvironment != null) {
taskData.setAdditionalClasspath(forkEnvironment.getAdditionalClasspath());
taskData.setJavaHome(forkEnvironment.getJavaHome());
taskData.setJvmArguments(forkEnvironment.getJVMArguments());
taskData.setWorkingDir(forkEnvironment.getWorkingDir());
if (forkEnvironment.getEnvScript() != null) {
taskData.setEnvScript(ScriptData.createForScript(forkEnvironment.getEnvScript(), taskData));
}
Map<String, String> systemEnvironment = forkEnvironment.getSystemEnvironment();
if (systemEnvironment != null) {
List<EnvironmentModifierData> envModifiers = new ArrayList<>(systemEnvironment.size());
for (Map.Entry<String, String> entry : systemEnvironment.entrySet()) {
envModifiers.add(EnvironmentModifierData.create(new PropertyModifier(entry.getKey(), entry.getValue()), taskData));
}
taskData.setEnvModifiers(envModifiers);
}
}
taskData.initTaskType(task);
return taskData;
}
Aggregations