use of build.buildfarm.worker.FuseCAS 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.worker.FuseCAS in project bazel-buildfarm by bazelbuild.
the class Worker method createFuseExecFileSystem.
private ExecFileSystem createFuseExecFileSystem(InputStreamFactory remoteInputStreamFactory, ContentAddressableStorage storage) {
InputStreamFactory storageInputStreamFactory = (digest, offset) -> storage.get(digest).getData().substring((int) offset).newInput();
InputStreamFactory localPopulatingInputStreamFactory = (blobDigest, offset) -> {
// FIXME use write
ByteString content = ByteString.readFrom(remoteInputStreamFactory.newInput(blobDigest, offset));
if (offset == 0) {
// extra computations
Blob blob = new Blob(content, digestUtil);
// here's hoping that our digest matches...
storage.put(blob);
}
return content.newInput();
};
return new FuseExecFileSystem(root, new FuseCAS(root, new EmptyInputStreamFactory(new FailoverInputStreamFactory(storageInputStreamFactory, localPopulatingInputStreamFactory))), storage);
}
Aggregations