Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNLP Support to Plugin #312

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 8
uses: actions/setup-java@v3
with:
java-version: '8'
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class ComputeEngineCloud extends AbstractCloudImpl {

private transient volatile ComputeClient client;
private boolean noDelayProvisioning;
private boolean jnlpSupport;

@DataBoundConstructor
public ComputeEngineCloud(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -262,7 +272,7 @@ public Collection<PlannedNode> 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));
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,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;
Expand Down Expand Up @@ -95,6 +98,8 @@ public class InstanceConfiguration implements Describable<InstanceConfiguration>
(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_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";
Expand Down Expand Up @@ -160,6 +165,18 @@ public class InstanceConfiguration implements Describable<InstanceConfiguration>
@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<Metadata.Items> mergeMetadataItems(
List<Metadata.Items> winner, List<Metadata.Items> loser) {
if (loser == null) {
Expand Down Expand Up @@ -296,30 +313,59 @@ public void appendLabel(String key, String value) {
googleLabels.put(key, value);
}

private void appendJnlpMetadataIfRequired() {
if (jnlpSupport) {
List<Metadata.Items> items = instance.getMetadata().getItems();

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())));
}
}

public ComputeEngineInstance provision() throws IOException {
try {
Instance instance = instance();
instance = instance();
appendJnlpMetadataIfRequired();
// TODO: JENKINS-55285
Operation operation =
cloud
.getClient()
.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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<f:entry title="${%No delay provisioning}" field="noDelayProvisioning">
<f:checkbox/>
</f:entry>
<f:entry title="${%JNLP Support}" field="jnlpSupport">
<f:checkbox/>
</f:entry>
<f:entry title="${%Instance Configurations}"
description="${%List of instance configurations that can be launched as Jenkins agents}">
<f:repeatable field="configurations">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
Copyright 2020 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing permissions and limitations under the
License.
-->
By default Jenkins use SSH to connect HSBC cloud nodes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HSBC?

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.