Skip to content

Commit

Permalink
Fix job lookup regular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Jul 24, 2015
1 parent 564ac11 commit 88cb833
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>com.tupilabs</groupId>
<artifactId>pbs-java-api</artifactId>
<version>0.9</version>
<version>0.10</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/jenkins/plugins/pbs/tasks/Qsub.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ public class Qsub implements Callable<Boolean, PBSException> {

private static final long serialVersionUID = -8294426519319612072L;

private static final String REGEX_JOB_STATUS = "(JOB_SUBSTATE_(.*)$|dequeuing [^,]+, state (.*)$)";
private static final String REGEX_JOB_SUBSTATUS = "Exit_status=([0-9]+)";
private static final Pattern JOB_SUBSTATUS_REGEX = Pattern.compile(REGEX_JOB_SUBSTATUS, Pattern.MULTILINE);
private static final Pattern JOB_STATUS_REGEX = Pattern.compile(REGEX_JOB_STATUS, Pattern.MULTILINE);
private static final String REGEX_JOB_STATUS = "(job_substate_(.*)$|exit_status=|dequeuing [^,]+, state (.*)$)";
private static final Pattern JOB_STATUS_REGEX = Pattern.compile(REGEX_JOB_STATUS, Pattern.MULTILINE|Pattern.CASE_INSENSITIVE);

private static final String REGEX_JOB_SUBSTATUS = "exit_status=([0-9]+)";
private static final Pattern JOB_SUBSTATUS_REGEX = Pattern.compile(REGEX_JOB_SUBSTATUS, Pattern.MULTILINE|Pattern.CASE_INSENSITIVE);

private final String script;
private final int numberOfDays;
Expand Down Expand Up @@ -181,26 +182,27 @@ private boolean seekEnd(String jobId, int numberOfDays, long span) {
private boolean loopSeek(String jobId) {
boolean toReturn = false;
while (true) {
CommandOutput cmd = PBS.traceJob(jobId, numberOfDays);
CommandOutput cmd = PBS.traceJob(jobId, numberOfDays, true /* quiet mode */);

final String out = cmd.getOutput();
// String err = cmd.getError();

// listener.getLogger().println(out);
// listener.getLogger().println("----");
Matcher matcher = JOB_STATUS_REGEX.matcher(out.toString());
Matcher matcher = JOB_STATUS_REGEX.matcher(out);
if (matcher.find()) {
String state = null;
if (matcher.groupCount() > 2) {
state = matcher.group(3);
if (matcher.groupCount() > 1) {
state = matcher.group(2);
}
if (StringUtils.isBlank(state)) {
state = matcher.group(1);
}
state = state.toLowerCase();
listener.getLogger().println("Found job state " + state);
if ("COMPLETE".equals(state)) {
if (state.contains("complete") || state.contains("exit_status")) {
// Now we look for the status
matcher = JOB_SUBSTATUS_REGEX.matcher(out.toString());
matcher = JOB_SUBSTATUS_REGEX.matcher(out);
if (matcher.find()) {
state = matcher.group(1);
listener.getLogger().println("Found run job status of " + state);
Expand Down
128 changes: 77 additions & 51 deletions src/main/resources/jenkins/plugins/pbs/PBSWidget/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,88 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:pane width="3" title="PBS Status" id="pbs">
<j:forEach var="computer" items="${it.computers}">
<tbody>
<tr>
<th class='pane' colspan='3'>
Jenkins slave: <a href="${rootURL}/computer/${computer.name}">${computer.name}</a>
</th>
</tr>
</tbody>
<colgroup>
<col width="1*"></col>
<col width="200*"></col>
<col width="24"></col>
</colgroup>
<tbody>
<thead>
<tr>
<th class='pane' colspan='3'>
Jenkins slave: <a href="${rootURL}/computer/${computer.name}">${computer.name}</a>
</th>
</tr>
</thead>
<colgroup>
<col width="1*"></col>
<col width="200*"></col>
<col width="24"></col>
</colgroup>
<tbody>
<j:choose>
<j:when test="${computer.getQueues().size() gt 0}">
<j:forEach var="queue" items="${computer.queues}">
<tr>
<tr>
<th class='pane' colspan='3'>Queue: ${queue.name}</th>
</tr>
<j:forEach var="job" items="${computer.getJobs(queue)}">
<tr>
<td class='pane'><a href="${rootURL}/pbsJob/index?jobId=${job.id}&amp;slaveName=${computer.name}">${job.id}</a></td>
<td class='pane'>${job.name}</td>
<td class='pane'></td>
</tr>
</j:forEach>
</tr>
<j:choose>
<j:set var="jobs" value="${computer.getJobs(queue)}" />
<j:when test="${jobs.size() gt 0}">
<j:forEach var="job" items="">
<tr>
<td class='pane'>
<a href="${rootURL}/pbsJob/index?jobId=${job.id}&amp;slaveName=${computer.name}">${job.id}</a>
</td>
<td class='pane'>${job.name}</td>
<td class='pane'></td>
</tr>
</j:forEach>
</j:when>
<j:otherwise>
<tr>
<td colspan="3">No jobs in this queue.</td>
</tr>
</j:otherwise>
</j:choose>
</j:forEach>
</j:when>
<j:otherwise>
<tr>
<td colspan="3">
<form method='get' action='${rootURL}/pbsJob/index'>
<input type="hidden" name="slaveName" value="${computer.name}" />
<table boder="0">
<tr>
<td>
<label for='jobId'>PBS Job ID</label>
</td>
<td>
<input type='text' name='jobId' id='jobId' />
</td>
</tr>
<tr>
<td>
<label for='numberOfDays'>Number of days</label>
</td>
<td>
<input type='text' name='numberOfDays' id='numberOfDays' value='1' />
</td>
</tr>
<tr>
<td colspan='2'>
<input type='submit' value='Search' />
</td>
</tr>
</table>
</form>
</td>
<td class="pane" colspan="3">No jobs in this queue.</td>
</tr>
</tbody>
</j:otherwise>
</j:choose>
<tr style="border-top: 10px solid #EEEEEE;">
<th colspan="3">
Search for jobs in the server
</th>
</tr>
<tr>
<td colspan="3">
<form method='get' action='${rootURL}/pbsJob/index'>
<input type="hidden" name="slaveName" value="${computer.name}" />
<table boder="0">
<tr>
<td>
<label for='jobId'>PBS Job ID</label>
</td>
<td>
<input type='text' name='jobId' id='jobId' />
</td>
</tr>
<tr>
<td>
<label for='numberOfDays'>Number of days</label>
</td>
<td>
<input type='text' name='numberOfDays' id='numberOfDays' value='1' />
</td>
</tr>
<tr>
<td colspan='2'>
<input type='submit' value='Search' />
</td>
</tr>
</table>
</form>
</td>
</tr>
</tbody>
</j:forEach>
</l:pane>
</j:jelly>

0 comments on commit 88cb833

Please sign in to comment.