|
23 | 23 | */ |
24 | 24 | package hudson.plugins.sshslaves; |
25 | 25 |
|
26 | | -import java.io.ByteArrayOutputStream; |
27 | | -import java.io.IOException; |
28 | | -import java.io.InputStream; |
29 | | -import java.io.OutputStream; |
30 | | -import java.io.PrintStream; |
31 | | -import java.io.UnsupportedEncodingException; |
32 | | -import java.nio.charset.Charset; |
33 | | -import java.security.MessageDigest; |
34 | | -import java.security.NoSuchAlgorithmException; |
35 | | -import java.text.MessageFormat; |
36 | | -import java.util.Collections; |
37 | | -import java.util.Date; |
38 | | -import java.util.HashSet; |
39 | | -import java.util.List; |
40 | | -import java.util.Set; |
41 | | -import java.util.concurrent.Callable; |
42 | | -import java.util.concurrent.CancellationException; |
43 | | -import java.util.concurrent.ExecutionException; |
44 | | -import java.util.concurrent.ExecutorService; |
45 | | -import java.util.concurrent.Executors; |
46 | | -import java.util.concurrent.Future; |
47 | | -import java.util.concurrent.TimeUnit; |
48 | | -import java.util.logging.Level; |
49 | | -import java.util.logging.Logger; |
| 26 | +import com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator; |
| 27 | +import com.cloudbees.plugins.credentials.CredentialsMatchers; |
| 28 | +import com.cloudbees.plugins.credentials.CredentialsProvider; |
| 29 | +import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials; |
| 30 | +import com.cloudbees.plugins.credentials.domains.HostnamePortRequirement; |
| 31 | +import com.cloudbees.plugins.credentials.domains.SchemeRequirement; |
| 32 | +import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel; |
50 | 33 | import com.trilead.ssh2.ChannelCondition; |
51 | 34 | import com.trilead.ssh2.Connection; |
52 | 35 | import com.trilead.ssh2.SCPClient; |
|
57 | 40 | import edu.umd.cs.findbugs.annotations.CheckForNull; |
58 | 41 | import edu.umd.cs.findbugs.annotations.NonNull; |
59 | 42 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
60 | | -import io.jenkins.plugins.sshbuildagents.Messages; |
61 | | -import org.apache.commons.io.IOUtils; |
62 | | -import org.apache.commons.lang.StringUtils; |
63 | | -import org.jenkinsci.Symbol; |
64 | | -import org.kohsuke.accmod.Restricted; |
65 | | -import org.kohsuke.accmod.restrictions.NoExternalUse; |
66 | | -import org.kohsuke.stapler.AncestorInPath; |
67 | | -import org.kohsuke.stapler.DataBoundConstructor; |
68 | | -import org.kohsuke.stapler.DataBoundSetter; |
69 | | -import org.kohsuke.stapler.QueryParameter; |
70 | | -import org.kohsuke.stapler.interceptor.RequirePOST; |
71 | 43 | import hudson.AbortException; |
72 | 44 | import hudson.EnvVars; |
73 | 45 | import hudson.Extension; |
|
93 | 65 | import hudson.util.ListBoxModel; |
94 | 66 | import hudson.util.NamingThreadFactory; |
95 | 67 | import java.util.Collections; |
96 | | -import io.jenkins.plugins.sshbuildagents.ssh.Connection; |
97 | | -import hudson.util.NullStream; |
98 | 68 | import jenkins.model.Jenkins; |
99 | | -import com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator; |
100 | | -import com.cloudbees.plugins.credentials.CredentialsMatchers; |
101 | | -import com.cloudbees.plugins.credentials.CredentialsProvider; |
102 | | -import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials; |
103 | | -import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel; |
104 | | -import com.cloudbees.plugins.credentials.domains.HostnamePortRequirement; |
105 | | -import com.cloudbees.plugins.credentials.domains.SchemeRequirement; |
| 69 | +import org.apache.commons.io.IOUtils; |
| 70 | +import org.apache.commons.lang.StringUtils; |
| 71 | +import org.jenkinsci.Symbol; |
| 72 | +import org.kohsuke.accmod.Restricted; |
| 73 | +import org.kohsuke.accmod.restrictions.NoExternalUse; |
| 74 | +import org.kohsuke.stapler.AncestorInPath; |
| 75 | +import org.kohsuke.stapler.DataBoundConstructor; |
| 76 | +import org.kohsuke.stapler.DataBoundSetter; |
| 77 | +import org.kohsuke.stapler.QueryParameter; |
| 78 | +import org.kohsuke.stapler.interceptor.RequirePOST; |
| 79 | + |
| 80 | +import java.io.ByteArrayOutputStream; |
| 81 | +import java.io.IOException; |
| 82 | +import java.io.InputStream; |
| 83 | +import java.io.OutputStream; |
| 84 | +import java.io.PrintStream; |
| 85 | +import java.lang.InterruptedException; |
| 86 | +import java.io.UnsupportedEncodingException; |
| 87 | +import java.nio.charset.Charset; |
| 88 | +import java.security.MessageDigest; |
| 89 | +import java.security.NoSuchAlgorithmException; |
| 90 | +import java.text.MessageFormat; |
| 91 | +import java.util.Date; |
| 92 | +import java.util.HashSet; |
| 93 | +import java.util.List; |
| 94 | +import java.util.Set; |
| 95 | +import java.util.concurrent.Callable; |
| 96 | +import java.util.concurrent.CancellationException; |
| 97 | +import java.util.concurrent.ExecutionException; |
| 98 | +import java.util.concurrent.ExecutorService; |
| 99 | +import java.util.concurrent.Executors; |
| 100 | +import java.util.concurrent.Future; |
| 101 | +import java.util.concurrent.TimeUnit; |
| 102 | +import java.util.logging.Level; |
| 103 | +import java.util.logging.Logger; |
| 104 | + |
106 | 105 | import static hudson.Util.fixEmpty; |
107 | 106 | import static java.util.logging.Level.WARNING; |
108 | 107 |
|
@@ -363,16 +362,6 @@ public String getJvmOptions() { |
363 | 362 | return jvmOptions == null ? "" : jvmOptions; |
364 | 363 | } |
365 | 364 |
|
366 | | - /** |
367 | | - * Gets the optional java command to use to launch the agent JVM. |
368 | | - * @return The optional java command to use to launch the agent JVM. |
369 | | - */ |
370 | | - @SuppressWarnings("unused") // Used by vsphere-cloud-plugin |
371 | | - @Deprecated |
372 | | - public String getJavaPath() { |
373 | | - return javaPath == null ? "" : javaPath; |
374 | | - } |
375 | | - |
376 | 365 | /** |
377 | 366 | * Gets the formatted current time stamp. |
378 | 367 | * |
@@ -427,54 +416,13 @@ public void launch(final SlaveComputer computer, final TaskListener listener) th |
427 | 416 | new NamingThreadFactory(Executors.defaultThreadFactory(), "SSHLauncher.launch for '" + computer.getName() + "' node")); |
428 | 417 | Set<Callable<Boolean>> callables = new HashSet<>(); |
429 | 418 | callables.add(() -> { |
430 | | - public Boolean call() throws InterruptedException { |
431 | | - Boolean rval = Boolean.FALSE; |
432 | | - try { |
433 | | - String[] preferredKeyAlgorithms = getSshHostKeyVerificationStrategyDefaulted().getPreferredKeyAlgorithms(computer); |
434 | | - if (preferredKeyAlgorithms != null && preferredKeyAlgorithms.length > 0) { // JENKINS-44832 |
435 | | - connection.setServerHostKeyAlgorithms(preferredKeyAlgorithms); |
436 | | - } else { |
437 | | - listener.getLogger().println("Warning: no key algorithms provided; JENKINS-42959 disabled"); |
438 | | - } |
439 | | - |
440 | | - listener.getLogger().println(logConfiguration()); |
441 | | - |
442 | | - openConnection(listener, computer); |
443 | | - |
444 | | - verifyNoHeaderJunk(listener); |
445 | | - reportEnvironment(listener); |
446 | | - |
447 | | - final String workingDirectory = getWorkingDirectory(computer); |
448 | | - if (workingDirectory == null) { |
449 | | - listener.error("Cannot get the working directory for " + computer); |
450 | | - return Boolean.FALSE; |
451 | | - } |
452 | | - |
453 | | - String java = "java"; |
454 | | - if (StringUtils.isNotBlank(javaPath)) { |
455 | | - java = expandExpression(computer, javaPath); |
456 | | - } else { |
457 | | - checkJavaIsInPath(listener); |
458 | | - } |
459 | | - |
460 | | - copyAgentJar(listener, workingDirectory); |
461 | | - |
462 | | - startAgent(computer, listener, java, workingDirectory); |
463 | | - |
464 | | - PluginImpl.register(connection); |
465 | | - rval = Boolean.TRUE; |
466 | | - } catch (RuntimeException|Error e) { |
467 | | - String msg = Messages.SSHLauncher_UnexpectedError(); |
468 | | - if(StringUtils.isNotBlank(e.getMessage())){ |
469 | | - msg = e.getMessage(); |
470 | | - } |
471 | | - e.printStackTrace(listener.error(msg)); |
472 | | - } catch (AbortException e) { |
473 | | - listener.getLogger().println(e.getMessage()); |
474 | | - } catch (IOException e) { |
475 | | - e.printStackTrace(listener.getLogger()); |
476 | | - } finally { |
477 | | - return rval; |
| 419 | + Boolean rval = Boolean.FALSE; |
| 420 | + try { |
| 421 | + String[] preferredKeyAlgorithms = getSshHostKeyVerificationStrategyDefaulted().getPreferredKeyAlgorithms(computer); |
| 422 | + if (preferredKeyAlgorithms != null && preferredKeyAlgorithms.length > 0) { // JENKINS-44832 |
| 423 | + connection.setServerHostKeyAlgorithms(preferredKeyAlgorithms); |
| 424 | + } else { |
| 425 | + listener.getLogger().println("Warning: no key algorithms provided; JENKINS-42959 disabled"); |
478 | 426 | } |
479 | 427 |
|
480 | 428 | listener.getLogger().println(logConfiguration()); |
@@ -552,28 +500,6 @@ public Boolean call() throws InterruptedException { |
552 | 500 | } |
553 | 501 | } |
554 | 502 |
|
555 | | - /** |
556 | | - * try to run the Java command in the PATH ad report its version. |
557 | | - * @param listener lister to print the output of the java command. |
558 | | - */ |
559 | | - private void checkJavaIsInPath(TaskListener listener) { |
560 | | - String msg = "Java is not in the PATH nor configured with the javaPath setting," |
561 | | - + " Jenkins will try to guess where is Java, " |
562 | | - + "this guess will be removed in the future. :" |
563 | | - + getDescriptor().getDisplayName(); |
564 | | - int ret = 0; |
565 | | - try { |
566 | | - listener.getLogger().println("Checking Java version in the PATH"); |
567 | | - ret = connection.exec("java -version", listener.getLogger()); |
568 | | - } catch (Exception e){ |
569 | | - ret = -1; |
570 | | - } |
571 | | - if(ret != 0){ |
572 | | - LOGGER.log(WARNING, msg); |
573 | | - listener.getLogger().println(msg); |
574 | | - } |
575 | | - } |
576 | | - |
577 | 503 | /** |
578 | 504 | * Called to terminate the SSH connection. Used liberally when we back out from an error. |
579 | 505 | */ |
@@ -860,7 +786,7 @@ private void copySlaveJarUsingSCP(TaskListener listener, String workingDirectory |
860 | 786 | } |
861 | 787 |
|
862 | 788 | // delete the agent jar as we do with SFTP |
863 | | - connection.exec("rm " + workingDirectory + SLASH_AGENT_JAR, new NullStream()); |
| 789 | + connection.exec("rm " + workingDirectory + SLASH_AGENT_JAR, OutputStream.nullOutputStream()); |
864 | 790 |
|
865 | 791 | // SCP it to the agent. hudson.Util.ByteArrayOutputStream2 doesn't work for this. It pads the byte array. |
866 | 792 | listener.getLogger().println(Messages.SSHLauncher_CopyingAgentJar(getTimestamp())); |
|
0 commit comments