Search in sources :

Example 1 with FileLock

use of org.ow2.proactive.scheduler.util.FileLock in project scheduling by ow2-proactive.

the class TestExecuteScriptsOnBusyNode method testRunningTaskDoesNotImpactScriptExecution.

public void testRunningTaskDoesNotImpactScriptExecution(boolean withSelectionScript) throws Exception {
    FileLock fileLock = new FileLock();
    Path fileLockPath = fileLock.lock();
    String scriptCode = "org.ow2.proactive.scheduler.util.FileLock.waitUntilUnlocked(\"" + fileLockPath.toString().replace("\\", "\\\\") + "\")";
    log("Submit script (handled asynchronously by the resource manager)");
    List<ScriptResult<Object>> resultsFuture = schedulerHelper.getResourceManager().executeScript(scriptCode, "groovy", TargetType.NODE_URL.name(), Sets.newSet(testNode.getNodeURL()));
    log("Submit job");
    final JobId jobId = schedulerHelper.submitJob(createNonBlockingJob(withSelectionScript));
    // We wait a bit to be sure the job went through the scheduling loop
    // if a selection script is set, the task start will be delayed as much as the SelectionManager is busy executing this script
    // (and thus cannot execute the selection script provided by the task)
    Thread.sleep(3000);
    // unlock the script.
    log("Unlock the script");
    fileLock.unlock();
    log("Wait when job finish");
    schedulerHelper.waitForEventJobFinished(jobId, TIMEOUT);
    Assert.assertEquals(1, resultsFuture.size());
    ScriptResult result = resultsFuture.get(0);
    if (result.errorOccured()) {
        result.getException().printStackTrace();
        Assert.fail("Script execution failed");
    }
    schedulerHelper.waitUntilState(testNode.getNodeURL(), NodeState.FREE, TIMEOUT);
    log("Check job result");
    checkJobResult(schedulerHelper.getSchedulerInterface(), jobId);
    checkActiveObjects();
}
Also used : Path(java.nio.file.Path) ScriptResult(org.ow2.proactive.scripting.ScriptResult) FileLock(org.ow2.proactive.scheduler.util.FileLock) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 2 with FileLock

use of org.ow2.proactive.scheduler.util.FileLock in project scheduling by ow2-proactive.

the class TestPauseJob method test.

@Test
public void test() throws Throwable {
    FileLock fileLock = new FileLock();
    Path fileLockPath = fileLock.lock();
    TaskFlowJob job = createJob(fileLockPath.toString());
    log("Submit job");
    JobId jobId = schedulerHelper.submitJob(job);
    log("Submitted job " + jobId);
    log("Waiting for task1 to start");
    schedulerHelper.waitForEventTaskRunning(jobId, "task1");
    JobState js = schedulerHelper.getSchedulerInterface().getJobState(jobId);
    assertEquals(JobStatus.RUNNING, js.getStatus());
    assertEquals(TaskStatus.RUNNING, getTaskState("task1", js).getStatus());
    assertEquals(TaskStatus.PENDING, getTaskState("task2", js).getStatus());
    log("Pause the job " + jobId);
    schedulerHelper.getSchedulerInterface().pauseJob(jobId);
    js = schedulerHelper.getSchedulerInterface().getJobState(jobId);
    assertEquals(JobStatus.PAUSED, js.getStatus());
    assertEquals(TaskStatus.RUNNING, getTaskState("task1", js).getStatus());
    assertEquals(TaskStatus.PAUSED, getTaskState("task2", js).getStatus());
    // let the task1 finish
    fileLock.unlock();
    log("Checking is the status of task2 remains unchanged");
    Thread.sleep(5000);
    js = schedulerHelper.getSchedulerInterface().getJobState(jobId);
    assertEquals(TaskStatus.PAUSED, getTaskState("task2", js).getStatus());
}
Also used : Path(java.nio.file.Path) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) FileLock(org.ow2.proactive.scheduler.util.FileLock) JobState(org.ow2.proactive.scheduler.common.job.JobState) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 3 with FileLock

use of org.ow2.proactive.scheduler.util.FileLock in project scheduling by ow2-proactive.

the class TestTaskRestartOnNodeFailure method testTaskKillNode.

private void testTaskKillNode(FileLock fileLock, boolean waitBeforeKill) throws Exception {
    Path fileLockPath = fileLock.lock();
    TestNode nodeToKill = startNode();
    log("Submit job");
    final JobId jobId = schedulerHelper.submitJob(createJob(fileLockPath.toString()));
    log("Wait when node becomes busy");
    RMNodeEvent event;
    do {
        event = schedulerHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, TIMEOUT);
    } while (!event.getNodeState().equals(NodeState.BUSY));
    log("Wait when task starts");
    schedulerHelper.waitForEventTaskRunning(jobId, "Test task");
    /*
         * Want to test two cases (existed at the time of this writing): - if wait some time before
         * killing node then node failure is detected by the pinger thread - if kill node
         * immediately then node failure is detected by the thread calling TaskLauncher.doTask
         */
    if (waitBeforeKill) {
        log("Wait some time");
        Thread.sleep(5000);
    }
    log("Stop task node process (node " + nodeToKill.getNode().getNodeInformation().getURL() + ")");
    nodeToKill.kill();
    TestNode newNode = startNode();
    log("Let task finish");
    fileLock.unlock();
    log("Wait when job finish");
    schedulerHelper.waitForEventJobFinished(jobId, TIMEOUT);
    event = schedulerHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, newNode.getNode().getNodeInformation().getURL(), TIMEOUT);
    assertEquals(NodeState.BUSY, event.getNodeState());
    event = schedulerHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, newNode.getNode().getNodeInformation().getURL(), TIMEOUT);
    assertEquals(NodeState.FREE, event.getNodeState());
    log("Check job result");
    checkJobResult(schedulerHelper.getSchedulerInterface(), jobId);
    schedulerHelper.getResourceManager().removeNode(newNode.getNodeURL(), true);
    newNode.kill();
}
Also used : Path(java.nio.file.Path) TestNode(functionaltests.utils.TestNode) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 4 with FileLock

use of org.ow2.proactive.scheduler.util.FileLock in project scheduling by ow2-proactive.

the class TestTaskRestartOnNodeFailure method testRestart.

@Test
public void testRestart() throws Exception {
    FileLock fileLock = new FileLock();
    testTaskKillNode(fileLock, false);
    testTaskKillNode(fileLock, true);
}
Also used : FileLock(org.ow2.proactive.scheduler.util.FileLock) Test(org.junit.Test)

Example 5 with FileLock

use of org.ow2.proactive.scheduler.util.FileLock in project scheduling by ow2-proactive.

the class TestForkedTaskWorkingDir method javaTaskTaskRestartedAnotherNode.

/*
     * SCHEDULING-2129 Mapping for a given space URI is already registered
     * 
     * Run a task, kill the node,let it restart on another node and check the the shared scratch
     * space was correctly setup by transferring a file created in working dir from the task
     */
private void javaTaskTaskRestartedAnotherNode() throws Exception {
    FileLock blockTaskFromTest = new FileLock();
    Path blockTaskFromTestPath = blockTaskFromTest.lock();
    FileLock blockTestBeforeKillingNode = new FileLock();
    Path blockTestBeforeKillingNodePath = blockTestBeforeKillingNode.lock();
    TaskFlowJob job = createFileInLocalSpaceJob(blockTaskFromTestPath.toString(), blockTestBeforeKillingNodePath.toString());
    JobId idJ1 = schedulerHelper.submitJob(job);
    SchedulerTHelper.log("Wait until task is in the middle of the run");
    final String taskNodeUrl = findNodeRunningTask();
    schedulerHelper.waitForEventTaskRunning(idJ1, "task1");
    FileLock.waitUntilUnlocked(blockTestBeforeKillingNodePath);
    SchedulerTHelper.log("Kill the node running the task");
    schedulerHelper.killNode(taskNodeUrl);
    SchedulerTHelper.log("Let the task finish");
    blockTaskFromTest.unlock();
    SchedulerTHelper.log("Waiting for job 1 to finish");
    schedulerHelper.waitForEventJobFinished(idJ1);
    String userSpaceUri = URI.create(schedulerHelper.getSchedulerInterface().getUserSpaceURIs().get(0)).getPath();
    assertTrue("Could not find expected output file", new File(userSpaceUri, "output_file.txt").exists());
}
Also used : Path(java.nio.file.Path) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) FileLock(org.ow2.proactive.scheduler.util.FileLock) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Aggregations

Path (java.nio.file.Path)6 JobId (org.ow2.proactive.scheduler.common.job.JobId)6 FileLock (org.ow2.proactive.scheduler.util.FileLock)6 Test (org.junit.Test)4 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)2 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)2 ScriptResult (org.ow2.proactive.scripting.ScriptResult)2 MonitorEventReceiver (functionaltests.monitor.MonitorEventReceiver)1 SchedulerMonitorsHandler (functionaltests.monitor.SchedulerMonitorsHandler)1 TestNode (functionaltests.utils.TestNode)1 File (java.io.File)1 CredData (org.ow2.proactive.authentication.crypto.CredData)1 Credentials (org.ow2.proactive.authentication.crypto.Credentials)1 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)1 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)1 SchedulerState (org.ow2.proactive.scheduler.common.SchedulerState)1 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)1 JobState (org.ow2.proactive.scheduler.common.job.JobState)1