Merge "make gearman-plugin enable/disable state persistant across jenkins restart"
This commit is contained in:
commit
174d783623
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package hudson.plugins.gearman;
|
||||
|
||||
import hudson.Extension;
|
||||
|
@ -61,7 +78,7 @@ public class ComputerListenerImpl extends ComputerListener {
|
|||
|
||||
@Override
|
||||
public void onConfigurationChange() {
|
||||
// gets called on any configuration change
|
||||
// gets called on any configuration change
|
||||
// includes new slave and delete slave
|
||||
logger.info("---- " + ComputerListenerImpl.class.getName() + ":"
|
||||
+ " onConfigurationChange");
|
||||
|
@ -127,8 +144,9 @@ public class ComputerListenerImpl extends ComputerListener {
|
|||
@Override
|
||||
public void onOnline(Computer c, TaskListener listener) throws IOException,
|
||||
InterruptedException {
|
||||
// gets called when master goes into online state
|
||||
// gets called when existing slave re-connects
|
||||
// gets called when new slave goes into online state.
|
||||
// gets called when new slave goes into online state
|
||||
logger.info("---- " + ComputerListenerImpl.class.getName() + ":"
|
||||
+ " onOnline");
|
||||
|
||||
|
@ -137,6 +155,43 @@ public class ComputerListenerImpl extends ComputerListener {
|
|||
return;
|
||||
}
|
||||
|
||||
// on creation of master
|
||||
if (Computer.currentComputer() == c) { //check to see if this is master
|
||||
logger.info("---- This is master node, name is = "+c.getName());
|
||||
|
||||
/*
|
||||
* Spawn management executor worker. This worker does not need any
|
||||
* executors. It only needs to work with gearman.
|
||||
*/
|
||||
String host = GearmanPluginConfig.get().getHost();
|
||||
int port = GearmanPluginConfig.get().getPort();
|
||||
|
||||
AbstractWorkerThread gwt = new ManagementWorkerThread(host, port, host);
|
||||
gwt.registerJobs();
|
||||
gwt.start();
|
||||
GearmanProxy.getGmwtHandles().add(gwt);
|
||||
|
||||
/*
|
||||
* Spawn executors for the jenkins master Need to treat the master
|
||||
* differently than slaves because the master is not the same as a
|
||||
* slave
|
||||
*/
|
||||
Node masterNode = c.getNode();
|
||||
int executors = c.getExecutors().size();
|
||||
for (int i = 0; i < executors; i++) {
|
||||
// create a gearman worker for every executor on the master
|
||||
gwt = new ExecutorWorkerThread(GearmanPluginConfig.get().getHost(),
|
||||
GearmanPluginConfig.get().getPort(),
|
||||
"master-exec"+ Integer.toString(i),
|
||||
masterNode);
|
||||
gwt.start();
|
||||
GearmanProxy.getGewtHandles().add(gwt);
|
||||
}
|
||||
GearmanProxy.setNumWorkerNodes(GearmanPluginUtil.getNumTotalNodes());
|
||||
logger.info("---- numWorkerNodes = "
|
||||
+ GearmanProxy.getNumWorkerNodes());
|
||||
}
|
||||
|
||||
// on re-connection of node
|
||||
// update gearman worker functions on existing threads
|
||||
List<AbstractWorkerThread> workers = GearmanProxy.getGewtHandles();
|
||||
|
@ -149,7 +204,7 @@ public class ComputerListenerImpl extends ComputerListener {
|
|||
|
||||
@Override
|
||||
public void onTemporarilyOnline(Computer c) {
|
||||
// gets called when existing slave is re-enabled
|
||||
// gets called when existing slave is re-enabled (including master)
|
||||
logger.info("---- " + ComputerListenerImpl.class.getName() + ":"
|
||||
+ " onTemporarilyOnline");
|
||||
|
||||
|
@ -169,7 +224,7 @@ public class ComputerListenerImpl extends ComputerListener {
|
|||
|
||||
@Override
|
||||
public void onTemporarilyOffline(Computer c, OfflineCause cause) {
|
||||
// gets called when existing slave is dis-enabled
|
||||
// gets called when existing slave is dis-enabled (including master)
|
||||
logger.info("---- " + ComputerListenerImpl.class.getName() + ":"
|
||||
+ " onTemporarilyOffline");
|
||||
|
||||
|
@ -187,4 +242,5 @@ public class ComputerListenerImpl extends ComputerListener {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -57,14 +57,6 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
|||
|
||||
gearmanProxy = new GearmanProxy();
|
||||
load();
|
||||
|
||||
/*
|
||||
* Not sure when to register gearman functions yet so for now always
|
||||
* initialize the launch worker flag to disabled state at jenkins
|
||||
* startup so we are always at a known state
|
||||
*/
|
||||
launchWorker = Constants.GEARMAN_DEFAULT_LAUNCH_WORKER;
|
||||
save();
|
||||
}
|
||||
|
||||
public static GearmanPluginConfig get() {
|
||||
|
|
|
@ -21,8 +21,8 @@ package hudson.plugins.gearman;
|
|||
import hudson.model.Computer;
|
||||
import hudson.model.Node;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import jenkins.model.Jenkins;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class GearmanProxy {
|
|||
private static List<AbstractWorkerThread> gewtHandles;
|
||||
private static List<AbstractWorkerThread> gmwtHandles;
|
||||
|
||||
// keep track of number of executor slaves in system
|
||||
// keep track of number of computers that are tied to gearman workers
|
||||
private static int numWorkerNodes;
|
||||
|
||||
|
||||
|
@ -52,8 +52,8 @@ public class GearmanProxy {
|
|||
public GearmanProxy() {
|
||||
logger.info("--- GearmanProxy Constructor ---");
|
||||
|
||||
gewtHandles = new Stack<AbstractWorkerThread>();
|
||||
gmwtHandles = new Stack<AbstractWorkerThread>();
|
||||
gewtHandles = new ArrayList<AbstractWorkerThread>();
|
||||
gmwtHandles = new ArrayList<AbstractWorkerThread>();
|
||||
numWorkerNodes = 0;
|
||||
}
|
||||
|
||||
|
@ -102,16 +102,18 @@ public class GearmanProxy {
|
|||
|
||||
if (masterNode != null) {
|
||||
Computer computer = masterNode.toComputer();
|
||||
int executors = computer.getExecutors().size();
|
||||
for (int i = 0; i < executors; i++) {
|
||||
// create a gearman worker for every executor on the master
|
||||
gwt = new ExecutorWorkerThread(host, port, "master-exec"
|
||||
+ Integer.toString(i), masterNode);
|
||||
gwt.registerJobs();
|
||||
gwt.start();
|
||||
gewtHandles.add(gwt);
|
||||
if (computer != null) {
|
||||
int executors = computer.getExecutors().size();
|
||||
for (int i = 0; i < executors; i++) {
|
||||
// create a gearman worker for every executor on the master
|
||||
gwt = new ExecutorWorkerThread(host, port, "master-exec"
|
||||
+ Integer.toString(i), masterNode);
|
||||
gwt.registerJobs();
|
||||
gwt.start();
|
||||
gewtHandles.add(gwt);
|
||||
}
|
||||
numWorkerNodes++;
|
||||
}
|
||||
numWorkerNodes++;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -121,15 +123,17 @@ public class GearmanProxy {
|
|||
if (!nodes.isEmpty()) {
|
||||
for (Node node : nodes) {
|
||||
Computer computer = node.toComputer();
|
||||
// create a gearman worker for every executor on the slave
|
||||
int slaveExecutors = computer.getExecutors().size();
|
||||
for (int i = 0; i < slaveExecutors; i++) {
|
||||
gwt = new ExecutorWorkerThread(host, port,
|
||||
node.getNodeName() + "-exec"
|
||||
+ Integer.toString(i), node);
|
||||
gwt.registerJobs();
|
||||
gwt.start();
|
||||
gewtHandles.add(gwt);
|
||||
if (computer != null) {
|
||||
// create a gearman worker for every executor on the slave
|
||||
int slaveExecutors = computer.getExecutors().size();
|
||||
for (int i = 0; i < slaveExecutors; i++) {
|
||||
gwt = new ExecutorWorkerThread(host, port,
|
||||
node.getNodeName() + "-exec"
|
||||
+ Integer.toString(i), node);
|
||||
gwt.registerJobs();
|
||||
gwt.start();
|
||||
gewtHandles.add(gwt);
|
||||
}
|
||||
}
|
||||
numWorkerNodes++;
|
||||
}
|
||||
|
@ -173,6 +177,13 @@ public class GearmanProxy {
|
|||
return gewtHandles;
|
||||
}
|
||||
|
||||
/*
|
||||
* This method returns the list of gearman management workers
|
||||
*/
|
||||
public static synchronized List<AbstractWorkerThread> getGmwtHandles() {
|
||||
return gmwtHandles;
|
||||
}
|
||||
|
||||
/*
|
||||
* This method returns the number of worker nodes
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue