Search in sources :

Example 26 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor in project scheduling by ow2-proactive.

the class LicenseSchedulingPolicy method removeFinishedTasks.

private void removeFinishedTasks(LinkedBlockingQueue<EligibleTaskDescriptor> eligibleTasksDescriptorsLicense) {
    Iterator<EligibleTaskDescriptor> iter = eligibleTasksDescriptorsLicense.iterator();
    EligibleTaskDescriptorImpl current_task;
    while (iter.hasNext()) {
        current_task = (EligibleTaskDescriptorImpl) iter.next();
        if (current_task.getInternal().getStatus().equals(TaskStatus.FINISHED)) {
            iter.remove();
        }
    }
}
Also used : EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) EligibleTaskDescriptorImpl(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl)

Example 27 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor in project scheduling by ow2-proactive.

the class SchedulingMethodImpl method getRMNodes.

/**
 * Ask to the RM the given number of node resources.<br>
 * If there is a problem with these task selection (such as bad selectionScript) this method
 * will terminate the corresponding tasks and jobs. As the selection scripts contain errors, the task
 * and its surrounding jobs must be stopped.
 *
 * @param neededResourcesNumber the number of resources to ask for (must be &gt; 0).
 * @param tasksToSchedule the task to be scheduled
 * @return A nodeSet that contains at most 'neededResourcesNumber' available compatible resources.
 * 		   An empty nodeSet if no nodes could be found
 * 		   null if the their was an exception when asking for the nodes (ie : selection script has failed)
 */
protected NodeSet getRMNodes(Map<JobId, JobDescriptor> jobMap, int neededResourcesNumber, LinkedList<EligibleTaskDescriptor> tasksToSchedule, Set<String> freeResources) {
    NodeSet nodeSet;
    if (neededResourcesNumber <= 0) {
        throw new IllegalArgumentException("'neededResourcesNumber' must be greater than 0");
    }
    EligibleTaskDescriptor etd = tasksToSchedule.getFirst();
    InternalJob currentJob = ((JobDescriptorImpl) jobMap.get(etd.getJobId())).getInternal();
    InternalTask internalTask0 = currentJob.getIHMTasks().get(etd.getTaskId());
    try {
        TopologyDescriptor descriptor = null;
        boolean bestEffort = true;
        if (internalTask0.isParallel()) {
            descriptor = internalTask0.getParallelEnvironment().getTopologyDescriptor();
            bestEffort = false;
            if (descriptor == null) {
                logger.debug("Topology is not defined for the task " + internalTask0.getName());
            }
        }
        if (descriptor == null) {
            // descriptor is not defined, use default
            descriptor = TopologyDescriptor.ARBITRARY;
        }
        try {
            Criteria criteria = new Criteria(neededResourcesNumber);
            criteria.setTopology(descriptor);
            // resolve script variables (if any) in the list of selection
            // scripts and then set it as the selection criteria.
            criteria.setScripts(resolveScriptVariables(internalTask0.getSelectionScripts(), internalTask0.getRuntimeVariables()));
            criteria.setBlackList(internalTask0.getNodeExclusion());
            criteria.setBestEffort(bestEffort);
            criteria.setAcceptableNodesUrls(freeResources);
            criteria.setBindings(createBindingsForSelectionScripts(currentJob, internalTask0));
            if (internalTask0.getRuntimeGenericInformation().containsKey(SchedulerConstants.NODE_ACCESS_TOKEN)) {
                criteria.setNodeAccessToken(internalTask0.getRuntimeGenericInformation().get(SchedulerConstants.NODE_ACCESS_TOKEN));
            }
            Collection<String> computationDescriptors = new ArrayList<>(tasksToSchedule.size());
            for (EligibleTaskDescriptor task : tasksToSchedule) {
                computationDescriptors.add(TaskLogger.getTaskLogRelativePath(task.getTaskId()));
            }
            criteria.setComputationDescriptors(computationDescriptors);
            nodeSet = getRMProxiesManager().getUserRMProxy(currentJob.getOwner(), currentJob.getCredentials()).getNodes(criteria);
        } catch (TopologyDisabledException tde) {
            jlogger.warn(currentJob.getId(), "will be canceled as the topology is disabled");
            schedulingService.simulateJobStartAndCancelIt(tasksToSchedule, "Topology is disabled");
            return null;
        }
        // the following line is used to unwrap the future, warning when moving or removing
        // it may also throw a ScriptException which is a RuntimeException
        PAFuture.waitFor(nodeSet, true);
        logger.debug("provided nodes " + nodeSet.size());
        return nodeSet;
    } catch (IOException | ClassNotFoundException e) {
        logger.warn("Failed to deserialize previous task variables before selection for task " + internalTask0.getId().toString(), e);
        schedulingService.simulateJobStartAndCancelIt(tasksToSchedule, "Failed to deserialize previous task variables before selection for task " + internalTask0.getId().toString());
        return null;
    } catch (RMProxyCreationException e) {
        logger.warn("Failed to create User RM Proxy", e);
        // simulate jobs starts and cancel it
        schedulingService.simulateJobStartAndCancelIt(tasksToSchedule, "Failed to create User RM Proxy : Authentication Failed to Resource Manager for user '" + currentJob.getOwner() + "'");
        // leave the method by ss failure
        return null;
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) Criteria(org.ow2.proactive.utils.Criteria) IOException(java.io.IOException) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) RMProxyCreationException(org.ow2.proactive.scheduler.core.rmproxies.RMProxyCreationException) TopologyDisabledException(org.ow2.proactive.resourcemanager.frontend.topology.TopologyDisabledException) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor)

Example 28 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor in project scheduling by ow2-proactive.

the class TaskResultCreator method extractTaskResultsAndMergeIntoMap.

private Map<String, byte[]> extractTaskResultsAndMergeIntoMap(SchedulerDBManager dbManager, EligibleTaskDescriptor eligibleTaskDescriptor, InternalJob job) {
    Map<String, byte[]> mergedVariables = new HashMap<>();
    int numberOfParentTasks = eligibleTaskDescriptor.getParents().size();
    List<TaskId> parentIds = new ArrayList<>(numberOfParentTasks);
    for (int i = 0; i < numberOfParentTasks; i++) {
        parentIds.add(eligibleTaskDescriptor.getParents().get(i).getTaskId());
    }
    // 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(dbManager.loadTasksResults(job.getId(), parentsSubList));
    }
    for (TaskResult taskResult : taskResults.values()) {
        if (taskResult.getPropagatedVariables() != null) {
            mergedVariables.putAll(taskResult.getPropagatedVariables());
        }
    }
    return mergedVariables;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult)

Example 29 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor in project scheduling by ow2-proactive.

the class JobDescriptorImpl method restoreInErrorTasks.

public void restoreInErrorTasks() {
    final Iterator<Entry<TaskId, EligibleTaskDescriptor>> iterator = eligibleTasks.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<TaskId, EligibleTaskDescriptor> entry = iterator.next();
        TaskId taskId = entry.getKey();
        EligibleTaskDescriptor task = entry.getValue();
        if (((EligibleTaskDescriptorImpl) task).getInternal().getStatus() == TaskStatus.IN_ERROR) {
            pausedTasks.put(taskId, task);
            iterator.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) TaskId(org.ow2.proactive.scheduler.common.task.TaskId)

Example 30 with EligibleTaskDescriptor

use of org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor in project scheduling by ow2-proactive.

the class JobDescriptorImpl method makeTree.

/**
 * Make a dependences tree of the job's tasks according to the dependence list
 * stored in taskDescriptor.
 * This list represents the ordered TaskDescriptor list of its parent tasks.
 */
private void makeTree(InternalJob job) {
    // create task descriptor list
    for (InternalTask td : job.getITasks()) {
        // if this task is a first task, put it in eligible tasks list
        EligibleTaskDescriptor lt = new EligibleTaskDescriptorImpl(td);
        if (isEntryPoint(td, job.getITasks())) {
            eligibleTasks.put(td.getId(), lt);
        }
        if (td.getJoinedBranches() != null || td.getIfBranch() != null) {
            branchTasks.put(td.getId(), lt);
        }
        allTasksWithTheirChildren.put(td, lt);
    }
    // now for each taskDescriptor, set the parents and children list
    for (InternalTask td : job.getITasks()) {
        if (td.getDependences() != null) {
            TaskDescriptor taskDescriptor = allTasksWithTheirChildren.get(td);
            for (InternalTask depends : td.getIDependences()) {
                ((EligibleTaskDescriptorImpl) taskDescriptor).addParent(allTasksWithTheirChildren.get(depends));
            }
            for (TaskDescriptor lt : taskDescriptor.getParents()) {
                ((EligibleTaskDescriptorImpl) lt).addChild(taskDescriptor);
                hasChildren.add(lt.getTaskId());
            }
        }
    }
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Aggregations

EligibleTaskDescriptor (org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor)25 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)18 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)16 JobId (org.ow2.proactive.scheduler.common.job.JobId)12 Test (org.junit.Test)10 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)9 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)8 JobDescriptorImpl (org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)7 EligibleTaskDescriptorImpl (org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl)6 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)3 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Entry (java.util.Map.Entry)2 TopologyDisabledException (org.ow2.proactive.resourcemanager.frontend.topology.TopologyDisabledException)2 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)2 RMProxyCreationException (org.ow2.proactive.scheduler.core.rmproxies.RMProxyCreationException)2