Search in sources :

Example 26 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class SchedulerTHelper method cleanJobs.

public void cleanJobs() throws Exception {
    Scheduler userInt = getSchedulerInterface();
    JobFilterCriteria criteria = new JobFilterCriteria(false, true, true, true);
    List<JobInfo> jobs = userInt.getJobs(0, 1000, criteria, ImmutableList.of(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
    for (JobInfo job : jobs) {
        userInt.removeJob(job.getJobId());
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) Scheduler(org.ow2.proactive.scheduler.common.Scheduler)

Example 27 with Criteria

use of org.ow2.proactive.utils.Criteria 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 28 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class TestLoadJobs method testLoadNoJob.

@Test
public void testLoadNoJob() throws Exception {
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    List<JobInfo> jobs = scheduler.getJobs(0, 0, criteria(true, true, true, true), null).getList();
    assertTrue(jobs.isEmpty());
}
Also used : JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) Test(org.junit.Test)

Example 29 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class SchedulingMethodImpl method getRMNodes.

/**
 * Ask to the RM the given number of node resources.<br>
 * If there is a problem with these task selection (such as bad selectionScript) this method
 * will terminate the corresponding tasks and jobs. As the selection scripts contain errors, the task
 * and its surrounding jobs must be stopped.
 *
 * @param neededResourcesNumber the number of resources to ask for (must be &gt; 0).
 * @param tasksToSchedule the task to be scheduled
 * @return A nodeSet that contains at most 'neededResourcesNumber' available compatible resources.
 * 		   An empty nodeSet if no nodes could be found
 * 		   null if the their was an exception when asking for the nodes (ie : selection script has failed)
 */
protected NodeSet getRMNodes(Map<JobId, JobDescriptor> jobMap, int neededResourcesNumber, LinkedList<EligibleTaskDescriptor> tasksToSchedule, Set<String> freeResources) {
    NodeSet nodeSet;
    if (neededResourcesNumber <= 0) {
        throw new IllegalArgumentException("'neededResourcesNumber' must be greater than 0");
    }
    EligibleTaskDescriptor etd = tasksToSchedule.getFirst();
    InternalJob currentJob = ((JobDescriptorImpl) jobMap.get(etd.getJobId())).getInternal();
    InternalTask internalTask0 = currentJob.getIHMTasks().get(etd.getTaskId());
    try {
        TopologyDescriptor descriptor = null;
        boolean bestEffort = true;
        if (internalTask0.isParallel()) {
            descriptor = internalTask0.getParallelEnvironment().getTopologyDescriptor();
            bestEffort = false;
            if (descriptor == null) {
                logger.debug("Topology is not defined for the task " + internalTask0.getName());
            }
        }
        if (descriptor == null) {
            // descriptor is not defined, use default
            descriptor = TopologyDescriptor.ARBITRARY;
        }
        try {
            Criteria criteria = new Criteria(neededResourcesNumber);
            criteria.setTopology(descriptor);
            // resolve script variables (if any) in the list of selection
            // scripts and then set it as the selection criteria.
            criteria.setScripts(resolveScriptVariables(internalTask0.getSelectionScripts(), internalTask0.getRuntimeVariables()));
            criteria.setBlackList(internalTask0.getNodeExclusion());
            criteria.setBestEffort(bestEffort);
            criteria.setAcceptableNodesUrls(freeResources);
            criteria.setBindings(createBindingsForSelectionScripts(currentJob, internalTask0));
            if (internalTask0.getRuntimeGenericInformation().containsKey(SchedulerConstants.NODE_ACCESS_TOKEN)) {
                criteria.setNodeAccessToken(internalTask0.getRuntimeGenericInformation().get(SchedulerConstants.NODE_ACCESS_TOKEN));
            }
            Collection<String> computationDescriptors = new ArrayList<>(tasksToSchedule.size());
            for (EligibleTaskDescriptor task : tasksToSchedule) {
                computationDescriptors.add(TaskLogger.getTaskLogRelativePath(task.getTaskId()));
            }
            criteria.setComputationDescriptors(computationDescriptors);
            nodeSet = getRMProxiesManager().getUserRMProxy(currentJob.getOwner(), currentJob.getCredentials()).getNodes(criteria);
        } catch (TopologyDisabledException tde) {
            jlogger.warn(currentJob.getId(), "will be canceled as the topology is disabled");
            schedulingService.simulateJobStartAndCancelIt(tasksToSchedule, "Topology is disabled");
            return null;
        }
        // the following line is used to unwrap the future, warning when moving or removing
        // it may also throw a ScriptException which is a RuntimeException
        PAFuture.waitFor(nodeSet, true);
        logger.debug("provided nodes " + nodeSet.size());
        return nodeSet;
    } catch (IOException | ClassNotFoundException e) {
        logger.warn("Failed to deserialize previous task variables before selection for task " + internalTask0.getId().toString(), e);
        schedulingService.simulateJobStartAndCancelIt(tasksToSchedule, "Failed to deserialize previous task variables before selection for task " + internalTask0.getId().toString());
        return null;
    } catch (RMProxyCreationException e) {
        logger.warn("Failed to create User RM Proxy", e);
        // simulate jobs starts and cancel it
        schedulingService.simulateJobStartAndCancelIt(tasksToSchedule, "Failed to create User RM Proxy : Authentication Failed to Resource Manager for user '" + currentJob.getOwner() + "'");
        // leave the method by ss failure
        return null;
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) Criteria(org.ow2.proactive.utils.Criteria) IOException(java.io.IOException) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) RMProxyCreationException(org.ow2.proactive.scheduler.core.rmproxies.RMProxyCreationException) TopologyDisabledException(org.ow2.proactive.resourcemanager.frontend.topology.TopologyDisabledException) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor)

Example 30 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class TestRMProxy method requestTooManyNodes.

private void requestTooManyNodes(RMProxy proxy, ResourceManager rm) throws Exception {
    log("Request more nodes than RM has");
    Criteria criteria = new Criteria(NODES_NUMBER + 1);
    criteria.setBestEffort(false);
    NodeSet nodeSet = proxy.getNodes(criteria);
    PAFuture.waitFor(nodeSet);
    assertEquals(0, nodeSet.size());
    assertEquals(NODES_NUMBER, rm.getState().getFreeNodesNumber());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Criteria(org.ow2.proactive.utils.Criteria)

Aggregations

Criteria (org.ow2.proactive.utils.Criteria)25 NodeSet (org.ow2.proactive.utils.NodeSet)23 Test (org.junit.Test)16 Node (org.objectweb.proactive.core.node.Node)9 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)7 ArrayList (java.util.ArrayList)7 RMCore (org.ow2.proactive.resourcemanager.core.RMCore)6 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)6 CredData (org.ow2.proactive.authentication.crypto.CredData)5 Credentials (org.ow2.proactive.authentication.crypto.Credentials)5 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)5 Client (org.ow2.proactive.resourcemanager.authentication.Client)4 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)4 LinkedList (java.util.LinkedList)3 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)3 RMState (org.ow2.proactive.resourcemanager.common.RMState)3 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)3 PublicKey (java.security.PublicKey)2 HashMap (java.util.HashMap)2 List (java.util.List)2