Search in sources :

Example 21 with SchedulerAuthenticationInterface

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

the class SchedulerUsageTest method testSchedulerUsage.

@Test
public void testSchedulerUsage() throws Exception {
    SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    PublicKey pubKey = auth.getPublicKey();
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), pubKey);
    Scheduler scheduler = auth.login(cred);
    fallbackToMyAccountUsage(scheduler);
    scheduler.disconnect();
}
Also used : PublicKey(java.security.PublicKey) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 22 with SchedulerAuthenticationInterface

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

the class SubmitJob method begin.

public void begin() {
    // non blocking method to use futur management
    try {
        // connect the Scheduler
        // get the authentication interface using the SchedulerConnection
        SchedulerAuthenticationInterface auth = SchedulerConnection.waitAndJoin(SchedulerTHelper.getLocalUrl());
        // get the user interface using the retrieved SchedulerAuthenticationInterface
        user = auth.login(Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey()));
        // let the client be notified of its own 'job termination' -> job running to finished event
        user.addEventListener((SubmitJob) PAActiveObject.getStubOnThis(), true, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_PENDING_TO_FINISHED);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)

Example 23 with SchedulerAuthenticationInterface

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

the class TestGetUsage method testGetMyAccountUsage.

@Test
public void testGetMyAccountUsage() throws Exception {
    Date beforeJobExecution = new Date();
    // put some data in the database
    Scheduler firstUser = schedulerHelper.getSchedulerInterface();
    JobId jobId = firstUser.submit(createJob());
    schedulerHelper.waitForEventJobFinished(jobId, 30000);
    Date afterJobExecution = new Date();
    // We try to retrieve usage on the job I just ran
    List<JobUsage> adminUsages = firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
    assertFalse(adminUsages.isEmpty());
    // Do we properly check for user connection ?
    firstUser.disconnect();
    try {
        firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
        fail("Should throw a not connected exception because i just disconnected");
    } catch (NotConnectedException e) {
    // Ok that is expected
    }
    // another user
    SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
    Scheduler otherUser = auth.login(cred);
    // This user has not ran any job
    List<JobUsage> userUsages = otherUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
    assertTrue(userUsages.isEmpty());
    otherUser.disconnect();
}
Also used : NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage) Date(java.util.Date) JobId(org.ow2.proactive.scheduler.common.job.JobId) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 24 with SchedulerAuthenticationInterface

use of org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface 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));
    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(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));
    JobId thirdJob = scheduler.submit(createJob(fileLockPath));
    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), 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));
    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("guest", "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));
    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 25 with SchedulerAuthenticationInterface

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

the class TestMultipleUsersMakingMassivGetResultRequest method testMultipleUsersMakingMassivGetResultRequest.

@Test
public void testMultipleUsersMakingMassivGetResultRequest() throws Throwable {
    final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    // create a job
    final TaskFlowJob job = new TaskFlowJob();
    for (int i = 0; i < taskPerJob; i++) {
        JavaTask task = new JavaTask();
        task.setName("jt" + i);
        task.setExecutableClassName(EmptyTask.class.getName());
        job.addTask(task);
    }
    // start threads
    for (int i = 0; i < ThreadNumber; i++) {
        new Thread() {

            @Override
            public void run() {
                try {
                    // connect the scheduler
                    log(Thread.currentThread().getName() + " -> Connecting the scheduler");
                    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
                    Scheduler user = auth.login(cred);
                    log(Thread.currentThread().getName() + " -> Connected");
                    long start = System.currentTimeMillis();
                    int submitted = 1;
                    while (true) {
                        log(Thread.currentThread().getName() + " -> Submit (" + submitted + ")");
                        JobId id = user.submit(job);
                        JobResult jr = null;
                        while (jr == null) {
                            Thread.sleep(getResultDelay);
                            jr = user.getJobResult(id);
                        }
                        if (System.currentTimeMillis() - start > jobSubmissionDuration) {
                            log(Thread.currentThread().getName() + " -> Terminate");
                            nbFinished++;
                            break;
                        }
                        submitted++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    while (nbFinished < ThreadNumber) {
        Thread.sleep(100);
    }
    log("All threads terminated.");
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) EmptyTask(org.ow2.proactive.scheduler.examples.EmptyTask) Credentials(org.ow2.proactive.authentication.crypto.Credentials) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)22 Credentials (org.ow2.proactive.authentication.crypto.Credentials)15 CredData (org.ow2.proactive.authentication.crypto.CredData)13 KeyException (java.security.KeyException)7 PublicKey (java.security.PublicKey)7 Test (org.junit.Test)6 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)6 LoginException (javax.security.auth.login.LoginException)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)5 InternalSchedulerException (org.ow2.proactive.scheduler.common.exception.InternalSchedulerException)4 HashMap (java.util.HashMap)3 JMXConnector (javax.management.remote.JMXConnector)3 JMXServiceURL (javax.management.remote.JMXServiceURL)3 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)3 MBeanServerConnection (javax.management.MBeanServerConnection)2 ObjectName (javax.management.ObjectName)2 UserData (org.ow2.proactive.authentication.UserData)2 AlreadyConnectedException (org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException)2 ConnectionException (org.ow2.proactive.scheduler.common.exception.ConnectionException)2 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)2