use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method pushFile.
/**
* Pushes a file from the local file system into the given DataSpace
*
* @param sessionId
* a valid session id
* @param spaceName
* the name of the DataSpace
* @param filePath
* the path inside the DataSpace where to put the file e.g.
* "/myfolder"
* @param multipart
* the form data containing : - fileName the name of the file
* that will be created on the DataSpace - fileContent the
* content of the file
* @return true if the transfer succeeded
* @see org.ow2.proactive.scheduler.common.SchedulerConstants for spaces
* names
*/
@Override
public boolean pushFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName, @PathParam("filePath") String filePath, MultipartFormDataInput multipart) throws IOException, NotConnectedRestException, PermissionRestException {
checkAccess(sessionId, "pushFile");
Session session = dataspaceRestApi.checkSessionValidity(sessionId);
Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();
List<InputPart> fNL = formDataMap.get("fileName");
if ((fNL == null) || (fNL.size() == 0)) {
throw new IllegalArgumentException("Illegal multipart argument definition (fileName), received " + fNL);
}
String fileName = fNL.get(0).getBody(String.class, null);
List<InputPart> fCL = formDataMap.get("fileContent");
if ((fCL == null) || (fCL.size() == 0)) {
throw new IllegalArgumentException("Illegal multipart argument definition (fileContent), received " + fCL);
}
InputStream fileContent = fCL.get(0).getBody(InputStream.class, null);
if (fileName == null) {
throw new IllegalArgumentException("Wrong file name : " + fileName);
}
filePath = normalizeFilePath(filePath, fileName);
FileObject destfo = dataspaceRestApi.resolveFile(session, spaceName, filePath);
URL targetUrl = destfo.getURL();
logger.info("[pushFile] pushing file to " + targetUrl);
if (!destfo.isWriteable()) {
RuntimeException ex = new IllegalArgumentException("File " + filePath + " is not writable in space " + spaceName);
logger.error(ex);
throw ex;
}
if (destfo.exists()) {
destfo.delete();
}
// used to create the necessary directories if needed
destfo.createFile();
dataspaceRestApi.writeFile(fileContent, destfo, null);
return true;
}
use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method listJobs.
/**
* Returns a JobState of the job identified by the id <code>jobid</code>
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job to retrieve
*/
@Override
@GET
@Path("jobs/{jobid}")
@Produces({ "application/json", "application/xml" })
public JobStateData listJobs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "/scheduler/jobs/" + jobId);
JobState js = s.getJobState(jobId);
js = PAFuture.getFutureValue(js);
return mapper.map(js, JobStateData.class);
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
}
}
use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method deleteFile.
/**
* Deletes a file or recursively delete a directory from the given DataSpace
*
* @param sessionId
* a valid session id
* @param spaceName
* the name of the data space involved (GLOBAL or USER)
* @param filePath
* the path to the file or directory which must be deleted
*/
@Override
public boolean deleteFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName, @PathParam("filePath") String filePath) throws IOException, NotConnectedRestException, PermissionRestException {
checkAccess(sessionId, "deleteFile");
Session session = dataspaceRestApi.checkSessionValidity(sessionId);
filePath = normalizeFilePath(filePath, null);
FileObject sourcefo = dataspaceRestApi.resolveFile(session, spaceName, filePath);
if (!sourcefo.exists() || !sourcefo.isWriteable()) {
RuntimeException ex = new IllegalArgumentException("File or Folder " + filePath + " does not exist or is not writable in space " + spaceName);
logger.error(ex);
throw ex;
}
if (sourcefo.getType().equals(FileType.FILE)) {
logger.info("[deleteFile] deleting file " + sourcefo.getURL());
sourcefo.delete();
} else if (sourcefo.getType().equals(FileType.FOLDER)) {
logger.info("[deleteFile] deleting folder (and all its descendants) " + sourcefo.getURL());
sourcefo.delete(Selectors.SELECT_ALL);
} else {
RuntimeException ex = new IllegalArgumentException("File " + filePath + " has an unsupported type " + sourcefo.getType());
logger.error(ex);
throw ex;
}
return true;
}
use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method valueOfTaskResultByTag.
/**
* Returns the value of the task result for a set of tasks of the job
* <code>jobId</code> filtered by a given tag. <strong>the result is
* deserialized before sending to the client, if the class is not found the
* content is replaced by the string 'Unknown value type' </strong>. To get
* the serialized form of a given result, one has to call the following
* restful service jobs/{jobid}/tasks/tag/{tasktag}/result/serializedvalue
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskTag
* the tag used to filter the tasks.
* @return the value of the task result
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/value")
@Produces("application/json")
public Map<String, String> valueOfTaskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws Throwable {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag/" + taskTag + "/result/value");
List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
Map<String, String> result = new HashMap<String, String>(taskResults.size());
for (TaskResult currentTaskResult : taskResults) {
result.put(currentTaskResult.getTaskId().getReadableName(), getTaskResultValueAsStringOrExceptionStackTrace(currentTaskResult));
}
return result;
}
use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.
the class SchedulerStateRest method metadataOfTaskResultByTag.
/**
* Returns the metadata of the task result of task <code>taskName</code> of the
* job <code>jobId</code>filtered by a given tag.
* <p>
* Metadata is a map containing additional information associated with a result. For example a file name if the result represents a file.
*
* @param sessionId a valid session id
* @param jobId the id of the job
* @param taskTag the tag used to filter the tasks.
* @return a map containing for each task entry, the metadata of the task result
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/metadata")
@Produces("application/json")
public Map<String, Map<String, String>> metadataOfTaskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws Throwable {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag" + taskTag + "/result/serializedvalue");
List<TaskResult> trs = s.getTaskResultsByTag(jobId, taskTag);
Map<String, Map<String, String>> result = new HashMap<>(trs.size());
for (TaskResult currentResult : trs) {
TaskResult r = PAFuture.getFutureValue(currentResult);
result.put(r.getTaskId().getReadableName(), r.getMetadata());
}
return result;
}
Aggregations