use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException 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);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException 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.scheduler.exception.NotConnectedRestException 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.scheduler.exception.NotConnectedRestException 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.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method submitPlannings.
@Consumes(MediaType.APPLICATION_JSON)
@POST
@Path("{path:plannings}")
@Produces("application/json")
@Override
public String submitPlannings(@HeaderParam("sessionid") String sessionId, @PathParam("path") PathSegment pathSegment, Map<String, String> jobContentXmlString) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
checkAccess(sessionId, "plannings");
Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
if (jobContentXmlString == null || jobContentXmlString.size() != 1) {
throw new JobCreationRestException("Cannot find job body: code " + HttpURLConnection.HTTP_BAD_REQUEST);
}
Map<String, Object> requestBody = new HashMap<>(2);
requestBody.put("variables", jobVariables);
requestBody.put("xmlContentString", jobContentXmlString.entrySet().iterator().next().getValue());
Response response = null;
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(PortalConfiguration.JOBPLANNER_URL.getValueAsString());
response = target.request().header("sessionid", sessionId).post(Entity.entity(requestBody, "application/json"));
if (HttpURLConnection.HTTP_OK != response.getStatus()) {
throw new IOException(String.format("Cannot access resource %s: code %d", PortalConfiguration.JOBPLANNER_URL.getValueAsString(), response.getStatus()));
}
return response.readEntity(String.class);
} finally {
if (response != null) {
response.close();
}
}
}
Aggregations