Search in sources :

Example 1 with Instance

use of build.buildfarm.instance.Instance in project bazel-buildfarm by bazelbuild.

the class Worker method start.

public void start() throws InterruptedException {
    try {
        Files.createDirectories(root);
        fileCache.start(/* skipLoad= */
        false);
    } catch (IOException e) {
        logger.log(SEVERE, "error starting file cache", e);
        return;
    }
    OperationQueueClient oq = new OperationQueueClient(operationQueueInstance, config.getPlatform(), config.getExecutionPoliciesList());
    Instance acInstance = newStubInstance(config.getActionCache(), casInstance.getDigestUtil());
    WorkerContext context = new OperationQueueWorkerContext(config, casInstance, acInstance, oq, uploader, fileCache, execOwner, root, retrier);
    PipelineStage completeStage = new PutOperationStage((operation) -> oq.deactivate(operation.getName()));
    PipelineStage reportResultStage = new ReportResultStage(context, completeStage, completeStage);
    PipelineStage executeActionStage = new ExecuteActionStage(context, reportResultStage, completeStage);
    PipelineStage inputFetchStage = new InputFetchStage(context, executeActionStage, new PutOperationStage(oq::requeue));
    PipelineStage matchStage = new MatchStage(context, inputFetchStage, completeStage);
    pipeline = new Pipeline();
    // pipeline.add(errorStage, 0);
    pipeline.add(matchStage, 4);
    pipeline.add(inputFetchStage, 3);
    pipeline.add(executeActionStage, 2);
    pipeline.add(reportResultStage, 1);
    pipeline.start();
    // uninterruptable
    pipeline.join();
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }
    stop();
}
Also used : ExecuteActionStage(build.buildfarm.worker.ExecuteActionStage) PipelineStage(build.buildfarm.worker.PipelineStage) StubInstance(build.buildfarm.instance.stub.StubInstance) Instance(build.buildfarm.instance.Instance) InputFetchStage(build.buildfarm.worker.InputFetchStage) IOException(java.io.IOException) MatchStage(build.buildfarm.worker.MatchStage) Pipeline(build.buildfarm.worker.Pipeline) PutOperationStage(build.buildfarm.worker.PutOperationStage) WorkerContext(build.buildfarm.worker.WorkerContext) ReportResultStage(build.buildfarm.worker.ReportResultStage)

Example 2 with Instance

use of build.buildfarm.instance.Instance in project bazel-buildfarm by bazelbuild.

the class IndexWorker method main.

public static void main(String[] args) throws Exception {
    String host = args[0];
    String instanceName = args[1];
    DigestUtil digestUtil = DigestUtil.forHash(args[2]);
    String reindexworker = args[3];
    ManagedChannel channel = createChannel(host);
    Instance instance = new StubInstance(instanceName, digestUtil, channel);
    CasIndexResults results = instance.reindexCas(reindexworker);
    System.out.println(results.toMessage());
    instance.stop();
}
Also used : StubInstance(build.buildfarm.instance.stub.StubInstance) Instance(build.buildfarm.instance.Instance) CasIndexResults(build.buildfarm.common.CasIndexResults) ManagedChannel(io.grpc.ManagedChannel) DigestUtil(build.buildfarm.common.DigestUtil) StubInstance(build.buildfarm.instance.stub.StubInstance)

Example 3 with Instance

use of build.buildfarm.instance.Instance in project bazel-buildfarm by bazelbuild.

the class Mount method main.

@SuppressWarnings("BusyWait")
public static void main(String[] args) throws Exception {
    String host = args[0];
    String instanceName = args[1];
    DigestUtil digestUtil = DigestUtil.forHash(args[2]);
    ManagedChannel channel = createChannel(host);
    Instance instance = new StubInstance(instanceName, digestUtil, channel);
    Path cwd = Paths.get(".");
    FuseCAS fuse = new FuseCAS(cwd.resolve(args[3]), new InputStreamFactory() {

        final Map<Digest, ByteString> cache = new HashMap<>();

        public synchronized InputStream newInput(Digest blobDigest, long offset) {
            if (cache.containsKey(blobDigest)) {
                return cache.get(blobDigest).substring((int) offset).newInput();
            }
            try {
                ByteString value = getBlob(instance, blobDigest, RequestMetadata.getDefaultInstance());
                if (offset == 0) {
                    cache.put(blobDigest, value);
                }
                return value.newInput();
            } catch (IOException e) {
                return null;
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                return null;
            }
        }
    });
    // FIXME make bettar
    fuse.createInputRoot(args[5], DigestUtil.parseDigest(args[4]));
    try {
        // noinspection InfiniteLoopStatement
        for (; ; ) {
            Thread.sleep(1000);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } finally {
        fuse.stop();
    }
}
Also used : Path(java.nio.file.Path) StubInstance(build.buildfarm.instance.stub.StubInstance) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) FuseCAS(build.buildfarm.worker.FuseCAS) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) DigestUtil(build.buildfarm.common.DigestUtil) InputStreamFactory(build.buildfarm.common.InputStreamFactory) StubInstance(build.buildfarm.instance.stub.StubInstance) ManagedChannel(io.grpc.ManagedChannel)

Example 4 with Instance

use of build.buildfarm.instance.Instance in project bazel-buildfarm by bazelbuild.

the class UtilTest method correctMissingBlobChecksAllWorkers.

@Test
public void correctMissingBlobChecksAllWorkers() throws Exception {
    String worker1Name = "worker1";
    String worker2Name = "worker2";
    String worker3Name = "worker3";
    Set<String> workerSet = ImmutableSet.of(worker1Name, worker2Name, worker3Name);
    Digest digest = Digest.newBuilder().setHash("digest").setSizeBytes(1).build();
    ImmutableList<Digest> digests = ImmutableList.of(digest);
    Instance foundInstance = mock(Instance.class);
    when(foundInstance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of()));
    Instance missingInstance = mock(Instance.class);
    when(missingInstance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of(digest)));
    Backplane backplane = mock(Backplane.class);
    Function<String, Instance> workerInstanceFactory = worker -> {
        if (worker.equals(worker1Name)) {
            return missingInstance;
        }
        if (worker.equals(worker2Name) || worker.equals(worker3Name)) {
            return foundInstance;
        }
        return null;
    };
    ListenableFuture<Set<String>> correctFuture = correctMissingBlob(backplane, workerSet, /* originalLocationSet=*/
    ImmutableSet.of(), workerInstanceFactory, digest, directExecutor(), RequestMetadata.getDefaultInstance());
    assertThat(correctFuture.get()).isEqualTo(ImmutableSet.of(worker2Name, worker3Name));
    verify(foundInstance, times(2)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    verify(missingInstance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    verify(backplane, times(1)).adjustBlobLocations(eq(digest), eq(ImmutableSet.of(worker2Name, worker3Name)), eq(ImmutableSet.of()));
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RunWith(org.junit.runner.RunWith) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Util.correctMissingBlob(build.buildfarm.instance.shard.Util.correctMissingBlob) Function(java.util.function.Function) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) Code(io.grpc.Status.Code) ImmutableList(com.google.common.collect.ImmutableList) Digest(build.bazel.remote.execution.v2.Digest) Status(io.grpc.Status) Backplane(build.buildfarm.backplane.Backplane) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instance(build.buildfarm.instance.Instance) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Digest(build.bazel.remote.execution.v2.Digest) Instance(build.buildfarm.instance.Instance) Backplane(build.buildfarm.backplane.Backplane) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 5 with Instance

use of build.buildfarm.instance.Instance in project bazel-buildfarm by bazelbuild.

the class UtilTest method correctMissingBlobIgnoresBackplaneException.

@Test
public void correctMissingBlobIgnoresBackplaneException() throws Exception {
    String workerName = "worker";
    Set<String> workerSet = ImmutableSet.of(workerName);
    Digest digest = Digest.newBuilder().setHash("digest").setSizeBytes(1).build();
    ImmutableList<Digest> digests = ImmutableList.of(digest);
    Instance instance = mock(Instance.class);
    when(instance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFailedFuture(Status.UNKNOWN.asRuntimeException())).thenReturn(immediateFuture(ImmutableList.of()));
    Backplane backplane = mock(Backplane.class);
    doThrow(new IOException("failed to adjustBlobLocations")).when(backplane).adjustBlobLocations(eq(digest), eq(ImmutableSet.of(workerName)), eq(ImmutableSet.of()));
    Function<String, Instance> workerInstanceFactory = worker -> {
        if (worker.equals(workerName)) {
            return instance;
        }
        return null;
    };
    ListenableFuture<Set<String>> correctFuture = correctMissingBlob(backplane, workerSet, /* originalLocationSet=*/
    ImmutableSet.of(), workerInstanceFactory, digest, directExecutor(), RequestMetadata.getDefaultInstance());
    assertThat(correctFuture.get()).isEqualTo(ImmutableSet.of(workerName));
    verify(instance, times(2)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    verify(backplane, times(1)).adjustBlobLocations(eq(digest), eq(ImmutableSet.of(workerName)), eq(ImmutableSet.of()));
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RunWith(org.junit.runner.RunWith) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Util.correctMissingBlob(build.buildfarm.instance.shard.Util.correctMissingBlob) Function(java.util.function.Function) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) Code(io.grpc.Status.Code) ImmutableList(com.google.common.collect.ImmutableList) Digest(build.bazel.remote.execution.v2.Digest) Status(io.grpc.Status) Backplane(build.buildfarm.backplane.Backplane) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instance(build.buildfarm.instance.Instance) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Digest(build.bazel.remote.execution.v2.Digest) Instance(build.buildfarm.instance.Instance) Backplane(build.buildfarm.backplane.Backplane) IOException(java.io.IOException) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Aggregations

Instance (build.buildfarm.instance.Instance)32 Test (org.junit.Test)19 Digest (build.bazel.remote.execution.v2.Digest)13 DigestUtil (build.buildfarm.common.DigestUtil)12 IOException (java.io.IOException)12 Status (io.grpc.Status)11 StubInstance (build.buildfarm.instance.stub.StubInstance)9 ImmutableList (com.google.common.collect.ImmutableList)9 ByteString (com.google.protobuf.ByteString)9 RunWith (org.junit.runner.RunWith)8 JUnit4 (org.junit.runners.JUnit4)8 Mockito.mock (org.mockito.Mockito.mock)8 Mockito.times (org.mockito.Mockito.times)8 Mockito.verify (org.mockito.Mockito.verify)8 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)7 Mockito.any (org.mockito.Mockito.any)7 Mockito.eq (org.mockito.Mockito.eq)7 ActionResult (build.bazel.remote.execution.v2.ActionResult)6 ByteStreamImplBase (com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)6