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