Search in sources :

Example 1 with FrontendResponse

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

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

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

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

the class DistBuildService method makeRequestChecked.

private FrontendResponse makeRequestChecked(FrontendRequest request) throws IOException {
    FrontendResponse response = service.makeRequest(request);
    Preconditions.checkState(response.isSetWasSuccessful());
    if (!response.wasSuccessful) {
        throw new IOException(String.format("Stampede request of type [%s] failed with error message [%s].", request.getType().toString(), response.getErrorMessage()));
    }
    Preconditions.checkState(request.getType().equals(response.getType()));
    return response;
}
Also used : FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) IOException(java.io.IOException)

Example 5 with FrontendResponse

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

the class FrontendService method makeRequest.

public FrontendResponse makeRequest(FrontendRequest request) throws IOException {
    FrontendResponse response = new FrontendResponse();
    makeRequest(request, response);
    return response;
}
Also used : FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse)

Aggregations

FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)20 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)18 Test (org.junit.Test)8 BuildJob (com.facebook.buck.distributed.thrift.BuildJob)5 IOException (java.io.IOException)5 StampedeId (com.facebook.buck.distributed.thrift.StampedeId)4 Announcement (com.facebook.buck.distributed.thrift.Announcement)2 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)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 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)1 BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)1 BuildJobStateTargetGraph (com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph)1 BuildJobStateTargetNode (com.facebook.buck.distributed.thrift.BuildJobStateTargetNode)1