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:
parent
fca2c7e325
commit
a5164d65a4
2
pom.xml
2
pom.xml
|
@ -28,7 +28,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.jenkins-ci.plugins</groupId>
|
<groupId>org.jenkins-ci.plugins</groupId>
|
||||||
<artifactId>plugin</artifactId>
|
<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>
|
</parent>
|
||||||
|
|
||||||
<artifactId>gearman-plugin</artifactId>
|
<artifactId>gearman-plugin</artifactId>
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class ExecutorWorkerThread extends AbstractWorkerThread{
|
||||||
if (!computer.isOffline()) {
|
if (!computer.isOffline()) {
|
||||||
Node node = computer.getNode();
|
Node node = computer.getNode();
|
||||||
|
|
||||||
List<AbstractProject> allProjects = Jenkins.getInstance().getAllItems(AbstractProject.class);
|
List<AbstractProject> allProjects = Jenkins.getActiveInstance().getAllItems(AbstractProject.class);
|
||||||
for (AbstractProject<?, ?> project : allProjects) {
|
for (AbstractProject<?, ?> project : allProjects) {
|
||||||
|
|
||||||
if (project.isDisabled()) { // ignore all disabled projects
|
if (project.isDisabled()) { // ignore all disabled projects
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class GearmanPluginUtil {
|
||||||
*/
|
*/
|
||||||
public static String getRealName(Computer computer) {
|
public static String getRealName(Computer computer) {
|
||||||
|
|
||||||
if (Computer.currentComputer() == computer) {
|
if (Jenkins.getActiveInstance().getComputer("") == computer) {
|
||||||
return "master";
|
return "master";
|
||||||
} else {
|
} else {
|
||||||
return computer.getName();
|
return computer.getName();
|
||||||
|
@ -70,7 +70,7 @@ public class GearmanPluginUtil {
|
||||||
*/
|
*/
|
||||||
public static Run<?,?> findBuild(String jobName, int buildNumber) {
|
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){
|
if (project != null){
|
||||||
Run<?,?> run = project.getBuildByNumber(buildNumber);
|
Run<?,?> run = project.getBuildByNumber(buildNumber);
|
||||||
if (run != null) {
|
if (run != null) {
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class GearmanProxy {
|
||||||
String hostname = Constants.GEARMAN_DEFAULT_EXECUTOR_NAME;
|
String hostname = Constants.GEARMAN_DEFAULT_EXECUTOR_NAME;
|
||||||
// query Jenkins for master's name
|
// query Jenkins for master's name
|
||||||
try {
|
try {
|
||||||
master = Jenkins.getInstance().getComputer("");
|
master = Jenkins.getActiveInstance().getComputer("");
|
||||||
hostname = master.getHostName();
|
hostname = master.getHostName();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Exception while getting hostname", e);
|
logger.warn("Exception while getting hostname", e);
|
||||||
|
@ -119,7 +119,7 @@ public class GearmanProxy {
|
||||||
// first make sure master is enabled (or has executors)
|
// first make sure master is enabled (or has executors)
|
||||||
Node masterNode = null;
|
Node masterNode = null;
|
||||||
try {
|
try {
|
||||||
masterNode = Computer.currentComputer().getNode();
|
masterNode = Jenkins.getActiveInstance().getComputer("").getNode();
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
logger.info("---- Master is offline");
|
logger.info("---- Master is offline");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -136,7 +136,7 @@ public class GearmanProxy {
|
||||||
/*
|
/*
|
||||||
* Spawn executors for the jenkins slaves
|
* Spawn executors for the jenkins slaves
|
||||||
*/
|
*/
|
||||||
List<Node> nodes = Jenkins.getInstance().getNodes();
|
List<Node> nodes = Jenkins.getActiveInstance().getNodes();
|
||||||
if (!nodes.isEmpty()) {
|
if (!nodes.isEmpty()) {
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
Computer computer = node.toComputer();
|
Computer computer = node.toComputer();
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class NodeAvailabilityMonitor implements AvailabilityMonitor {
|
||||||
{
|
{
|
||||||
this.computer = computer;
|
this.computer = computer;
|
||||||
queue = Queue.getInstance();
|
queue = Queue.getInstance();
|
||||||
jenkins = Jenkins.getInstance();
|
jenkins = Jenkins.getActiveInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Computer getComputer() {
|
public Computer getComputer() {
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class GearmanPluginConfigTest {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Jenkins jenkins = mock(Jenkins.class);
|
Jenkins jenkins = mock(Jenkins.class);
|
||||||
PowerMockito.mockStatic(Jenkins.class);
|
PowerMockito.mockStatic(Jenkins.class);
|
||||||
when(Jenkins.getInstance()).thenReturn(jenkins);
|
when(Jenkins.getActiveInstance()).thenReturn(jenkins);
|
||||||
|
|
||||||
gpc = new GearmanPluginConfig();
|
gpc = new GearmanPluginConfig();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package hudson.plugins.gearman;
|
||||||
|
|
||||||
import hudson.model.Computer;
|
import hudson.model.Computer;
|
||||||
import hudson.slaves.DumbSlave;
|
import hudson.slaves.DumbSlave;
|
||||||
|
import jenkins.model.Jenkins;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.jvnet.hudson.test.HudsonTestCase;
|
import org.jvnet.hudson.test.HudsonTestCase;
|
||||||
|
@ -45,7 +46,7 @@ public class GearmanPluginUtilTest extends HudsonTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testGetRealNameMaster() throws Exception {
|
public void testGetRealNameMaster() throws Exception {
|
||||||
|
|
||||||
assertEquals("master", GearmanPluginUtil.getRealName(Computer.currentComputer()));
|
assertEquals("master", GearmanPluginUtil.getRealName(Jenkins.getActiveInstance().getComputer("")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue