Skip to content

Commit 7b4313d

Browse files
jglickRoemer
andauthored
Fixing Pipeline resumption (#126)
Co-authored-by: Roman <[email protected]>
1 parent 5cf9df8 commit 7b4313d

File tree

5 files changed

+9
-47
lines changed

5 files changed

+9
-47
lines changed

src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgent.java

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@
22

33
import java.io.IOException;
44
import java.util.Collections;
5-
import java.util.Set;
6-
import java.util.TreeSet;
75
import java.util.logging.Level;
86
import java.util.logging.Logger;
97

108
import org.jenkinsci.plugins.docker.swarm.docker.api.service.DeleteServiceRequest;
119

1210
import akka.actor.ActorRef;
1311
import hudson.model.Descriptor;
14-
import hudson.model.Label;
15-
import hudson.model.Node;
1612
import hudson.model.Queue;
1713
import hudson.model.TaskListener;
18-
import hudson.model.labels.LabelAtom;
19-
import hudson.model.queue.CauseOfBlockage;
2014
import hudson.slaves.AbstractCloudSlave;
21-
import hudson.slaves.EphemeralNode;
2215
import jenkins.model.Jenkins;
2316

24-
public class DockerSwarmAgent extends AbstractCloudSlave implements EphemeralNode {
17+
public class DockerSwarmAgent extends AbstractCloudSlave {
2518

2619
private static final Logger LOGGER = Logger.getLogger(DockerSwarmAgent.class.getName());
2720

@@ -40,40 +33,9 @@ public DockerSwarmComputer createComputer() {
4033

4134
@Override
4235
protected void _terminate(final TaskListener listener) throws IOException, InterruptedException {
36+
DockerSwarmPlugin swarmPlugin = Jenkins.getInstance().getPlugin(DockerSwarmPlugin.class);
37+
ActorRef agentLauncherRef = swarmPlugin.getActorSystem().actorFor("/user/" + getComputer().getName());
38+
agentLauncherRef.tell(new DeleteServiceRequest(getComputer().getName()), ActorRef.noSender());
4339
}
4440

45-
@Override
46-
public Node asNode() {
47-
return this;
48-
}
49-
50-
@Override
51-
public CauseOfBlockage canTake(final Queue.BuildableItem item) {
52-
final Label l = item.getAssignedLabel();
53-
if (l != null && this.name.equals(l.getName())) {
54-
return null;
55-
}
56-
return super.canTake(item);
57-
}
58-
59-
@Override
60-
public Set<LabelAtom> getAssignedLabels() {
61-
final TreeSet<LabelAtom> labels = new TreeSet<>();
62-
labels.add(new LabelAtom(getLabelString()));
63-
return labels;
64-
}
65-
66-
public void terminate() throws IOException {
67-
try {
68-
DockerSwarmPlugin swarmPlugin = Jenkins.getInstance().getPlugin(DockerSwarmPlugin.class);
69-
ActorRef agentLauncherRef = swarmPlugin.getActorSystem().actorFor("/user/" + getComputer().getName());
70-
agentLauncherRef.tell(new DeleteServiceRequest(getComputer().getName()), ActorRef.noSender());
71-
} finally {
72-
try {
73-
Jenkins.getInstance().removeNode(this);
74-
} catch (IOException e) {
75-
LOGGER.log(Level.WARNING, "Failed to remove computer", e);
76-
}
77-
}
78-
}
7941
}

src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentRetentionStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private synchronized void done(final DockerSwarmComputer c) {
108108
if (node != null) {
109109
try {
110110
node.terminate();
111-
} catch (IOException e) {
111+
} catch (IOException | InterruptedException e) {
112112
LOGGER.log(Level.WARNING, "Failed to terminate " + c.getName(), e);
113113
}
114114
}

src/main/java/org/jenkinsci/plugins/docker/swarm/OneShotProvisionQueueListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void onLeft(final Queue.LeftItem li) {
4040
Computer.threadPoolForRemoting.submit(() -> {
4141
try {
4242
((DockerSwarmAgent) node).terminate();
43-
} catch (IOException e) {
43+
} catch (IOException | InterruptedException e) {
4444
LOGGER.log(Level.WARNING, "Failed to terminate agent.", e);
4545
}
4646
});

src/main/java/org/jenkinsci/plugins/docker/swarm/ResetStuckBuildsInQueueActor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static Props props() {
3131
return Props.create(ResetStuckBuildsInQueueActor.class, ResetStuckBuildsInQueueActor::new);
3232
}
3333

34-
private void resetStuckBuildsInQueue() throws IOException {
34+
private void resetStuckBuildsInQueue() throws IOException, InterruptedException {
3535
try (ACLContext context = ACL.as(ACL.SYSTEM)) {
3636
long resetMinutes = Optional.ofNullable(DockerSwarmCloud.get().getTimeoutMinutes()).orElse(DEFAULT_RESET_MINUTES);
3737
final Queue.Item[] items = Jenkins.getInstance().getQueue().getItems();

src/main/resources/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate/config.jelly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<f:textbox value="${dockerSwarmAgentTemplate.image}" default="java:8"/>
1111
</f:entry>
1212
<f:entry title="Unix Command" field="unixCommand">
13-
<f:textarea value="${dockerSwarmAgentTemplate.unixCommand}" default="sh&#10;-cx&#10;curl --connect-timeout 20 --max-time 60 -o agent.jar $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL &amp;&amp; java -classpath agent.jar hudson.remoting.jnlp.Main -headless -url $DOCKER_SWARM_PLUGIN_JENKINS_URL -noreconnect -workDir /tmp $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME"/>
13+
<f:textarea value="${dockerSwarmAgentTemplate.unixCommand}" default="sh&#10;-cx&#10;curl --connect-timeout 20 --max-time 60 -o agent.jar $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL &amp;&amp; java -classpath agent.jar hudson.remoting.jnlp.Main -headless -url $DOCKER_SWARM_PLUGIN_JENKINS_URL -workDir /tmp $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME"/>
1414
</f:entry>
1515
<f:entry title="Windows Command" field="windowsCommand">
16-
<f:textbox value="${dockerSwarmAgentTemplate.windowsCommand}" default="powershell.exe &amp; { Invoke-WebRequest -TimeoutSec 20 -OutFile agent.jar %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL%; if($?) { java -classpath agent.jar hudson.remoting.jnlp.Main -headless -url %DOCKER_SWARM_PLUGIN_JENKINS_URL% -noreconnect %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET% %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME% } }"/>
16+
<f:textbox value="${dockerSwarmAgentTemplate.windowsCommand}" default="powershell.exe &amp; { Invoke-WebRequest -TimeoutSec 20 -OutFile agent.jar %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL%; if($?) { java -classpath agent.jar hudson.remoting.jnlp.Main -headless -url %DOCKER_SWARM_PLUGIN_JENKINS_URL% %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET% %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME% } }"/>
1717
</f:entry>
1818
<f:entry title="Working Directory" field="workingDir">
1919
<f:textbox value="${dockerSwarmAgentTemplate.workingDir}" default="/tmp"/>

0 commit comments

Comments
 (0)