From 8dd7629d4364c294f3d26df0d2c09f8321977349 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 3 Mar 2022 19:18:49 +0530 Subject: [PATCH 1/4] JNLP Support --- .../computeengine/ComputeEngineCloud.java | 14 +++- .../computeengine/InstanceConfiguration.java | 64 +++++++++++++++---- .../ComputeEngineCloud/config.jelly | 3 + .../ComputeEngineCloud/help-jnlpSupport.html | 16 +++++ 4 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/help-jnlpSupport.html diff --git a/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineCloud.java b/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineCloud.java index 860d8854..183fa349 100644 --- a/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineCloud.java +++ b/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineCloud.java @@ -92,6 +92,7 @@ public class ComputeEngineCloud extends AbstractCloudImpl { private transient volatile ComputeClient client; private boolean noDelayProvisioning; + private boolean jnlpSupport; @DataBoundConstructor public ComputeEngineCloud( @@ -153,6 +154,15 @@ public void setNoDelayProvisioning(boolean noDelayProvisioning) { this.noDelayProvisioning = noDelayProvisioning; } + public boolean isJnlpSupport() { + return jnlpSupport; + } + + @DataBoundSetter + public void setJnlpSupport(boolean jnlpSupport) { + this.jnlpSupport = jnlpSupport; + } + protected Object readResolve() { if (configurations != null) { for (InstanceConfiguration configuration : configurations) { @@ -262,7 +272,7 @@ public Collection provision(Label label, int excessWorkload) { } InstanceConfiguration config = chooseConfigFromList(configs); - + config.setJnlpSupport(jnlpSupport); final ComputeEngineInstance node = config.provision(); Jenkins.get().addNode(node); result.add(createPlannedNode(config, node)); @@ -431,7 +441,7 @@ public HttpResponse doProvision(@QueryParameter String configuration) if (c == null) { throw HttpResponses.error(SC_BAD_REQUEST, "No such Instance Configuration: " + configuration); } - + c.setJnlpSupport(jnlpSupport); ComputeEngineInstance node = c.provision(); if (node == null) throw HttpResponses.error(SC_BAD_REQUEST, "Could not provision new node."); Jenkins.get().addNode(node); diff --git a/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java b/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java index 03a9f02a..0696729a 100644 --- a/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java +++ b/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java @@ -50,6 +50,8 @@ import hudson.model.Label; import hudson.model.Node; import hudson.model.labels.LabelAtom; +import hudson.slaves.ComputerLauncher; +import hudson.slaves.JNLPLauncher; import hudson.util.FormValidation; import hudson.util.ListBoxModel; import java.io.IOException; @@ -95,6 +97,7 @@ public class InstanceConfiguration implements Describable (DEFAULT_LAUNCH_TIMEOUT_SECONDS / 60) + 1; public static final String DEFAULT_RUN_AS_USER = "jenkins"; public static final String METADATA_LINUX_STARTUP_SCRIPT_KEY = "startup-script"; + public static final String METADATA_CONTROLLER_URL = "controller-url"; public static final String METADATA_WINDOWS_STARTUP_SCRIPT_KEY = "windows-startup-script-ps1"; public static final String NAT_TYPE = "ONE_TO_ONE_NAT"; public static final String NAT_NAME = "External NAT"; @@ -160,6 +163,18 @@ public class InstanceConfiguration implements Describable @Setter(AccessLevel.PROTECTED) protected transient ComputeEngineCloud cloud; + private Instance instance; + private boolean jnlpSupport; + + public boolean isJnlpSupport() { + return jnlpSupport; + } + + @DataBoundSetter + public void setJnlpSupport(boolean jnlpSupport) { + this.jnlpSupport = jnlpSupport; + } + private static List mergeMetadataItems( List winner, List loser) { if (loser == null) { @@ -296,9 +311,22 @@ public void appendLabel(String key, String value) { googleLabels.put(key, value); } + private void appendJnlpMetadataIfRequired() { + if (jnlpSupport) { + log.info( + "Adding JNLP Meta Data " + METADATA_CONTROLLER_URL + " = " + Jenkins.get().getRootUrl()); + List items = instance.getMetadata().getItems(); + items.add( + new Metadata.Items() + .setKey(METADATA_CONTROLLER_URL) + .setValue(Jenkins.get().getRootUrl())); + } + } + public ComputeEngineInstance provision() throws IOException { try { - Instance instance = instance(); + instance = instance(); + appendJnlpMetadataIfRequired(); // TODO: JENKINS-55285 Operation operation = cloud @@ -306,20 +334,28 @@ public ComputeEngineInstance provision() throws IOException { .insertInstance(cloud.getProjectId(), Optional.ofNullable(template), instance); log.info("Sent insert request for instance configuration [" + description + "]"); String targetRemoteFs = this.remoteFs; - ComputeEngineComputerLauncher launcher; - if (this.windowsConfiguration != null) { - launcher = - new ComputeEngineWindowsLauncher( - cloud.getCloudName(), operation, this.useInternalAddress); - if (Strings.isNullOrEmpty(targetRemoteFs)) { - targetRemoteFs = "C:\\"; - } + ComputerLauncher launcher; + + if (jnlpSupport) { + log.info("JNLP Support Enabled for HSBC GCE Plugin"); + JNLPLauncher jnlpLauncher = new JNLPLauncher(true); + jnlpLauncher.setWebSocket(true); + launcher = jnlpLauncher; } else { - launcher = - new ComputeEngineLinuxLauncher( - cloud.getCloudName(), operation, this.useInternalAddress); - if (Strings.isNullOrEmpty(targetRemoteFs)) { - targetRemoteFs = "/tmp"; + if (this.windowsConfiguration != null) { + launcher = + new ComputeEngineWindowsLauncher( + cloud.getCloudName(), operation, this.useInternalAddress); + if (Strings.isNullOrEmpty(targetRemoteFs)) { + targetRemoteFs = "C:\\"; + } + } else { + launcher = + new ComputeEngineLinuxLauncher( + cloud.getCloudName(), operation, this.useInternalAddress); + if (Strings.isNullOrEmpty(targetRemoteFs)) { + targetRemoteFs = "/tmp"; + } } } return ComputeEngineInstance.builder() diff --git a/src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/config.jelly b/src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/config.jelly index e998af54..7fc60958 100644 --- a/src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/config.jelly +++ b/src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/config.jelly @@ -32,6 +32,9 @@ + + + diff --git a/src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/help-jnlpSupport.html b/src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/help-jnlpSupport.html new file mode 100644 index 00000000..680b6083 --- /dev/null +++ b/src/main/resources/com/google/jenkins/plugins/computeengine/ComputeEngineCloud/help-jnlpSupport.html @@ -0,0 +1,16 @@ + +By default Jenkins use SSH to connect HSBC cloud nodes. +With this option enabled, a new node is created on GCP and will be connected using JNLP Protocol. +User needs to setup start-up script for Nodes to connect to master. \ No newline at end of file From ababa8aba0a598916f9faae6a56de3ab38800ead Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 3 Mar 2022 22:08:17 +0530 Subject: [PATCH 2/4] JNLP Meta Data --- .../computeengine/InstanceConfiguration.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java b/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java index 0696729a..f3c35042 100644 --- a/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java +++ b/src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java @@ -66,6 +66,7 @@ import java.util.Set; import java.util.logging.Level; import jenkins.model.Jenkins; +import jenkins.slaves.JnlpAgentReceiver; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -98,6 +99,7 @@ public class InstanceConfiguration implements Describable public static final String DEFAULT_RUN_AS_USER = "jenkins"; public static final String METADATA_LINUX_STARTUP_SCRIPT_KEY = "startup-script"; public static final String METADATA_CONTROLLER_URL = "controller-url"; + public static final String METADATA_JNLP_SECRET = "jnlp-secret"; public static final String METADATA_WINDOWS_STARTUP_SCRIPT_KEY = "windows-startup-script-ps1"; public static final String NAT_TYPE = "ONE_TO_ONE_NAT"; public static final String NAT_NAME = "External NAT"; @@ -313,13 +315,21 @@ public void appendLabel(String key, String value) { private void appendJnlpMetadataIfRequired() { if (jnlpSupport) { - log.info( - "Adding JNLP Meta Data " + METADATA_CONTROLLER_URL + " = " + Jenkins.get().getRootUrl()); List items = instance.getMetadata().getItems(); - items.add( - new Metadata.Items() + + log.info("Adding JNLP Meta Data " + METADATA_CONTROLLER_URL + " = " + Jenkins.get().getRootUrl()); + + items.add( + new Metadata.Items() .setKey(METADATA_CONTROLLER_URL) .setValue(Jenkins.get().getRootUrl())); + + log.info("Adding JNLP Meta Data " + METADATA_JNLP_SECRET + " = " + JnlpAgentReceiver.SLAVE_SECRET.mac(instance.getName())); + + items.add( + new Metadata.Items() + .setKey(METADATA_JNLP_SECRET) + .setValue(JnlpAgentReceiver.SLAVE_SECRET.mac(instance.getName()))); } } From e2008a5ec19779571bd2ecbfb4801647142fc6d7 Mon Sep 17 00:00:00 2001 From: Vikrant Singh Nirban Date: Thu, 24 Aug 2023 10:15:31 +0530 Subject: [PATCH 3/4] Update release-drafter.yml --- .github/workflows/release-drafter.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 832442dd..00a46780 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -4,13 +4,24 @@ on: push: branches: - - master + - develop jobs: - update_release_draft: + build: + runs-on: ubuntu-latest + steps: - # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn clean package --file pom.xml -DskipTests + - uses: actions/upload-artifact@v3 + with: + name: gce-plugin + path: target/*.hpi From 97b23ca5ac32aab8f07203818bac6661db3ae204 Mon Sep 17 00:00:00 2001 From: Vikrant Singh Nirban Date: Tue, 29 Aug 2023 11:35:19 +0530 Subject: [PATCH 4/4] Update release-drafter.yml --- .github/workflows/release-drafter.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 00a46780..8d7a348e 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Set up JDK 8 uses: actions/setup-java@v3 with: - java-version: '17' + java-version: '8' distribution: 'temurin' cache: maven - name: Build with Maven