提交 ffb5b650 编写于 作者: K Kohsuke Kawaguchi

Switched from annotation based scheme to a function based scheme.

上级 59456c73
......@@ -26,7 +26,7 @@ package hudson;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.util.CaseInsensitiveComparator;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import java.io.File;
import java.io.IOException;
......@@ -213,8 +213,7 @@ public class EnvVars extends TreeMap<String,String> {
return channel.call(new GetEnvVars());
}
@MasterToSlave
private static final class GetEnvVars implements Callable<EnvVars,RuntimeException> {
private static final class GetEnvVars extends MasterToSlaveCallable<EnvVars,RuntimeException> {
public EnvVars call() {
return new EnvVars(EnvVars.masterEnvVars);
}
......
......@@ -38,7 +38,7 @@ import hudson.remoting.VirtualChannel;
import hudson.util.StreamCopyThread;
import hudson.util.ArgumentListBuilder;
import hudson.util.ProcessTree;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.apache.commons.io.input.NullInputStream;
import java.io.BufferedOutputStream;
......@@ -888,8 +888,7 @@ public abstract class Launcher {
getChannel().call(new KillTask(modelEnvVars));
}
@MasterToSlave
private static final class KillTask implements Callable<Void,RuntimeException> {
private static final class KillTask extends MasterToSlaveCallable<Void,RuntimeException> {
private final Map<String, String> modelEnvVars;
public KillTask(Map<String, String> modelEnvVars) {
......@@ -964,8 +963,7 @@ public abstract class Launcher {
IOTriplet getIOtriplet();
}
@MasterToSlave
private static class RemoteLaunchCallable implements Callable<RemoteProcess,IOException> {
private static class RemoteLaunchCallable extends MasterToSlaveCallable<RemoteProcess,IOException> {
private final List<String> cmd;
private final boolean[] masks;
private final String[] env;
......@@ -1035,8 +1033,7 @@ public abstract class Launcher {
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static class RemoteChannelLaunchCallable implements Callable<OutputStream,IOException> {
private static class RemoteChannelLaunchCallable extends MasterToSlaveCallable<OutputStream,IOException> {
private final String[] cmd;
private final Pipe out;
private final String workDir;
......
......@@ -36,8 +36,7 @@ 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 jenkins.security.MasterToSlaveCallable;
import org.acegisecurity.Authentication;
import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.context.SecurityContext;
......@@ -361,8 +360,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
return checkChannel().call(new GetSystemProperty(name));
}
@MasterToSlave
private static final class GetSystemProperty implements Callable<String, IOException> {
private static final class GetSystemProperty extends MasterToSlaveCallable<String, IOException> {
private final String name;
private GetSystemProperty(String name) {
......@@ -391,8 +389,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
}
}
@MasterToSlave @SlaveToMaster
private static final class GetCharset implements Callable<String, IOException> {
private static final class GetCharset extends MasterToSlaveCallable<String, IOException> {
public String call() throws IOException {
return Charset.defaultCharset().name();
}
......@@ -407,8 +404,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
return checkChannel().call(new GetEnvironmentVariable(name));
}
@MasterToSlave
private static final class GetEnvironmentVariable implements Callable<String, IOException> {
private static final class GetEnvironmentVariable extends MasterToSlaveCallable<String, IOException> {
private final String name;
private GetEnvironmentVariable(String name) {
......
......@@ -28,7 +28,7 @@ import jenkins.model.Jenkins;
import hudson.model.Job;
import hudson.model.Run;
import hudson.remoting.Callable;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.kohsuke.args4j.CmdLineException;
import java.io.IOException;
......@@ -82,8 +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<String[],IOException> {
private static final class GetCharacteristicEnvironmentVariables extends MasterToSlaveCallable<String[],IOException> {
public String[] call() throws IOException {
return new String[] {
System.getenv("JOB_NAME"),
......
......@@ -31,10 +31,7 @@ import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.Executor;
import hudson.model.Node;
import hudson.model.EnvironmentSpecific;
import hudson.model.Item;
import hudson.remoting.Callable;
import hudson.slaves.NodeSpecific;
import hudson.util.EditDistance;
import hudson.util.StreamTaskListener;
import hudson.tools.ToolDescriptor;
......@@ -44,7 +41,7 @@ import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.kohsuke.args4j.Argument;
/**
......@@ -129,8 +126,7 @@ public class InstallToolCommand extends CLICommand {
return 0;
}
@MasterToSlave
private static final class BuildIDs implements Callable<BuildIDs, IOException> {
private static final class BuildIDs extends MasterToSlaveCallable<BuildIDs, IOException> {
String job,number,id;
public BuildIDs call() throws IOException {
......
package hudson.cli.util;
import hudson.AbortException;
import hudson.remoting.Callable;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
......@@ -17,8 +16,7 @@ import java.net.URL;
*
* @author vjuranek
*/
@MasterToSlave
public class ScriptLoader implements Callable<String,IOException> {
public class ScriptLoader extends MasterToSlaveCallable<String,IOException> {
private final String script;
......
......@@ -42,7 +42,7 @@ import hudson.slaves.ComputerListener;
import hudson.util.CopyOnWriteList;
import hudson.util.RingBufferLogHandler;
import hudson.util.XStream2;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
......@@ -161,8 +161,7 @@ public class LogRecorder extends AbstractModelObject implements Saveable {
}
@MasterToSlave
private static final class SetLevel implements Callable<Void,Error> {
private static final class SetLevel extends MasterToSlaveCallable<Void,Error> {
/** known loggers (kept per slave), to avoid GC */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") private static final Set<Logger> loggers = new HashSet<Logger>();
private final String name;
......
......@@ -34,7 +34,6 @@ import hudson.cli.declarative.CLIMethod;
import hudson.cli.declarative.CLIResolver;
import hudson.model.listeners.ItemListener;
import hudson.model.listeners.SaveableListener;
import hudson.remoting.Callable;
import hudson.security.AccessControlled;
import hudson.security.Permission;
import hudson.security.ACL;
......@@ -44,6 +43,7 @@ import hudson.util.AtomicFileWriter;
import hudson.util.IOException2;
import hudson.util.IOUtils;
import jenkins.model.Jenkins;
import jenkins.security.NotReallyRoleSensitiveCallable;
import org.acegisecurity.Authentication;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FileSet;
......@@ -216,7 +216,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
// the test to see if the project already exists or not needs to be done in escalated privilege
// to avoid overwriting
ACL.impersonate(ACL.SYSTEM,new Callable<Void,IOException>() {
ACL.impersonate(ACL.SYSTEM,new NotReallyRoleSensitiveCallable<Void,IOException>() {
final Authentication user = Jenkins.getAuthentication();
@Override
public Void call() throws IOException {
......
......@@ -58,7 +58,7 @@ import hudson.util.RemotingDiagnostics.HeapDump;
import hudson.util.RunList;
import hudson.util.Futures;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.stapler.StaplerRequest;
......@@ -1025,8 +1025,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
oneOffExecutors.remove(e);
}
@MasterToSlave
private static class ListPossibleNames implements Callable<List<String>,IOException> {
private static class ListPossibleNames extends MasterToSlaveCallable<List<String>,IOException> {
public List<String> call() throws IOException {
List<String> names = new ArrayList<String>();
......@@ -1056,8 +1055,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static class GetFallbackName implements Callable<String,IOException> {
private static class GetFallbackName extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
return System.getProperty("host.name");
}
......@@ -1146,8 +1144,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
w.close();
}
@MasterToSlave
private static final class DumpExportTableTask implements Callable<String,IOException> {
private static final class DumpExportTableTask extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
......
......@@ -58,7 +58,7 @@ import javax.servlet.ServletException;
import hudson.util.TimeUnit2;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import jenkins.slaves.WorkspaceLocator;
import org.apache.commons.io.IOUtils;
......@@ -439,8 +439,7 @@ public abstract class Slave extends Node implements Serializable {
* <li>When it's read on this side as a return value, it morphs itself into {@link ClockDifference}.
* </ol>
*/
@MasterToSlave
private static final class GetClockDifference1 implements Callable<ClockDifference,IOException> {
private static final class GetClockDifference1 extends MasterToSlaveCallable<ClockDifference,IOException> {
public ClockDifference call() {
// this method must be being invoked locally, which means the clock is in sync
return new ClockDifference(0);
......@@ -453,8 +452,7 @@ public abstract class Slave extends Node implements Serializable {
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static final class GetClockDifference2 implements Callable<GetClockDifference3,IOException> {
private static final class GetClockDifference2 extends MasterToSlaveCallable<GetClockDifference3,IOException> {
/**
* Capture the time on the master when this object is sent to remote, which is when
* {@link GetClockDifference1#writeReplace()} is run.
......@@ -468,7 +466,6 @@ 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;
......
......@@ -26,7 +26,7 @@ package hudson.node_monitors;
import hudson.model.Computer;
import hudson.remoting.Callable;
import hudson.Extension;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
......@@ -57,8 +57,7 @@ public class ArchitectureMonitor extends NodeMonitor {
/**
* Obtains the string that represents the architecture.
*/
@MasterToSlave
private static class GetArchTask implements Callable<String,IOException> {
private static class GetArchTask extends MasterToSlaveCallable<String,IOException> {
public String call() {
String os = System.getProperty("os.name");
String arch = System.getProperty("os.arch");
......
......@@ -23,8 +23,7 @@
*/
package hudson.node_monitors;
import hudson.FilePath.FileCallable;
import hudson.model.Computer;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.remoting.VirtualChannel;
import hudson.Util;
import hudson.slaves.OfflineCause;
......@@ -159,7 +158,7 @@ public abstract class DiskSpaceMonitorDescriptor extends AbstractAsyncNodeMonito
private static final long serialVersionUID = 2L;
}
protected static final class GetUsableSpace implements FileCallable<DiskSpace> {
protected static final class GetUsableSpace extends MasterToSlaveFileCallable<DiskSpace> {
public GetUsableSpace() {}
@IgnoreJRERequirement
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException {
......
......@@ -32,8 +32,7 @@ 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 jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
......@@ -94,8 +93,7 @@ public class ResponseTimeMonitor extends NodeMonitor {
}
};
@MasterToSlave
private static final class Step1 implements Callable<Data,IOException> {
private static final class Step1 extends MasterToSlaveCallable<Data,IOException> {
private Data cur;
private Step1(Data cur) {
......@@ -114,8 +112,7 @@ public class ResponseTimeMonitor extends NodeMonitor {
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static final class Step2 implements Callable<Step3,IOException> {
private static final class Step2 extends MasterToSlaveCallable<Step3,IOException> {
private final Data cur;
private final long start = System.currentTimeMillis();
......@@ -131,7 +128,6 @@ 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;
......
......@@ -27,8 +27,7 @@ import hudson.Util;
import hudson.Extension;
import hudson.model.Computer;
import jenkins.model.Jenkins;
import hudson.remoting.Callable;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.jvnet.hudson.MemoryMonitor;
import org.jvnet.hudson.MemoryUsage;
......@@ -98,8 +97,7 @@ public class SwapSpaceMonitor extends NodeMonitor {
/**
* Obtains the string that represents the architecture.
*/
@MasterToSlave
private static class MonitorTask implements Callable<MemoryUsage,IOException> {
private static class MonitorTask extends MasterToSlaveCallable<MemoryUsage,IOException> {
public MemoryUsage call() throws IOException {
MemoryMonitor mm;
try {
......
......@@ -25,7 +25,7 @@ package hudson.node_monitors;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Functions;
import hudson.model.Computer;
import hudson.remoting.Callable;
......@@ -82,7 +82,7 @@ public class TemporarySpaceMonitor extends AbstractDiskSpaceMonitor {
return null;
}
protected static final class GetTempSpace implements FileCallable<DiskSpace> {
protected static final class GetTempSpace extends MasterToSlaveFileCallable<DiskSpace> {
@IgnoreJRERequirement
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException {
try {
......
......@@ -23,13 +23,13 @@
*/
package hudson.os.solaris;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.FileSystemProvisioner;
import hudson.FilePath;
import hudson.WorkspaceSnapshot;
import hudson.FileSystemProvisionerDescriptor;
import hudson.Extension;
import hudson.remoting.VirtualChannel;
import hudson.FilePath.FileCallable;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import hudson.model.AbstractProject;
......@@ -52,7 +52,7 @@ public class ZFSProvisioner extends FileSystemProvisioner implements Serializabl
private final String rootDataset;
public ZFSProvisioner(Node node) throws IOException, InterruptedException {
rootDataset = node.getRootPath().act(new FileCallable<String>() {
rootDataset = node.getRootPath().act(new MasterToSlaveFileCallable<String>() {
private static final long serialVersionUID = -2142349338699797436L;
public String invoke(File f, VirtualChannel channel) throws IOException {
......@@ -68,7 +68,7 @@ public class ZFSProvisioner extends FileSystemProvisioner implements Serializabl
public void prepareWorkspace(AbstractBuild<?,?> build, FilePath ws, final TaskListener listener) throws IOException, InterruptedException {
final String name = build.getProject().getFullName();
ws.act(new FileCallable<Void>() {
ws.act(new MasterToSlaveFileCallable<Void>() {
private static final long serialVersionUID = 2129531727963121198L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
......@@ -87,7 +87,7 @@ public class ZFSProvisioner extends FileSystemProvisioner implements Serializabl
}
public void discardWorkspace(AbstractProject<?, ?> project, FilePath ws) throws IOException, InterruptedException {
ws.act(new FileCallable<Void>() {
ws.act(new MasterToSlaveFileCallable<Void>() {
private static final long serialVersionUID = 1916618107019257530L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
......
......@@ -4,9 +4,8 @@ import groovy.lang.Binding;
import hudson.FilePath;
import hudson.cli.CLICommand;
import jenkins.model.Jenkins;
import hudson.remoting.Callable;
import hudson.util.spring.BeanBuilder;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
......@@ -141,8 +140,7 @@ public abstract class AbstractPasswordBasedSecurityRealm extends SecurityRealm i
/**
* Asks for the password.
*/
@MasterToSlave
private static class InteractivelyAskForPassword implements Callable<String,IOException> {
private static class InteractivelyAskForPassword extends MasterToSlaveCallable<String,IOException> {
@IgnoreJRERequirement
public String call() throws IOException {
Console console = System.console();
......
......@@ -28,10 +28,9 @@ import hudson.FilePath;
import hudson.model.Computer;
import hudson.model.Slave;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.PingThread;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
......@@ -86,8 +85,7 @@ public class ChannelPinger extends ComputerListener {
setUpPingForChannel(channel, pingInterval);
}
@MasterToSlave
private static class SetUpRemotePing implements Callable<Void, IOException> {
private static class SetUpRemotePing extends MasterToSlaveCallable<Void, IOException> {
private static final long serialVersionUID = -2702219700841759872L;
private int pingInterval;
public SetUpRemotePing(int pingInterval) {
......
......@@ -30,10 +30,8 @@ import hudson.model.Computer;
import hudson.util.TimeUnit2;
import hudson.remoting.VirtualChannel;
import hudson.remoting.Channel;
import hudson.remoting.Callable;
import hudson.Extension;
import jenkins.security.MasterToSlave;
import jenkins.security.SlaveToMaster;
import jenkins.security.SlaveToMasterCallable;
import java.io.IOException;
import java.util.logging.Logger;
......@@ -104,8 +102,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<Void,RuntimeException> {
private static final class PingCommand extends SlaveToMasterCallable<Void,RuntimeException> {
public Void call() throws RuntimeException {
return null;
}
......
......@@ -72,8 +72,7 @@ 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.security.MasterToSlaveCallable;
import jenkins.slaves.JnlpSlaveAgentProtocol;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
......@@ -401,8 +400,7 @@ public class SlaveComputer extends Computer {
return channel.call(new LoadingTime(true));
}
@MasterToSlave @SlaveToMaster
static class LoadingCount implements Callable<Integer,RuntimeException> {
static class LoadingCount extends MasterToSlaveCallable<Integer,RuntimeException> {
private final boolean resource;
LoadingCount(boolean resource) {
this.resource = resource;
......@@ -413,15 +411,13 @@ public class SlaveComputer extends Computer {
}
}
@MasterToSlave
static class LoadingPrefetchCacheCount implements Callable<Integer,RuntimeException> {
static class LoadingPrefetchCacheCount extends MasterToSlaveCallable<Integer,RuntimeException> {
@Override public Integer call() {
return Channel.current().classLoadingPrefetchCacheCount.get();
}
}
@MasterToSlave
static class LoadingTime implements Callable<Long,RuntimeException> {
static class LoadingTime extends MasterToSlaveCallable<Long,RuntimeException> {
private final boolean resource;
LoadingTime(boolean resource) {
this.resource = resource;
......@@ -716,22 +712,19 @@ public class SlaveComputer extends Computer {
private static final Logger logger = Logger.getLogger(SlaveComputer.class.getName());
@MasterToSlave
private static final class SlaveVersion implements Callable<String,IOException> {
private static final class SlaveVersion extends MasterToSlaveCallable<String,IOException> {
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<Boolean,IOException> {
private static final class DetectOS extends MasterToSlaveCallable<Boolean,IOException> {
public Boolean call() throws IOException {
return File.pathSeparatorChar==':';
}
}
@MasterToSlave @SlaveToMaster
private static final class DetectDefaultCharset implements Callable<String,IOException> {
private static final class DetectDefaultCharset extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
return Charset.defaultCharset().name();
}
......@@ -748,8 +741,7 @@ public class SlaveComputer extends Computer {
static final RingBufferLogHandler SLAVE_LOG_HANDLER = new RingBufferLogHandler();
}
@MasterToSlave
private static class SlaveInitializer implements Callable<Void,RuntimeException> {
private static class SlaveInitializer extends MasterToSlaveCallable<Void,RuntimeException> {
public Void call() {
// avoid double installation of the handler. JNLP slaves can reconnect to the master multiple times
// and each connection gets a different RemoteClassLoader, so we need to evict them by class name,
......@@ -796,8 +788,7 @@ public class SlaveComputer extends Computer {
return null;
}
@MasterToSlave
private static class SlaveLogFetcher implements Callable<List<LogRecord>,RuntimeException> {
private static class SlaveLogFetcher extends MasterToSlaveCallable<List<LogRecord>,RuntimeException> {
public List<LogRecord> call() {
return new ArrayList<LogRecord>(SLAVE_LOG_HANDLER.getView());
}
......
......@@ -24,6 +24,7 @@
package hudson.tasks;
import hudson.FilePath;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.Extension;
......@@ -169,7 +170,7 @@ public class ArtifactArchiver extends Recorder {
return true;
}
private static final class ListFiles implements FilePath.FileCallable<Map<String,String>> {
private static final class ListFiles extends MasterToSlaveFileCallable<Map<String,String>> {
private static final long serialVersionUID = 1;
private final String includes, excludes;
ListFiles(String includes, String excludes) {
......
......@@ -28,6 +28,7 @@ import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.matrix.MatrixConfiguration;
......@@ -220,7 +221,7 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
return;
}
List<Record> records = ws.act(new FileCallable<List<Record>>() {
List<Record> records = ws.act(new MasterToSlaveFileCallable<List<Record>>() {
public List<Record> invoke(File baseDir, VirtualChannel channel) throws IOException {
List<Record> results = new ArrayList<Record>();
......
......@@ -24,6 +24,7 @@
package hudson.tasks;
import hudson.Extension;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Functions;
import hudson.EnvVars;
......@@ -219,7 +220,7 @@ public class Maven extends Builder {
* Looks for <tt>pom.xlm</tt> or <tt>project.xml</tt> to determine the maven executable
* name.
*/
private static final class DecideDefaultMavenCommand implements FileCallable<String> {
private static final class DecideDefaultMavenCommand extends MasterToSlaveFileCallable<String> {
private static final long serialVersionUID = -2327576423452215146L;
// command line arguments.
private final String arguments;
......
......@@ -28,12 +28,11 @@ import hudson.Functions;
import hudson.Util;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.util.FormValidation;
import java.io.IOException;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
......@@ -195,8 +194,7 @@ public class Shell extends CommandInterpreter {
return FormValidation.validateExecutable(value);
}
@MasterToSlave
private static final class Shellinterpreter implements Callable<String, IOException> {
private static final class Shellinterpreter extends MasterToSlaveCallable<String, IOException> {
private static final long serialVersionUID = 1L;
......
......@@ -23,6 +23,7 @@
*/
package hudson.tasks.junit;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.model.TaskListener;
import hudson.tasks.test.TestResultParser;
import hudson.model.AbstractBuild;
......@@ -87,8 +88,8 @@ public class JUnitParser extends TestResultParser {
return workspace.act(new ParseResultCallable(testResultLocations, buildTime, timeOnMaster, keepLongStdio));
}
private static final class ParseResultCallable implements
FilePath.FileCallable<TestResult> {
private static final class ParseResultCallable extends
MasterToSlaveFileCallable<TestResult> {
private final long buildTime;
private final String testResults;
private final long nowMaster;
......
......@@ -25,7 +25,7 @@ package hudson.tasks.test;
import hudson.AbortException;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
......@@ -74,7 +74,7 @@ public abstract class DefaultTestResultParserImpl extends TestResultParser imple
@Override
public TestResult parse(final String testResultLocations, final AbstractBuild build, final Launcher launcher, final TaskListener listener) throws InterruptedException, IOException {
return build.getWorkspace().act(new FileCallable<TestResult>() {
return build.getWorkspace().act(new MasterToSlaveFileCallable<TestResult>() {
final boolean ignoreTimestampCheck = IGNORE_TIMESTAMP_CHECK; // so that the property can be set on the master
final long buildTime = build.getTimestamp().getTimeInMillis();
final long nowMaster = System.currentTimeMillis();
......
......@@ -40,7 +40,7 @@ import hudson.util.FormValidation;
import hudson.util.HttpResponses;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
......@@ -502,8 +502,7 @@ public class JDKInstaller extends ToolInstaller {
throw new DetectionFailedException("Unknown CPU name: "+arch);
}
@MasterToSlave
static class GetCurrentPlatform implements Callable<Platform,DetectionFailedException> {
static class GetCurrentPlatform extends MasterToSlaveCallable<Platform,DetectionFailedException> {
private static final long serialVersionUID = 1L;
public Platform call() throws DetectionFailedException {
return current();
......@@ -565,8 +564,7 @@ public class JDKInstaller extends ToolInstaller {
throw new DetectionFailedException("Unknown CPU architecture: "+arch);
}
@MasterToSlave
static class GetCurrentCPU implements Callable<CPU,DetectionFailedException> {
static class GetCurrentCPU extends MasterToSlaveCallable<CPU,DetectionFailedException> {
private static final long serialVersionUID = 1L;
public CPU call() throws DetectionFailedException {
return current();
......
......@@ -26,7 +26,7 @@ package hudson.tools;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.ProxyConfiguration;
import hudson.Util;
import hudson.Functions;
......@@ -119,7 +119,7 @@ public class ZipExtractionInstaller extends ToolInstaller {
* Sets execute permission on all files, since unzip etc. might not do this.
* Hackish, is there a better way?
*/
static class ChmodRecAPlusX implements FileCallable<Void> {
static class ChmodRecAPlusX extends MasterToSlaveFileCallable<Void> {
private static final long serialVersionUID = 1L;
public Void invoke(File d, VirtualChannel channel) throws IOException {
if(!Functions.isWindows())
......
......@@ -34,7 +34,7 @@ import hudson.remoting.DelegatingCallable;
import hudson.remoting.Future;
import hudson.remoting.VirtualChannel;
import hudson.security.AccessControlled;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.kohsuke.stapler.StaplerRequest;
......@@ -71,8 +71,7 @@ public final class RemotingDiagnostics {
return channel.call(new GetSystemProperties());
}
@MasterToSlave
private static final class GetSystemProperties implements Callable<Map<Object,Object>,RuntimeException> {
private static final class GetSystemProperties extends MasterToSlaveCallable<Map<Object,Object>,RuntimeException> {
public Map<Object,Object> call() {
return new TreeMap<Object,Object>(System.getProperties());
}
......@@ -91,8 +90,7 @@ public final class RemotingDiagnostics {
return channel.callAsync(new GetThreadDump());
}
@MasterToSlave
private static final class GetThreadDump implements Callable<Map<String,String>,RuntimeException> {
private static final class GetThreadDump extends MasterToSlaveCallable<Map<String,String>,RuntimeException> {
public Map<String,String> call() {
Map<String,String> r = new LinkedHashMap<String,String>();
try {
......@@ -122,8 +120,7 @@ public final class RemotingDiagnostics {
return channel.call(new Script(script));
}
@MasterToSlave
private static final class Script implements DelegatingCallable<String,RuntimeException> {
private static final class Script extends MasterToSlaveCallable<String,RuntimeException> implements DelegatingCallable<String,RuntimeException> {
private final String script;
private transient ClassLoader cl;
......@@ -205,8 +202,7 @@ public final class RemotingDiagnostics {
}
}
@MasterToSlave
private static class GetHeapDump implements Callable<FilePath, IOException> {
private static class GetHeapDump extends MasterToSlaveCallable<FilePath, IOException> {
public FilePath call() throws IOException {
final File hprof = File.createTempFile("hudson-heapdump", "hprof");
hprof.delete();
......
package jenkins.security;
import hudson.remoting.Callable;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Annotates {@link Callable} that this callable is meant to be run on the slave.
*
* @author Kohsuke Kawaguchi
* @see SlaveToMaster
* @since 1.THU
*/
@Retention(RUNTIME)
@Target(TYPE)
@Inherited
@Documented
public @interface MasterToSlave {
}
package jenkins.security;
import hudson.remoting.Callable;
import org.jenkinsci.remoting.Role;
import java.util.Collection;
/**
* Convenient {@link Callable} with {@link MasterToSlave} to create anonymous Callable class.
* Convenient {@link Callable} meant to be run on slave.
*
* @author Kohsuke Kawaguchi
* @since 1.THU
*/
@MasterToSlave
public abstract class MasterToSlaveCallable<V, T extends Throwable> implements Callable<V,T> {
@Override
public Collection<Role> getRecipients() {
return Roles.FOR_SLAVE;
}
private static final long serialVersionUID = 1L;
}
package jenkins.security;
import hudson.remoting.Callable;
import org.jenkinsci.remoting.Role;
import java.util.Collection;
/**
* {@link Callable} adapter for situations where Callable is not used for remoting but
* just as a convenient function that has parameterized return value and exception type.
*
* @author Kohsuke Kawaguchi
* @since 1.THU
*/
public abstract class NotReallyRoleSensitiveCallable<V,T extends Throwable> implements Callable<V,T> {
@Override
public final Collection<Role> getRecipients() {
// not meant to be used where this matters
throw new UnsupportedOperationException();
}
}
package jenkins.security;
import hudson.remoting.Callable;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* Annotates {@link Callable} that are meant for the slave to execute on the master.
*
* @author Kohsuke Kawaguchi
* @see MasterToSlave
* @see CallableDirectionChecker
* @since 1.THU
*/
@Retention(RUNTIME)
@Target(TYPE)
@Inherited
@Documented
public @interface SlaveToMaster {
}
package jenkins.security;
import hudson.remoting.Callable;
import org.jenkinsci.remoting.Role;
import java.util.Collection;
/**
* Convenient {@link Callable} with {@link SlaveToMaster} to create anonymous Callable class.
* Convenient {@link Callable} that are meant to run on the master (sent by slave/CLI/etc).
*
* @author Kohsuke Kawaguchi
* @since 1.THU
*/
@SlaveToMaster
public abstract class SlaveToMasterCallable<V, T extends Throwable> implements Callable<V,T> {
@Override
public Collection<Role> getRecipients() {
return Roles.FOR_MASTER;
}
private static final long serialVersionUID = 1L;
}
......@@ -4,12 +4,11 @@ import hudson.Extension;
import hudson.FilePath;
import hudson.model.Computer;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.StandardOutputStream;
import hudson.slaves.ComputerListener;
import hudson.util.jna.GNUCLibrary;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import java.io.File;
import java.io.FileDescriptor;
......@@ -36,8 +35,7 @@ public class StandardOutputSwapper extends ComputerListener {
}
}
@MasterToSlave
private static final class ChannelSwapper implements Callable<Boolean,Exception> {
private static final class ChannelSwapper extends MasterToSlaveCallable<Boolean,Exception> {
public Boolean call() throws Exception {
if (File.pathSeparatorChar==';') return false; // Windows
......
......@@ -39,6 +39,8 @@ import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import static hudson.FilePath.MasterToSlaveFileCallable;
/**
* Abstraction over {@link File}, {@link FilePath}, or other items such as network resources or ZIP entries.
* Assumed to be read-only and makes very limited assumptions, just enough to display content and traverse directories.
......@@ -334,7 +336,7 @@ public abstract class VirtualFile implements Comparable<VirtualFile> {
}
};
}
private static final class Scanner implements FilePath.FileCallable<String[]> {
private static final class Scanner extends MasterToSlaveFileCallable<String[]> {
private final String glob;
Scanner(String glob) {
this.glob = glob;
......@@ -351,7 +353,7 @@ public abstract class VirtualFile implements Comparable<VirtualFile> {
}
}
private static final class Readable implements FilePath.FileCallable<Boolean> {
private static final class Readable extends MasterToSlaveFileCallable<Boolean> {
@Override public Boolean invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return f.canRead();
}
......
......@@ -31,6 +31,8 @@ import hudson.util.ProcessTree;
import hudson.util.StreamTaskListener;
import hudson.remoting.Callable;
import java.io.ByteArrayOutputStream;
import jenkins.security.MasterToSlaveCallable;
import org.apache.commons.io.FileUtils;
import org.jvnet.hudson.test.Bug;
......@@ -74,7 +76,7 @@ public class LauncherTest extends ChannelTestCase {
}
}
private static final Callable<Object,RuntimeException> NOOP = new Callable<Object,RuntimeException>() {
private static final Callable<Object,RuntimeException> NOOP = new MasterToSlaveCallable<Object,RuntimeException>() {
public Object call() throws RuntimeException {
return null;
}
......
......@@ -2,6 +2,7 @@ package hudson.os;
import hudson.remoting.Callable;
import hudson.util.StreamTaskListener;
import jenkins.security.MasterToSlaveCallable;
import java.io.FileOutputStream;
......@@ -10,7 +11,7 @@ import java.io.FileOutputStream;
*/
public class SUTester {
public static void main(String[] args) throws Throwable {
SU.execute(StreamTaskListener.fromStdout(),"kohsuke","bogus",new Callable<Object, Throwable>() {
SU.execute(StreamTaskListener.fromStdout(),"kohsuke","bogus",new MasterToSlaveCallable<Object, Throwable>() {
public Object call() throws Throwable {
System.out.println("Touching /tmp/x");
new FileOutputStream("/tmp/x").close();
......
......@@ -5,6 +5,7 @@ import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.util.ProcessTree.OSProcess;
import hudson.util.ProcessTree.ProcessCallable;
import jenkins.security.MasterToSlaveCallable;
import java.io.IOException;
import java.io.Serializable;
......@@ -35,7 +36,7 @@ public class ProcessTreeTest extends ChannelTestCase {
t.p.act(new ProcessCallableImpl());
}
private static class MyCallable implements Callable<Tag, IOException>, Serializable {
private static class MyCallable extends MasterToSlaveCallable<Tag, IOException> implements Serializable {
public Tag call() throws IOException {
Tag t = new Tag();
t.tree = ProcessTree.get();
......
......@@ -3,13 +3,12 @@ package hudson;
import hudson.Launcher.LocalLauncher;
import hudson.Launcher.RemoteLauncher;
import hudson.Proc.RemoteProc;
import hudson.remoting.Callable;
import hudson.remoting.Future;
import hudson.remoting.Pipe;
import hudson.remoting.VirtualChannel;
import hudson.slaves.DumbSlave;
import hudson.util.IOUtils;
import hudson.util.StreamTaskListener;
import jenkins.security.MasterToSlaveCallable;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
......@@ -70,7 +69,7 @@ public class ProcTest extends HudsonTestCase {
return ch;
}
private static class ChannelFiller implements Callable<Void,IOException> {
private static class ChannelFiller extends MasterToSlaveCallable<Void,IOException> {
private final OutputStream o;
private ChannelFiller(OutputStream o) {
......
......@@ -23,6 +23,7 @@
*/
package hudson.logging;
import jenkins.security.MasterToSlaveCallable;
import org.jvnet.hudson.test.Url;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
......@@ -109,7 +110,7 @@ public class LogRecorderManagerTest {
assertFalse(text, text.contains("msg #4"));
}
private static final class Log implements Callable<Boolean,Error> {
private static final class Log extends MasterToSlaveCallable<Boolean,Error> {
private final Level level;
private final String logger;
private final String message;
......
......@@ -35,8 +35,7 @@ import hudson.remoting.Callable;
import hudson.remoting.Which;
import hudson.util.ArgumentListBuilder;
import jenkins.security.MasterToSlave;
import jenkins.security.SlaveToMaster;
import jenkins.security.SlaveToMasterCallable;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestExtension;
......@@ -156,8 +155,7 @@ public class JNLPLauncherTest extends HudsonTestCase {
return c;
}
@MasterToSlave @SlaveToMaster
private static class NoopTask implements Callable<String,RuntimeException> {
private static class NoopTask extends SlaveToMasterCallable<String,RuntimeException> {
public String call() {
return "done";
}
......
......@@ -28,6 +28,9 @@ import hudson.FilePath;
import hudson.model.Slave;
import hudson.remoting.Callable;
import java.io.File;
import java.util.Collection;
import org.jenkinsci.remoting.Role;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Rule;
......@@ -51,7 +54,7 @@ public class DefaultFilePathFilterTest {
// good
}
assertFalse(reverse.exists());
System.setProperty(DefaultFilePathFilter.BYPASS_PROP, "true");
DefaultFilePathFilter.BYPASS = true;
s.getChannel().call(new ReverseCallable(reverse));
assertTrue(reverse.exists());
assertEquals("goodbye", reverse.readToString());
......@@ -66,6 +69,10 @@ public class DefaultFilePathFilterTest {
assertFalse(p.isRemote());
return p.readToString();
}
@Override
public Collection<Role> getRecipients() {
return null; // simulate legacy Callable impls
}
}
private static class ReverseCallable implements Callable<Void,Exception> {
......@@ -78,6 +85,9 @@ public class DefaultFilePathFilterTest {
p.write("goodbye", null);
return null;
}
@Override
public Collection<Role> getRecipients() {
return null; // simulate legacy Callable impls
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册