Search in sources :

Example 1 with FileInfo

use of com.facebook.buck.distributed.thrift.FileInfo in project buck by facebook.

the class BuckVersionUtil method createFromLocalBinary.

public static BuckVersion createFromLocalBinary(Path localBuckBinary) throws IOException {
    byte[] data = Files.readAllBytes(localBuckBinary);
    String hash = Hashing.sha1().newHasher().putBytes(data).hash().toString();
    FileInfo buckBinary = new FileInfo();
    buckBinary.setContent(data);
    buckBinary.setContentHash(hash);
    BuckVersion buckVersion = new BuckVersion();
    buckVersion.setType(BuckVersionType.DEVELOPMENT);
    buckVersion.setDevelopmentVersion(buckBinary);
    return buckVersion;
}
Also used : FileInfo(com.facebook.buck.distributed.thrift.FileInfo) BuckVersion(com.facebook.buck.distributed.thrift.BuckVersion)

Example 2 with FileInfo

use of com.facebook.buck.distributed.thrift.FileInfo in project buck by facebook.

the class DistBuildService method uploadBuckDotFiles.

public ListenableFuture<Void> uploadBuckDotFiles(final StampedeId id, final ProjectFilesystem filesystem, FileHashCache fileHashCache, ListeningExecutorService executorService) throws IOException {
    ListenableFuture<Pair<List<FileInfo>, List<PathInfo>>> filesFuture = executorService.submit(() -> {
        List<Path> buckDotFilesExceptConfig = Lists.newArrayList();
        for (Path path : filesystem.getDirectoryContents(filesystem.getRootPath())) {
            String fileName = path.getFileName().toString();
            if (!filesystem.isDirectory(path) && !filesystem.isSymLink(path) && fileName.startsWith(".") && fileName.contains("buck") && !fileName.startsWith(".buckconfig")) {
                buckDotFilesExceptConfig.add(path);
            }
        }
        List<FileInfo> fileEntriesToUpload = new LinkedList<>();
        List<PathInfo> pathEntriesToUpload = new LinkedList<>();
        for (Path path : buckDotFilesExceptConfig) {
            FileInfo fileInfoObject = new FileInfo();
            fileInfoObject.setContent(filesystem.readFileIfItExists(path).get().getBytes());
            fileInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
            fileEntriesToUpload.add(fileInfoObject);
            PathInfo pathInfoObject = new PathInfo();
            pathInfoObject.setPath(path.toString());
            pathInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
            pathEntriesToUpload.add(pathInfoObject);
        }
        return new Pair<>(fileEntriesToUpload, pathEntriesToUpload);
    });
    ListenableFuture<Void> setFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
        setBuckDotFiles(id, filesAndPaths.getSecond());
        return Futures.immediateFuture(null);
    }, executorService);
    ListenableFuture<Void> uploadFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
        uploadMissingFilesFromList(filesAndPaths.getFirst(), executorService);
        return Futures.immediateFuture(null);
    }, executorService);
    return Futures.transform(Futures.allAsList(ImmutableList.of(setFilesFuture, uploadFilesFuture)), new Function<List<Void>, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable List<Void> input) {
            return null;
        }
    });
}
Also used : Path(java.nio.file.Path) LinkedList(java.util.LinkedList) FileInfo(com.facebook.buck.distributed.thrift.FileInfo) PathInfo(com.facebook.buck.distributed.thrift.PathInfo) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) Nullable(javax.annotation.Nullable) Pair(com.facebook.buck.model.Pair)

Example 3 with FileInfo

use of com.facebook.buck.distributed.thrift.FileInfo in project buck by facebook.

the class DistBuildService method fetchSourceFile.

public InputStream fetchSourceFile(String hashCode) throws IOException {
    FrontendRequest request = createFetchSourceFileRequest(hashCode);
    FrontendResponse response = makeRequestChecked(request);
    Preconditions.checkState(response.isSetFetchSourceFilesResponse());
    Preconditions.checkState(response.getFetchSourceFilesResponse().isSetFiles());
    FetchSourceFilesResponse fetchSourceFilesResponse = response.getFetchSourceFilesResponse();
    Preconditions.checkState(1 == fetchSourceFilesResponse.getFilesSize());
    FileInfo file = fetchSourceFilesResponse.getFiles().get(0);
    Preconditions.checkState(file.isSetContent());
    return new ByteArrayInputStream(file.getContent());
}
Also used : FetchSourceFilesResponse(com.facebook.buck.distributed.thrift.FetchSourceFilesResponse) FileInfo(com.facebook.buck.distributed.thrift.FileInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest)

Example 4 with FileInfo

use of com.facebook.buck.distributed.thrift.FileInfo in project buck by facebook.

the class DistBuildService method uploadMissingFiles.

public ListenableFuture<Void> uploadMissingFiles(final List<BuildJobStateFileHashes> fileHashes, ListeningExecutorService executorService) {
    List<FileInfo> requiredFiles = new ArrayList<>();
    for (BuildJobStateFileHashes filesystem : fileHashes) {
        if (!filesystem.isSetEntries()) {
            continue;
        }
        for (BuildJobStateFileHashEntry file : filesystem.entries) {
            if (file.isSetRootSymLink()) {
                LOG.info("File with path [%s] is a symlink. Skipping upload..", file.path.getPath());
                continue;
            } else if (file.isIsDirectory()) {
                LOG.info("Path [%s] is a directory. Skipping upload..", file.path.getPath());
                continue;
            } else if (file.isPathIsAbsolute()) {
                LOG.info("Path [%s] is absolute. Skipping upload..", file.path.getPath());
                continue;
            }
            // TODO(shivanker): Eventually, we won't have file contents in BuildJobState.
            // Then change this code to load file contents inline (only for missing files)
            FileInfo fileInfo = new FileInfo();
            fileInfo.setContent(file.getContents());
            fileInfo.setContentHash(file.getHashCode());
            requiredFiles.add(fileInfo);
        }
    }
    return uploadMissingFilesFromList(requiredFiles, executorService);
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) FileInfo(com.facebook.buck.distributed.thrift.FileInfo) ArrayList(java.util.ArrayList)

Example 5 with FileInfo

use of com.facebook.buck.distributed.thrift.FileInfo in project buck by facebook.

the class DistBuildService method uploadMissingFilesFromList.

private ListenableFuture<Void> uploadMissingFilesFromList(final List<FileInfo> fileList, ListeningExecutorService executorService) {
    return executorService.submit(() -> {
        Map<String, FileInfo> sha1ToFileInfo = new HashMap<>();
        for (FileInfo file : fileList) {
            sha1ToFileInfo.put(file.getContentHash(), file);
        }
        List<String> contentHashes = ImmutableList.copyOf(sha1ToFileInfo.keySet());
        CASContainsRequest containsReq = new CASContainsRequest();
        containsReq.setContentSha1s(contentHashes);
        FrontendRequest request = new FrontendRequest();
        request.setType(FrontendRequestType.CAS_CONTAINS);
        request.setCasContainsRequest(containsReq);
        FrontendResponse response = makeRequestChecked(request);
        Preconditions.checkState(response.getCasContainsResponse().exists.size() == contentHashes.size());
        List<Boolean> isPresent = response.getCasContainsResponse().exists;
        List<FileInfo> filesToBeUploaded = new LinkedList<>();
        for (int i = 0; i < isPresent.size(); ++i) {
            if (isPresent.get(i)) {
                continue;
            }
            filesToBeUploaded.add(sha1ToFileInfo.get(contentHashes.get(i)));
        }
        LOG.info("%d out of %d files already exist in the cache. Uploading %d files..", sha1ToFileInfo.size() - filesToBeUploaded.size(), sha1ToFileInfo.size(), filesToBeUploaded.size());
        request = new FrontendRequest();
        StoreLocalChangesRequest storeReq = new StoreLocalChangesRequest();
        storeReq.setFiles(filesToBeUploaded);
        request.setType(FrontendRequestType.STORE_LOCAL_CHANGES);
        request.setStoreLocalChangesRequest(storeReq);
        makeRequestChecked(request);
        // No response expected.
        return null;
    });
}
Also used : CASContainsRequest(com.facebook.buck.distributed.thrift.CASContainsRequest) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) FileInfo(com.facebook.buck.distributed.thrift.FileInfo) StoreLocalChangesRequest(com.facebook.buck.distributed.thrift.StoreLocalChangesRequest) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest)

Aggregations

FileInfo (com.facebook.buck.distributed.thrift.FileInfo)5 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)2 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 BuckVersion (com.facebook.buck.distributed.thrift.BuckVersion)1 BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)1 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)1 CASContainsRequest (com.facebook.buck.distributed.thrift.CASContainsRequest)1 FetchSourceFilesResponse (com.facebook.buck.distributed.thrift.FetchSourceFilesResponse)1 PathInfo (com.facebook.buck.distributed.thrift.PathInfo)1 StoreLocalChangesRequest (com.facebook.buck.distributed.thrift.StoreLocalChangesRequest)1 Pair (com.facebook.buck.model.Pair)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1