Search in sources :

Example 16 with NodeInfo

use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method variablesPropagation_fromParentTask.

@Test
public void variablesPropagation_fromParentTask() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    Map<String, Serializable> variablesFromParent = new HashMap<>();
    variablesFromParent.put("var", "parent");
    variablesFromParent.put(SchedulerVars.PA_TASK_ID.toString(), "1234");
    TaskResult[] previousTasksResults = { new TaskResultImpl(null, null, null, null, null, SerializationUtil.serializeVariableMap(variablesFromParent), false) };
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var'));print(variables.get('PA_TASK_ID'))", "groovy"))), initializer, previousTasksResults, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
    assertEquals("parent42", taskOutput.output());
}
Also used : Serializable(java.io.Serializable) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 17 with NodeInfo

use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method simpleScriptTask.

@Test
public void simpleScriptTask() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setPreScript(new SimpleScript("println('pre')", "groovy"));
    initializer.setPostScript(new SimpleScript("println('post')", "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println('hello'); java.lang.Thread.sleep(5); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
    assertEquals(String.format("pre%nhello%npost%n"), taskOutput.output());
    assertEquals("hello", result.value());
    assertTrue("Task duration should be at least 5", result.getTaskDuration() >= 5);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 18 with NodeInfo

use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.

the class TaskContextTest method createTaskContext.

private TaskContext createTaskContext() throws NodeException, InvalidScriptException {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1L, "testSerializeContextToFile"), "testSerializeContextToFile", 1L));
    // Invoke method to test it
    return new TaskContext(new ScriptExecutableContainer(new TaskScript(new ForkEnvironmentScript(new SimpleScript("", "python")))), taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) ForkEnvironmentScript(org.ow2.proactive.scripting.ForkEnvironmentScript)

Example 19 with NodeInfo

use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.

the class TaskLauncher method doTask.

public void doTask(ExecutableContainer executableContainer, TaskResult[] previousTasksResults, TaskTerminateNotification terminateNotification, String terminateNotificationNodeURL, boolean taskRecoverable) {
    TaskResultImpl taskResult;
    WallTimer wallTimer = null;
    TaskContext context = null;
    Stopwatch taskStopwatchForFailures = null;
    TaskDataspaces dataspaces = null;
    File taskLogFile = null;
    try {
        taskStarted.set(true);
        logger.info("Task started " + taskId.getJobId().getReadableName() + " : " + taskId.getReadableName());
        wallTimer = new WallTimer(initializer.getWalltime(), taskKiller);
        taskStopwatchForFailures = Stopwatch.createUnstarted();
        taskLauncherRebinder = new TaskLauncherRebinder(taskId, terminateNotificationNodeURL, taskRecoverable);
        addShutdownHook();
        if (decrypter != null) {
            decrypter.setCredentials(executableContainer.getCredentials());
        }
        // lock the cache space cleaning mechanism
        DataSpaceNodeConfigurationAgent.lockCacheSpaceCleaning();
        dataspaces = factory.createTaskDataspaces(taskId, initializer.getNamingService(), executableContainer.isRunAsUser(), decrypter, taskLogger);
        copyTaskLogsFromUserSpace(taskLogger.createLogFilePath(dataspaces.getScratchFolder()), dataspaces);
        taskLogFile = taskLogger.createFileAppender(dataspaces.getScratchFolder());
        progressFileReader.start(dataspaces.getScratchFolder(), taskId);
        context = new TaskContext(executableContainer, initializer, previousTasksResults, new NodeDataSpacesURIs(dataspaces.getScratchURI(), dataspaces.getCacheURI(), dataspaces.getInputURI(), dataspaces.getOutputURI(), dataspaces.getUserURI(), dataspaces.getGlobalURI()), progressFileReader.getProgressFile().toString(), new NodeInfo(getHostName(), getNodeUrl(), getNodeName(), getNodeSourceName()), decrypter);
        File workingDir = getTaskWorkingDir(context, dataspaces);
        logger.info("Task working dir: " + workingDir);
        logger.info("Cache space: " + context.getNodeDataSpaceURIs().getCacheURI());
        logger.info("Input space: " + context.getNodeDataSpaceURIs().getInputURI());
        logger.info("Output space: " + context.getNodeDataSpaceURIs().getOutputURI());
        logger.info("User space: " + context.getNodeDataSpaceURIs().getUserURI());
        logger.info("Global space: " + context.getNodeDataSpaceURIs().getGlobalURI());
        logger.info("Scheduler rest url: " + context.getSchedulerRestUrl());
        wallTimer.start();
        // should handle interrupt
        dataspaces.copyInputDataToScratch(initializer.getFilteredInputFiles(fileSelectorsFilters(context)));
        TaskExecutor taskExecutor = factory.createTaskExecutor(workingDir);
        initializer.fetchUrlsIfNeeded();
        ((ScriptExecutableContainer) executableContainer).getScript().fetchUrlIfNeeded();
        taskStopwatchForFailures.start();
        taskResult = taskExecutor.execute(context, taskLogger.getOutputSink(), taskLogger.getErrorSink());
        taskStopwatchForFailures.stop();
        // by the time the task finishes, the scheduler might have had a
        // transient failure, so we need to make sure that the placeholder
        // for the task's result still exists, or get the new place for
        // the result if it does not exist anymore.
        TaskTerminateNotification rebindedTerminateNotification = taskLauncherRebinder.makeSureSchedulerIsConnected(terminateNotification);
        switch(taskKiller.getStatus()) {
            case WALLTIME_REACHED:
                taskResult = getWalltimedTaskResult(context, taskStopwatchForFailures);
                copyTaskLogsToUserSpace(taskLogFile, dataspaces);
                sendResultToScheduler(rebindedTerminateNotification, taskResult);
                return;
            case KILLED_MANUALLY:
                // killed by Scheduler, no need to send results back
                copyTaskLogsToUserSpace(taskLogFile, dataspaces);
                return;
        }
        dataspaces.copyScratchDataToOutput(initializer.getFilteredOutputFiles(fileSelectorsFilters(context, taskResult)));
        wallTimer.stop();
        copyTaskLogsToUserSpace(taskLogFile, dataspaces);
        sendResultToScheduler(rebindedTerminateNotification, taskResult);
    } catch (Throwable taskFailure) {
        if (wallTimer != null) {
            wallTimer.stop();
        }
        switch(taskKiller.getStatus()) {
            case WALLTIME_REACHED:
                taskResult = getWalltimedTaskResult(context, taskStopwatchForFailures);
                copyTaskLogsToUserSpace(taskLogFile, dataspaces);
                sendResultToScheduler(terminateNotification, taskResult);
                break;
            case KILLED_MANUALLY:
                // killed by Scheduler, no need to send results back
                copyTaskLogsToUserSpace(taskLogFile, dataspaces);
                return;
            default:
                logger.info("Failed to execute task", taskFailure);
                long elapsedTime = 0;
                if (taskStopwatchForFailures != null) {
                    elapsedTime = taskStopwatchForFailures.elapsed(TimeUnit.MILLISECONDS);
                }
                taskFailure.printStackTrace(taskLogger.getErrorSink());
                Map<String, byte[]> serializedVariables = extractVariablesFromContext(context);
                taskResult = new TaskResultImpl(taskId, taskFailure, taskLogger.getLogs(), elapsedTime);
                taskResult.setPropagatedVariables(serializedVariables);
                sendResultToScheduler(terminateNotification, taskResult);
        }
    } finally {
        try {
            progressFileReader.stop();
            taskLogger.close();
            if (dataspaces != null) {
                dataspaces.close();
            }
            // unlocks the cache space cleaning thread
            DataSpaceNodeConfigurationAgent.unlockCacheSpaceCleaning();
            removeShutdownHook();
        } finally {
            terminate();
        }
    }
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskDataspaces(org.ow2.proactive.scheduler.task.data.TaskDataspaces) Stopwatch(com.google.common.base.Stopwatch) WallTimer(org.ow2.proactive.scheduler.task.utils.WallTimer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskTerminateNotification(org.ow2.proactive.scheduler.common.TaskTerminateNotification) TaskExecutor(org.ow2.proactive.scheduler.task.executors.TaskExecutor) NodeInfo(org.ow2.proactive.scheduler.task.context.NodeInfo) File(java.io.File) Map(java.util.Map)

Example 20 with NodeInfo

use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.

the class TaskContextSerializerTest method createTaskContext.

private TaskContext createTaskContext() throws NodeException, InvalidScriptException {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1L, "testSerializeContextToFile"), "testSerializeContextToFile", 1L));
    // Invoke method to test it
    return new TaskContext(new ScriptExecutableContainer(new TaskScript(new ForkEnvironmentScript(new SimpleScript("", "python")))), taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) ForkEnvironmentScript(org.ow2.proactive.scripting.ForkEnvironmentScript)

Aggregations

ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)54 Test (org.junit.Test)49 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)46 NodeInfo (org.ow2.proactive.scheduler.task.context.NodeInfo)46 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)46 SimpleScript (org.ow2.proactive.scripting.SimpleScript)43 TaskScript (org.ow2.proactive.scripting.TaskScript)43 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)29 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)22 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)13 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)11 Serializable (java.io.Serializable)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 File (java.io.File)8 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)8 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)8 HashMap (java.util.HashMap)7 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)6