diff --git a/core/src/main/java/hudson/EnvVars.java b/core/src/main/java/hudson/EnvVars.java index 0ad75f775d..b0a9962259 100644 --- a/core/src/main/java/hudson/EnvVars.java +++ b/core/src/main/java/hudson/EnvVars.java @@ -26,6 +26,7 @@ package hudson; import hudson.remoting.Callable; import hudson.remoting.VirtualChannel; import hudson.util.CaseInsensitiveComparator; +import jenkins.security.MasterToSlave; import java.io.File; import java.io.IOException; @@ -212,6 +213,7 @@ public class EnvVars extends TreeMap { return channel.call(new GetEnvVars()); } + @MasterToSlave private static final class GetEnvVars implements Callable { public EnvVars call() { return new EnvVars(EnvVars.masterEnvVars); diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 322607d9b5..f6e01374ac 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -53,6 +53,9 @@ import static hudson.FilePath.TarCompression.GZIP; import hudson.org.apache.tools.tar.TarInputStream; import hudson.util.io.Archiver; import hudson.util.io.ArchiverFactory; +import jenkins.security.MasterToSlave; +import jenkins.security.MasterToSlaveCallable; +import jenkins.security.SlaveToMaster; import jenkins.util.VirtualFile; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -2091,6 +2094,7 @@ public final class FilePath implements Serializable { return new RemoteLauncher(listener,channel,channel.call(new IsUnix())); } + @MasterToSlave @SlaveToMaster private static final class IsUnix implements Callable { public Boolean call() throws IOException { return File.pathSeparatorChar==':'; @@ -2489,7 +2493,7 @@ public final class FilePath implements Serializable { * (User's home directory in the Unix sense) of the given channel. */ public static FilePath getHomeDirectory(VirtualChannel ch) throws InterruptedException, IOException { - return ch.call(new Callable() { + return ch.call(new MasterToSlaveCallable() { public FilePath call() throws IOException { return new FilePath(new File(System.getProperty("user.home"))); } diff --git a/core/src/main/java/hudson/Launcher.java b/core/src/main/java/hudson/Launcher.java index faad258a84..6f1b4b2205 100644 --- a/core/src/main/java/hudson/Launcher.java +++ b/core/src/main/java/hudson/Launcher.java @@ -38,6 +38,7 @@ import hudson.remoting.VirtualChannel; import hudson.util.StreamCopyThread; import hudson.util.ArgumentListBuilder; import hudson.util.ProcessTree; +import jenkins.security.MasterToSlave; import org.apache.commons.io.input.NullInputStream; import java.io.BufferedOutputStream; @@ -887,6 +888,7 @@ public abstract class Launcher { getChannel().call(new KillTask(modelEnvVars)); } + @MasterToSlave private static final class KillTask implements Callable { private final Map modelEnvVars; @@ -962,6 +964,7 @@ public abstract class Launcher { IOTriplet getIOtriplet(); } + @MasterToSlave private static class RemoteLaunchCallable implements Callable { private final List cmd; private final boolean[] masks; @@ -1032,6 +1035,7 @@ public abstract class Launcher { private static final long serialVersionUID = 1L; } + @MasterToSlave private static class RemoteChannelLaunchCallable implements Callable { private final String[] cmd; private final Pipe out; diff --git a/core/src/main/java/hudson/cli/CLICommand.java b/core/src/main/java/hudson/cli/CLICommand.java index dc8b9fcba3..0efb64f3f9 100644 --- a/core/src/main/java/hudson/cli/CLICommand.java +++ b/core/src/main/java/hudson/cli/CLICommand.java @@ -36,6 +36,8 @@ import hudson.remoting.Channel; import hudson.remoting.ChannelProperty; import hudson.security.CliAuthenticator; import hudson.security.SecurityRealm; +import jenkins.security.MasterToSlave; +import jenkins.security.SlaveToMaster; import org.acegisecurity.Authentication; import org.acegisecurity.BadCredentialsException; import org.acegisecurity.context.SecurityContext; @@ -359,6 +361,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable { return checkChannel().call(new GetSystemProperty(name)); } + @MasterToSlave private static final class GetSystemProperty implements Callable { private final String name; @@ -388,6 +391,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable { } } + @MasterToSlave @SlaveToMaster private static final class GetCharset implements Callable { public String call() throws IOException { return Charset.defaultCharset().name(); @@ -403,6 +407,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable { return checkChannel().call(new GetEnvironmentVariable(name)); } + @MasterToSlave private static final class GetEnvironmentVariable implements Callable { private final String name; diff --git a/core/src/main/java/hudson/cli/ClientAuthenticationCache.java b/core/src/main/java/hudson/cli/ClientAuthenticationCache.java index cd727e7ba4..f04143a0ba 100644 --- a/core/src/main/java/hudson/cli/ClientAuthenticationCache.java +++ b/core/src/main/java/hudson/cli/ClientAuthenticationCache.java @@ -6,6 +6,7 @@ import jenkins.model.Jenkins.MasterComputer; import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.util.Secret; +import jenkins.security.MasterToSlaveCallable; import org.acegisecurity.Authentication; import org.acegisecurity.AuthenticationException; import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; @@ -40,7 +41,7 @@ public class ClientAuthenticationCache implements Serializable { private final Properties props = new Properties(); public ClientAuthenticationCache(Channel channel) throws IOException, InterruptedException { - store = (channel==null ? MasterComputer.localChannel : channel).call(new Callable() { + store = (channel==null ? MasterComputer.localChannel : channel).call(new MasterToSlaveCallable() { public FilePath call() throws IOException { File home = new File(System.getProperty("user.home")); return new FilePath(new File(home, ".hudson/cli-credentials")); diff --git a/core/src/main/java/hudson/cli/CommandDuringBuild.java b/core/src/main/java/hudson/cli/CommandDuringBuild.java index 6f9230b3ee..759563744a 100644 --- a/core/src/main/java/hudson/cli/CommandDuringBuild.java +++ b/core/src/main/java/hudson/cli/CommandDuringBuild.java @@ -28,6 +28,7 @@ import jenkins.model.Jenkins; import hudson.model.Job; import hudson.model.Run; import hudson.remoting.Callable; +import jenkins.security.MasterToSlave; import org.kohsuke.args4j.CmdLineException; import java.io.IOException; @@ -81,6 +82,7 @@ public abstract class CommandDuringBuild extends CLICommand { /** * Gets the environment variables that points to the build being executed. */ + @MasterToSlave private static final class GetCharacteristicEnvironmentVariables implements Callable { public String[] call() throws IOException { return new String[] { diff --git a/core/src/main/java/hudson/cli/InstallToolCommand.java b/core/src/main/java/hudson/cli/InstallToolCommand.java index fb30efd0c0..e39d90fba4 100644 --- a/core/src/main/java/hudson/cli/InstallToolCommand.java +++ b/core/src/main/java/hudson/cli/InstallToolCommand.java @@ -44,6 +44,7 @@ import java.util.List; import java.util.ArrayList; import java.io.IOException; +import jenkins.security.MasterToSlave; import org.kohsuke.args4j.Argument; /** @@ -128,6 +129,7 @@ public class InstallToolCommand extends CLICommand { return 0; } + @MasterToSlave private static final class BuildIDs implements Callable { String job,number,id; diff --git a/core/src/main/java/hudson/cli/util/ScriptLoader.java b/core/src/main/java/hudson/cli/util/ScriptLoader.java index badf963f1f..5b590ac313 100644 --- a/core/src/main/java/hudson/cli/util/ScriptLoader.java +++ b/core/src/main/java/hudson/cli/util/ScriptLoader.java @@ -2,6 +2,9 @@ package hudson.cli.util; import hudson.AbortException; import hudson.remoting.Callable; +import jenkins.security.MasterToSlave; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import java.io.File; import java.io.IOException; @@ -9,16 +12,12 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import jenkins.security.UnsafeBySlave; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; - /** * Reads a file (either a path or URL) over a channel. * * @author vjuranek */ -@UnsafeBySlave +@MasterToSlave public class ScriptLoader implements Callable { private final String script; diff --git a/core/src/main/java/hudson/logging/LogRecorder.java b/core/src/main/java/hudson/logging/LogRecorder.java index f780252af4..9cc456f9f4 100644 --- a/core/src/main/java/hudson/logging/LogRecorder.java +++ b/core/src/main/java/hudson/logging/LogRecorder.java @@ -42,6 +42,7 @@ import hudson.slaves.ComputerListener; import hudson.util.CopyOnWriteList; import hudson.util.RingBufferLogHandler; import hudson.util.XStream2; +import jenkins.security.MasterToSlave; import net.sf.json.JSONObject; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.StaplerRequest; @@ -160,6 +161,7 @@ public class LogRecorder extends AbstractModelObject implements Saveable { } + @MasterToSlave private static final class SetLevel implements Callable { /** known loggers (kept per slave), to avoid GC */ @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") private static final Set loggers = new HashSet(); diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index b4a052349e..42c2c76b89 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -58,6 +58,7 @@ import hudson.util.RemotingDiagnostics.HeapDump; import hudson.util.RunList; import hudson.util.Futures; import jenkins.model.Jenkins; +import jenkins.security.MasterToSlave; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.stapler.StaplerRequest; @@ -1024,6 +1025,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces oneOffExecutors.remove(e); } + @MasterToSlave private static class ListPossibleNames implements Callable,IOException> { public List call() throws IOException { List names = new ArrayList(); @@ -1054,6 +1056,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces private static final long serialVersionUID = 1L; } + @MasterToSlave private static class GetFallbackName implements Callable { public String call() throws IOException { return System.getProperty("host.name"); @@ -1143,6 +1146,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces w.close(); } + @MasterToSlave private static final class DumpExportTableTask implements Callable { public String call() throws IOException { StringWriter sw = new StringWriter(); diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index 46b4849596..35bdee8631 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -58,6 +58,7 @@ import javax.servlet.ServletException; import hudson.util.TimeUnit2; import jenkins.model.Jenkins; +import jenkins.security.MasterToSlave; import jenkins.slaves.WorkspaceLocator; import org.apache.commons.io.IOUtils; @@ -440,6 +441,7 @@ public abstract class Slave extends Node implements Serializable { *
  • When it's read on this side as a return value, it morphs itself into {@link ClockDifference}. * */ + @MasterToSlave private static final class GetClockDifference1 implements Callable { public ClockDifference call() { // this method must be being invoked locally, which means the clock is in sync @@ -453,6 +455,7 @@ public abstract class Slave extends Node implements Serializable { private static final long serialVersionUID = 1L; } + @MasterToSlave private static final class GetClockDifference2 implements Callable { /** * Capture the time on the master when this object is sent to remote, which is when @@ -467,6 +470,7 @@ public abstract class Slave extends Node implements Serializable { private static final long serialVersionUID = 1L; } + @MasterToSlave private static final class GetClockDifference3 implements Serializable { private final long remoteTime = System.currentTimeMillis(); private final long startTime; diff --git a/core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java b/core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java index 9f127a7f72..05c59a91dd 100644 --- a/core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java +++ b/core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java @@ -26,6 +26,7 @@ package hudson.node_monitors; import hudson.model.Computer; import hudson.remoting.Callable; import hudson.Extension; +import jenkins.security.MasterToSlave; import net.sf.json.JSONObject; import org.kohsuke.stapler.StaplerRequest; @@ -56,6 +57,7 @@ public class ArchitectureMonitor extends NodeMonitor { /** * Obtains the string that represents the architecture. */ + @MasterToSlave private static class GetArchTask implements Callable { public String call() { String os = System.getProperty("os.name"); diff --git a/core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java b/core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java index 6248b84d86..491b991e7a 100644 --- a/core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java +++ b/core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java @@ -32,6 +32,8 @@ import hudson.remoting.Future; import hudson.util.ClockDifference; import hudson.util.TimeUnit2; import hudson.util.IOException2; +import jenkins.security.MasterToSlave; +import jenkins.security.SlaveToMaster; import net.sf.json.JSONObject; import org.kohsuke.stapler.StaplerRequest; @@ -92,6 +94,7 @@ public class ResponseTimeMonitor extends NodeMonitor { } }; + @MasterToSlave private static final class Step1 implements Callable { private Data cur; @@ -111,6 +114,7 @@ public class ResponseTimeMonitor extends NodeMonitor { private static final long serialVersionUID = 1L; } + @MasterToSlave private static final class Step2 implements Callable { private final Data cur; private final long start = System.currentTimeMillis(); @@ -127,6 +131,7 @@ public class ResponseTimeMonitor extends NodeMonitor { private static final long serialVersionUID = 1L; } + @SlaveToMaster private static final class Step3 implements Serializable { private final Data cur; private final long start; diff --git a/core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java b/core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java index e09efe3c17..a72b94e84d 100644 --- a/core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java +++ b/core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java @@ -28,6 +28,7 @@ import hudson.Extension; import hudson.model.Computer; import jenkins.model.Jenkins; import hudson.remoting.Callable; +import jenkins.security.MasterToSlave; import net.sf.json.JSONObject; import org.jvnet.hudson.MemoryMonitor; import org.jvnet.hudson.MemoryUsage; @@ -97,6 +98,7 @@ public class SwapSpaceMonitor extends NodeMonitor { /** * Obtains the string that represents the architecture. */ + @MasterToSlave private static class MonitorTask implements Callable { public MemoryUsage call() throws IOException { MemoryMonitor mm; diff --git a/core/src/main/java/hudson/os/solaris/ZFSInstaller.java b/core/src/main/java/hudson/os/solaris/ZFSInstaller.java index ec0d51ccb8..17a3bb48ac 100644 --- a/core/src/main/java/hudson/os/solaris/ZFSInstaller.java +++ b/core/src/main/java/hudson/os/solaris/ZFSInstaller.java @@ -38,6 +38,7 @@ import hudson.util.HudsonIsRestarting; import hudson.util.StreamTaskListener; import static hudson.util.jna.GNUCLibrary.*; +import jenkins.security.MasterToSlaveCallable; import org.apache.commons.io.output.ByteArrayOutputStream; import org.jvnet.libpam.impl.CLibrary.passwd; import org.jvnet.solaris.libzfs.ACLBuilder; @@ -167,7 +168,7 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable // this is the actual creation of the file system. // return true indicating a success - return SU.execute(listener, rootUsername, rootPassword, new Callable() { + return SU.execute(listener, rootUsername, rootPassword, new MasterToSlaveCallable() { private static final long serialVersionUID = 7731167233498214301L; public String call() throws IOException { diff --git a/core/src/main/java/hudson/security/AbstractPasswordBasedSecurityRealm.java b/core/src/main/java/hudson/security/AbstractPasswordBasedSecurityRealm.java index de3b806f60..84e9b163d6 100644 --- a/core/src/main/java/hudson/security/AbstractPasswordBasedSecurityRealm.java +++ b/core/src/main/java/hudson/security/AbstractPasswordBasedSecurityRealm.java @@ -6,6 +6,7 @@ import hudson.cli.CLICommand; import jenkins.model.Jenkins; import hudson.remoting.Callable; import hudson.util.spring.BeanBuilder; +import jenkins.security.MasterToSlave; import org.acegisecurity.Authentication; import org.acegisecurity.AuthenticationException; import org.acegisecurity.AuthenticationManager; @@ -140,6 +141,7 @@ public abstract class AbstractPasswordBasedSecurityRealm extends SecurityRealm i /** * Asks for the password. */ + @MasterToSlave private static class InteractivelyAskForPassword implements Callable { @IgnoreJRERequirement public String call() throws IOException { diff --git a/core/src/main/java/hudson/slaves/ChannelPinger.java b/core/src/main/java/hudson/slaves/ChannelPinger.java index 4141af49b8..f7de0f0349 100644 --- a/core/src/main/java/hudson/slaves/ChannelPinger.java +++ b/core/src/main/java/hudson/slaves/ChannelPinger.java @@ -31,6 +31,7 @@ import hudson.model.TaskListener; import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.remoting.PingThread; +import jenkins.security.MasterToSlave; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; @@ -85,6 +86,7 @@ public class ChannelPinger extends ComputerListener { setUpPingForChannel(channel, pingInterval); } + @MasterToSlave private static class SetUpRemotePing implements Callable { private static final long serialVersionUID = -2702219700841759872L; private int pingInterval; diff --git a/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java b/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java index 03890303d1..997a47525f 100644 --- a/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java +++ b/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java @@ -32,6 +32,8 @@ import hudson.remoting.VirtualChannel; import hudson.remoting.Channel; import hudson.remoting.Callable; import hudson.Extension; +import jenkins.security.MasterToSlave; +import jenkins.security.SlaveToMaster; import java.io.IOException; import java.util.logging.Logger; @@ -102,6 +104,7 @@ public class ConnectionActivityMonitor extends AsyncPeriodicWork { public boolean enabled = Boolean.getBoolean(ConnectionActivityMonitor.class.getName()+".enabled"); private static final PingCommand PING_COMMAND = new PingCommand(); + @MasterToSlave @SlaveToMaster private static final class PingCommand implements Callable { public Void call() throws RuntimeException { return null; diff --git a/core/src/main/java/hudson/slaves/SlaveComputer.java b/core/src/main/java/hudson/slaves/SlaveComputer.java index 70f78785a7..1b7348128b 100644 --- a/core/src/main/java/hudson/slaves/SlaveComputer.java +++ b/core/src/main/java/hudson/slaves/SlaveComputer.java @@ -72,6 +72,8 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import javax.servlet.RequestDispatcher; import jenkins.model.Jenkins; +import jenkins.security.MasterToSlave; +import jenkins.security.SlaveToMaster; import jenkins.slaves.JnlpSlaveAgentProtocol; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -399,6 +401,7 @@ public class SlaveComputer extends Computer { return channel.call(new LoadingTime(true)); } + @MasterToSlave @SlaveToMaster static class LoadingCount implements Callable { private final boolean resource; LoadingCount(boolean resource) { @@ -410,12 +413,14 @@ public class SlaveComputer extends Computer { } } + @MasterToSlave static class LoadingPrefetchCacheCount implements Callable { @Override public Integer call() { return Channel.current().classLoadingPrefetchCacheCount.get(); } } + @MasterToSlave static class LoadingTime implements Callable { private final boolean resource; LoadingTime(boolean resource) { @@ -711,18 +716,21 @@ public class SlaveComputer extends Computer { private static final Logger logger = Logger.getLogger(SlaveComputer.class.getName()); + @MasterToSlave private static final class SlaveVersion implements Callable { public String call() throws IOException { try { return Launcher.VERSION; } catch (Throwable ex) { return "< 1.335"; } // Older slave.jar won't have VERSION } } + @MasterToSlave @SlaveToMaster private static final class DetectOS implements Callable { public Boolean call() throws IOException { return File.pathSeparatorChar==':'; } } + @MasterToSlave @SlaveToMaster private static final class DetectDefaultCharset implements Callable { public String call() throws IOException { return Charset.defaultCharset().name(); @@ -740,6 +748,7 @@ public class SlaveComputer extends Computer { static final RingBufferLogHandler SLAVE_LOG_HANDLER = new RingBufferLogHandler(); } + @MasterToSlave private static class SlaveInitializer implements Callable { public Void call() { // avoid double installation of the handler. JNLP slaves can reconnect to the master multiple times @@ -787,6 +796,7 @@ public class SlaveComputer extends Computer { return null; } + @MasterToSlave private static class SlaveLogFetcher implements Callable,RuntimeException> { public List call() { return new ArrayList(SLAVE_LOG_HANDLER.getView()); diff --git a/core/src/main/java/hudson/tasks/Maven.java b/core/src/main/java/hudson/tasks/Maven.java index 609947de10..aed029341e 100644 --- a/core/src/main/java/hudson/tasks/Maven.java +++ b/core/src/main/java/hudson/tasks/Maven.java @@ -59,6 +59,7 @@ import hudson.util.VariableResolver.ByMap; import hudson.util.VariableResolver.Union; import hudson.util.FormValidation; import hudson.util.XStream2; +import jenkins.security.MasterToSlaveCallable; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; @@ -507,7 +508,7 @@ public class Maven extends Builder { public boolean meetsMavenReqVersion(Launcher launcher, int mavenReqVersion) throws IOException, InterruptedException { // FIXME using similar stuff as in the maven plugin could be better // olamy : but will add a dependency on maven in core -> so not so good - String mavenVersion = launcher.getChannel().call(new Callable() { + String mavenVersion = launcher.getChannel().call(new MasterToSlaveCallable() { private static final long serialVersionUID = -4143159957567745621L; public String call() throws IOException { @@ -563,7 +564,7 @@ public class Maven extends Builder { * Gets the executable path of this maven on the given target system. */ public String getExecutable(Launcher launcher) throws IOException, InterruptedException { - return launcher.getChannel().call(new Callable() { + return launcher.getChannel().call(new MasterToSlaveCallable() { private static final long serialVersionUID = 2373163112639943768L; public String call() throws IOException { diff --git a/core/src/main/java/hudson/tasks/Shell.java b/core/src/main/java/hudson/tasks/Shell.java index 346a124e4a..64c0192f6f 100644 --- a/core/src/main/java/hudson/tasks/Shell.java +++ b/core/src/main/java/hudson/tasks/Shell.java @@ -32,6 +32,8 @@ import hudson.remoting.Callable; import hudson.remoting.VirtualChannel; import hudson.util.FormValidation; import java.io.IOException; + +import jenkins.security.MasterToSlave; import net.sf.json.JSONObject; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.StaplerRequest; @@ -193,6 +195,7 @@ public class Shell extends CommandInterpreter { return FormValidation.validateExecutable(value); } + @MasterToSlave private static final class Shellinterpreter implements Callable { private static final long serialVersionUID = 1L; diff --git a/core/src/main/java/hudson/tools/JDKInstaller.java b/core/src/main/java/hudson/tools/JDKInstaller.java index ac5e311dbb..2b6fc24327 100644 --- a/core/src/main/java/hudson/tools/JDKInstaller.java +++ b/core/src/main/java/hudson/tools/JDKInstaller.java @@ -40,6 +40,7 @@ import hudson.util.FormValidation; import hudson.util.HttpResponses; import hudson.util.Secret; import jenkins.model.Jenkins; +import jenkins.security.MasterToSlave; import net.sf.json.JSONObject; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.HttpClient; @@ -501,6 +502,7 @@ public class JDKInstaller extends ToolInstaller { throw new DetectionFailedException("Unknown CPU name: "+arch); } + @MasterToSlave static class GetCurrentPlatform implements Callable { private static final long serialVersionUID = 1L; public Platform call() throws DetectionFailedException { @@ -563,6 +565,7 @@ public class JDKInstaller extends ToolInstaller { throw new DetectionFailedException("Unknown CPU architecture: "+arch); } + @MasterToSlave static class GetCurrentCPU implements Callable { private static final long serialVersionUID = 1L; public CPU call() throws DetectionFailedException { diff --git a/core/src/main/java/hudson/util/ProcessTree.java b/core/src/main/java/hudson/util/ProcessTree.java index 2dd927d6fa..3145b63d70 100644 --- a/core/src/main/java/hudson/util/ProcessTree.java +++ b/core/src/main/java/hudson/util/ProcessTree.java @@ -29,13 +29,13 @@ import com.sun.jna.ptr.IntByReference; import hudson.EnvVars; import hudson.Util; import jenkins.model.Jenkins; -import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.remoting.VirtualChannel; import hudson.slaves.SlaveComputer; import hudson.util.ProcessTree.OSProcess; import hudson.util.ProcessTreeRemoting.IOSProcess; import hudson.util.ProcessTreeRemoting.IProcessTree; +import jenkins.security.SlaveToMasterCallable; import org.apache.commons.io.FileUtils; import org.jvnet.winp.WinProcess; import org.jvnet.winp.WinpException; @@ -158,7 +158,7 @@ public abstract class ProcessTree implements Iterable, IProcessTree, try { VirtualChannel channelToMaster = SlaveComputer.getChannelToMaster(); if (channelToMaster!=null) { - killers = channelToMaster.call(new Callable, IOException>() { + killers = channelToMaster.call(new SlaveToMasterCallable, IOException>() { public List call() throws IOException { return new ArrayList(ProcessKiller.all()); } diff --git a/core/src/main/java/hudson/util/RemotingDiagnostics.java b/core/src/main/java/hudson/util/RemotingDiagnostics.java index 9a95218df7..a0edd54abf 100644 --- a/core/src/main/java/hudson/util/RemotingDiagnostics.java +++ b/core/src/main/java/hudson/util/RemotingDiagnostics.java @@ -85,7 +85,7 @@ public final class RemotingDiagnostics { return channel.call(new GetThreadDump()); } - public static Future> getThreakdDumpAsync(VirtualChannel channel) throws IOException, InterruptedException { + public static Future> getThreadDumpAsync(VirtualChannel channel) throws IOException, InterruptedException { if(channel==null) return new AsyncFutureImpl>(Collections.singletonMap("N/A","offline")); return channel.callAsync(new GetThreadDump()); @@ -165,30 +165,12 @@ public final class RemotingDiagnostics { * Obtains the heap dump in an HPROF file. */ public static FilePath getHeapDump(VirtualChannel channel) throws IOException, InterruptedException { - return channel.call(new Callable() { - public FilePath call() throws IOException { - final File hprof = File.createTempFile("hudson-heapdump", "hprof"); - hprof.delete(); - try { - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); - server.invoke(new ObjectName("com.sun.management:type=HotSpotDiagnostic"), "dumpHeap", - new Object[]{hprof.getAbsolutePath(), true}, new String[]{String.class.getName(), boolean.class.getName()}); - - return new FilePath(hprof); - } catch (JMException e) { - throw new IOException2(e); - } - } - - private static final long serialVersionUID = 1L; - }); + return channel.call(new GetHeapDump()); } /** * Heap dump, exposable to URL via Stapler. - * */ - @MasterToSlave public static class HeapDump { private final AccessControlled owner; private final VirtualChannel channel; @@ -222,4 +204,23 @@ public final class RemotingDiagnostics { return RemotingDiagnostics.getHeapDump(channel); } } + + @MasterToSlave + private static class GetHeapDump implements Callable { + public FilePath call() throws IOException { + final File hprof = File.createTempFile("hudson-heapdump", "hprof"); + hprof.delete(); + try { + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + server.invoke(new ObjectName("com.sun.management:type=HotSpotDiagnostic"), "dumpHeap", + new Object[]{hprof.getAbsolutePath(), true}, new String[]{String.class.getName(), boolean.class.getName()}); + + return new FilePath(hprof); + } catch (JMException e) { + throw new IOException2(e); + } + } + + private static final long serialVersionUID = 1L; + } } diff --git a/core/src/main/java/hudson/util/io/ParserConfigurator.java b/core/src/main/java/hudson/util/io/ParserConfigurator.java index cd4a8642e2..dde6a1d342 100644 --- a/core/src/main/java/hudson/util/io/ParserConfigurator.java +++ b/core/src/main/java/hudson/util/io/ParserConfigurator.java @@ -25,9 +25,9 @@ package hudson.util.io; import hudson.ExtensionList; import hudson.ExtensionPoint; -import hudson.remoting.Callable; import hudson.remoting.Channel; import jenkins.model.Jenkins; +import jenkins.security.SlaveToMasterCallable; import org.dom4j.io.SAXReader; import java.io.IOException; @@ -78,7 +78,7 @@ public abstract class ParserConfigurator implements ExtensionPoint, Serializable if (Jenkins.getInstance()==null) { Channel ch = Channel.current(); if (ch!=null) - all = ch.call(new Callable, IOException>() { + all = ch.call(new SlaveToMasterCallable, IOException>() { private static final long serialVersionUID = -2178106894481500733L; diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 1dc792015a..18ac0e6331 100755 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -200,6 +200,7 @@ import jenkins.InitReactorRunner; import jenkins.model.ProjectNamingStrategy.DefaultProjectNamingStrategy; import jenkins.security.ConfidentialKey; import jenkins.security.ConfidentialStore; +import jenkins.security.MasterToSlaveCallable; import jenkins.slaves.WorkspaceLocator; import jenkins.util.io.FileBoolean; import net.sf.json.JSONObject; @@ -1966,7 +1967,7 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro @Override public Callable getClockDifferenceCallable() { - return new Callable() { + return new MasterToSlaveCallable() { public ClockDifference call() throws IOException { return new ClockDifference(0); } diff --git a/core/src/main/java/jenkins/slaves/StandardOutputSwapper.java b/core/src/main/java/jenkins/slaves/StandardOutputSwapper.java index 4abcf3c409..f0bb18593d 100644 --- a/core/src/main/java/jenkins/slaves/StandardOutputSwapper.java +++ b/core/src/main/java/jenkins/slaves/StandardOutputSwapper.java @@ -9,6 +9,7 @@ import hudson.remoting.Channel; import hudson.remoting.StandardOutputStream; import hudson.slaves.ComputerListener; import hudson.util.jna.GNUCLibrary; +import jenkins.security.MasterToSlave; import java.io.File; import java.io.FileDescriptor; @@ -35,6 +36,7 @@ public class StandardOutputSwapper extends ComputerListener { } } + @MasterToSlave private static final class ChannelSwapper implements Callable { public Boolean call() throws Exception { if (File.pathSeparatorChar==';') return false; // Windows diff --git a/maven-plugin/src/main/java/hudson/maven/AbstractMavenBuilder.java b/maven-plugin/src/main/java/hudson/maven/AbstractMavenBuilder.java index 353954645c..9ad0316d8a 100644 --- a/maven-plugin/src/main/java/hudson/maven/AbstractMavenBuilder.java +++ b/maven-plugin/src/main/java/hudson/maven/AbstractMavenBuilder.java @@ -43,12 +43,14 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutionException; import jenkins.model.Jenkins; +import jenkins.security.MasterToSlave; /** * @author Olivier Lamy * @author Christoph Kutzinski * */ +@MasterToSlave public abstract class AbstractMavenBuilder implements DelegatingCallable { private static final long serialVersionUID = -2687215937784908860L; diff --git a/maven-plugin/src/main/java/hudson/maven/AbstractMavenProcessFactory.java b/maven-plugin/src/main/java/hudson/maven/AbstractMavenProcessFactory.java index fb1adefab9..d004f394db 100644 --- a/maven-plugin/src/main/java/hudson/maven/AbstractMavenProcessFactory.java +++ b/maven-plugin/src/main/java/hudson/maven/AbstractMavenProcessFactory.java @@ -43,6 +43,8 @@ import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; import jenkins.model.Jenkins; +import jenkins.security.MasterToSlave; +import jenkins.security.SlaveToMaster; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Zip; @@ -157,6 +159,7 @@ public abstract class AbstractMavenProcessFactory * Opens a server socket and returns {@link Acceptor} so that * we can accept a connection later on it. */ + @MasterToSlave private static final class SocketHandler implements Callable { public Acceptor call() throws IOException { return new AcceptorImpl(); @@ -199,6 +202,7 @@ public abstract class AbstractMavenProcessFactory } } + @MasterToSlave private static final class GetCharset implements Callable { private static final long serialVersionUID = 3459269768733083577L; @@ -284,6 +288,7 @@ public abstract class AbstractMavenProcessFactory } /** Verifies that the channel is open and functioning, and (if the second time around) sets properties for the original JDK. */ + @MasterToSlave private static final class ConfigureOriginalJDK implements Callable { private static final long serialVersionUID = 1; private final JDK jdk; @@ -302,6 +307,7 @@ public abstract class AbstractMavenProcessFactory } /** Locates JRE this slave agent is running on, or null. */ + @MasterToSlave @SlaveToMaster private static final class FindJavaHome implements Callable { private static final long serialVersionUID = 1; @Override public JDK call() throws Error { @@ -487,7 +493,7 @@ public abstract class AbstractMavenProcessFactory return jdk; } - + @MasterToSlave @SlaveToMaster protected static final class GetRemotingJar implements Callable { private static final long serialVersionUID = 6022357183425911351L; diff --git a/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java b/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java index e5a4dfb2eb..387e3b0089 100644 --- a/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java +++ b/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java @@ -31,6 +31,7 @@ import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.tasks.Maven.MavenInstallation; import jenkins.maven3.agent.Maven31Main; +import jenkins.security.MasterToSlave; import org.jvnet.hudson.maven3.launcher.Maven31Interceptor; import org.jvnet.hudson.maven3.listeners.HudsonMavenExecutionResult; @@ -73,6 +74,7 @@ public class Maven31ProcessFactory extends Maven3ProcessFactory channel.call(new InstallPlexusModulesTask(context)); } + @MasterToSlave private static final class InstallPlexusModulesTask implements Callable { PlexusModuleContributor c; diff --git a/maven-plugin/src/main/java/hudson/maven/Maven3Builder.java b/maven-plugin/src/main/java/hudson/maven/Maven3Builder.java index a87449644e..d5d5a31a2e 100644 --- a/maven-plugin/src/main/java/hudson/maven/Maven3Builder.java +++ b/maven-plugin/src/main/java/hudson/maven/Maven3Builder.java @@ -58,7 +58,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; -import static hudson.Util.fixNull; +import static hudson.Util.*; /** * @author Olivier Lamy diff --git a/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java b/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java index 61d1a69dcb..223fcc2947 100644 --- a/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java +++ b/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java @@ -32,6 +32,7 @@ import hudson.model.TaskListener; import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.tasks.Maven.MavenInstallation; +import jenkins.security.MasterToSlave; import org.jvnet.hudson.maven3.agent.Maven3Main; import org.jvnet.hudson.maven3.launcher.Maven3Launcher; import org.jvnet.hudson.maven3.listeners.HudsonMavenExecutionResult; @@ -106,6 +107,7 @@ public class Maven3ProcessFactory extends AbstractMavenProcessFactory implements /** * Finds classworlds.jar */ + @MasterToSlave protected static final class GetClassWorldsJar implements Callable { private static final long serialVersionUID = -2599434124883557137L; private final String mvnHome; diff --git a/maven-plugin/src/main/java/hudson/maven/MavenBuildProxy.java b/maven-plugin/src/main/java/hudson/maven/MavenBuildProxy.java index 3e15a6d4f9..e13973f5e5 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenBuildProxy.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenBuildProxy.java @@ -33,6 +33,7 @@ import java.io.Serializable; import java.util.Calendar; import java.util.List; import jenkins.model.ArtifactManager; +import jenkins.security.SlaveToMaster; /** * Remoting proxy interface for {@link MavenReporter}s to talk to {@link MavenBuild} @@ -266,6 +267,7 @@ public interface MavenBuildProxy { /** * {@link Callable} for invoking {@link BuildCallable} asynchronously. */ + @SlaveToMaster protected static final class AsyncInvoker implements DelegatingCallable { private final MavenBuildProxy proxy; private final BuildCallable program; diff --git a/maven-plugin/src/main/java/hudson/maven/MavenBuilder.java b/maven-plugin/src/main/java/hudson/maven/MavenBuilder.java index 72a60954d9..2ff9180106 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenBuilder.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenBuilder.java @@ -34,18 +34,6 @@ import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.remoting.DelegatingCallable; import hudson.util.IOException2; - -import java.io.IOException; -import java.io.PrintStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.text.NumberFormat; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; - import org.apache.maven.BuildFailureException; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; @@ -60,6 +48,17 @@ import org.codehaus.classworlds.NoSuchRealmException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.text.NumberFormat; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; + /** * {@link Callable} that invokes Maven CLI (in process) and drives a build. * diff --git a/maven-plugin/src/main/java/hudson/maven/MavenProcessFactory.java b/maven-plugin/src/main/java/hudson/maven/MavenProcessFactory.java index 41fe5abd42..895435a8d4 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenProcessFactory.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenProcessFactory.java @@ -34,6 +34,7 @@ import hudson.model.TaskListener; import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.tasks.Maven.MavenInstallation; +import jenkins.security.MasterToSlave; import java.io.File; import java.io.FilenameFilter; @@ -110,6 +111,7 @@ final class MavenProcessFactory extends AbstractMavenProcessFactory implements P channel.call(new InstallPlexusModulesTask(context)); } + @MasterToSlave private static final class InstallPlexusModulesTask implements Callable { PlexusModuleContributor c; @@ -126,6 +128,7 @@ final class MavenProcessFactory extends AbstractMavenProcessFactory implements P /** * Finds classworlds.jar */ + @MasterToSlave private static final class GetClassWorldsJar implements Callable { private static final long serialVersionUID = 5812919424079344101L; private final String mvnHome; diff --git a/maven-plugin/src/main/java/hudson/maven/MavenVersionCallable.java b/maven-plugin/src/main/java/hudson/maven/MavenVersionCallable.java index f4a0f55cf1..80ffb81032 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenVersionCallable.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenVersionCallable.java @@ -30,14 +30,15 @@ import hudson.remoting.Callable; import java.io.File; import java.io.IOException; +import jenkins.security.MasterToSlave; import org.kohsuke.stapler.framework.io.IOException2; /** * * @author Olivier Lamy * @since 3.0 - * */ +@MasterToSlave public class MavenVersionCallable implements Callable { diff --git a/maven-plugin/src/main/java/hudson/maven/ProcessCache.java b/maven-plugin/src/main/java/hudson/maven/ProcessCache.java index 165a7aa68a..f61bf4643a 100644 --- a/maven-plugin/src/main/java/hudson/maven/ProcessCache.java +++ b/maven-plugin/src/main/java/hudson/maven/ProcessCache.java @@ -35,6 +35,8 @@ import hudson.remoting.RequestAbortedException; import hudson.tasks.Maven.MavenInstallation; import hudson.util.DelegatingOutputStream; import hudson.util.NullStream; +import jenkins.security.MasterToSlave; +import jenkins.security.SlaveToMaster; import java.io.IOException; import java.io.OutputStream; @@ -248,6 +250,7 @@ public final class ProcessCache { /** * Noop callable used for checking the sanity of the maven process in the cache. */ + @MasterToSlave private static class SetSystemProperties implements Callable { private final Properties properties; @@ -262,6 +265,7 @@ public final class ProcessCache { private static final long serialVersionUID = 1L; } + @MasterToSlave private static class GetSystemProperties implements Callable { public Properties call() { return System.getProperties(); diff --git a/maven-plugin/src/main/java/hudson/maven/RedeployPublisher.java b/maven-plugin/src/main/java/hudson/maven/RedeployPublisher.java index 5d0ef7ffe6..8440f80bc7 100644 --- a/maven-plugin/src/main/java/hudson/maven/RedeployPublisher.java +++ b/maven-plugin/src/main/java/hudson/maven/RedeployPublisher.java @@ -53,6 +53,7 @@ import java.util.Properties; import jenkins.model.Jenkins; import jenkins.mvn.GlobalSettingsProvider; import jenkins.mvn.SettingsProvider; +import jenkins.security.MasterToSlave; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; @@ -286,6 +287,7 @@ public class RedeployPublisher extends Recorder { } } + @MasterToSlave private static final class GetUserHome implements Callable { private static final long serialVersionUID = -8755705771716056636L; diff --git a/maven-plugin/src/main/java/hudson/maven/SplittableBuildListener.java b/maven-plugin/src/main/java/hudson/maven/SplittableBuildListener.java index e17dc74b86..416a503592 100644 --- a/maven-plugin/src/main/java/hudson/maven/SplittableBuildListener.java +++ b/maven-plugin/src/main/java/hudson/maven/SplittableBuildListener.java @@ -31,6 +31,7 @@ import hudson.model.StreamBuildListener; import hudson.remoting.Callable; import hudson.remoting.Channel; import hudson.util.AbstractTaskListener; +import jenkins.security.MasterToSlave; import jenkins.util.MarkFindingOutputStream; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.io.output.DeferredFileOutputStream; @@ -233,6 +234,7 @@ final class SplittableBuildListener extends AbstractTaskListener implements Buil } } + @MasterToSlave private static class SendMark implements Callable { public Void call() throws IOException { // write a mark diff --git a/test/src/test/java/hudson/slaves/JNLPLauncherTest.java b/test/src/test/java/hudson/slaves/JNLPLauncherTest.java index ab9afba1ee..8d1e6bf7f4 100644 --- a/test/src/test/java/hudson/slaves/JNLPLauncherTest.java +++ b/test/src/test/java/hudson/slaves/JNLPLauncherTest.java @@ -35,6 +35,8 @@ import hudson.remoting.Callable; import hudson.remoting.Which; import hudson.util.ArgumentListBuilder; +import jenkins.security.MasterToSlave; +import jenkins.security.SlaveToMaster; import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.TestExtension; @@ -154,6 +156,7 @@ public class JNLPLauncherTest extends HudsonTestCase { return c; } + @MasterToSlave @SlaveToMaster private static class NoopTask implements Callable { public String call() { return "done";