use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class InputFetcher method fetchPolled.
private long fetchPolled(Stopwatch stopwatch) throws InterruptedException {
String operationName = operationContext.queueEntry.getExecuteEntry().getOperationName();
logger.log(Level.FINE, format("fetching inputs: %s", operationName));
ExecutedActionMetadata.Builder executedAction = operationContext.executeResponse.getResultBuilder().getExecutionMetadataBuilder().setInputFetchStartTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
final Map<Digest, Directory> directoriesIndex;
QueuedOperation queuedOperation;
Path execDir;
try {
queuedOperation = workerContext.getQueuedOperation(operationContext.queueEntry);
if (queuedOperation == null || !isQueuedOperationValid(queuedOperation)) {
if (queuedOperation != null) {
logger.log(Level.SEVERE, format("invalid queued operation: %s", operationName));
}
owner.error().put(operationContext);
return 0;
}
if (queuedOperation.hasTree()) {
directoriesIndex = DigestUtil.proxyDirectoriesIndex(queuedOperation.getTree().getDirectoriesMap());
} else {
// TODO remove legacy interpretation and field after transition
directoriesIndex = workerContext.getDigestUtil().createDirectoriesIndex(queuedOperation.getLegacyTree());
}
execDir = workerContext.createExecDir(operationName, directoriesIndex, queuedOperation.getAction(), queuedOperation.getCommand());
} catch (IOException e) {
logger.log(Level.SEVERE, format("error creating exec dir for %s", operationName), e);
owner.error().put(operationContext);
return 0;
}
success = true;
/* tweak command executable used */
String programName = queuedOperation.getCommand().getArguments(0);
Directory root = directoriesIndex.get(queuedOperation.getTree().getRootDigest());
Command command = queuedOperation.getCommand().toBuilder().clearArguments().addArguments(getExecutablePath(programName, root, directoriesIndex)).addAllArguments(Iterables.skip(queuedOperation.getCommand().getArgumentsList(), 1)).build();
executedAction.setInputFetchCompletedTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
// we are now responsible for destroying the exec dir if anything goes wrong
boolean completed = false;
try {
long fetchUSecs = stopwatch.elapsed(MICROSECONDS);
proceedToOutput(queuedOperation.getAction(), command, execDir);
completed = true;
return stopwatch.elapsed(MICROSECONDS) - fetchUSecs;
} finally {
if (!completed) {
try {
workerContext.destroyExecDir(execDir);
} catch (IOException e) {
logger.log(Level.SEVERE, format("error deleting exec dir for %s after interrupt", operationName));
}
}
}
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class InputFetcher method getExecutablePath.
static String getExecutablePath(String programPath, Directory root, Map<Digest, Directory> directoriesIndex) {
if (!programPath.startsWith(BAZEL_HOST_BIN_PREFIX)) {
return programPath;
}
Digest programDigest = pathDigest(programPath, root, directoriesIndex);
if (programDigest == null) {
return programPath;
}
String runfilesProgramPath = programPath + BAZEL_RUNFILES_SUFFIX + programPath.substring(BAZEL_HOST_BIN_PREFIX.length());
Digest runfilesProgramDigest = pathDigest(runfilesProgramPath, root, directoriesIndex);
if (runfilesProgramDigest == null) {
return programPath;
}
if (!programDigest.equals(runfilesProgramDigest)) {
return programPath;
}
return runfilesProgramPath;
}
use of com.google.cloud.kms.v1.Digest 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 com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class UploadManifest method addFile.
private void addFile(Path file) throws IOException {
Digest digest = digestUtil.compute(file);
result.addOutputFilesBuilder().setPath(execRoot.relativize(file).toString()).setIsExecutable(Files.isExecutable(file)).setDigest(digest);
digestToFile.put(digest, file);
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class CFCExecFileSystem method put.
@SuppressWarnings("ConstantConditions")
private ListenableFuture<Void> put(Path path, FileNode fileNode, ImmutableList.Builder<String> inputFiles) {
Path filePath = path.resolve(fileNode.getName());
Digest digest = fileNode.getDigest();
if (digest.getSizeBytes() == 0) {
return listeningDecorator(fetchService).submit(() -> {
Files.createFile(filePath);
// ignore executable
return null;
});
}
String key = fileCache.getKey(digest, fileNode.getIsExecutable());
return transformAsync(fileCache.put(digest, fileNode.getIsExecutable(), fetchService), (fileCachePath) -> {
checkNotNull(key);
// we saw null entries in the built immutable list without synchronization
synchronized (inputFiles) {
inputFiles.add(key);
}
if (fileNode.getDigest().getSizeBytes() != 0) {
try {
Files.createLink(filePath, fileCachePath);
} catch (IOException e) {
return immediateFailedFuture(e);
}
}
return immediateFuture(null);
}, fetchService);
}
Aggregations