agave-jobs/jobs-api/src/main/java/org/iplantc/service/jobs/resources/QuartzResource.java
/**
	 * This method represents the HTTP GET action. A list of jobs is retrieved
	 * from the service database and serialized to a {@link org.json.JSONArray
	 * JSONArray} of {@link org.json.JSONObject JSONObject}. On error, a HTTP
	 * {@link org.restlet.data.Status#SERVER_ERROR_INTERNAL 500} code is sent.
	 */
This method represents the HTTP GET action. A list of jobs is retrieved
from the service database and serialized to a {@link org.json.JSONArray
JSONArray} of  org.json.JSONObject JSONObject. On error, a HTTP
org.restlet.data.Status#SERVER_ERROR_INTERNAL 500 code is sent.
This method represents the HTTP GET action . A list of jobs is retrieved from the service database and serialized to a { @link org . json . JSONArray JSONArray } of org . json . JSONObject JSONObject . On error a HTTP org . restlet . data . Status#SERVER_ERROR_INTERNAL 500 code is sent .
@Override
	public Representation represent(Variant variant) throws ResourceException
	{
		try {
			if (ServiceUtils.isAdmin(username)) {
				try {
					Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
					ObjectMapper mapper = new ObjectMapper();
					ObjectNode json = mapper.createObjectNode()
							.put("id", sched.getSchedulerInstanceId())
							.put("name", sched.getSchedulerName());
					ObjectNode jsonJobs = mapper.createObjectNode();
					Map<String, Trigger> triggerMap = new HashMap<String, Trigger>();
					ArrayNode allJobs = jsonJobs.putArray("available");
					List<JobExecutionContext> currentJobs = sched.getCurrentlyExecutingJobs();
					for (String group : sched.getJobGroupNames()) {
						GroupMatcher<JobKey> groupMatcher = groupEquals(group);
						for (JobKey jobKey : sched.getJobKeys(groupMatcher)) {
							JobDetail jobDetail = sched.getJobDetail(jobKey);
							ObjectNode jsonJob = mapper.createObjectNode()
									.put("key", jobDetail.getKey().toString())
									.put("description", jobDetail.getDescription())
									.put("allowsConcurrentExecution", jobDetail.isConcurrentExectionDisallowed())
									.put("type", jobDetail.getClass().getSimpleName());
							allJobs.add(jsonJob);
						}
					}
					ArrayNode activeJobs = jsonJobs.putArray("active");
					for (JobExecutionContext job : currentJobs) {
						ObjectNode jsonJob = mapper.createObjectNode()
								.put("key", job.getJobDetail().getKey().toString())
								.put("isActive", job.getJobRunTime() == -1)
								.put("type", job.getJobDetail().getClass().getSimpleName())
								.put("description", job.getJobDetail().getDescription())
								.put("scheduledAt", new DateTime(job.getScheduledFireTime()).toString())
								.put("firedAt", new DateTime(job.getFireTime()).toString())
								.put("nextFireAt", new DateTime(job.getNextFireTime()).toString())
								.put("previousFiredAt", new DateTime(job.getPreviousFireTime()).toString())
								.put("refireCount", job.getRefireCount())
								.put("isRecovering", job.isRecovering())
								.put("lastFireDuration", job.getJobRunTime())
								.put("allowsConcurrentExecution", job.getJobDetail().isConcurrentExectionDisallowed())
								.put("result", job.getResult() == null ? null : job.getResult().toString())
								.put("triggerKey", job.getTrigger().getKey().toString());
						if (!triggerMap.containsKey(job.getTrigger().getKey().toString())) {
							triggerMap.put(job.getTrigger().getKey().toString(), job.getTrigger());
						}
						activeJobs.add(jsonJob);
					}
					json.put("jobs", jsonJobs);
					ArrayNode triggers = json.putArray("triggers");
					for (String group : sched.getTriggerGroupNames()) {
						GroupMatcher<TriggerKey> groupMatcher = groupEquals(group);
						for (TriggerKey triggerKey : sched.getTriggerKeys(groupMatcher)) {
							Trigger trigger = sched.getTrigger(triggerKey);
							ObjectNode jsonTrigger = mapper.createObjectNode()
									.put("key", triggerKey.toString())
									.put("description", trigger.getDescription())
									.put("nextFireAt", new DateTime(trigger.getNextFireTime()).toString())
									.put("previousFiredAt", new DateTime(trigger.getPreviousFireTime()).toString())
									.put("finalFireAt", new DateTime(trigger.getEndTime()).toString());
							triggers.add(jsonTrigger);
						}
					}
					return new IplantSuccessRepresentation(json.toString());
				} catch (Exception e) {
					getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
					return new IplantErrorRepresentation(e.getMessage());
				}
			} else {
				getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN);
				return new IplantErrorRepresentation(
						"User does not have permission to view this resource");
			}
		}
		finally {
			try { HibernateUtil.closeSession(); } catch (Throwable ignored) {}
		}
	}
@ Override public Representation represent ( Variant variant ) throws ResourceException { try { if ( ServiceUtils . isAdmin ( username ) ) { try { Scheduler sched = StdSchedulerFactory . getDefaultScheduler ( ) ; ObjectMapper mapper = new ObjectMapper ( ) ; ObjectNode json = mapper . createObjectNode ( ) . put ( "id" , sched . getSchedulerInstanceId ( ) ) . put ( "name" , sched . getSchedulerName ( ) ) ; ObjectNode jsonJobs = mapper . createObjectNode ( ) ; Map < String , Trigger > triggerMap = new HashMap < String , Trigger > ( ) ; ArrayNode allJobs = jsonJobs . putArray ( "available" ) ; List < JobExecutionContext > currentJobs = sched . getCurrentlyExecutingJobs ( ) ; for ( String group : sched . getJobGroupNames ( ) ) { GroupMatcher < JobKey > groupMatcher = groupEquals ( group ) ; for ( JobKey jobKey : sched . getJobKeys ( groupMatcher ) ) { JobDetail jobDetail = sched . getJobDetail ( jobKey ) ; ObjectNode jsonJob = mapper . createObjectNode ( ) . put ( "key" , jobDetail . getKey ( ) . toString ( ) ) . put ( "description" , jobDetail . getDescription ( ) ) . put ( "allowsConcurrentExecution" , jobDetail . isConcurrentExectionDisallowed ( ) ) . put ( "type" , jobDetail . getClass ( ) . getSimpleName ( ) ) ; allJobs . add ( jsonJob ) ; } } ArrayNode activeJobs = jsonJobs . putArray ( "active" ) ; for ( JobExecutionContext job : currentJobs ) { ObjectNode jsonJob = mapper . createObjectNode ( ) . put ( "key" , job . getJobDetail ( ) . getKey ( ) . toString ( ) ) . put ( "isActive" , job . getJobRunTime ( ) == - 1 ) . put ( "type" , job . getJobDetail ( ) . getClass ( ) . getSimpleName ( ) ) . put ( "description" , job . getJobDetail ( ) . getDescription ( ) ) . put ( "scheduledAt" , new DateTime ( job . getScheduledFireTime ( ) ) . toString ( ) ) . put ( "firedAt" , new DateTime ( job . getFireTime ( ) ) . toString ( ) ) . put ( "nextFireAt" , new DateTime ( job . getNextFireTime ( ) ) . toString ( ) ) . put ( "previousFiredAt" , new DateTime ( job . getPreviousFireTime ( ) ) . toString ( ) ) . put ( "refireCount" , job . getRefireCount ( ) ) . put ( "isRecovering" , job . isRecovering ( ) ) . put ( "lastFireDuration" , job . getJobRunTime ( ) ) . put ( "allowsConcurrentExecution" , job . getJobDetail ( ) . isConcurrentExectionDisallowed ( ) ) . put ( "result" , job . getResult ( ) == null ? null : job . getResult ( ) . toString ( ) ) . put ( "triggerKey" , job . getTrigger ( ) . getKey ( ) . toString ( ) ) ; if ( ! triggerMap . containsKey ( job . getTrigger ( ) . getKey ( ) . toString ( ) ) ) { triggerMap . put ( job . getTrigger ( ) . getKey ( ) . toString ( ) , job . getTrigger ( ) ) ; } activeJobs . add ( jsonJob ) ; } json . put ( "jobs" , jsonJobs ) ; ArrayNode triggers = json . putArray ( "triggers" ) ; for ( String group : sched . getTriggerGroupNames ( ) ) { GroupMatcher < TriggerKey > groupMatcher = groupEquals ( group ) ; for ( TriggerKey triggerKey : sched . getTriggerKeys ( groupMatcher ) ) { Trigger trigger = sched . getTrigger ( triggerKey ) ; ObjectNode jsonTrigger = mapper . createObjectNode ( ) . put ( "key" , triggerKey . toString ( ) ) . put ( "description" , trigger . getDescription ( ) ) . put ( "nextFireAt" , new DateTime ( trigger . getNextFireTime ( ) ) . toString ( ) ) . put ( "previousFiredAt" , new DateTime ( trigger . getPreviousFireTime ( ) ) . toString ( ) ) . put ( "finalFireAt" , new DateTime ( trigger . getEndTime ( ) ) . toString ( ) ) ; triggers . add ( jsonTrigger ) ; } } return new IplantSuccessRepresentation ( json . toString ( ) ) ; } catch ( Exception e ) { getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; return new IplantErrorRepresentation ( e . getMessage ( ) ) ; } } else { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_FORBIDDEN ) ; return new IplantErrorRepresentation ( "User does not have permission to view this resource" ) ; } } finally { try { HibernateUtil . closeSession ( ) ; } catch ( Throwable ignored ) { } } }
This method represents the HTTP GET action.
This method represents the HTTP GET action .
//		AgaveLogServiceClient.log(AgaveLogServiceClient.ServiceKeys.JOBS02.name(),  //				AgaveLogServiceClient.ActivityKeys.WorkerCheck.name(),  //				username, "", getRequest().getClientInfo().getUpstreamAddress()); // enumerate each trigger in group