always run management worker
This commit is a fix to bug 1185952. While the jenkins host is running its master node may be in a disabled state (master has 0 executors) however the host should still be able to run a management worker and communicate with a Gearman Server. This commit makes sure that the manaegement worker runs regardless the master node's state. This commit also makes sure that we are setting the management worker's name to something. Change-Id: I871019fadde47787cfe20bec666e24d242728f30
This commit is contained in:
parent
b4e3ed8e3a
commit
18a3fa68cc
|
@ -36,7 +36,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
public abstract class AbstractWorkerThread implements Runnable {
|
||||
|
||||
public static final String DEFAULT_EXECUTOR_NAME = "anonymous";
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(Constants.PLUGIN_LOGGER_NAME);
|
||||
|
||||
|
@ -49,7 +48,7 @@ public abstract class AbstractWorkerThread implements Runnable {
|
|||
private boolean running = false;
|
||||
|
||||
public AbstractWorkerThread(String host, int port) {
|
||||
this(host, port, DEFAULT_EXECUTOR_NAME);
|
||||
this(host, port, Constants.GEARMAN_DEFAULT_EXECUTOR_NAME);
|
||||
}
|
||||
|
||||
public AbstractWorkerThread(String host, int port, String name) {
|
||||
|
|
|
@ -84,23 +84,23 @@ public class ComputerListenerImpl extends ComputerListener {
|
|||
return;
|
||||
}
|
||||
|
||||
// on creation of master
|
||||
/*
|
||||
* Need to treat the master differently than slaves because
|
||||
* the master is not the same as a slave
|
||||
*/
|
||||
GearmanProxy gp = GearmanProxy.getInstance();
|
||||
if (Computer.currentComputer() == c) { //check to see if this is master
|
||||
logger.info("---- This is master node, name is = "+c.getName());
|
||||
|
||||
if (gp.getGmwtHandles().isEmpty()) {
|
||||
/*
|
||||
* Spawn management executor worker. This worker does not need any
|
||||
* executors. It only needs to work with gearman.
|
||||
* Spawn management executor worker if one doesn't exist yet.
|
||||
* This worker does not need any executors. It only needs
|
||||
* to work with gearman.
|
||||
*/
|
||||
gp.createManagementWorker();
|
||||
|
||||
/*
|
||||
* Spawn executors for the jenkins master Need to treat the master
|
||||
* differently than slaves because the master is not the same as a
|
||||
* slave
|
||||
*/
|
||||
gp.createExecutorWorkersOnNode(c);
|
||||
// Spawn executors for the jenkins master
|
||||
if (Computer.currentComputer() == c) { //check to see if this is master
|
||||
gp.createExecutorWorkersOnNode(c);
|
||||
}
|
||||
}
|
||||
|
||||
// on creation of new slave
|
||||
|
|
|
@ -24,6 +24,7 @@ package hudson.plugins.gearman;
|
|||
public interface Constants {
|
||||
/* Defines. */
|
||||
|
||||
public static final String GEARMAN_DEFAULT_EXECUTOR_NAME = "anonymous";
|
||||
public static final boolean GEARMAN_DEFAULT_ENABLE_PLUGIN = false;
|
||||
public static final String GEARMAN_DEFAULT_TCP_HOST = "127.0.0.1";
|
||||
public static final int GEARMAN_DEFAULT_TCP_PORT = 4730;
|
||||
|
|
|
@ -21,6 +21,7 @@ package hudson.plugins.gearman;
|
|||
import hudson.model.Computer;
|
||||
import hudson.model.Node;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
@ -63,14 +64,23 @@ public class GearmanProxy {
|
|||
gmwtHandles = Collections.synchronizedList(new ArrayList<AbstractWorkerThread>());
|
||||
|
||||
Computer master = null;
|
||||
String hostname = null;
|
||||
String hostname = Constants.GEARMAN_DEFAULT_EXECUTOR_NAME;
|
||||
// query Jenkins for master's name
|
||||
try {
|
||||
master = Jenkins.getInstance().getComputer("");
|
||||
hostname = master.getHostName();
|
||||
} catch (Exception e) {
|
||||
logger.info("---- Can't get Master");
|
||||
e.printStackTrace();
|
||||
}
|
||||
// master node may not be enabled so get masterName from system
|
||||
if (master == null) {
|
||||
try {
|
||||
hostname = java.net.InetAddress.getLocalHost().getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
masterName = hostname;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue