Skip to content

Commit

Permalink
Add functionality: Enable to not require a polling node.
Browse files Browse the repository at this point in the history
Fix JENKINS-18889
  • Loading branch information
gboissinot committed Aug 2, 2013
1 parent fe64bab commit f35d4f8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
46 changes: 31 additions & 15 deletions src/main/java/org/jenkinsci/lib/xtrigger/AbstractTrigger.java
Expand Up @@ -177,31 +177,38 @@ public void run() {
log.info("Polling started on " + DateFormat.getDateTimeInstance().format(new Date(start)));
log.info("Polling for the job " + job.getName());

boolean changed;

Node pollingNode = getPollingNode(log);
if (pollingNode == null) {
log.info("Can't find any complete active node for the polling action.");
log.info("Maybe slaves are not yet active at this time or the number of executor of the master is 0.");
log.info("Checking again in next polling schedule.");
return;
}
if (requirePollingNode()) {

Node pollingNode = getPollingNode(log);
if (pollingNode == null) {
log.info("Can't find any complete active node for the polling action.");
log.info("Maybe slaves are not yet active at this time or the number of executor of the master is 0.");
log.info("Checking again in next polling schedule.");
return;
}

if (pollingNode.getRootPath() == null) {
log.info("The running slave might be offline at the moment.");
log.info("Waiting for next schedule.");
return;
}

displayPollingNode(pollingNode, log);
changed = checkIfModified(pollingNode, log);

if (pollingNode.getRootPath() == null) {
log.info("The running slave might be offline at the moment.");
log.info("Waiting for next schedule.");
return;
} else {
changed = checkIfModified(log);
}

displayPollingNode(pollingNode, log);

//Check if there are modifications in the environment
boolean changed = checkIfModified(pollingNode, log);
log.info("\nPolling complete. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start) + ".");

if (changed) {
log.info("Changes found. Scheduling a build.");
AbstractProject project = (AbstractProject) job;
project.scheduleBuild(0, new XTriggerCause(triggerName, getCause(), true), getScheduledXTriggerActions(pollingNode, log));
project.scheduleBuild(0, new XTriggerCause(triggerName, getCause(), true), getScheduledXTriggerActions(null, log));
} else {
log.info("No changes.");
}
Expand Down Expand Up @@ -235,6 +242,7 @@ public int hashCode() {
}
}


private void reportError(XTriggerLog log, Throwable e) {
log.error("Polling error...");
String message = e.getMessage();
Expand Down Expand Up @@ -273,6 +281,14 @@ protected Action[] getScheduledXTriggerActions(Node pollingNode, XTriggerLog log
*/
protected abstract boolean checkIfModified(Node pollingNode, XTriggerLog log) throws XTriggerException;

protected boolean requirePollingNode() {
return true;
}

protected boolean checkIfModified(XTriggerLog log) throws XTriggerException {
return true;
}

/**
* Gets the trigger cause
*
Expand Down
Expand Up @@ -71,12 +71,44 @@ protected boolean checkIfModified(Node pollingNode, XTriggerLog log) throws XTri
return changed;
}

@Override
protected boolean checkIfModified(XTriggerLog log) throws XTriggerException {
C newContext = getContext(log);

if (context == null) {
log.info("Recording context. Check changes in next poll.");
setNewContext(newContext);
return false;
}

boolean changed = checkIfModified(context, newContext, log);
setNewContext(newContext);
return changed;
}

private void setNewContext(C context) {
this.context = context;
}

protected abstract C getContext(Node pollingNode, XTriggerLog log) throws XTriggerException;
/**
* Captures the context
* This method is alternative to getContext(XTriggerLog log)
* It must be overridden
* from 0.26
*/
protected C getContext(Node pollingNode, XTriggerLog log) throws XTriggerException {
return null;
}

/**
* Captures the context
* This method is alternative to getContext(Node pollingNode, XTriggerLog log)
* It must be overridden
* from 0.26
*/
protected C getContext(XTriggerLog log) throws XTriggerException {
return null;
}

/**
* Checks if there are modifications in the environment between last poll
Expand Down

0 comments on commit f35d4f8

Please sign in to comment.