use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobsInfo.
/**
* Returns a subset of the scheduler state, including pending, running,
* finished jobs (in this particular order). each jobs is described using -
* its id - its owner - the JobInfo class
*
* @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 sessionId
* a valid session id
* @return a list of UserJobData
*/
@Override
@GET
@Path("jobsinfo")
@Produces({ "application/json", "application/xml" })
public RestPage<UserJobData> jobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit) throws PermissionRestException, NotConnectedRestException {
try {
Scheduler s = checkAccess(sessionId, "/scheduler/jobsinfo");
Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(false, true, true, true), DEFAULT_JOB_SORT_PARAMS);
List<UserJobData> userJobInfoList = new ArrayList<UserJobData>(page.getList().size());
for (JobInfo jobInfo : page.getList()) {
userJobInfoList.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
}
return new RestPage<UserJobData>(userJobInfoList, page.getSize());
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (PermissionException e) {
throw new PermissionRestException(e);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData 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);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData in project scheduling by ow2-proactive.
the class SchedulerClientExample method main.
public static void main(String[] args) throws Exception {
// LOGIN IN
SchedulerRestClient client = new SchedulerRestClient("http://localhost:9191/rest/rest/");
SchedulerRestInterface scheduler = client.getScheduler();
String sessionId = scheduler.login("admin", "admin");
// JOB SUBMISSION
File xmlJobFile = new File("/home/ybonnaffe/src/cloud_service_provider_conectors/cloudstack/vminfo_job.xml");
JobIdData xmlJob;
try (FileInputStream inputStream = new FileInputStream(xmlJobFile)) {
xmlJob = client.submitXml(sessionId, inputStream);
}
System.out.println(xmlJob.getReadableName() + " " + xmlJob.getId());
// FLAT JOB SUBMISSION
JobIdData flatJob = scheduler.submitFlat(sessionId, "echo hello", "test-hello", null, null);
System.out.println("Jobid=" + flatJob);
String serverlog = scheduler.jobServerLog(sessionId, Long.toString(flatJob.getId()));
System.out.println(serverlog);
while (true) {
JobStateData jobState2 = scheduler.listJobs(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobState2);
if (jobState2.getJobInfo().getStatus().name().equals("FINISHED")) {
break;
}
Thread.sleep(100);
}
JobResultData jobResultData = scheduler.jobResult(sessionId, Long.toString(flatJob.getId()));
System.out.println(jobResultData);
TaskResultData taskresult = scheduler.taskResult(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(taskresult);
List<TaskStateData> jobTaskStates = scheduler.getJobTaskStates(sessionId, Long.toString(flatJob.getId())).getList();
System.out.println(jobTaskStates);
TaskStateData task_1 = scheduler.jobTask(sessionId, Long.toString(flatJob.getId()), "task_1");
System.out.println(task_1);
// OTHER CALLS
List<SchedulerUserData> users = scheduler.getUsers(sessionId);
System.out.println(users);
System.out.println(users.size());
RestMapPage<Long, ArrayList<UserJobData>> page = scheduler.revisionAndJobsInfo(sessionId, 0, 50, true, true, true, true);
Map<Long, ArrayList<UserJobData>> map = page.getMap();
System.out.println(map);
System.out.println(scheduler.getSchedulerStatus(sessionId));
System.out.println(scheduler.getUsageOnMyAccount(sessionId, new Date(), new Date()));
// FAILING CALL
try {
JobStateData jobState = scheduler.listJobs(sessionId, "601");
System.out.println(jobState);
} catch (UnknownJobRestException e) {
System.err.println("exception! " + e.getMessage());
e.printStackTrace();
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData in project scheduling by ow2-proactive.
the class StringUtility method jobsAsString.
public static String jobsAsString(List<UserJobData> jobs) {
ObjectArrayFormatter formatter = new ObjectArrayFormatter();
formatter.setMaxColumnLength(30);
formatter.setSpace(4);
List<String> columnNames = new ArrayList<>(7);
columnNames.add("ID");
columnNames.add("NAME");
columnNames.add("OWNER");
columnNames.add("PRIORITY");
columnNames.add("STATUS");
columnNames.add("START AT");
columnNames.add("DURATION");
formatter.setTitle(columnNames);
formatter.addEmptyLine();
for (UserJobData job : jobs) {
formatter.addLine(rowList(job));
}
return Tools.getStringAsArray(formatter);
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData in project scheduling by ow2-proactive.
the class ListJobCommandTest method createUserJobInfoList.
private List<UserJobData> createUserJobInfoList(int jobsNumber) {
List<UserJobData> userJobInfoList = new ArrayList<UserJobData>(1);
for (int i = 0; i < jobsNumber; i++) {
JobInfoData jobInfoData = new JobInfoData();
JobIdData jobIdData = new JobIdData();
jobIdData.setId(i);
jobIdData.setReadableName(i + "name");
jobInfoData.setJobId(jobIdData);
jobInfoData.setPriority(JobPriorityData.HIGH);
jobInfoData.setStatus(JobStatusData.FINISHED);
jobInfoData.setStartTime(System.currentTimeMillis() - 1000);
jobInfoData.setFinishedTime(System.currentTimeMillis());
jobInfoData.setJobOwner("test");
userJobInfoList.add(new UserJobData(jobInfoData));
}
return userJobInfoList;
}
Aggregations