From c5fb8b5e42ec15d7e3086de8a354f6a82880aa78 Mon Sep 17 00:00:00 2001 From: Khai Do Date: Fri, 11 Jan 2013 15:09:50 -0800 Subject: [PATCH] Gearman configuration UI is setup in the jenkins config page Change-Id: I46a03e51b9d2eafdc71a6cdbff46992b82a7c820 --- debug | 3 + pom.xml | 601 +++++++++--------- .../hudson/plugins/gearman/GearmanPlugin.java | 86 ++- .../gearman/GearmanPlugin/global.jelly | 19 +- src/main/webapp/help-launchWorker.html | 5 + src/main/webapp/help-serverHost.html | 5 + src/main/webapp/help-serverPort.html | 5 + 7 files changed, 425 insertions(+), 299 deletions(-) create mode 100755 debug create mode 100644 src/main/webapp/help-launchWorker.html create mode 100644 src/main/webapp/help-serverHost.html create mode 100644 src/main/webapp/help-serverPort.html diff --git a/debug b/debug new file mode 100755 index 0000000..0cc8383 --- /dev/null +++ b/debug @@ -0,0 +1,3 @@ +export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n" +rm -rf work/plugins +mvn -Dmaven.test.skip=true -DskipTests=true clean hpi:run diff --git a/pom.xml b/pom.xml index ea18a42..7329483 100644 --- a/pom.xml +++ b/pom.xml @@ -16,312 +16,323 @@ limitations under the License. --> - + - 4.0.0 + 4.0.0 - - org.jenkins-ci.plugins - plugin - 1.460 - + + org.jenkins-ci.plugins + plugin + 1.460 + + gearman-plugin + hpi - gearman-plugin - hpi + Gearman Plugin + http://wiki.jenkins-ci.org/display/JENKINS/Gearman+Plugin - Gearman Plugin - http://wiki.jenkins-ci.org/display/JENKINS/Gearman+Plugin + + + Apache License Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + - - - Apache License Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - + + + khaido + Khai Do + do.khai@gmail.com + + - - - khaido - Khai Do - do.khai@gmail.com - - + + scm:git:git://github.com/openstack-infra/gearman-plugin.git + scm:git:git@github.com:openstack-infra/gearman-plugin.git + https://github.com/openstack-infra/gearman-plugin + - - scm:git:git://github.com/openstack-infra/gearman-plugin.git - scm:git:git@github.com:openstack-infra/gearman-plugin.git - https://github.com/openstack-infra/gearman-plugin - + + + repo.jenkins-ci.org + http://repo.jenkins-ci.org/public/ + + - - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ - - + + + repo.jenkins-ci.org + http://repo.jenkins-ci.org/public/ + + - - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ - - + + + java.net-m2-repository + http://maven.jenkins-ci.org/content/repositories/releases/ + + + github-project-site + gitsite:git@github.com/openstack-infra/gearman-plugin + + - - - java.net-m2-repository - http://maven.jenkins-ci.org/content/repositories/releases/ - - - github-project-site - gitsite:git@github.com/openstack-infra/gearman-plugin - - + + + UTF-8 + 1.6 + + 3.0.1 + 1.6 + 2.2 + 2.2 + 2.6 + 2.4.1 + 2.3.2 + 2.1 + 2.5 + 1.0 + 2.8 + 1.0 + 2.1.1 + 2.3.1 + 2.7 + 2.3.1 + 6.1.26 + 2.2 + 2.5 + 2.3.1 + 2.4.3 + 1.0 + 2.1 + 1.1 + 2.4.3 + 2.1.1 + 2.1.2 + 2.7.2 + 2.7.2 + 2.1.1 + 1.0-alpha-4 + 1.4 + 1.0-beta-4 + 1.5 + 1.0.5 + 2.4 + 1.2 + 2.3.1 + 2.1.0-1 + 2.0 + 2.0-beta-2 + 1.2 + 2.4 + 1.2 + 1.0-beta-3 + - - - UTF-8 - 1.6 - - 3.0.1 - 1.6 - 2.2 - 2.2 - 2.6 - 2.4.1 - 2.3.2 - 2.1 - 2.5 - 1.0 - 2.8 - 1.0 - 2.1.1 - 2.3.1 - 2.7 - 2.3.1 - 6.1.26 - 2.2 - 2.5 - 2.3.1 - 2.4.3 - 1.0 - 2.1 - 1.1 - 2.4.3 - 2.1.1 - 2.1.2 - 2.7.2 - 2.7.2 - 2.1.1 - 1.0-alpha-4 - 1.4 - 1.0-beta-4 - 1.5 - 1.0.5 - 2.4 - 1.2 - 2.3.1 - 2.1.0-1 - 2.0 - 2.0-beta-2 - 1.2 - 2.4 - 1.2 - 1.0-beta-3 - - - - - - org.apache.maven.scm - maven-scm-provider-gitexe - 1.3 - - - org.apache.maven.scm - maven-scm-manager-plexus - 1.3 - - - org.kathrynhuxtable.maven.wagon - wagon-gitsite - 0.3.1 - - - - - - maven-clean-plugin - ${maven-clean-plugin.version} - - - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${compileSource} - ${compileTarget} - true - true - - - - maven-deploy-plugin - ${maven-deploy-plugin.version} - - - maven-enforcer-plugin - ${maven-enforcer-plugin.version} - - - maven-install-plugin - ${maven-install-plugin.version} - - - maven-jar-plugin - ${maven-jar-plugin.version} - - - maven-release-plugin - ${maven-release-plugin.version} - - true - true - clean deploy - clean deploy - release - - - - maven-remote-resources-plugin - ${maven-remote-resources-plugin.version} - - - maven-resources-plugin - ${maven-resources-plugin.version} - - - maven-site-plugin - ${maven-site-plugin.version} - - - maven-source-plugin - ${maven-source-plugin.version} - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - methods - true - 4 - - - - - - - maven-doap-plugin - ${maven-doap-plugin.version} - - - site - pre-site - - generate - - - - - ${project.reporting.outputDirectory}/doap.rdf - - false - - - - - maven-site-plugin - ${maven-site-plugin.version} - - - - - - - - maven-changelog-plugin - ${maven-changelog-plugin.version} - - - maven-checkstyle-plugin - ${maven-checkstyle-plugin.version} - - - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - maven-jxr-plugin - ${maven-jxr-plugin.version} - - - maven-pmd-plugin - ${maven-pmd-plugin.version} - - - maven-plugin-plugin - ${maven-plugin-plugin.version} - - - maven-project-info-reports-plugin - ${maven-project-info-reports-plugin.version} - - - - cim - distribution-management - index - issue-tracking - license - mailing-list - project-team - scm - summary - - - - - - maven-surefire-report-plugin - ${maven-surefire-report-plugin.version} - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura-maven-plugin.version} - - - org.codehaus.mojo - findbugs-maven-plugin - ${findbugs-maven-plugin.version} - - - org.codehaus.mojo - javancss-maven-plugin - ${javancss-maven-plugin.version} - - - org.codehaus.mojo - jdepend-maven-plugin - ${jdepend-maven-plugin.version} - - - org.codehaus.mojo - taglist-maven-plugin - ${taglist-maven-plugin.version} - - - + + + + org.apache.maven.scm + maven-scm-provider-gitexe + 1.3 + + + org.apache.maven.scm + maven-scm-manager-plexus + 1.3 + + + org.kathrynhuxtable.maven.wagon + wagon-gitsite + 0.3.1 + + + + + + maven-clean-plugin + ${maven-clean-plugin.version} + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${compileSource} + ${compileTarget} + true + true + + + + maven-deploy-plugin + ${maven-deploy-plugin.version} + + + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + maven-install-plugin + ${maven-install-plugin.version} + + + maven-jar-plugin + ${maven-jar-plugin.version} + + + maven-release-plugin + ${maven-release-plugin.version} + + true + true + clean deploy + clean deploy + release + + + + maven-remote-resources-plugin + ${maven-remote-resources-plugin.version} + + + maven-resources-plugin + ${maven-resources-plugin.version} + + + maven-site-plugin + ${maven-site-plugin.version} + + + maven-source-plugin + ${maven-source-plugin.version} + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + methods + true + 4 + + + + + + + maven-doap-plugin + ${maven-doap-plugin.version} + + + site + pre-site + + generate + + + + + ${project.reporting.outputDirectory}/doap.rdf + + false + + + + + maven-site-plugin + ${maven-site-plugin.version} + + + + + + + maven-changelog-plugin + ${maven-changelog-plugin.version} + + + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + maven-jxr-plugin + ${maven-jxr-plugin.version} + + + maven-pmd-plugin + ${maven-pmd-plugin.version} + + + maven-plugin-plugin + ${maven-plugin-plugin.version} + + + maven-project-info-reports-plugin + ${maven-project-info-reports-plugin.version} + + + + cim + distribution-management + index + issue-tracking + license + mailing-list + project-team + scm + summary + + + + + + maven-surefire-report-plugin + ${maven-surefire-report-plugin.version} + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura-maven-plugin.version} + + + org.codehaus.mojo + findbugs-maven-plugin + ${findbugs-maven-plugin.version} + + + org.codehaus.mojo + javancss-maven-plugin + ${javancss-maven-plugin.version} + + + org.codehaus.mojo + jdepend-maven-plugin + ${jdepend-maven-plugin.version} + + + org.codehaus.mojo + taglist-maven-plugin + ${taglist-maven-plugin.version} + + + + + + org.slf4j + slf4j-api + 1.6.1 + + + org.slf4j + slf4j-simple + 1.7.2 + + diff --git a/src/main/java/hudson/plugins/gearman/GearmanPlugin.java b/src/main/java/hudson/plugins/gearman/GearmanPlugin.java index db21cbc..8b8515f 100644 --- a/src/main/java/hudson/plugins/gearman/GearmanPlugin.java +++ b/src/main/java/hudson/plugins/gearman/GearmanPlugin.java @@ -25,8 +25,12 @@ import hudson.model.BuildListener; import hudson.model.AbstractBuild; import hudson.tasks.Builder; import hudson.tasks.BuildStepDescriptor; + +import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.DataBoundConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.management.Descriptor; @@ -44,10 +48,13 @@ import net.sf.json.JSONObject; */ public class GearmanPlugin extends Builder { + private static final Logger logger = LoggerFactory + .getLogger(GearmanPlugin.class); private final String name; @DataBoundConstructor public GearmanPlugin(String name) { + logger.info("--- GearmanPlugin Constructor ---" + name); this.name = name; } @@ -68,10 +75,29 @@ public class GearmanPlugin extends Builder { } @Extension - public static final class DescriptorImpl extends BuildStepDescriptor { + public static final class DescriptorImpl extends + BuildStepDescriptor { + private static final Logger logger = LoggerFactory + .getLogger(DescriptorImpl.class); + private boolean launchWorker; // launchWorker state (from UI checkbox) + private String host; // gearman server host + private int port; // gearman server port + public DescriptorImpl() { + logger.info("--- DescriptorImpl Constructor ---"); + logger.info("--- DescriptorImpl Constructor ---" + host); + logger.info("--- DescriptorImpl Constructor ---" + port); + 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 + */ + this.launchWorker = false; + save(); } @Override @@ -85,11 +111,65 @@ public class GearmanPlugin extends Builder { } @Override - public boolean configure(StaplerRequest staplerRequest, JSONObject json) throws FormException { - + public boolean configure(StaplerRequest staplerRequest, JSONObject json) + throws FormException { + launchWorker = json.getBoolean("launchWorker"); + logger.info("--- DescriptorImpl Configure function ---" + + this.launchWorker()); + + // set the gearman server host from value in jenkins config page + try { + host = json.getString("host"); + } catch (Exception e) { + throw new RuntimeException( + "Error getting the gearman host name"); + } + + // user input vaerification + if (StringUtils.isEmpty(host) || StringUtils.isBlank(host)) + throw new RuntimeException("Invalid gearman host name"); + + // set the gearman server port from value in jenkins config page + try { + port = Integer.parseInt(json.getString("port")); + } catch (Exception e) { + throw new RuntimeException("Invalid gearman port value"); + } + + // i believe gearman already checks for port range, just want to do + // basic verification here + if (port <= 0) + throw new RuntimeException("Invalid gearman port value"); + + logger.info("--- DescriptorImpl Configure function ---" + + this.getHost()); + logger.info("--- DescriptorImpl Configure function ---" + + this.getPort()); + save(); return true; } + /** + * This method returns true if the global configuration says we should + * launch worker. + */ + public boolean launchWorker() { + return launchWorker; + } + + /** + * This method returns the value from the server host text box + */ + public String getHost() { + return host; + } + + /** + * This method returns the value from the server port text box + */ + public int getPort() { + return port; + } } } diff --git a/src/main/resources/hudson/plugins/gearman/GearmanPlugin/global.jelly b/src/main/resources/hudson/plugins/gearman/GearmanPlugin/global.jelly index 23e6a39..c75df87 100644 --- a/src/main/resources/hudson/plugins/gearman/GearmanPlugin/global.jelly +++ b/src/main/resources/hudson/plugins/gearman/GearmanPlugin/global.jelly @@ -1,4 +1,21 @@ - + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/help-launchWorker.html b/src/main/webapp/help-launchWorker.html new file mode 100644 index 0000000..c21cab3 --- /dev/null +++ b/src/main/webapp/help-launchWorker.html @@ -0,0 +1,5 @@ +
+

+ Select then press save to start the Gearman workers. +

+
\ No newline at end of file diff --git a/src/main/webapp/help-serverHost.html b/src/main/webapp/help-serverHost.html new file mode 100644 index 0000000..c21638e --- /dev/null +++ b/src/main/webapp/help-serverHost.html @@ -0,0 +1,5 @@ +
+

+ Set the Gearman Server's host name, something like 'localhost', '127.0.0.1' or 'server.domain.com' +

+
\ No newline at end of file diff --git a/src/main/webapp/help-serverPort.html b/src/main/webapp/help-serverPort.html new file mode 100644 index 0000000..4e218fa --- /dev/null +++ b/src/main/webapp/help-serverPort.html @@ -0,0 +1,5 @@ +
+

+ Set the Gearman server port. The Gearman server's port is typically set to 4730 by default. +

+
\ No newline at end of file