Search in sources :

Example 6 with FileLock

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

the class TestLoadJobs method testLoadJobs.

@Test
public void testLoadJobs() throws Exception {
    long time = System.currentTimeMillis();
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    FileLock fileLock = new FileLock();
    Path lock = fileLock.lock();
    String fileLockPath = lock.toString();
    logger.info("File lock location is " + fileLockPath);
    JobInfo job;
    List<JobInfo> jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    JobId firstJob = scheduler.submit(createJob(fileLockPath, null));
    schedulerHelper.waitForEventTaskRunning(firstJob, "Test");
    jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob);
    job = jobs.get(0);
    assertEquals(this.getClass().getSimpleName(), job.getJobId().getReadableName());
    assertEquals(this.getClass().getSimpleName(), job.getProjectName());
    assertEquals(1, job.getTotalNumberOfTasks());
    assertEquals(0, job.getNumberOfFinishedTasks());
    assertEquals(0, job.getNumberOfPendingTasks());
    assertEquals(1, job.getNumberOfRunningTasks());
    assertEquals(JobStatus.RUNNING, job.getStatus());
    assertTrue("Unexpected submit time: " + job.getSubmittedTime(), job.getSubmittedTime() > time && job.getSubmittedTime() < System.currentTimeMillis());
    assertTrue("Unexpected start time: " + job.getStartTime(), job.getStartTime() > time && job.getStartTime() < System.currentTimeMillis());
    assertEquals(-1, job.getFinishedTime());
    assertEquals(-1, job.getRemovedTime());
    assertEquals(TestUsers.DEMO.username, job.getJobOwner());
    assertEquals(JobPriority.NORMAL, job.getPriority());
    JobId secondJob = scheduler.submit(createJob(fileLockPath, null));
    JobId thirdJob = scheduler.submit(createJob(fileLockPath, secondJob.value()));
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    jobs = scheduler.getJobs(1, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob, thirdJob);
    jobs = scheduler.getJobs(1, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true, false), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_DESC).getList();
    checkJobs(jobs, thirdJob, secondJob, firstJob);
    fileLock.unlock();
    for (JobInfo jobInfo : jobs) {
        schedulerHelper.waitForEventJobFinished(jobInfo.getJobId(), 30000);
    }
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, false), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    scheduler.disconnect();
    // connect as another user
    SchedulerMonitorsHandler monitorsHandler = new SchedulerMonitorsHandler();
    SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
    scheduler = auth.login(cred);
    eventReceiver = new MonitorEventReceiver(monitorsHandler);
    eventReceiver = PAActiveObject.turnActive(eventReceiver);
    SchedulerState state = scheduler.addEventListener(eventReceiver, true, true);
    monitorsHandler.init(state);
    jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    fileLockPath = fileLock.lock().toString();
    JobId fourthJob = scheduler.submit(createJob(fileLockPath, null));
    monitorsHandler.waitForEventTask(SchedulerEvent.TASK_PENDING_TO_RUNNING, fourthJob, "Test", 30000);
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, fourthJob);
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs);
    jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
    jobs = scheduler.getJobs(2, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, thirdJob, fourthJob);
    fileLock.unlock();
    monitorsHandler.waitForFinishedJob(fourthJob, 30000);
    jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, fourthJob);
    jobs = scheduler.getJobs(0, 10, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
    jobs = scheduler.getJobs(1, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob);
    jobs = scheduler.getJobs(1, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, secondJob, thirdJob);
    jobs = scheduler.getJobs(2, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, thirdJob);
    jobs = scheduler.getJobs(2, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, thirdJob, fourthJob);
    scheduler.disconnect();
    PAActiveObject.terminateActiveObject(eventReceiver, true);
    // connect as a user who can see only its own jobs
    cred = Credentials.createCredentials(new CredData("user", "pwd"), auth.getPublicKey());
    scheduler = auth.login(cred);
    monitorsHandler = new SchedulerMonitorsHandler();
    eventReceiver = new MonitorEventReceiver(monitorsHandler);
    eventReceiver = PAActiveObject.turnActive(eventReceiver);
    state = scheduler.addEventListener(eventReceiver, true, true);
    monitorsHandler.init(state);
    JobId myjob = scheduler.submit(createJob(fileLockPath, null));
    jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, myjob);
    jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
    checkJobs(jobs, myjob);
    scheduler.disconnect();
}
Also used : Path(java.nio.file.Path) MonitorEventReceiver(functionaltests.monitor.MonitorEventReceiver) SchedulerState(org.ow2.proactive.scheduler.common.SchedulerState) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) FileLock(org.ow2.proactive.scheduler.util.FileLock) JobId(org.ow2.proactive.scheduler.common.job.JobId) SchedulerMonitorsHandler(functionaltests.monitor.SchedulerMonitorsHandler) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 7 with FileLock

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

the class TestExecuteScriptsOnBusyNode method testExecuteScriptOnBusyNode.

@Test
public void testExecuteScriptOnBusyNode() throws Exception {
    FileLock fileLock = new FileLock();
    Path fileLockPath = fileLock.lock();
    log("Submit job");
    final JobId jobId = schedulerHelper.submitJob(createJobWithLock(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");
    log("Wait some time until task launcher is started");
    Thread.sleep(5000);
    List<ScriptResult<Object>> results = schedulerHelper.getResourceManager().executeScript("println \"Executing Script\";", "groovy", TargetType.NODE_URL.name(), Sets.newSet(testNode.getNodeURL()));
    Assert.assertEquals(1, results.size());
    ScriptResult result = results.get(0);
    if (result.errorOccured()) {
        result.getException().printStackTrace();
        Assert.fail("Script execution failed");
    }
    log("Let task finish");
    fileLock.unlock();
    log("Wait when job finish");
    schedulerHelper.waitForEventJobFinished(jobId, TIMEOUT);
    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) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

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