diff options
author | 2017-06-19 14:17:52 +0200 | |
---|---|---|
committer | 2017-06-19 18:25:13 +0200 | |
commit | 77c9f5ec751f4adf3a8095e2e2943ec59dc12d26 (patch) | |
tree | e26c02e39bbec73d4fdc47edbbfa7469fa0f291d /src/main/java/com/google/devtools/build/lib/worker | |
parent | 34e22458c6058773b41958b75ef5e7459482c109 (diff) |
Rewrite the Executor/ActionExecutionContext split
Move everything to ActionExecutionContext, and drop Executor whereever possible.
This clarifies the API, makes it simpler to test, and simplifies the code.
PiperOrigin-RevId: 159414816
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/worker')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java | 15 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java | 15 |
2 files changed, 12 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java index e72551bef0..8db06b5c0a 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java @@ -31,7 +31,6 @@ import com.google.devtools.build.lib.actions.ActionStatusMessage; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.ExecutionRequirements; import com.google.devtools.build.lib.actions.ExecutionStrategy; -import com.google.devtools.build.lib.actions.Executor; import com.google.devtools.build.lib.actions.ResourceManager; import com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle; import com.google.devtools.build.lib.actions.SandboxedSpawnActionContext; @@ -112,19 +111,19 @@ public final class WorkerSpawnStrategy implements SandboxedSpawnActionContext { ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException { - Executor executor = actionExecutionContext.getExecutor(); if (!spawn.getExecutionInfo().containsKey(ExecutionRequirements.SUPPORTS_WORKERS) || !spawn.getExecutionInfo().get(ExecutionRequirements.SUPPORTS_WORKERS).equals("1")) { StandaloneSpawnStrategy standaloneStrategy = - Preconditions.checkNotNull(executor.getContext(StandaloneSpawnStrategy.class)); - executor.getEventHandler().handle( + Preconditions.checkNotNull( + actionExecutionContext.getContext(StandaloneSpawnStrategy.class)); + actionExecutionContext.getEventHandler().handle( Event.warn( String.format(ERROR_MESSAGE_PREFIX + REASON_NO_EXECUTION_INFO, spawn.getMnemonic()))); standaloneStrategy.exec(spawn, actionExecutionContext); return; } - EventBus eventBus = actionExecutionContext.getExecutor().getEventBus(); + EventBus eventBus = actionExecutionContext.getEventBus(); ActionExecutionMetadata owner = spawn.getResourceOwner(); eventBus.post(ActionStatusMessage.schedulingStrategy(owner)); try (ResourceHandle handle = @@ -139,10 +138,8 @@ public final class WorkerSpawnStrategy implements SandboxedSpawnActionContext { ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException { - Executor executor = actionExecutionContext.getExecutor(); - - if (executor.reportsSubcommands()) { - executor.reportSubcommand(spawn); + if (actionExecutionContext.reportsSubcommands()) { + actionExecutionContext.reportSubcommand(spawn); } if (Iterables.isEmpty(spawn.getToolFiles())) { diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java index d3846945b6..6fd225e4bd 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java @@ -23,7 +23,6 @@ import com.google.common.hash.HashCode; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.ExecutionStrategy; -import com.google.devtools.build.lib.actions.Executor; import com.google.devtools.build.lib.actions.Spawn; import com.google.devtools.build.lib.actions.TestExecException; import com.google.devtools.build.lib.actions.UserExecException; @@ -104,7 +103,7 @@ public class WorkerTestStrategy extends StandaloneTestStrategy { actionExecutionContext, addPersistentRunnerVars(spawn.getEnvironment()), startupArgs, - actionExecutionContext.getExecutor().getExecRoot()); + actionExecutionContext.getExecRoot()); } private TestResultData execInWorker( @@ -114,10 +113,8 @@ public class WorkerTestStrategy extends StandaloneTestStrategy { List<String> startupArgs, Path execRoot) throws ExecException, InterruptedException, IOException { - Executor executor = actionExecutionContext.getExecutor(); - // TODO(kush): Remove once we're out of the experimental phase. - executor + actionExecutionContext .getEventHandler() .handle( Event.warn( @@ -128,7 +125,7 @@ public class WorkerTestStrategy extends StandaloneTestStrategy { Path testLogPath = action.getTestLog().getPath(); Worker worker = null; WorkerKey key = null; - long startTime = executor.getClock().currentTimeMillis(); + long startTime = actionExecutionContext.getClock().currentTimeMillis(); try { HashCode workerFilesHash = WorkerFilesHash.getWorkerFilesHash( action.getTools(), actionExecutionContext); @@ -167,7 +164,7 @@ public class WorkerTestStrategy extends StandaloneTestStrategy { .exception(e) .logText(data) .build(); - executor.getEventHandler().handle(Event.warn(errorMessage.toString())); + actionExecutionContext.getEventHandler().handle(Event.warn(errorMessage.toString())); throw e; } @@ -188,7 +185,7 @@ public class WorkerTestStrategy extends StandaloneTestStrategy { actionExecutionContext.getFileOutErr().getErrorStream().write( response.getOutputBytes().toByteArray()); - long duration = executor.getClock().currentTimeMillis() - startTime; + long duration = actionExecutionContext.getClock().currentTimeMillis() - startTime; builder.addTestTimes(duration); builder.setRunDurationMillis(duration); if (response.getExitCode() == 0) { @@ -204,7 +201,7 @@ public class WorkerTestStrategy extends StandaloneTestStrategy { .addFailedLogs(testLogPath.getPathString()); } TestCase details = parseTestResult( - action.resolve(actionExecutionContext.getExecutor().getExecRoot()).getXmlOutputPath()); + action.resolve(actionExecutionContext.getExecRoot()).getXmlOutputPath()); if (details != null) { builder.setTestCase(details); } |