Search in sources :

Example 11 with Task

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

the class TaskData method toInternalTask.

InternalTask toInternalTask(InternalJob internalJob, boolean loadFullState) throws InvalidScriptException {
    TaskId taskId = createTaskId(internalJob);
    InternalTask internalTask;
    if (taskType.equals(SCRIPT_TASK)) {
        internalTask = new InternalScriptTask(internalJob);
    } else if (taskType.equals(FORKED_SCRIPT_TASK)) {
        internalTask = new InternalForkedScriptTask(internalJob);
    } else {
        throw new IllegalStateException("Unexpected stored task type: " + taskType);
    }
    internalTask.setId(taskId);
    internalTask.setDescription(getDescription());
    internalTask.setTag(this.getTag());
    internalTask.setStatus(getTaskStatus());
    internalTask.setJobInfo(internalJob.getJobInfo());
    internalTask.setName(getTaskName());
    internalTask.setExecutionDuration(getExecutionDuration());
    internalTask.setFinishedTime(getFinishedTime());
    internalTask.setInErrorTime(getInErrorTime());
    internalTask.setStartTime(getStartTime());
    internalTask.setScheduledTime(getScheduledTime());
    internalTask.setExecutionHostName(getExecutionHostName());
    internalTask.setOnTaskError(OnTaskError.getInstance(this.onTaskErrorString));
    internalTask.setPreciousLogs(isPreciousLogs());
    internalTask.setPreciousResult(isPreciousResult());
    internalTask.setRunAsMe(isRunAsMe());
    internalTask.setWallTime(getWallTime());
    internalTask.setMaxNumberOfExecution(getMaxNumberOfExecution());
    internalTask.setNumberOfExecutionLeft(getNumberOfExecutionLeft());
    internalTask.setNumberOfExecutionOnFailureLeft(getNumberOfExecutionOnFailureLeft());
    internalTask.setRestartTaskOnError(getRestartMode());
    internalTask.setFlowBlock(getFlowBlock());
    internalTask.setIterationIndex(getIteration());
    internalTask.setReplicationIndex(getReplication());
    internalTask.setMatchingBlock(getMatchingBlock());
    internalTask.setVariables(variablesToTaskVariables());
    if (hasAliveTaskLauncher() && getExecuterInformationData() != null) {
        internalTask.setExecuterInformation(getExecuterInformationData().toExecuterInformation(loadFullState));
    }
    ForkEnvironment forkEnv = createForkEnvironment();
    internalTask.setForkEnvironment(forkEnv);
    return internalTask;
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 12 with Task

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

the class TaskResultCreator method getTaskResult.

public TaskResultImpl getTaskResult(SchedulerDBManager dbManager, InternalJob job, InternalTask task, Throwable exception, TaskLogs output) throws UnknownTaskException {
    if (task == null) {
        throw new UnknownTaskException();
    }
    JobDescriptor jobDescriptor = job.getJobDescriptor();
    EligibleTaskDescriptor eligibleTaskDescriptor = null;
    if (jobDescriptor.getPausedTasks().get(task.getId()) != null) {
        eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getPausedTasks().get(task.getId());
    } else if (jobDescriptor.getRunningTasks().get(task.getId()) != null) {
        eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getRunningTasks().get(task.getId());
    }
    TaskResultImpl taskResult = getEmptyTaskResult(task, exception, output);
    taskResult.setPropagatedVariables(getPropagatedVariables(dbManager, eligibleTaskDescriptor, job, task));
    return taskResult;
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor)

Example 13 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 14 with Task

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

the class JobDescriptorImpl method terminate.

/**
 * Update the eligible list of task and dependencies if necessary.
 * This function considered that the taskId is in eligible task list.
 * Visibility is package because user cannot use this method.
 *
 * @param taskId the task to remove from running task.
 */
public void terminate(TaskId taskId, boolean inErrorTask) {
    Map<TaskId, ? extends TaskDescriptor> currentTasks = inErrorTask ? pausedTasks : runningTasks;
    List<TaskId> taskIdsToSkip = new ArrayList<>();
    if (getInternal().getType() == JobType.TASKSFLOW) {
        TaskDescriptor taskToTerminate = currentTasks.get(taskId);
        if (taskToTerminate != null) {
            for (TaskDescriptor childTask : taskToTerminate.getChildren()) {
                decreaseParentCount(childTask);
                if (((EligibleTaskDescriptorImpl) childTask).getCount() == 0) {
                    if (internalJob.getStatus() == JobStatus.PAUSED) {
                        pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                    } else if (internalJob.getStatus() == JobStatus.IN_ERROR && ((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.PAUSED) {
                        pausedTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                    } else if (((EligibleTaskDescriptorImpl) childTask).getInternal().getStatus() == TaskStatus.SKIPPED) {
                        runningTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                        taskIdsToSkip.add(childTask.getTaskId());
                    } else {
                        eligibleTasks.put(childTask.getTaskId(), (EligibleTaskDescriptor) childTask);
                    }
                }
            }
            decreaseChildrenCountForAllParents(taskToTerminate);
        }
    }
    currentTasks.remove(taskId);
    for (TaskId taskIdToSkip : taskIdsToSkip) {
        terminate(taskIdToSkip);
    }
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ArrayList(java.util.ArrayList)

Example 15 with Task

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

the class JobDescriptorImpl method doLoop.

/**
 * Complete LOOP action on JobDescriptor side
 *
 * @param initiator Task initiating the LOOP action
 * @param tree InternalTask tree of replicated tasks
 * @param target Target task of the LOOP action
 */
public void doLoop(TaskId initiator, Map<TaskId, InternalTask> tree, InternalTask target, InternalTask newInit) {
    Map<TaskId, EligibleTaskDescriptorImpl> acc = new HashMap<>();
    // create new EligibleTasks and accumulate it
    for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
        TaskId itId = it.getValue().getId();
        EligibleTaskDescriptorImpl td = new EligibleTaskDescriptorImpl(it.getValue());
        acc.put(itId, td);
    }
    EligibleTaskDescriptorImpl oldEnd = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
    EligibleTaskDescriptorImpl newStart = acc.get(target.getId());
    EligibleTaskDescriptorImpl newEnd = acc.get(newInit.getId());
    // plug the end of the old tree (initiator) to the beginning of the new (target)
    for (TaskDescriptor ot : oldEnd.getChildren()) {
        newEnd.addChild(ot);
        ot.getParents().remove(oldEnd);
        ot.getParents().add(newEnd);
    }
    oldEnd.clearChildren();
    // recreate the dependencies
    for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
        TaskId itId = it.getValue().getTaskInfo().getTaskId();
        EligibleTaskDescriptorImpl down = acc.get(itId);
        List<InternalTask> ideps = new ArrayList<>();
        int deptype = 0;
        if (it.getValue().hasDependences()) {
            ideps.addAll(it.getValue().getIDependences());
        }
        if (it.getValue().getIfBranch() != null) {
            deptype = 1;
            ideps.add(it.getValue().getIfBranch());
        }
        if (it.getValue().getJoinedBranches() != null) {
            deptype = 2;
            ideps.addAll(it.getValue().getJoinedBranches());
        }
        if (ideps.size() > 0 && !target.equals(itId)) {
            for (InternalTask parent : ideps) {
                if (parent == null) {
                    continue;
                }
                EligibleTaskDescriptorImpl up = acc.get(parent.getTaskInfo().getTaskId());
                switch(deptype) {
                    case 0:
                        if (parent.getId().equals(initiator)) {
                            up = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
                        }
                        up.addChild(down);
                        down.addParent(up);
                        break;
                    case 1:
                    case 2:
                        // 'weak' dependencies from FlowAction#IF are not
                        // represented in TaskDescriptor
                        branchTasks.put(down.getTaskId(), down);
                        break;
                }
            }
        }
    }
    // EligibleTaskDescriptorImpl newTask = (EligibleTaskDescriptorImpl) acc.get(target.getId());
    setNewLoopTaskToPausedIfJobIsPaused(newStart);
    putNewLoopTaskIntoPausedOrEligableList(target.getId(), newStart);
    runningTasks.remove(initiator);
}
Also used : TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.Test)152 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)112 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)100 JobId (org.ow2.proactive.scheduler.common.job.JobId)73 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)69 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)68 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)60 ArrayList (java.util.ArrayList)49 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)48 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)43 Task (org.ow2.proactive.scheduler.common.task.Task)41 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)41 File (java.io.File)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)34 HashMap (java.util.HashMap)33 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)33 SimpleScript (org.ow2.proactive.scripting.SimpleScript)33 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)27 TaskScript (org.ow2.proactive.scripting.TaskScript)27 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)26