Update to Jenkins LTS 1.625.3 and fix function registration

Using a newer Jenkins LTS (ver 1.625.3) did not work with the
gearman-plugin. Gearman function registeration wasn't working
correct because Computer.currentComputer()[1] and getInstance()[2]
methods seemed to always return null on initialization of the
plugin. The Jenkins.getActiveInstance method (introduced in
Jenkins-1.589)[3] works more reliably.

[1] http://javadoc.jenkins-ci.org/hudson/model/Node.html#getNodeName()
[2] http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#getActiveInstance()
[3] e6c2e16f7a

Change-Id: I1534beda9c39a9d15da4d7b96f17e7b75699a631
This commit is contained in:
Khai Do 2015-12-02 22:11:03 -08:00
parent fca2c7e325
commit a5164d65a4
7 changed files with 11 additions and 10 deletions

View File

@ -28,7 +28,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.565.3</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.625.3</version> <!--which version of Jenkins is this plugin built against? -->
</parent>
<artifactId>gearman-plugin</artifactId>

View File

@ -117,7 +117,7 @@ public class ExecutorWorkerThread extends AbstractWorkerThread{
if (!computer.isOffline()) {
Node node = computer.getNode();
List<AbstractProject> allProjects = Jenkins.getInstance().getAllItems(AbstractProject.class);
List<AbstractProject> allProjects = Jenkins.getActiveInstance().getAllItems(AbstractProject.class);
for (AbstractProject<?, ?> project : allProjects) {
if (project.isDisabled()) { // ignore all disabled projects

View File

@ -51,7 +51,7 @@ public class GearmanPluginUtil {
*/
public static String getRealName(Computer computer) {
if (Computer.currentComputer() == computer) {
if (Jenkins.getActiveInstance().getComputer("") == computer) {
return "master";
} else {
return computer.getName();
@ -70,7 +70,7 @@ public class GearmanPluginUtil {
*/
public static Run<?,?> findBuild(String jobName, int buildNumber) {
AbstractProject<?,?> project = Jenkins.getInstance().getItemByFullName(jobName, AbstractProject.class);
AbstractProject<?,?> project = Jenkins.getActiveInstance().getItemByFullName(jobName, AbstractProject.class);
if (project != null){
Run<?,?> run = project.getBuildByNumber(buildNumber);
if (run != null) {

View File

@ -70,7 +70,7 @@ public class GearmanProxy {
String hostname = Constants.GEARMAN_DEFAULT_EXECUTOR_NAME;
// query Jenkins for master's name
try {
master = Jenkins.getInstance().getComputer("");
master = Jenkins.getActiveInstance().getComputer("");
hostname = master.getHostName();
} catch (Exception e) {
logger.warn("Exception while getting hostname", e);
@ -119,7 +119,7 @@ public class GearmanProxy {
// first make sure master is enabled (or has executors)
Node masterNode = null;
try {
masterNode = Computer.currentComputer().getNode();
masterNode = Jenkins.getActiveInstance().getComputer("").getNode();
} catch (NullPointerException npe) {
logger.info("---- Master is offline");
} catch (Exception e) {
@ -136,7 +136,7 @@ public class GearmanProxy {
/*
* Spawn executors for the jenkins slaves
*/
List<Node> nodes = Jenkins.getInstance().getNodes();
List<Node> nodes = Jenkins.getActiveInstance().getNodes();
if (!nodes.isEmpty()) {
for (Node node : nodes) {
Computer computer = node.toComputer();

View File

@ -38,7 +38,7 @@ public class NodeAvailabilityMonitor implements AvailabilityMonitor {
{
this.computer = computer;
queue = Queue.getInstance();
jenkins = Jenkins.getInstance();
jenkins = Jenkins.getActiveInstance();
}
public Computer getComputer() {

View File

@ -48,7 +48,7 @@ public class GearmanPluginConfigTest {
public void setUp() {
Jenkins jenkins = mock(Jenkins.class);
PowerMockito.mockStatic(Jenkins.class);
when(Jenkins.getInstance()).thenReturn(jenkins);
when(Jenkins.getActiveInstance()).thenReturn(jenkins);
gpc = new GearmanPluginConfig();
}

View File

@ -20,6 +20,7 @@ package hudson.plugins.gearman;
import hudson.model.Computer;
import hudson.slaves.DumbSlave;
import jenkins.model.Jenkins;
import org.junit.Test;
import org.jvnet.hudson.test.HudsonTestCase;
@ -45,7 +46,7 @@ public class GearmanPluginUtilTest extends HudsonTestCase {
@Test
public void testGetRealNameMaster() throws Exception {
assertEquals("master", GearmanPluginUtil.getRealName(Computer.currentComputer()));
assertEquals("master", GearmanPluginUtil.getRealName(Jenkins.getActiveInstance().getComputer("")));
}
}