Search in sources :

Example 1 with FrontendRequest

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

the class PublicAnnouncementManager method getAndPostAnnouncements.

public void getAndPostAnnouncements() {
    final ListenableFuture<ImmutableList<Announcement>> message = service.submit(() -> {
        Optional<ClientSideSlb> slb = logConfig.getFrontendConfig().tryCreatingClientSideSlb(clock, eventBus, new CommandThreadFactory("PublicAnnouncement"));
        if (slb.isPresent()) {
            try (FrontendService frontendService = new FrontendService(ThriftOverHttpServiceConfig.of(new LoadBalancedService(slb.get(), logConfig.createOkHttpClient(), eventBus)))) {
                AnnouncementRequest announcementRequest = new AnnouncementRequest();
                announcementRequest.setBuckVersion(getBuckVersion());
                announcementRequest.setRepository(repository);
                FrontendRequest request = new FrontendRequest();
                request.setType(FrontendRequestType.ANNOUNCEMENT);
                request.setAnnouncementRequest(announcementRequest);
                FrontendResponse response = frontendService.makeRequest(request);
                return ImmutableList.copyOf(response.announcementResponse.announcements);
            } catch (IOException e) {
                throw new HumanReadableException("Failed to perform request", e);
            }
        } else {
            throw new HumanReadableException("Failed to establish connection to server.");
        }
    });
    Futures.addCallback(message, new FutureCallback<ImmutableList<Announcement>>() {

        @Override
        public void onSuccess(ImmutableList<Announcement> announcements) {
            LOG.info("Public announcements fetched successfully.");
            if (!announcements.isEmpty()) {
                String announcement = HEADER_MSG;
                for (Announcement entry : announcements) {
                    announcement = announcement.concat(String.format(ANNOUNCEMENT_TEMPLATE, entry.getErrorMessage(), entry.getSolutionMessage()));
                }
                consoleEventBusListener.setPublicAnnouncements(eventBus, Optional.of(announcement));
            }
        }

        @Override
        public void onFailure(Throwable t) {
            LOG.warn("Failed to get public announcements. Reason: %s", t.getMessage());
        }
    });
}
Also used : Announcement(com.facebook.buck.distributed.thrift.Announcement) ImmutableList(com.google.common.collect.ImmutableList) CommandThreadFactory(com.facebook.buck.log.CommandThreadFactory) IOException(java.io.IOException) ClientSideSlb(com.facebook.buck.slb.ClientSideSlb) HumanReadableException(com.facebook.buck.util.HumanReadableException) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendService(com.facebook.buck.distributed.FrontendService) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) LoadBalancedService(com.facebook.buck.slb.LoadBalancedService) AnnouncementRequest(com.facebook.buck.distributed.thrift.AnnouncementRequest)

Example 2 with FrontendRequest

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

the class DistBuildService method startBuild.

public BuildJob startBuild(StampedeId id) throws IOException {
    // Start the build
    StartBuildRequest startRequest = new StartBuildRequest();
    startRequest.setStampedeId(id);
    FrontendRequest request = new FrontendRequest();
    request.setType(FrontendRequestType.START_BUILD);
    request.setStartBuildRequest(startRequest);
    FrontendResponse response = makeRequestChecked(request);
    BuildJob job = response.getStartBuildResponse().getBuildJob();
    Preconditions.checkState(job.getStampedeId().equals(id));
    return job;
}
Also used : FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) BuildJob(com.facebook.buck.distributed.thrift.BuildJob) StartBuildRequest(com.facebook.buck.distributed.thrift.StartBuildRequest)

Example 3 with FrontendRequest

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

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

the class DistBuildService method createFrontendBuildStatusRequest.

public static FrontendRequest createFrontendBuildStatusRequest(StampedeId stampedeId) {
    BuildStatusRequest buildStatusRequest = new BuildStatusRequest();
    buildStatusRequest.setStampedeId(stampedeId);
    FrontendRequest frontendRequest = new FrontendRequest();
    frontendRequest.setType(FrontendRequestType.BUILD_STATUS);
    frontendRequest.setBuildStatusRequest(buildStatusRequest);
    return frontendRequest;
}
Also used : FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) BuildStatusRequest(com.facebook.buck.distributed.thrift.BuildStatusRequest)

Example 5 with FrontendRequest

use of com.facebook.buck.distributed.thrift.FrontendRequest 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)

Aggregations

FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)25 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)18 Test (org.junit.Test)9 BuildJob (com.facebook.buck.distributed.thrift.BuildJob)5 StampedeId (com.facebook.buck.distributed.thrift.StampedeId)5 IOException (java.io.IOException)4 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)3 Announcement (com.facebook.buck.distributed.thrift.Announcement)2 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)2 BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)2 BuildStatusRequest (com.facebook.buck.distributed.thrift.BuildStatusRequest)2 FileInfo (com.facebook.buck.distributed.thrift.FileInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 FrontendService (com.facebook.buck.distributed.FrontendService)1 AnnouncementRequest (com.facebook.buck.distributed.thrift.AnnouncementRequest)1 AnnouncementResponse (com.facebook.buck.distributed.thrift.AnnouncementResponse)1 BuildJobStateTargetGraph (com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph)1