use of org.ow2.proactive_grid_cloud_portal.common.Session 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();
}
use of org.ow2.proactive_grid_cloud_portal.common.Session 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);
}
}
use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method deleteLiveLogJob.
/**
* remove the live log object.
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job to retrieve
* @throws NotConnectedRestException
*/
@Override
@DELETE
@Path("jobs/{jobid}/livelog")
@Produces("application/json")
public boolean deleteLiveLogJob(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException {
checkAccess(sessionId, "delete /scheduler/jobs/livelog" + jobId);
Session ss = sessionStore.get(sessionId);
ss.getJobsOutputController().removeAppender(jobId);
return true;
}
use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method submitFlat.
/**
* Submit job using flat command file
*
* @param sessionId
* valid session id
* @param commandFileContent
* content of a command file: endline separated native commands
* @param jobName
* name of the job to create
* @param selectionScriptContent
* content of a selection script, or null
* @param selectionScriptExtension
* extension of the selectionscript to determine script engine
* ("js", "py", "rb")
* @return Id of the submitted job
* @throws NotConnectedRestException
* @throws IOException
* @throws JobCreationRestException
* @throws PermissionRestException
* @throws SubmissionClosedRestException
*/
@Override
@POST
@Path("submitflat")
@Produces("application/json")
public JobIdData submitFlat(@HeaderParam("sessionid") String sessionId, @FormParam("commandFileContent") String commandFileContent, @FormParam("jobName") String jobName, @FormParam("selectionScriptContent") String selectionScriptContent, @FormParam("selectionScriptExtension") String selectionScriptExtension) throws NotConnectedRestException, IOException, JobCreationRestException, PermissionRestException, SubmissionClosedRestException {
Scheduler s = checkAccess(sessionId, "submitflat");
try {
File command = File.createTempFile("flatsubmit_commands_", ".txt");
command.deleteOnExit();
String selectionPath = null;
File selection = null;
if (selectionScriptContent != null && selectionScriptContent.trim().length() > 0) {
selection = File.createTempFile("flatsubmit_selection_", "." + selectionScriptExtension);
selection.deleteOnExit();
try (PrintWriter pw = new PrintWriter(new FileOutputStream(selection))) {
pw.print(selectionScriptContent);
}
selectionPath = selection.getAbsolutePath();
}
try (PrintWriter pw = new PrintWriter(new FileOutputStream(command))) {
pw.print(commandFileContent);
}
Job j = FlatJobFactory.getFactory().createNativeJobFromCommandsFile(command.getAbsolutePath(), jobName, selectionPath, null);
JobId id = s.submit(j);
command.delete();
if (selection != null) {
selection.delete();
}
return mapper.map(id, JobIdData.class);
} catch (IOException e) {
throw new IOException("I/O Error: " + e.getMessage(), e);
} catch (JobCreationException e) {
throw new JobCreationRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (SubmissionClosedException e) {
throw new SubmissionClosedRestException(e);
} catch (PermissionException e) {
throw new PermissionRestException(e);
}
}
use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method getLiveLogJob.
/**
* Stream the output of job identified by the id <code>jobid</code> only
* stream currently available logs, call this method several times to get
* the complete output.
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job to retrieve
* @throws IOException
* @throws LogForwardingRestException
*/
@GET
@GZIP
@Path("jobs/{jobid}/livelog")
@Produces("application/json")
@Override
public String getLiveLogJob(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException, LogForwardingRestException, IOException {
try {
Scheduler scheduler = checkAccess(sessionId, "/scheduler/jobs/" + jobId + "/livelog");
Session session = sessionStore.get(sessionId);
JobState jobState = scheduler.getJobState(jobId);
boolean isFinished = jobState != null && jobState.isFinished();
int availableLinesCount = session.getJobsOutputController().availableLinesCount(jobId);
if (!isFinished || availableLinesCount > 0) {
return session.getJobsOutputController().getNewLogs(jobId);
} else {
session.getJobsOutputController().removeAppender(jobId);
return "";
}
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (LogForwardingException e) {
throw new LogForwardingRestException(e);
}
}
Aggregations