fix for bug 1162887
Users no longer need to disable the plugin to connect to a different gearman server. Along with this commit I changed the 'launchWorker' plugin config name to 'enablePlugin' because enabling plugin is distinct from running gearman workers. Change-Id: Ia81d78da3dbdc83fd46dd7f5d40ccb9aca3af97f
This commit is contained in:
parent
07026b7b71
commit
0de925f6d8
|
@ -47,7 +47,7 @@ public class ComputerListenerImpl extends ComputerListener {
|
||||||
+ " onConfigurationChange");
|
+ " onConfigurationChange");
|
||||||
|
|
||||||
// update functions only when gearman-plugin is enabled
|
// update functions only when gearman-plugin is enabled
|
||||||
if (!GearmanPluginConfig.get().launchWorker()) {
|
if (!GearmanPluginConfig.get().enablePlugin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class ComputerListenerImpl extends ComputerListener {
|
||||||
+ " onOffline");
|
+ " onOffline");
|
||||||
|
|
||||||
// update functions only when gearman-plugin is enabled
|
// update functions only when gearman-plugin is enabled
|
||||||
if (!GearmanPluginConfig.get().launchWorker()) {
|
if (!GearmanPluginConfig.get().enablePlugin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class ComputerListenerImpl extends ComputerListener {
|
||||||
+ " onOnline");
|
+ " onOnline");
|
||||||
|
|
||||||
// update functions only when gearman-plugin is enabled
|
// update functions only when gearman-plugin is enabled
|
||||||
if (!GearmanPluginConfig.get().launchWorker()) {
|
if (!GearmanPluginConfig.get().enablePlugin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ package hudson.plugins.gearman;
|
||||||
public interface Constants {
|
public interface Constants {
|
||||||
/* Defines. */
|
/* Defines. */
|
||||||
|
|
||||||
public static final boolean GEARMAN_DEFAULT_LAUNCH_WORKER = false;
|
public static final boolean GEARMAN_DEFAULT_ENABLE_PLUGIN = false;
|
||||||
public static final String GEARMAN_DEFAULT_TCP_HOST = "127.0.0.1";
|
public static final String GEARMAN_DEFAULT_TCP_HOST = "127.0.0.1";
|
||||||
public static final int GEARMAN_DEFAULT_TCP_PORT = 4730;
|
public static final int GEARMAN_DEFAULT_TCP_PORT = 4730;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory
|
private static final Logger logger = LoggerFactory
|
||||||
.getLogger(Constants.PLUGIN_LOGGER_NAME);
|
.getLogger(Constants.PLUGIN_LOGGER_NAME);
|
||||||
private boolean launchWorker; // enable/disable plugin
|
private boolean enablePlugin; // config to enable and disable plugin
|
||||||
private String host; // gearman server host
|
private String host; // gearman server host
|
||||||
private int port; // gearman server port
|
private int port; // gearman server port
|
||||||
|
|
||||||
|
@ -56,8 +56,6 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public GearmanPluginConfig() {
|
public GearmanPluginConfig() {
|
||||||
logger.info("---- GearmanPluginConfig Constructor ---");
|
|
||||||
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +63,7 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||||
return GlobalConfiguration.all().get(GearmanPluginConfig.class);
|
return GlobalConfiguration.all().get(GearmanPluginConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This method runs when user clicks Test Connection button.
|
* This method runs when user clicks Test Connection button.
|
||||||
*
|
*
|
||||||
|
@ -89,28 +88,50 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||||
public boolean configure(StaplerRequest req, JSONObject json)
|
public boolean configure(StaplerRequest req, JSONObject json)
|
||||||
throws Descriptor.FormException {
|
throws Descriptor.FormException {
|
||||||
|
|
||||||
// set the gearman config from user entered values in jenkins config
|
// save current plugin config so we can compare to new user settings
|
||||||
// page
|
String prevHost = this.host;
|
||||||
launchWorker = json.getBoolean("launchWorker");
|
int prevPort = this.port;
|
||||||
|
boolean prevEnablePlugin = this.enablePlugin;
|
||||||
|
|
||||||
|
// get the new gearman plugin configs from jenkins config page settings
|
||||||
|
enablePlugin = json.getBoolean("enablePlugin");
|
||||||
host = json.getString("host");
|
host = json.getString("host");
|
||||||
port = json.getInt("port");
|
port = json.getInt("port");
|
||||||
|
|
||||||
if (launchWorker) {
|
if (!enablePlugin && prevEnablePlugin) { // gearman-plugin goes from ON to OFF state
|
||||||
|
GearmanProxy.getInstance().stopAll();
|
||||||
|
|
||||||
// check for a valid connection to gearman server
|
} else if (enablePlugin && !prevEnablePlugin) { // gearman-plugin goes from OFF to ON state
|
||||||
logger.info("---- Check connection to Gearman Server " + host + ":"
|
// check for a valid connection to server
|
||||||
+ port);
|
|
||||||
if (!connectionIsAvailable(host, port, 5000)) {
|
if (!connectionIsAvailable(host, port, 5000)) {
|
||||||
launchWorker = false;
|
enablePlugin = false;
|
||||||
throw new FormException("Unable to connect to Gearman server. "
|
throw new FormException("Unable to connect to Gearman server. "
|
||||||
+ "Please check the server connection settings and retry.",
|
+ "Please check the server connection settings and retry.",
|
||||||
"host");
|
"host");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run workers
|
||||||
GearmanProxy.getInstance().initWorkers();
|
GearmanProxy.getInstance().initWorkers();
|
||||||
|
|
||||||
} else {
|
} else if (enablePlugin && prevEnablePlugin) { // gearman-plugin stays in the ON state
|
||||||
|
// update connection for a plugin config change
|
||||||
|
if (!host.equals(prevHost) || port != prevPort) {
|
||||||
|
|
||||||
|
// stop the workers on the current connected
|
||||||
GearmanProxy.getInstance().stopAll();
|
GearmanProxy.getInstance().stopAll();
|
||||||
|
|
||||||
|
// check for a valid connection to server
|
||||||
|
if (!connectionIsAvailable(host, port, 5000)) {
|
||||||
|
enablePlugin = false;
|
||||||
|
throw new FormException("Unable to connect to Gearman server. "
|
||||||
|
+ "Please check the server connection settings and retry.",
|
||||||
|
"host");
|
||||||
|
}
|
||||||
|
|
||||||
|
// run workers with new connection
|
||||||
|
GearmanProxy.getInstance().initWorkers();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.bindJSON(this, json);
|
req.bindJSON(this, json);
|
||||||
|
@ -118,12 +139,13 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns true if the global configuration says we should
|
* This method returns true if the global configuration says we should
|
||||||
* launch worker.
|
* enable the plugin.
|
||||||
*/
|
*/
|
||||||
public boolean launchWorker() {
|
public boolean enablePlugin() {
|
||||||
return Objects.firstNonNull(launchWorker, Constants.GEARMAN_DEFAULT_LAUNCH_WORKER);
|
return Objects.firstNonNull(enablePlugin, Constants.GEARMAN_DEFAULT_ENABLE_PLUGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,7 +168,7 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This method checks whether a connection open and available
|
* This method checks whether a connection is open and available
|
||||||
* on $host:$port
|
* on $host:$port
|
||||||
*
|
*
|
||||||
* @param host
|
* @param host
|
||||||
|
|
|
@ -82,7 +82,6 @@ public class GearmanProxy {
|
||||||
* executor' then use the gearman worker to execute builds on that
|
* executor' then use the gearman worker to execute builds on that
|
||||||
* jenkins nodes
|
* jenkins nodes
|
||||||
*/
|
*/
|
||||||
if (getNumExecutors() == 0) {
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Spawn management executor worker. This worker does not need any
|
* Spawn management executor worker. This worker does not need any
|
||||||
|
@ -126,7 +125,6 @@ public class GearmanProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("---- Num of executors running = " + getNumExecutors());
|
logger.info("---- Num of executors running = " + getNumExecutors());
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class SaveableListenerImpl extends SaveableListener {
|
||||||
+ " onChange");
|
+ " onChange");
|
||||||
|
|
||||||
// update functions only when gearman-plugin is enabled
|
// update functions only when gearman-plugin is enabled
|
||||||
if (!GearmanPluginConfig.get().launchWorker()) {
|
if (!GearmanPluginConfig.get().enablePlugin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
<f:validateButton
|
<f:validateButton
|
||||||
title="${%Test Connection}" progress="${%Testing...}"
|
title="${%Test Connection}" progress="${%Testing...}"
|
||||||
method="testConnection" with="host,port"/>
|
method="testConnection" with="host,port"/>
|
||||||
<f:entry title="Launch Worker" field="launchWorker"
|
<f:entry title="Enable Gearman" field="enablePlugin"
|
||||||
description="Select to run Gearman workers, Unselect to stop">
|
description="Select to enable Gearman plugin, Unselect to disable">
|
||||||
<f:checkbox checked="${descriptor.launchWorker()}"/>
|
<f:checkbox checked="${descriptor.enablePlugin()}"/>
|
||||||
</f:entry>
|
</f:entry>
|
||||||
</f:section>
|
</f:section>
|
||||||
</j:jelly>
|
</j:jelly>
|
|
@ -69,7 +69,7 @@ public class GearmanPluginConfigTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultLaunchWorker() {
|
public void testDefaultLaunchWorker() {
|
||||||
assertEquals(Constants.GEARMAN_DEFAULT_LAUNCH_WORKER,
|
assertEquals(Constants.GEARMAN_DEFAULT_ENABLE_PLUGIN,
|
||||||
gpc.launchWorker());
|
gpc.enablePlugin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue