Search in sources :

Example 1 with Task

use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.

the class SchedulingMethodImpl method getNextcompatibleTasks.

/**
 * Extract the n first compatible tasks from the first argument list,
 * and return them according that the extraction is stopped when the maxResource number is reached.<br>
 * Two tasks are compatible if and only if they have the same list of selection script and
 * the same list of node exclusion.
 * The check of compliance is currently done by the {@link SchedulingTaskComparator} class.<br>
 * This method has two side effects : extracted tasks are removed from the bagOfTasks and put in the toFill list
 *
 * @param bagOfTasks the list of tasks form which to extract tasks
 * @param maxResource the limit number of resources that the extraction should not exceed
 * @param toFill the list that will contains the task to schedule at the end. This list must not be null but must be empty.<br>
 * 		  this list will be filled with the n first compatible tasks according that the number of resources needed
 * 		  by these tasks does not exceed the given max resource number.
 * @return the number of nodes needed to start every task present in the 'toFill' argument at the end of the method.
 */
protected int getNextcompatibleTasks(Map<JobId, JobDescriptor> jobsMap, LinkedList<EligibleTaskDescriptor> bagOfTasks, int maxResource, LinkedList<EligibleTaskDescriptor> toFill) {
    if (toFill == null || bagOfTasks == null) {
        throw new IllegalArgumentException("The two given lists must not be null !");
    }
    int neededResource = 0;
    if (!PASchedulerProperties.SCHEDULER_REST_URL.isSet()) {
        Iterator<EligibleTaskDescriptor> it = bagOfTasks.iterator();
        EligibleTaskDescriptor etd;
        while (it.hasNext()) {
            etd = it.next();
            if (checkEligibleTaskDescriptorScript.isTaskContainsAPIBinding(etd)) {
                // skip task here
                it.remove();
            }
        }
    }
    if (maxResource > 0 && !bagOfTasks.isEmpty()) {
        EligibleTaskDescriptor etd = bagOfTasks.removeFirst();
        ((EligibleTaskDescriptorImpl) etd).addAttempt();
        InternalJob currentJob = ((JobDescriptorImpl) jobsMap.get(etd.getJobId())).getInternal();
        InternalTask internalTask = currentJob.getIHMTasks().get(etd.getTaskId());
        int neededNodes = internalTask.getNumberOfNodesNeeded();
        SchedulingTaskComparator referent = new SchedulingTaskComparator(internalTask, currentJob);
        boolean firstLoop = true;
        do {
            if (!firstLoop) {
                // if bagOfTasks is not empty
                if (!bagOfTasks.isEmpty()) {
                    etd = bagOfTasks.removeFirst();
                    ((EligibleTaskDescriptorImpl) etd).addAttempt();
                    currentJob = ((JobDescriptorImpl) jobsMap.get(etd.getJobId())).getInternal();
                    internalTask = currentJob.getIHMTasks().get(etd.getTaskId());
                    neededNodes = internalTask.getNumberOfNodesNeeded();
                }
            } else {
                firstLoop = false;
            }
            if (neededNodes > maxResource) {
            // no instruction is important :
            // in this case, a multi node task leads the search to be stopped and the
            // the current task would be retried on the next step
            // we continue to start the maximum number of task in a single scheduling loop.
            // this case will focus on starting single node task first if lot of resources are busy.
            // (multi-nodes starvation may occurs)
            } else {
                // check if the task is compatible with the other previous one
                if (referent.equals(new SchedulingTaskComparator(internalTask, currentJob))) {
                    tlogger.debug(internalTask.getId(), "scheduling");
                    neededResource += neededNodes;
                    maxResource -= neededNodes;
                    toFill.add(etd);
                } else {
                    bagOfTasks.addFirst(etd);
                    break;
                }
            }
        } while (maxResource > 0 && !bagOfTasks.isEmpty());
    }
    return neededResource;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) EligibleTaskDescriptorImpl(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)

Example 2 with Task

use of org.ow2.proactive.scheduler.common.task.Task 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());
    }
}
Also used : DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) Task(org.ow2.proactive.scheduler.common.task.Task) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList)

Example 3 with Task

use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.

the class RMProxyActiveObject method handleCleaningScript.

/**
 * Execute the given script on the given node.
 * Also register a callback on {@link #cleanCallBack(Future, NodeSet)} method when script has returned.
 * @param nodes           the nodeset on which to start the script
 * @param cleaningScript the script to be executed
 * @param variables
 * @param genericInformation
 * @param taskId
 * @param creds credentials with CredData containing third party credentials
 */
private void handleCleaningScript(NodeSet nodes, Script<?> cleaningScript, VariablesMap variables, Map<String, String> genericInformation, TaskId taskId, Credentials creds) {
    TaskLogger instance = TaskLogger.getInstance();
    try {
        this.nodesTaskId.put(nodes, taskId);
        // create a decrypter to access scheduler and retrieve Third Party User Credentials
        String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
        Decrypter decrypter = new Decrypter(Credentials.getPrivateKey(privateKeyPath));
        decrypter.setCredentials(creds);
        HashMap<String, Serializable> dictionary = new HashMap<>();
        dictionary.putAll(variables.getScriptMap());
        dictionary.putAll(variables.getInheritedMap());
        dictionary.putAll(variables.getPropagatedVariables());
        dictionary.putAll(variables.getScopeMap());
        // start handler for binding
        ScriptHandler handler = ScriptLoader.createHandler(nodes.get(0));
        VariablesMap resolvedMap = new VariablesMap();
        resolvedMap.setInheritedMap(VariableSubstitutor.resolveVariables(variables.getInheritedMap(), dictionary));
        resolvedMap.setScopeMap(VariableSubstitutor.resolveVariables(variables.getScopeMap(), dictionary));
        handler.addBinding(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) resolvedMap);
        handler.addBinding(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) genericInformation);
        // retrieve scheduler URL to bind with schedulerapi, globalspaceapi, and userspaceapi
        String schedulerUrl = PASchedulerProperties.SCHEDULER_REST_URL.getValueAsString();
        logger.debug("Binding schedulerapi...");
        SchedulerNodeClient client = new SchedulerNodeClient(decrypter, schedulerUrl);
        handler.addBinding(SchedulerConstants.SCHEDULER_CLIENT_BINDING_NAME, (Serializable) client);
        logger.debug("Binding globalspaceapi...");
        RemoteSpace globalSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.GLOBAL, schedulerUrl);
        handler.addBinding(SchedulerConstants.DS_GLOBAL_API_BINDING_NAME, (Serializable) globalSpaceClient);
        logger.debug("Binding userspaceapi...");
        RemoteSpace userSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.USER, schedulerUrl);
        handler.addBinding(SchedulerConstants.DS_USER_API_BINDING_NAME, (Serializable) userSpaceClient);
        logger.debug("Binding credentials...");
        Map<String, String> resolvedThirdPartyCredentials = VariableSubstitutor.filterAndUpdate(decrypter.decrypt().getThirdPartyCredentials(), dictionary);
        handler.addBinding(SchedulerConstants.CREDENTIALS_VARIABLE, (Serializable) resolvedThirdPartyCredentials);
        ScriptResult<?> future = handler.handle(cleaningScript);
        try {
            PAEventProgramming.addActionOnFuture(future, "cleanCallBack", nodes);
        } catch (IllegalArgumentException e) {
            // TODO - linked to PROACTIVE-936 -> IllegalArgumentException is raised if method name is unknown
            // should be replaced by checked exception
            instance.error(taskId, "ERROR : Callback method won't be executed, node won't be released. This is a critical state, check the callback method name", e);
        }
        instance.info(taskId, "Cleaning Script started on node " + nodes.get(0).getNodeInformation().getURL());
    } catch (Exception e) {
        // if active object cannot be created or script has failed
        instance.error(taskId, "Error while starting cleaning script for task " + taskId + " on " + nodes.get(0), e);
        releaseNodes(nodes).booleanValue();
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) LoginException(javax.security.auth.login.LoginException) TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger) RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) DataSpaceNodeClient(org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 4 with Task

use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.

the class InternalForkedScriptTask method createLauncher.

/**
 * {@inheritDoc}
 */
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
    logger.info(getTaskInfo().getTaskId(), "creating forked task launcher");
    TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveForkedTaskLauncherFactory() }, node);
    // wait until the task launcher is active
    launcher.isActivated();
    setExecuterInformation(new ExecuterInformation(launcher, node));
    return launcher;
}
Also used : TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) ProActiveForkedTaskLauncherFactory(org.ow2.proactive.scheduler.task.ProActiveForkedTaskLauncherFactory)

Example 5 with Task

use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.

the class InternalScriptTask method createLauncher.

/**
 * {@inheritDoc}
 */
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
    logger.info(getTaskInfo().getTaskId(), "creating non forked task launcher");
    TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveNonForkedTaskLauncherFactory() }, node);
    // wait until the task launcher is active
    launcher.isActivated();
    setExecuterInformation(new ExecuterInformation(launcher, node));
    return launcher;
}
Also used : TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) ProActiveNonForkedTaskLauncherFactory(org.ow2.proactive.scheduler.task.ProActiveNonForkedTaskLauncherFactory)

Aggregations

Test (org.junit.Test)175 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)124 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)116 JobId (org.ow2.proactive.scheduler.common.job.JobId)97 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)79 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)77 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)76 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)56 File (java.io.File)52 ArrayList (java.util.ArrayList)52 Task (org.ow2.proactive.scheduler.common.task.Task)50 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)50 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)47 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)42 HashMap (java.util.HashMap)40 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)36 SimpleScript (org.ow2.proactive.scripting.SimpleScript)34 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)33 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)32 IOException (java.io.IOException)27