Search in sources :

Example 21 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerStateRest method revisionAndJobsInfo.

/**
 * Returns a map containing one entry with the revision id as key and the
 * list of UserJobData as value. each jobs is described using - its id - its
 * owner - the JobInfo class
 *
 * @param sessionId
 *            a valid session id
 * @param index
 *            optional, if a sublist has to be returned the index of the
 *            sublist
 * @param limit
 *            optional, if a sublist has to be returned, the limit of the
 *            sublist
 * @param myJobs
 *            fetch only the jobs for the user making the request
 * @param pending
 *            fetch pending jobs
 * @param running
 *            fetch running jobs
 * @param finished
 *            fetch finished jobs
 * @return a map containing one entry with the revision id as key and the
 *         list of UserJobData as value.
 */
@Override
@GET
@GZIP
@Path("revisionjobsinfo")
@Produces({ "application/json", "application/xml" })
public RestMapPage<Long, ArrayList<UserJobData>> revisionAndJobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit, @QueryParam("myjobs") @DefaultValue("false") boolean myJobs, @QueryParam("pending") @DefaultValue("true") boolean pending, @QueryParam("running") @DefaultValue("true") boolean running, @QueryParam("finished") @DefaultValue("true") boolean finished) throws PermissionRestException, NotConnectedRestException {
    try {
        Scheduler s = checkAccess(sessionId, "revisionjobsinfo?index=" + index + "&limit=" + limit);
        String user = sessionStore.get(sessionId).getUserName();
        boolean onlyUserJobs = (myJobs && user != null && user.trim().length() > 0);
        Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(onlyUserJobs, pending, running, finished), DEFAULT_JOB_SORT_PARAMS);
        List<JobInfo> jobsInfo = page.getList();
        ArrayList<UserJobData> jobs = new ArrayList<>(jobsInfo.size());
        for (JobInfo jobInfo : jobsInfo) {
            jobs.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
        }
        HashMap<Long, ArrayList<UserJobData>> map = new HashMap<Long, ArrayList<UserJobData>>(1);
        map.put(SchedulerStateListener.getInstance().getSchedulerStateRevision(), jobs);
        RestMapPage<Long, ArrayList<UserJobData>> restMapPage = new RestMapPage<Long, ArrayList<UserJobData>>();
        restMapPage.setMap(map);
        restMapPage.setSize(page.getSize());
        return restMapPage;
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) RestMapPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestMapPage) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) HashMap(java.util.HashMap) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UserJobData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 22 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerStateRest method submitFromUrl.

/**
 * Submits a workflow to the scheduler from a workflow URL, creating hence a
 * new job resource.
 *
 * @param sessionId
 *            a valid session id
 * @param url
 *            url to the workflow content
 * @param pathSegment
 *            variables of the workflow
 * @return the <code>jobid</code> of the newly created job
 * @throws NotConnectedRestException
 * @throws IOException
 * @throws JobCreationRestException
 * @throws PermissionRestException
 * @throws SubmissionClosedRestException
 */
@Override
@POST
@Path("{path:jobs}")
@Produces("application/json")
public JobIdData submitFromUrl(@HeaderParam("sessionid") String sessionId, @HeaderParam("link") String url, @PathParam("path") PathSegment pathSegment) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
    Scheduler s = checkAccess(sessionId, "jobs");
    File tmpWorkflowFile = null;
    try {
        String jobXml = downloadWorkflowContent(sessionId, url);
        tmpWorkflowFile = File.createTempFile("job", "d");
        JobId jobId;
        try (OutputStream outputStream = new FileOutputStream(tmpWorkflowFile)) {
            IOUtils.write(jobXml, outputStream);
            WorkflowSubmitter workflowSubmitter = new WorkflowSubmitter(s);
            jobId = workflowSubmitter.submit(tmpWorkflowFile, workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment));
        }
        return mapper.map(jobId, JobIdData.class);
    } catch (IOException e) {
        throw new IOException("Cannot save temporary job file on submission: " + e.getMessage(), e);
    } finally {
        FileUtils.deleteQuietly(tmpWorkflowFile);
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 23 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class NoVncSecuredTargetResolver method doResolve.

// package-protected for testing
InetSocketAddress doResolve(String sessionId, String jobId, String taskName) {
    if (sessionId == null || jobId == null || taskName == null) {
        LOGGER.warn("One of the web socket path parameter is missing (sessionId, jobId, taskName).");
        return null;
    }
    Session session = SharedSessionStore.getInstance().get(sessionId);
    if (session == null) {
        LOGGER.warn("Unknown sessionId.");
        return null;
    }
    SchedulerProxyUserInterface scheduler = session.getScheduler();
    try {
        TaskResult taskResult = scheduler.getTaskResult(jobId, taskName);
        List<String> paRemoteConnectionLines = retrievePaRemoteConnectionLines(session, jobId, taskResult);
        String taskId = retrieveTaskId(taskName, scheduler.getJobState(jobId));
        return resolveVncTargetFromLogs(paRemoteConnectionLines, jobId, taskId);
    } catch (NotConnectedException e) {
        LOGGER.warn("Failed to connect to scheduler", e);
    } catch (UnknownJobException e) {
        LOGGER.warn("Job does not exist", e);
    } catch (UnknownTaskException e) {
        LOGGER.warn("Task does not exist", e);
    } catch (PermissionException e) {
        LOGGER.warn("Not allowed to access task", e);
    }
    return null;
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 24 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SessionStoreTest method testRmCreatedOnLoginAndSchedulerLazyCreation.

@Test
public void testRmCreatedOnLoginAndSchedulerLazyCreation() throws Exception {
    String sessionId = sessionStore.createUnnamedSession().getSessionId();
    Session session = sessionStore.get(sessionId);
    verifyZeroInteractions(schedulerProxyFactory);
    assertNull(session.getScheduler());
    when(schedulerProxyFactory.connectToScheduler(Matchers.<CredData>any())).thenReturn(mock(SchedulerProxyUserInterface.class));
    when(schedulerProxyFactory.connectToRM(Matchers.<CredData>any())).thenReturn(mock(RMProxyUserInterface.class));
    session.connectToRM(new CredData("login", "password"));
    assertNotNull(session.getRM());
    assertNotNull(session.getScheduler());
    assertEquals("login", session.getUserName());
}
Also used : SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) CredData(org.ow2.proactive.authentication.crypto.CredData) Test(org.junit.Test)

Example 25 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SessionStoreTest method testSchedulerCreatedOnLoginAndRmLazyCreation.

@Test
public void testSchedulerCreatedOnLoginAndRmLazyCreation() throws Exception {
    String sessionId = sessionStore.createUnnamedSession().getSessionId();
    Session session = sessionStore.get(sessionId);
    verifyZeroInteractions(schedulerProxyFactory);
    assertNull(session.getScheduler());
    when(schedulerProxyFactory.connectToScheduler(Matchers.<CredData>any())).thenReturn(mock(SchedulerProxyUserInterface.class));
    when(schedulerProxyFactory.connectToRM(Matchers.<CredData>any())).thenReturn(mock(RMProxyUserInterface.class));
    session.connectToScheduler(new CredData("login", "password"));
    assertNotNull(session.getScheduler());
    assertNotNull(session.getRM());
    assertEquals("login", session.getUserName());
}
Also used : SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) CredData(org.ow2.proactive.authentication.crypto.CredData) Test(org.junit.Test)

Aggregations

Path (javax.ws.rs.Path)49 Produces (javax.ws.rs.Produces)47 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)39 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)36 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)34 GET (javax.ws.rs.GET)32 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)29 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)25 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)24 GZIP (org.jboss.resteasy.annotations.GZIP)23 Session (org.ow2.proactive_grid_cloud_portal.common.Session)18 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)17 ArrayList (java.util.ArrayList)16 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)15 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)15 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)15 JobState (org.ow2.proactive.scheduler.common.job.JobState)12 IOException (java.io.IOException)11 POST (javax.ws.rs.POST)11