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

[JENKINS-75011] Use Apache Mina as ssh transport layer, remove trilead #1022

Merged
Merged
Show file tree
Hide file tree
Changes from 12 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
12 changes: 8 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ THE SOFTWARE.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
<artifactId>mina-sshd-api-core</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
<artifactId>mina-sshd-api-scp</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
Expand Down Expand Up @@ -138,10 +146,6 @@ THE SOFTWARE.
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-credentials</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>trilead-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.aws-java-sdk</groupId>
<artifactId>aws-java-sdk-ec2</artifactId>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/hudson/plugins/ec2/EC2ComputerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@
*/
package hudson.plugins.ec2;

import static org.apache.sshd.client.session.ClientSession.REMOTE_COMMAND_WAIT_EVENTS;

import com.amazonaws.AmazonClientException;
import hudson.model.TaskListener;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.SlaveComputer;
import java.io.IOException;
import java.time.Duration;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.sshd.client.channel.ClientChannel;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.scp.client.CloseableScpClient;
import org.apache.sshd.scp.client.ScpClient;
import org.apache.sshd.scp.client.ScpClientCreator;

/**
* {@link ComputerLauncher} for EC2 that wraps the real user-specified {@link ComputerLauncher}.
Expand All @@ -39,6 +49,8 @@
public abstract class EC2ComputerLauncher extends ComputerLauncher {
private static final Logger LOGGER = Logger.getLogger(EC2ComputerLauncher.class.getName());

private static final long timeout = Duration.ofSeconds(10).toMillis();

Choose a reason for hiding this comment

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

Nit: make the constant all-caps

Choose a reason for hiding this comment

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

I didn't want to publish the comment until it was marked as ready for review, I am still learning GitHub.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem 🙂
This should use the timeout from the node anyway: 7680d4e


@Override
public void launch(SlaveComputer slaveComputer, TaskListener listener) {
try {
Expand Down Expand Up @@ -81,4 +93,19 @@
*/
protected abstract void launchScript(EC2Computer computer, TaskListener listener)
throws AmazonClientException, IOException, InterruptedException;

protected int waitCompletion(ClientChannel clientChannel) {
Set<ClientChannelEvent> clientChannelEvents = clientChannel.waitFor(REMOTE_COMMAND_WAIT_EVENTS, timeout);
if (clientChannelEvents.contains(ClientChannelEvent.TIMEOUT)) {
return -1;
} else {
return clientChannel.getExitStatus();
}
}

protected CloseableScpClient createScpClient(ClientSession session) {
ScpClientCreator creator = ScpClientCreator.instance();
ScpClient client = creator.createScpClient(session);
return CloseableScpClient.singleSessionInstance(client);

Check warning on line 109 in src/main/java/hudson/plugins/ec2/EC2ComputerLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 98-109 are not covered by tests
}
}
530 changes: 328 additions & 202 deletions src/main/java/hudson/plugins/ec2/ssh/EC2MacLauncher.java

Large diffs are not rendered by default.

Loading
Loading