Search in sources :

Example 1 with BuildJobStateFileHashEntry

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry 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 2 with BuildJobStateFileHashEntry

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

the class DistBuildFileHashesTest method recordsFileHashes.

@Test
public void recordsFileHashes() throws Exception {
    SingleFileFixture f = new SingleFileFixture(tempDir);
    List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
    assertThat(recordedHashes, Matchers.hasSize(3));
    BuildJobStateFileHashes rootCellHashes = getRootCellHashes(recordedHashes);
    assertThat(rootCellHashes.entries, Matchers.hasSize(1));
    BuildJobStateFileHashEntry fileHashEntry = rootCellHashes.entries.get(0);
    // It's intentional that we hardcode the path as a string here as we expect the thrift data
    // to contain unix-formated paths.
    assertThat(fileHashEntry.getPath().getPath(), Matchers.equalTo("src/A.java"));
    assertFalse(fileHashEntry.isPathIsAbsolute());
    assertFalse(fileHashEntry.isIsDirectory());
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) Test(org.junit.Test)

Example 3 with BuildJobStateFileHashEntry

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

the class DistBuildServiceTest method canUploadFiles.

@Test
public void canUploadFiles() throws Exception {
    final List<Boolean> fileExistence = Arrays.asList(true, false, true);
    Capture<FrontendRequest> containsRequest = EasyMock.newCapture();
    FrontendResponse containsResponse = new FrontendResponse();
    containsResponse.setType(FrontendRequestType.CAS_CONTAINS);
    CASContainsResponse casContainsResponse = new CASContainsResponse();
    casContainsResponse.setExists(fileExistence);
    containsResponse.setCasContainsResponse(casContainsResponse);
    containsResponse.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(containsRequest))).andReturn(containsResponse).once();
    Capture<FrontendRequest> storeRequest = EasyMock.newCapture();
    FrontendResponse storeResponse = new FrontendResponse();
    storeResponse.setType(FrontendRequestType.STORE_LOCAL_CHANGES);
    storeResponse.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(storeRequest))).andReturn(storeResponse).once();
    EasyMock.replay(frontendService);
    BuildJobStateFileHashEntry[] files = new BuildJobStateFileHashEntry[3];
    for (int i = 0; i < 3; i++) {
        files[i] = new BuildJobStateFileHashEntry();
        files[i].setHashCode(Integer.toString(i));
        files[i].setContents(("content" + Integer.toString(i)).getBytes());
        files[i].setPath(new PathWithUnixSeparators("/tmp/" + i));
    }
    List<BuildJobStateFileHashes> fileHashes = new ArrayList<>();
    fileHashes.add(new BuildJobStateFileHashes());
    fileHashes.get(0).setCellIndex(0);
    fileHashes.get(0).setEntries(new ArrayList<BuildJobStateFileHashEntry>());
    fileHashes.get(0).getEntries().add(files[0]);
    fileHashes.get(0).getEntries().add(files[1]);
    fileHashes.add(new BuildJobStateFileHashes());
    fileHashes.get(1).setCellIndex(1);
    fileHashes.get(1).setEntries(new ArrayList<BuildJobStateFileHashEntry>());
    fileHashes.get(1).getEntries().add(files[2]);
    distBuildService.uploadMissingFiles(fileHashes, executor).get();
    Assert.assertEquals(containsRequest.getValue().getType(), FrontendRequestType.CAS_CONTAINS);
    Assert.assertTrue(containsRequest.getValue().isSetCasContainsRequest());
    Assert.assertTrue(containsRequest.getValue().getCasContainsRequest().isSetContentSha1s());
    Assert.assertEquals(new HashSet<String>(containsRequest.getValue().getCasContainsRequest().getContentSha1s()), new HashSet<String>(Arrays.asList("0", "1", "2")));
    Assert.assertEquals(storeRequest.getValue().getType(), FrontendRequestType.STORE_LOCAL_CHANGES);
    Assert.assertTrue(storeRequest.getValue().isSetStoreLocalChangesRequest());
    Assert.assertTrue(storeRequest.getValue().getStoreLocalChangesRequest().isSetFiles());
    Assert.assertEquals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().size(), 1);
    Assert.assertEquals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().get(0).getContentHash(), "1");
    Assert.assertTrue(Arrays.equals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().get(0).getContent(), "content1".getBytes()));
}
Also used : ArrayList(java.util.ArrayList) PathWithUnixSeparators(com.facebook.buck.distributed.thrift.PathWithUnixSeparators) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) CASContainsResponse(com.facebook.buck.distributed.thrift.CASContainsResponse) Test(org.junit.Test)

Example 4 with BuildJobStateFileHashEntry

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

the class LocalFsContentsProviderTest method setUp.

@Before
public void setUp() {
    cacheRootDir = tempDir.getRoot().toPath();
    entry = new BuildJobStateFileHashEntry();
    entry.setHashCode("1237987abc");
    targetAbsPath = cacheRootDir.resolve("topspin.file.txt");
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) Before(org.junit.Before)

Example 5 with BuildJobStateFileHashEntry

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

the class DistBuildFileHashesTest method recordsArchiveHashes.

@Test
public void recordsArchiveHashes() throws Exception {
    try (ArchiveFilesFixture f = ArchiveFilesFixture.create(archiveTempDir)) {
        List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
        assertThat(recordedHashes, Matchers.hasSize(3));
        BuildJobStateFileHashes hashes = getRootCellHashes(recordedHashes);
        assertThat(hashes.entries, Matchers.hasSize(1));
        BuildJobStateFileHashEntry fileHashEntry = hashes.entries.get(0);
        assertThat(fileHashEntry.getPath().getPath(), Matchers.equalTo("src/archive.jar"));
        assertTrue(fileHashEntry.isSetArchiveMemberPath());
        assertThat(fileHashEntry.getArchiveMemberPath(), Matchers.equalTo("Archive.class"));
        assertFalse(fileHashEntry.isPathIsAbsolute());
        assertFalse(fileHashEntry.isIsDirectory());
    }
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) Test(org.junit.Test)

Aggregations

BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)17 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)11 Path (java.nio.file.Path)11 Test (org.junit.Test)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)5 ProjectFileHashCache (com.facebook.buck.util.cache.ProjectFileHashCache)3 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)2 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)2 PathWithUnixSeparators (com.facebook.buck.distributed.thrift.PathWithUnixSeparators)2 FakeProjectFileHashCache (com.facebook.buck.testutil.FakeProjectFileHashCache)2 ArrayList (java.util.ArrayList)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 CASContainsResponse (com.facebook.buck.distributed.thrift.CASContainsResponse)1 FileInfo (com.facebook.buck.distributed.thrift.FileInfo)1 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)1 StoreBuildGraphRequest (com.facebook.buck.distributed.thrift.StoreBuildGraphRequest)1 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)1 Parser (com.facebook.buck.parser.Parser)1