Search in sources :

Example 1 with ResourceHandle

use of com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle 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 ResourceHandle

use of com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle 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 3 with ResourceHandle

use of com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle 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 4 with ResourceHandle

use of com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle 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

EventBus (com.google.common.eventbus.EventBus)4 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)4 ResourceHandle (com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle)4 Executor (com.google.devtools.build.lib.actions.Executor)3 StandaloneSpawnStrategy (com.google.devtools.build.lib.standalone.StandaloneSpawnStrategy)1