agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/managers/monitors/parsers/TorqueJobStatusResponseParser.java
/**
	 * The job status query to Torque was of the form {@code "qstat -a | grep ^<job_id>}. That means the response should
	 * come back in a tabbed column with the following fields.
	 *
	 * <pre>
	 * JobID                         Username        Queue           Jobname         SessID   NDS  TSK   ReqMemory ReqTime  S ElapsedTime
	 * </pre>
	 *
	 * A sample matching status like will look like:
	 * <pre>
	 * 0.33cf4118fced          testuser    debug    torque.submit       --    --     --     --   00:01:00 Q       --
	 * </pre>
	 *
	 * It is sufficient to split the string and look at the value in column 10 or 5.
	 *
	 * @param remoteJobId the remote job id to parse from the response
	 * @param schedulerResponseText the response text from the remote scheduler
	 * @return a {@link JobStatusResponse} containing remote status info about the job with {@code remoteJobId}
	 * @throws RemoteJobMonitorEmptyResponseException if {@code schedulerResponseText} is blank
	 * @throws RemoteJobMonitorResponseParsingException if {@code schedulerResponseText} could not be parsed
	 */
The job status query to Torque was of the form  "qstat -a | grep ^. That means the response should
come back in a tabbed column with the following fields.





It is sufficient to split the string and look at the value in column 10 or 5.


The job status query to Torque was of the form " qstat - a | grep ^ . That means the response should come back in a tabbed column with the following fields . It is sufficient to split the string and look at the value in column 10 or 5 .
@Override
	public JobStatusResponse parse(String remoteJobId, String schedulerResponseText) throws RemoteJobMonitorEmptyResponseException, RemoteJobMonitorResponseParsingException {
		if (StringUtils.isBlank(schedulerResponseText)) {
			throw new RemoteJobMonitorEmptyResponseException(
					"Empty response received from job status check on the remote system. Since the job was " +
							"successfully placed into queue, this is likely caused by a communication issue with the " +
							"scheduler. Retrying may clear up the issue.");
		} else if (schedulerResponseText.toLowerCase().contains("qstat: unknown job id")) {
			throw new RemoteJobMonitorEmptyResponseException(
					"Error response from job status check on the remote system. This is likely due to the job " +
							"completing and being purged from the qstat job cache. Calling tracejob with sufficient " +
							"permissions or examining the job logs should provide more information about the job.");
		}
		else if (schedulerResponseText.toLowerCase().contains("error")) {
			throw new RemoteJobMonitorResponseParsingException("Unable to obtain job status in the response from the scheduler: " + schedulerResponseText);
		} else {
			String[] lines = StringUtils.stripToEmpty(schedulerResponseText).split("[\\r\\n]+");
			for (String line: lines) {
				if (line.startsWith(remoteJobId)) {
					try {
						return parseLine(remoteJobId, line);
					} catch (RemoteJobMonitorResponseParsingException e) {
						throw new RemoteJobMonitorResponseParsingException(e.getMessage() + ": " + schedulerResponseText, e);
					}
				}
			}
			throw new RemoteJobMonitorResponseParsingException("Unable to obtain job status in the response from the scheduler");
		}
	}
@ Override public JobStatusResponse parse ( String remoteJobId , String schedulerResponseText ) throws RemoteJobMonitorEmptyResponseException , RemoteJobMonitorResponseParsingException { if ( StringUtils . isBlank ( schedulerResponseText ) ) { throw new RemoteJobMonitorEmptyResponseException ( "Empty response received from job status check on the remote system. Since the job was " + "successfully placed into queue, this is likely caused by a communication issue with the " + "scheduler. Retrying may clear up the issue." ) ; } else if ( schedulerResponseText . toLowerCase ( ) . contains ( "qstat: unknown job id" ) ) { throw new RemoteJobMonitorEmptyResponseException ( "Error response from job status check on the remote system. This is likely due to the job " + "completing and being purged from the qstat job cache. Calling tracejob with sufficient " + "permissions or examining the job logs should provide more information about the job." ) ; } else if ( schedulerResponseText . toLowerCase ( ) . contains ( "error" ) ) { throw new RemoteJobMonitorResponseParsingException ( "Unable to obtain job status in the response from the scheduler: " + schedulerResponseText ) ; } else { String [ ] lines = StringUtils . stripToEmpty ( schedulerResponseText ) . split ( "[\\r\\n]+" ) ; for ( String line : lines ) { if ( line . startsWith ( remoteJobId ) ) { try { return parseLine ( remoteJobId , line ) ; } catch ( RemoteJobMonitorResponseParsingException e ) { throw new RemoteJobMonitorResponseParsingException ( e . getMessage ( ) + ": " + schedulerResponseText , e ) ; } } } throw new RemoteJobMonitorResponseParsingException ( "Unable to obtain job status in the response from the scheduler" ) ; } }
The job status query to Torque was of the form {@code "qstat -a | grep ^<job_id>}.
The job status query to Torque was of the form { @code " qstat - a | grep ^<job_id > } .
// iterate over each line, finding the one starting with the job id // PBS status lines start with the job id // parse the line with the status info in it