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());
}
});
}
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;
}
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());
}
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;
}
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;
}
Aggregations