Search in sources :

Example 6 with Scheduler

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

the class SchedulerStateRest method getLiveLogJobAvailable.

/**
 * number of available bytes in the stream or -1 if the stream does not
 * exist.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job to retrieve
 */
@Override
@GET
@Path("jobs/{jobid}/livelog/available")
@Produces("application/json")
public int getLiveLogJobAvailable(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException {
    checkAccess(sessionId, "/scheduler/jobs/" + jobId + "/livelog/available");
    Session ss = sessionStore.get(sessionId);
    return ss.getJobsOutputController().availableLinesCount(jobId);
}
Also used : HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with Scheduler

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

the class SchedulerStateRest method taskLogErrByTag.

/**
 * Returns the list of standard error outputs (stderr) generated by a set of
 * tasks filtered by a given tag.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks
 * @return the list of stderr generated by the set of tasks filtered by the
 *         given tag or an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/log/err")
@Produces("application/json")
public String taskLogErrByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag/" + taskTag + "/result/log/err");
        List<TaskResult> trs = s.getTaskResultsByTag(jobId, taskTag);
        StringBuffer buf = new StringBuffer();
        for (TaskResult tr : trs) {
            if (tr.getOutput() != null) {
                buf.append(tr.getOutput().getStderrLogs(true));
            }
        }
        return buf.toString();
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 8 with Scheduler

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

the class SchedulerStateRest method login.

/**
 * Login to the scheduler using a form containing 2 fields (username and
 * password).
 *
 * @param username
 *            username
 * @param password
 *            password
 * @return the session id associated to the login.
 * @throws LoginException
 */
@Override
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("login")
@Produces("application/json")
public String login(@FormParam("username") String username, @FormParam("password") String password) throws LoginException, SchedulerRestException {
    try {
        if ((username == null) || (password == null)) {
            throw new LoginException("Empty login/password");
        }
        Session session = sessionStore.create(username);
        session.connectToScheduler(new CredData(username, password));
        logger.info("Binding user " + username + " to session " + session.getSessionId());
        return session.getSessionId();
    } catch (ActiveObjectCreationException e) {
        throw new SchedulerRestException(e);
    } catch (SchedulerException e) {
        throw new SchedulerRestException(e);
    } catch (NodeException e) {
        throw new SchedulerRestException(e);
    }
}
Also used : InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) NodeException(org.objectweb.proactive.core.node.NodeException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 9 with Scheduler

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

the class SchedulerStateRest method serializedValueOfTaskResult.

/**
 * Returns the value of the task result of the task <code>taskName</code> of
 * the job <code>jobId</code> This method returns the result as a byte array
 * whatever the result is.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return the value of the task result as a byte array.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/serializedvalue")
@Produces("*/*")
public byte[] serializedValueOfTaskResult(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws Throwable {
    Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result/serializedvalue");
    TaskResult tr = s.getTaskResult(jobId, taskname);
    tr = PAFuture.getFutureValue(tr);
    return tr.getSerializedValue();
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 10 with Scheduler

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

the class SchedulerStateRest method loginWithCredential.

/**
 * Login to the scheduler using a multipart form can be used either by
 * submitting 2 fields ({@code username} and {@code password}) or by sending
 * a credential file with field name {@code credential}.
 *
 * @return the session id associated to this new connection.
 * @throws KeyException
 * @throws LoginException
 * @throws SchedulerRestException
 */
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("login")
@Produces("application/json")
public String loginWithCredential(@MultipartForm LoginForm multipart) throws LoginException, KeyException, SchedulerRestException {
    try {
        Session session;
        if (multipart.getCredential() != null) {
            Credentials credentials;
            try {
                session = sessionStore.createUnnamedSession();
                credentials = Credentials.getCredentials(multipart.getCredential());
                session.connectToScheduler(credentials);
            } catch (IOException e) {
                throw new LoginException(e.getMessage());
            }
        } else {
            if ((multipart.getUsername() == null) || (multipart.getPassword() == null)) {
                throw new LoginException("empty login/password");
            }
            session = sessionStore.create(multipart.getUsername());
            CredData credData = new CredData(CredData.parseLogin(multipart.getUsername()), CredData.parseDomain(multipart.getUsername()), multipart.getPassword(), multipart.getSshKey());
            session.connectToScheduler(credData);
        }
        return session.getSessionId();
    } catch (PermissionException e) {
        throw new SchedulerRestException(e);
    } catch (ActiveObjectCreationException e) {
        throw new SchedulerRestException(e);
    } catch (SchedulerException e) {
        throw new SchedulerRestException(e);
    } catch (NodeException e) {
        throw new SchedulerRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) NodeException(org.objectweb.proactive.core.node.NodeException) IOException(java.io.IOException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Scheduler (org.ow2.proactive.scheduler.common.Scheduler)97 JobId (org.ow2.proactive.scheduler.common.job.JobId)51 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)49 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)46 Path (javax.ws.rs.Path)45 Produces (javax.ws.rs.Produces)43 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)42 Test (org.junit.Test)39 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)38 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)36 File (java.io.File)34 GET (javax.ws.rs.GET)34 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)31 SchedulerRestInterface (org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface)31 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)30 JobState (org.ow2.proactive.scheduler.common.job.JobState)29 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)28 GZIP (org.jboss.resteasy.annotations.GZIP)23 KeyException (java.security.KeyException)20 CredData (org.ow2.proactive.authentication.crypto.CredData)19