agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/managers/monitors/parsers/TorqueJobStatusResponseParser.java
/**
	 * Parses a single status line from the remote server response. This should be the line containing the actual
	 * status info for the PBS job, trimmed of any headers, debug info, etc.
	 *
	 * @param remoteJobId the remote job id to parse from the response
	 * @param statusLine the qstat job status line
	 * @return a {@link JobStatusResponse} containing remote status info about the job with {@code remoteJobId}
	 * @throws RemoteJobMonitorResponseParsingException if unable to parse the job status
	 */
Parses a single status line from the remote server response. This should be the line containing the actual
status info for the PBS job, trimmed of any headers, debug info, etc.

@param remoteJobId the remote job id to parse from the response
@param statusLine the qstat job status line
@return a  JobStatusResponse containing remote status info about the job with  remoteJobId
@throws RemoteJobMonitorResponseParsingException if unable to parse the job status
Parses a single status line from the remote server response . This should be the line containing the actual status info for the PBS job trimmed of any headers debug info etc . @param remoteJobId the remote job id to parse from the response @param statusLine the qstat job status line @return a JobStatusResponse containing remote status info about the job with remoteJobId @throws RemoteJobMonitorResponseParsingException if unable to parse the job status
protected JobStatusResponse<TorqueJobStatus> parseLine(String remoteJobId, String statusLine) throws RemoteJobMonitorResponseParsingException {
		JobStatusResponse<TorqueJobStatus> jobStatusResponse = null;
		List<String> tokens = Arrays.asList(StringUtils.split(statusLine));
		if (tokens.size() == 11 || tokens.size() == 6) {
			try {
				TorqueJobStatus remoteJobStatus = TorqueJobStatus.valueOfCode(tokens.get(tokens.size() - 2));
				String exitCode = "0";
				jobStatusResponse = new JobStatusResponse<>(remoteJobId, remoteJobStatus, exitCode);
			}
			catch (Throwable e) {
				throw new RemoteJobMonitorResponseParsingException("Unexpected fields in the response from the scheduler");
			}
		}
		else {
			String exitCode = "0";
			for (int i=tokens.size()-1; i > 0; i--) {
				if (tokens.get(i).matches("^([a-zA-Z]{1})$")) {
					try {
						TorqueJobStatus remoteJobStatus = TorqueJobStatus.valueOfCode(tokens.get(i));
						jobStatusResponse = new JobStatusResponse<>(remoteJobId, remoteJobStatus, exitCode);
						break;
					}
					catch (Throwable e) {
						throw new RemoteJobMonitorResponseParsingException("Unexpected fields in the response from the scheduler");
					}
				}
			}
			if (tokens.get(0).equals(remoteJobId)) {
				jobStatusResponse = new JobStatusResponse<>(remoteJobId, TorqueJobStatus.UNKNOWN, exitCode);
			} else {
				throw new RemoteJobMonitorResponseParsingException("Unable to obtain job status in the response from the scheduler: " + statusLine);
			}
		}
		return jobStatusResponse;
	}
protected JobStatusResponse < TorqueJobStatus > parseLine ( String remoteJobId , String statusLine ) throws RemoteJobMonitorResponseParsingException { JobStatusResponse < TorqueJobStatus > jobStatusResponse = null ; List < String > tokens = Arrays . asList ( StringUtils . split ( statusLine ) ) ; if ( tokens . size ( ) == 11 || tokens . size ( ) == 6 ) { try { TorqueJobStatus remoteJobStatus = TorqueJobStatus . valueOfCode ( tokens . get ( tokens . size ( ) - 2 ) ) ; String exitCode = "0" ; jobStatusResponse = new JobStatusResponse < > ( remoteJobId , remoteJobStatus , exitCode ) ; } catch ( Throwable e ) { throw new RemoteJobMonitorResponseParsingException ( "Unexpected fields in the response from the scheduler" ) ; } } else { String exitCode = "0" ; for ( int i = tokens . size ( ) - 1 ; i > 0 ; i -- ) { if ( tokens . get ( i ) . matches ( "^([a-zA-Z]{1})$" ) ) { try { TorqueJobStatus remoteJobStatus = TorqueJobStatus . valueOfCode ( tokens . get ( i ) ) ; jobStatusResponse = new JobStatusResponse < > ( remoteJobId , remoteJobStatus , exitCode ) ; break ; } catch ( Throwable e ) { throw new RemoteJobMonitorResponseParsingException ( "Unexpected fields in the response from the scheduler" ) ; } } } if ( tokens . get ( 0 ) . equals ( remoteJobId ) ) { jobStatusResponse = new JobStatusResponse < > ( remoteJobId , TorqueJobStatus . UNKNOWN , exitCode ) ; } else { throw new RemoteJobMonitorResponseParsingException ( "Unable to obtain job status in the response from the scheduler: " + statusLine ) ; } } return jobStatusResponse ; }
Parses a single status line from the remote server response.
Parses a single status line from the remote server response .
// output frsom {@code qstat -a <job_id> } should be similar to one of the two following formats depending on torque/pbspro // <pre>Job ID                         Username        Queue           Jobname         SessID   NDS  TSK   Memory Time  S Time</pre> // in case the response is customized, we start checking from the last column inward, // looking for single character values, which is what the status would be. // The status line wasn't delimited like we thought and/or we couldn't find a valid status code, so we // check for the job id as the first token indicating that it was a status line, but that we could // not decipher the status. If found, we return a JobStatusResponse with TorqueJobStatus.UNKNOWN // letting the scheduler know that the job was present, but no longer in a known running state. // Otherwise, we don't really know what we have, so we reject the status line and throw a // RemoteJobMonitorResponseParsingException indicating we couldn't parse the response.