Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-39150] report remoting diagnostics when it's available
Since this plugin cannot assume the version of core, access the method in question via reflection (and also report the failure to find that method, so that we have evidence either way.)
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/cloudbees/jenkins/support/impl/RemotingDiagnostics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.cloudbees.jenkins.support.impl; | ||
|
||
import com.cloudbees.jenkins.support.api.Component; | ||
import com.cloudbees.jenkins.support.api.Container; | ||
import com.cloudbees.jenkins.support.api.PrintedContent; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.remoting.Channel; | ||
import hudson.security.Permission; | ||
import jenkins.model.Jenkins; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.lang.reflect.Method; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* Captures diagnostics information from remoting channels. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class RemotingDiagnostics extends Component { | ||
|
||
@NonNull | ||
@Override | ||
public Set<Permission> getRequiredPermissions() { | ||
return Collections.singleton(Jenkins.ADMINISTER); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return "Remoting Channel Diagnostics"; | ||
} | ||
|
||
@Override | ||
public void addContents(@NonNull Container container) { | ||
container.add(new PrintedContent("channel-diagnostics.md") { | ||
@Override | ||
protected void printTo(PrintWriter out) throws IOException { | ||
// this method is new in remoting. see JENKINS-39150 change in remoting | ||
try { | ||
Method m = Channel.class.getMethod("dumpDiagnosticsForAll", PrintWriter.class); | ||
m.invoke(null,out); | ||
} catch (Exception e) { | ||
e.printStackTrace(out); | ||
} | ||
} | ||
}); | ||
} | ||
} |