Add new feature smooth disable
Change-Id: I7064b43c5725b07609f854055bd681641c93db0a
This commit is contained in:
parent
6f898a9b4d
commit
bd66eb0b72
@ -26,6 +26,7 @@ public interface Constants {
|
||||
|
||||
public static final String GEARMAN_DEFAULT_EXECUTOR_NAME = "anonymous";
|
||||
public static final boolean GEARMAN_DEFAULT_ENABLE_PLUGIN = false;
|
||||
public static final boolean GEARMAN_DEFAULT_SMOOTH_DISABLE = false;
|
||||
public static final String GEARMAN_DEFAULT_TCP_HOST = "127.0.0.1";
|
||||
public static final int GEARMAN_DEFAULT_TCP_PORT = 4730;
|
||||
|
||||
|
@ -24,6 +24,7 @@ import hudson.util.FormValidation;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
@ -51,6 +52,7 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||
private boolean enablePlugin; // config to enable and disable plugin
|
||||
private String host; // gearman server host
|
||||
private int port; // gearman server port
|
||||
private boolean smoothDisable; // If set, a disable of the plugin should be done when all workers are idled
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -91,17 +93,28 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||
// save current plugin config so we can compare to new user settings
|
||||
String prevHost = this.host;
|
||||
int prevPort = this.port;
|
||||
boolean prevSmoothDisable = this.smoothDisable;
|
||||
boolean prevEnablePlugin = this.enablePlugin;
|
||||
|
||||
// get the new gearman smooth disable mode
|
||||
smoothDisable = json.getBoolean("smoothDisable");
|
||||
|
||||
// get the new gearman plugin configs from jenkins config page settings
|
||||
enablePlugin = json.getBoolean("enablePlugin");
|
||||
host = json.getString("host");
|
||||
port = json.getInt("port");
|
||||
|
||||
if (!enablePlugin && prevEnablePlugin) { // gearman-plugin goes from ON to OFF state
|
||||
GearmanProxy.getInstance().stopAll();
|
||||
if (!smoothDisable) {
|
||||
GearmanProxy.getInstance().stopAll();
|
||||
}
|
||||
|
||||
} else if (enablePlugin && !prevEnablePlugin) { // gearman-plugin goes from OFF to ON state
|
||||
// Cleanup if smooth disable was set
|
||||
if (prevSmoothDisable) {
|
||||
GearmanProxy.getInstance().stopAll();
|
||||
}
|
||||
|
||||
// check for a valid connection to server
|
||||
if (!connectionIsAvailable(host, port, 5000)) {
|
||||
enablePlugin = false;
|
||||
@ -117,7 +130,8 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||
// update connection for a plugin config change
|
||||
if (!host.equals(prevHost) || port != prevPort) {
|
||||
|
||||
// stop the workers on the current connected
|
||||
// stop the workers on the current connected whatever is the smoothDisable setting
|
||||
// The use case in not yet identified
|
||||
GearmanProxy.getInstance().stopAll();
|
||||
|
||||
// check for a valid connection to server
|
||||
@ -132,6 +146,8 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||
GearmanProxy.getInstance().initWorkers();
|
||||
}
|
||||
|
||||
} else if (!smoothDisable && prevSmoothDisable && !enablePlugin && !prevEnablePlugin){ // Smooth disable was unset while plugin is disabled
|
||||
GearmanProxy.getInstance().stopAll();
|
||||
}
|
||||
|
||||
req.bindJSON(this, json);
|
||||
@ -148,6 +164,14 @@ public class GearmanPluginConfig extends GlobalConfiguration {
|
||||
return Objects.firstNonNull(enablePlugin, Constants.GEARMAN_DEFAULT_ENABLE_PLUGIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns true if the global configuration says we should
|
||||
* enable the smooth disable feature.
|
||||
*/
|
||||
public boolean smoothDisable() {
|
||||
return Objects.firstNonNull(smoothDisable, Constants.GEARMAN_DEFAULT_SMOOTH_DISABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the value from the server host text box
|
||||
*/
|
||||
|
@ -451,9 +451,13 @@ public class MyGearmanWorkerImpl implements GearmanSessionEventHandler {
|
||||
LOG.info("---- Worker " + this + " received unique job assignment");
|
||||
return addNewJob(event);
|
||||
case NOOP:
|
||||
LOG.debug("---- Worker " + this + " sending grab job after wakeup");
|
||||
try {
|
||||
sendGrabJob(s);
|
||||
if (GearmanPluginConfig.get().smoothDisable() && !GearmanPluginConfig.get().enablePlugin()) {
|
||||
LOG.info("---- Worker " + this + " do not send grab while in smooth disabling");
|
||||
} else {
|
||||
LOG.debug("---- Worker " + this + " sending grab job after wakeup");
|
||||
sendGrabJob(s);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warn("---- Worker " + this + " interrupted while waiting for okay to send " +
|
||||
"grab job", e);
|
||||
|
@ -13,5 +13,9 @@
|
||||
description="Select to enable Gearman plugin, Unselect to disable">
|
||||
<f:checkbox checked="${descriptor.enablePlugin()}"/>
|
||||
</f:entry>
|
||||
<f:entry title="Smooth disable" field="smoothDisable"
|
||||
description="Select to enable smooth disable plugin, Unselect to disable">
|
||||
<f:checkbox checked="${descriptor.smoothDisable()}"/>
|
||||
</f:entry>
|
||||
</f:section>
|
||||
</j:jelly>
|
@ -0,0 +1,5 @@
|
||||
<div>
|
||||
<p>
|
||||
If set, let a chance to ongoing job to finish when gearman is disabled. No more job are accepted while gearman is disabled.
|
||||
</p>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user