Search in sources :

Example 31 with Digest

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));
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) Command(build.bazel.remote.execution.v2.Command) ExecutedActionMetadata(build.bazel.remote.execution.v2.ExecutedActionMetadata) QueuedOperation(build.buildfarm.v1test.QueuedOperation) IOException(java.io.IOException) Directory(build.bazel.remote.execution.v2.Directory)

Example 32 with Digest

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;
}
Also used : Digest(build.bazel.remote.execution.v2.Digest)

Example 33 with Digest

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();
    }
}
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 34 with Digest

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);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest)

Example 35 with Digest

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);
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) Utils.getInterruptiblyOrIOException(build.buildfarm.common.io.Utils.getInterruptiblyOrIOException) IOException(java.io.IOException)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)191 ByteString (com.google.protobuf.ByteString)110 Test (org.junit.Test)99 IOException (java.io.IOException)55 Directory (build.bazel.remote.execution.v2.Directory)42 ImmutableList (com.google.common.collect.ImmutableList)35 Path (java.nio.file.Path)33 Status (io.grpc.Status)30 ExecutionException (java.util.concurrent.ExecutionException)29 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)27 InputStream (java.io.InputStream)25 Instance (build.buildfarm.instance.Instance)24 Action (build.bazel.remote.execution.v2.Action)22 DigestUtil (build.buildfarm.common.DigestUtil)22 OutputStream (java.io.OutputStream)22 Write (build.buildfarm.common.Write)21 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)21 Operation (com.google.longrunning.Operation)21 UUID (java.util.UUID)20 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)19