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();
}
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();
}
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();
}
}
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()));
}
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()));
}
Aggregations