Search in sources :

Example 1 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.

the class SchedulingService method kill.

public boolean kill() {
    if (status.isKilled()) {
        return false;
    }
    status = SchedulerStatus.KILLED;
    pinger.interrupt();
    schedulingThread.interrupt();
    logger.info("Killing all running task processes...");
    for (RunningTaskData taskData : jobs.getRunningTasks()) {
        NodeSet nodes = taskData.getTask().getExecuterInformation().getNodes();
        try {
            taskData.getLauncher().kill();
        } catch (Throwable t) {
            logger.error("Failed to terminate launcher", t);
        }
        try {
            infrastructure.getRMProxiesManager().getUserRMProxy(taskData.getUser(), taskData.getCredentials()).releaseNodes(nodes, taskData.getTask().getCleaningScript(), addThirdPartyCredentials(taskData.getCredentials()));
        } catch (Throwable t) {
            logger.error("Failed to release nodes", t);
        }
    }
    listenJobLogsSupport.shutdown();
    infrastructure.shutdown();
    listener.schedulerStateUpdated(SchedulerEvent.KILLED);
    return true;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet)

Example 2 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.

the class TerminationData method terminateRunningTask.

private void terminateRunningTask(SchedulingService service, TaskTerminationData taskToTerminate, RunningTaskData taskData) {
    Map<String, String> genericInformation = new HashMap<>();
    VariablesMap variables = null;
    if (taskToTerminate.internalJob != null) {
        genericInformation = taskData.getTask().getRuntimeGenericInformation();
    }
    try {
        variables = getStringSerializableMap(service, taskToTerminate);
    } catch (Exception e) {
        logger.error("Exception occurred, fail to get variables into the cleaning script: ", e);
    }
    try {
        if (taskToTerminate.terminationStatus == ABORTED) {
            taskData.getLauncher().kill();
        }
    } catch (Throwable t) {
        logger.info("Cannot terminate task launcher for task '" + taskData.getTask().getId() + "'", t);
        try {
            logger.info("Task launcher that cannot be terminated is identified by " + taskData.getLauncher().toString());
        } catch (Throwable ignore) {
            logger.info("Getting information about Task launcher failed (remote object not accessible?)");
        }
    }
    try {
        logger.debug("Releasing nodes for task '" + taskData.getTask().getId() + "'");
        RMProxiesManager proxiesManager = service.getInfrastructure().getRMProxiesManager();
        proxiesManager.getUserRMProxy(taskData.getUser(), taskData.getCredentials()).releaseNodes(taskData.getNodes(), taskToTerminate.terminationStatus != NODEFAILED ? taskData.getTask().getCleaningScript() : null, variables, genericInformation, taskToTerminate.taskData.getTask().getId(), service.addThirdPartyCredentials(taskData.getCredentials()));
    } catch (Throwable t) {
        logger.info("Failed to release nodes for task '" + taskData.getTask().getId() + "'", t);
    }
}
Also used : HashMap(java.util.HashMap) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) IOException(java.io.IOException) RMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.RMProxiesManager)

Example 3 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData 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) {
            Set<TaskId> parentIds = new HashSet<>(iDependences.size());
            for (InternalTask parentTask : iDependences) {
                parentIds.addAll(InternalTaskParentFinder.getInstance().getFirstNotSkippedParentTaskIds(parentTask));
            }
            // Batch fetching of parent tasks results
            Map<TaskId, TaskResult> taskResults = new HashMap<>();
            for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds), PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
                taskResults.putAll(service.getInfrastructure().getDBManager().loadTasksResults(taskData.getTask().getJobId(), parentsSubList));
            }
            getResultsFromListOfTaskResults(variablesMap.getInheritedMap(), taskResults);
        } 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;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) HashMap(java.util.HashMap) Map(java.util.Map) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) HashSet(java.util.HashSet)

Example 4 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.

the class JobData method toJobUsage.

JobUsage toJobUsage() {
    JobIdImpl jobId = new JobIdImpl(getId(), getJobName());
    JobUsage jobUsage = new JobUsage(getOwner(), getProjectName(), jobId.value(), getJobName(), getFinishedTime() - getStartTime());
    for (TaskData taskData : getTasks()) {
        TaskUsage taskUsage = taskData.toTaskUsage(jobId);
        jobUsage.add(taskUsage);
    }
    return jobUsage;
}
Also used : TaskUsage(org.ow2.proactive.scheduler.common.usage.TaskUsage) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage)

Example 5 with TaskData

use of org.ow2.proactive.scheduler.core.db.TaskData in project scheduling by ow2-proactive.

the class SchedulerDBManager method batchLoadJobs.

// Executed in a transaction from the caller
private void batchLoadJobs(Session session, boolean fullState, Query jobQuery, List<Long> ids, Collection<InternalJob> jobs) {
    Map<Long, List<TaskData>> tasksMap = loadJobsTasks(session, ids);
    jobQuery.setParameterList("ids", ids);
    List<JobData> jobsList = (List<JobData>) jobQuery.list();
    for (JobData jobData : jobsList) {
        InternalJob internalJob = jobData.toInternalJob();
        internalJob.setTasks(toInternalTasks(fullState, internalJob, tasksMap.get(jobData.getId())));
        jobs.add(internalJob);
    }
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)20 Test (org.junit.Test)12 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)7 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)7 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)5 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)5 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)4 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)4 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)4 Query (org.hibernate.Query)3 DBTaskId (org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId)3 List (java.util.List)2 TaskAbortedException (org.ow2.proactive.scheduler.common.exception.TaskAbortedException)2 TaskPreemptedException (org.ow2.proactive.scheduler.common.exception.TaskPreemptedException)2 TaskRestartedException (org.ow2.proactive.scheduler.common.exception.TaskRestartedException)2