Send node label with data status packet

Zuul can use this information to organize its build data by node type.
This will give us more granular insights into load and capacity.

Change-Id: Ibca938fcf8a65facd7e39dab4eb994dfc637722a
This commit is contained in:
Timothy Chavez 2015-07-23 09:59:58 -05:00
parent 08e9c429de
commit b54921152f
3 changed files with 16 additions and 9 deletions

View File

@ -51,30 +51,32 @@ public class CustomGearmanFunctionFactory extends DefaultGearmanFunctionFactory
public CustomGearmanFunctionFactory(String functionName, String className,
AbstractProject<?,?> project, Computer computer,
String masterName,
MyGearmanWorkerImpl worker) {
MyGearmanWorkerImpl worker,
String label) {
super(functionName, className);
this.theClass = className;
this.project = project;
this.computer = computer;
this.masterName = masterName;
this.worker = worker;
this.label = label;
}
@Override
public GearmanFunction getFunction() {
return createFunctionInstance(theClass, project, computer, masterName,
worker);
worker, label);
}
private static GearmanFunction createFunctionInstance(String className, AbstractProject<?,?> project, Computer computer, String masterName, MyGearmanWorkerImpl worker) {
private static GearmanFunction createFunctionInstance(String className, AbstractProject<?,?> project, Computer computer, String masterName, MyGearmanWorkerImpl worker, String label) {
GearmanFunction f = null;
try {
Class<?> c = Class.forName(className);
Constructor<?> con = c.getConstructor(new Class[]{AbstractProject.class, Computer.class, String.class, MyGearmanWorkerImpl.class});
Object o = con.newInstance(new Object[] {project, computer, masterName, worker});
Constructor<?> con = c.getConstructor(new Class[]{AbstractProject.class, Computer.class, String.class, MyGearmanWorkerImpl.class, String.class});
Object o = con.newInstance(new Object[] {project, computer, masterName, worker, label});
if (o instanceof GearmanFunction) {
f = (GearmanFunction) o;

View File

@ -133,7 +133,7 @@ public class ExecutorWorkerThread extends AbstractWorkerThread{
String jobFunctionName = "build:" + projectName;
newFunctionMap.put(jobFunctionName, new CustomGearmanFunctionFactory(
jobFunctionName, StartJobWorker.class.getName(),
project, computer, this.masterName, worker));
project, computer, this.masterName, worker, null));
}
} else { // register "build:$projectName:$label" if this
// node matches a node from the project label
@ -152,7 +152,7 @@ public class ExecutorWorkerThread extends AbstractWorkerThread{
// register without label (i.e. "build:$projectName")
newFunctionMap.put(jobFunctionName, new CustomGearmanFunctionFactory(
jobFunctionName, StartJobWorker.class.getName(),
project, computer, this.masterName, worker));
project, computer, this.masterName, worker, null));
// iterate over the intersection of project and node labels
for (LabelAtom labelAtom : nodeProjectLabelAtoms) {
jobFunctionName = "build:" + projectName
@ -160,7 +160,8 @@ public class ExecutorWorkerThread extends AbstractWorkerThread{
// register with label (i.e. "build:$projectName:$label")
newFunctionMap.put(jobFunctionName, new CustomGearmanFunctionFactory(
jobFunctionName, StartJobWorker.class.getName(),
project, computer, this.masterName, worker));
project, computer, this.masterName, worker,
labelAtom.getDisplayName()));
}
}
}

View File

@ -72,11 +72,12 @@ public class StartJobWorker extends AbstractGearmanFunction {
MyGearmanWorkerImpl worker;
public StartJobWorker(AbstractProject<?, ?> project, Computer computer, String masterName,
MyGearmanWorkerImpl worker) {
MyGearmanWorkerImpl worker, String label) {
this.project = project;
this.computer = computer;
this.masterName = masterName;
this.worker = worker;
this.label = label;
}
private String buildStatusData(AbstractBuild<?, ?> build) {
@ -89,6 +90,9 @@ public class StartJobWorker extends AbstractGearmanFunction {
data.put("number", build.getNumber());
data.put("manager", masterName);
data.put("worker", this.worker.getWorkerID());
if (label != null) {
data.put("label", label);
}
String rootUrl = Hudson.getInstance().getRootUrl();
if (rootUrl != null) {