Search in sources :

Example 36 with TaskId

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

the class TaskData method createTaskInfo.

TaskInfoImpl createTaskInfo(JobIdImpl jobId) {
    TaskId taskId = TaskIdImpl.createTaskId(jobId, getTaskName(), getId().getTaskId(), getTag());
    TaskInfoImpl taskInfo = new TaskInfoImpl();
    taskInfo.setTaskId(taskId);
    taskInfo.setStatus(getTaskStatus());
    taskInfo.setStartTime(getStartTime());
    taskInfo.setProgress(0);
    taskInfo.setInErrorTime(getInErrorTime());
    taskInfo.setNumberOfExecutionOnFailureLeft(getNumberOfExecutionOnFailureLeft());
    taskInfo.setNumberOfExecutionLeft(getNumberOfExecutionLeft());
    taskInfo.setJobInfo(getJobData().toJobInfo());
    taskInfo.setJobId(jobId);
    taskInfo.setFinishedTime(getFinishedTime());
    taskInfo.setScheduledTime(getScheduledTime());
    taskInfo.setExecutionHostName(getExecutionHostName());
    taskInfo.setExecutionDuration(getExecutionDuration());
    return taskInfo;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl)

Example 37 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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 38 with TaskId

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

the class StartAtUpdater method updateStartAtAndTasksScheduledTime.

private Set<TaskId> updateStartAtAndTasksScheduledTime(InternalJob job, String startAt, long scheduledTime) {
    List<InternalTask> internalTasks = job.getITasks();
    Set<TaskId> updatedTasks = new HashSet<>(internalTasks.size());
    if (resetJobGenericInformation(job, startAt)) {
        for (InternalTask td : internalTasks) {
            td.setScheduledTime(scheduledTime);
            updatedTasks.add(td.getId());
            job.getJobDescriptor().updateTaskScheduledTime(td.getId(), scheduledTime);
        }
    }
    return updatedTasks;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashSet(java.util.HashSet)

Example 39 with TaskId

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

the class RMProxyActiveObject method printCleaningScriptInformations.

private void printCleaningScriptInformations(NodeSet nodes, ScriptResult<?> sResult, TaskId taskId) {
    if (logger.isInfoEnabled()) {
        TaskLogger instance = TaskLogger.getInstance();
        String nodeUrl = nodes.get(0).getNodeInformation().getURL();
        if (sResult.errorOccured()) {
            instance.error(taskId, "Exception while running cleaning script on " + nodeUrl, sResult.getException());
        } else {
            instance.info(taskId, "Cleaning script successful.");
        }
        if (sResult.getOutput() != null && !sResult.getOutput().isEmpty()) {
            instance.info(taskId, "Cleaning script output on node " + nodeUrl + ":");
            instance.info(taskId, sResult.getOutput());
        }
    }
}
Also used : TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger)

Example 40 with TaskId

use of org.ow2.proactive.scheduler.common.task.TaskId 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)

Aggregations

TaskId (org.ow2.proactive.scheduler.common.task.TaskId)100 Test (org.junit.Test)43 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)43 JobId (org.ow2.proactive.scheduler.common.job.JobId)33 ArrayList (java.util.ArrayList)27 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)25 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)22 HashMap (java.util.HashMap)18 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)18 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)15 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)12 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)12 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)11 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)11 List (java.util.List)10 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9