Search in sources :

Example 1 with ClientSideSlb

use of com.facebook.buck.slb.ClientSideSlb 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 ClientSideSlb

use of com.facebook.buck.slb.ClientSideSlb in project buck by facebook.

the class DefaultDefectReporter method submitReport.

@Override
public DefectSubmitResult submitReport(DefectReport defectReport) throws IOException {
    DefectSubmitResult.Builder defectSubmitResult = DefectSubmitResult.builder();
    defectSubmitResult.setRequestProtocol(rageConfig.getProtocolVersion());
    Optional<SlbBuckConfig> frontendConfig = rageConfig.getFrontendConfig();
    if (frontendConfig.isPresent()) {
        Optional<ClientSideSlb> slb = frontendConfig.get().tryCreatingClientSideSlb(clock, buckEventBus, new CommandThreadFactory("RemoteLog.HttpLoadBalancer"));
        if (slb.isPresent()) {
            try {
                return uploadReport(defectReport, defectSubmitResult, slb.get());
            } catch (IOException e) {
                LOG.debug(e, "Failed uploading report to server.");
                defectSubmitResult.setIsRequestSuccessful(false);
                defectSubmitResult.setReportSubmitErrorMessage(e.getMessage());
            }
        }
    }
    filesystem.mkdirs(filesystem.getBuckPaths().getBuckOut());
    Path defectReportPath = filesystem.createTempFile(filesystem.getBuckPaths().getBuckOut(), "defect_report", ".zip");
    try (OutputStream outputStream = filesystem.newFileOutputStream(defectReportPath)) {
        writeReport(defectReport, outputStream);
    }
    return defectSubmitResult.setIsRequestSuccessful(Optional.empty()).setReportSubmitLocation(defectReportPath.toString()).build();
}
Also used : Path(java.nio.file.Path) ClientSideSlb(com.facebook.buck.slb.ClientSideSlb) SlbBuckConfig(com.facebook.buck.slb.SlbBuckConfig) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) CommandThreadFactory(com.facebook.buck.log.CommandThreadFactory) IOException(java.io.IOException)

Example 3 with ClientSideSlb

use of com.facebook.buck.slb.ClientSideSlb in project buck by facebook.

the class DistBuildFactory method newFrontendService.

public static FrontendService newFrontendService(CommandRunnerParams params) {
    DistBuildConfig config = new DistBuildConfig(params.getBuckConfig());
    ClientSideSlb slb = config.getFrontendConfig().createClientSideSlb(params.getClock(), params.getBuckEventBus(), new CommandThreadFactory("StampedeNetworkThreadPool", SLB_THREAD_PRIORITY));
    OkHttpClient client = config.createOkHttpClient();
    return new FrontendService(ThriftOverHttpServiceConfig.of(new LoadBalancedService(slb, client, params.getBuckEventBus())));
}
Also used : ClientSideSlb(com.facebook.buck.slb.ClientSideSlb) OkHttpClient(okhttp3.OkHttpClient) CommandThreadFactory(com.facebook.buck.log.CommandThreadFactory) FrontendService(com.facebook.buck.distributed.FrontendService) LoadBalancedService(com.facebook.buck.slb.LoadBalancedService) DistBuildConfig(com.facebook.buck.distributed.DistBuildConfig)

Aggregations

CommandThreadFactory (com.facebook.buck.log.CommandThreadFactory)3 ClientSideSlb (com.facebook.buck.slb.ClientSideSlb)3 FrontendService (com.facebook.buck.distributed.FrontendService)2 LoadBalancedService (com.facebook.buck.slb.LoadBalancedService)2 IOException (java.io.IOException)2 DistBuildConfig (com.facebook.buck.distributed.DistBuildConfig)1 Announcement (com.facebook.buck.distributed.thrift.Announcement)1 AnnouncementRequest (com.facebook.buck.distributed.thrift.AnnouncementRequest)1 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)1 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)1 SlbBuckConfig (com.facebook.buck.slb.SlbBuckConfig)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 CustomZipOutputStream (com.facebook.buck.zip.CustomZipOutputStream)1 ImmutableList (com.google.common.collect.ImmutableList)1 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 OkHttpClient (okhttp3.OkHttpClient)1