Search in sources :

Example 1 with ActionExecutionMetadata

use of com.google.devtools.build.lib.actions.ActionExecutionMetadata in project bazel by bazelbuild.

the class WorkerSpawnStrategy method exec.

@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    if (!spawn.getExecutionInfo().containsKey("supports-workers") || !spawn.getExecutionInfo().get("supports-workers").equals("1")) {
        StandaloneSpawnStrategy standaloneStrategy = Preconditions.checkNotNull(executor.getContext(StandaloneSpawnStrategy.class));
        executor.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();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
        eventBus.post(ActionStatusMessage.runningStrategy(spawn.getResourceOwner(), "worker"));
        actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) StandaloneSpawnStrategy(com.google.devtools.build.lib.standalone.StandaloneSpawnStrategy) EventBus(com.google.common.eventbus.EventBus)

Example 2 with ActionExecutionMetadata

use of com.google.devtools.build.lib.actions.ActionExecutionMetadata in project bazel by bazelbuild.

the class ExperimentalStateTrackerTest method testActionStrategyVisible.

@Test
public void testActionStrategyVisible() throws Exception {
    // verify that, if a strategy was reported for a shown action, it is visible
    // in the progress bar.
    String strategy = "verySpecialStrategy";
    String primaryOutput = "some/path/to/a/file";
    ManualClock clock = new ManualClock();
    Path path = outputBase.getRelative(new PathFragment(primaryOutput));
    Artifact artifact = new Artifact(path, Root.asSourceRoot(path));
    ActionExecutionMetadata actionMetadata = Mockito.mock(ActionExecutionMetadata.class);
    when(actionMetadata.getOwner()).thenReturn(Mockito.mock(ActionOwner.class));
    when(actionMetadata.getPrimaryOutput()).thenReturn(artifact);
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    stateTracker.actionStarted(new ActionStartedEvent(mockAction("Some random action", primaryOutput), clock.nanoTime()));
    stateTracker.actionStatusMessage(ActionStatusMessage.runningStrategy(actionMetadata, strategy));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Output should mention strategy '" + strategy + "', but was: " + output, output.contains(strategy));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) Artifact(com.google.devtools.build.lib.actions.Artifact) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 3 with ActionExecutionMetadata

use of com.google.devtools.build.lib.actions.ActionExecutionMetadata in project bazel by bazelbuild.

the class StandaloneSpawnStrategy method exec.

/**
   * Executes the given {@code spawn}.
   */
@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException {
    EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = resourceManager.acquireResources(owner, spawn.getLocalResources())) {
        eventBus.post(ActionStatusMessage.runningStrategy(owner, "standalone"));
        actuallyExec(spawn, actionExecutionContext);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

Example 4 with ActionExecutionMetadata

use of com.google.devtools.build.lib.actions.ActionExecutionMetadata in project bazel by bazelbuild.

the class DarwinSandboxedStrategy method exec.

@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    // Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
    if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
        SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
        return;
    }
    EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
        SandboxHelpers.postActionStatusMessage(eventBus, spawn);
        actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

Example 5 with ActionExecutionMetadata

use of com.google.devtools.build.lib.actions.ActionExecutionMetadata in project bazel by bazelbuild.

the class LinuxSandboxedStrategy method exec.

@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    // Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
    if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
        SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
        return;
    }
    EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
        SandboxHelpers.postActionStatusMessage(eventBus, spawn);
        actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

Aggregations

ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)5 EventBus (com.google.common.eventbus.EventBus)4 ResourceHandle (com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle)4 Executor (com.google.devtools.build.lib.actions.Executor)3 ActionOwner (com.google.devtools.build.lib.actions.ActionOwner)1 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 StandaloneSpawnStrategy (com.google.devtools.build.lib.standalone.StandaloneSpawnStrategy)1 ManualClock (com.google.devtools.build.lib.testutil.ManualClock)1 LoggingTerminalWriter (com.google.devtools.build.lib.util.io.LoggingTerminalWriter)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 Test (org.junit.Test)1