use of com.facebook.buck.log.CommandThreadFactory in project buck by facebook.
the class AdbHelper method adbCall.
/**
* Execute an {@link AdbCallable} for all matching devices. This functions performs device
* filtering based on three possible arguments:
*
* -e (emulator-only) - only emulators are passing the filter
* -d (device-only) - only real devices are passing the filter
* -s (serial) - only device/emulator with specific serial number are passing the filter
*
* If more than one device matches the filter this function will fail unless multi-install
* mode is enabled (-x). This flag is used as a marker that user understands that multiple
* devices will be used to install the apk if needed.
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
@SuppressForbidden
public boolean adbCall(AdbCallable adbCallable, boolean quiet) throws InterruptedException {
List<IDevice> devices;
try (SimplePerfEvent.Scope ignored = SimplePerfEvent.scope(buckEventBus, "set_up_adb_call")) {
devices = getDevices(quiet);
if (devices.size() == 0) {
return false;
}
}
int adbThreadCount = options.getAdbThreadCount();
if (adbThreadCount <= 0) {
adbThreadCount = devices.size();
}
// Start executions on all matching devices.
List<ListenableFuture<Boolean>> futures = Lists.newArrayList();
ListeningExecutorService executorService = listeningDecorator(newMultiThreadExecutor(new CommandThreadFactory(getClass().getSimpleName()), adbThreadCount));
for (final IDevice device : devices) {
futures.add(executorService.submit(adbCallable.forDevice(device)));
}
// Wait for all executions to complete or fail.
List<Boolean> results = null;
try {
results = Futures.allAsList(futures).get();
} catch (ExecutionException ex) {
console.printBuildFailure("Failed: " + adbCallable);
ex.printStackTrace(console.getStdErr());
return false;
} catch (InterruptedException e) {
try {
Futures.allAsList(futures).cancel(true);
} catch (CancellationException ignored) {
// Rethrow original InterruptedException instead.
}
Thread.currentThread().interrupt();
throw e;
} finally {
MostExecutors.shutdownOrThrow(executorService, 10, TimeUnit.MINUTES, new InterruptionFailedException("Failed to shutdown ExecutorService."));
}
int successCount = 0;
for (Boolean result : results) {
if (result) {
successCount++;
}
}
int failureCount = results.size() - successCount;
// Report results.
if (successCount > 0 && !quiet) {
console.printSuccess(String.format("Successfully ran %s on %d device(s)", adbCallable, successCount));
}
if (failureCount > 0) {
console.printBuildFailure(String.format("Failed to %s on %d device(s).", adbCallable, failureCount));
}
return failureCount == 0;
}
use of com.facebook.buck.log.CommandThreadFactory 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.log.CommandThreadFactory in project buck by facebook.
the class ArtifactCaches method createHttpArtifactCache.
private static ArtifactCache createHttpArtifactCache(HttpCacheEntry cacheDescription, final String hostToReportToRemote, final BuckEventBus buckEventBus, ProjectFilesystem projectFilesystem, ListeningExecutorService httpWriteExecutorService, ArtifactCacheBuckConfig config, NetworkCacheFactory factory, boolean distributedBuildModeEnabled) {
// Setup the default client to use.
OkHttpClient.Builder storeClientBuilder = new OkHttpClient.Builder();
storeClientBuilder.networkInterceptors().add(chain -> chain.proceed(chain.request().newBuilder().addHeader("X-BuckCache-User", stripNonAscii(System.getProperty("user.name", "<unknown>"))).addHeader("X-BuckCache-Host", stripNonAscii(hostToReportToRemote)).build()));
int timeoutSeconds = cacheDescription.getTimeoutSeconds();
setTimeouts(storeClientBuilder, timeoutSeconds);
storeClientBuilder.connectionPool(new ConnectionPool(/* maxIdleConnections */
(int) config.getThreadPoolSize(), /* keepAliveDurationMs */
config.getThreadPoolKeepAliveDurationMillis(), TimeUnit.MILLISECONDS));
// The artifact cache effectively only connects to a single host at a time. We should allow as
// many concurrent connections to that host as we allow threads.
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequestsPerHost((int) config.getThreadPoolSize());
storeClientBuilder.dispatcher(dispatcher);
final ImmutableMap<String, String> readHeaders = cacheDescription.getReadHeaders();
final ImmutableMap<String, String> writeHeaders = cacheDescription.getWriteHeaders();
// If write headers are specified, add them to every default client request.
if (!writeHeaders.isEmpty()) {
storeClientBuilder.networkInterceptors().add(chain -> chain.proceed(addHeadersToBuilder(chain.request().newBuilder(), writeHeaders).build()));
}
OkHttpClient storeClient = storeClientBuilder.build();
// For fetches, use a client with a read timeout.
OkHttpClient.Builder fetchClientBuilder = storeClient.newBuilder();
setTimeouts(fetchClientBuilder, timeoutSeconds);
// If read headers are specified, add them to every read client request.
if (!readHeaders.isEmpty()) {
fetchClientBuilder.networkInterceptors().add(chain -> chain.proceed(addHeadersToBuilder(chain.request().newBuilder(), readHeaders).build()));
}
fetchClientBuilder.networkInterceptors().add((chain -> {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder().body(new ProgressResponseBody(originalResponse.body(), buckEventBus)).build();
}));
OkHttpClient fetchClient = fetchClientBuilder.build();
HttpService fetchService;
HttpService storeService;
switch(config.getLoadBalancingType()) {
case CLIENT_SLB:
HttpLoadBalancer clientSideSlb = config.getSlbConfig().createClientSideSlb(new DefaultClock(), buckEventBus, new CommandThreadFactory("ArtifactCaches.HttpLoadBalancer", SLB_THREAD_PRIORITY));
fetchService = new RetryingHttpService(buckEventBus, new LoadBalancedService(clientSideSlb, fetchClient, buckEventBus), config.getMaxFetchRetries());
storeService = new LoadBalancedService(clientSideSlb, storeClient, buckEventBus);
break;
case SINGLE_SERVER:
URI url = cacheDescription.getUrl();
fetchService = new SingleUriService(url, fetchClient);
storeService = new SingleUriService(url, storeClient);
break;
default:
throw new IllegalArgumentException("Unknown HttpLoadBalancer type: " + config.getLoadBalancingType());
}
String cacheName = cacheDescription.getName().map(input -> "http-" + input).orElse("http");
boolean doStore = cacheDescription.getCacheReadMode().isDoStore();
return factory.newInstance(NetworkCacheArgs.builder().setThriftEndpointPath(config.getHybridThriftEndpoint()).setCacheName(cacheName).setRepository(config.getRepository()).setScheduleType(config.getScheduleType()).setFetchClient(fetchService).setStoreClient(storeService).setDoStore(doStore).setProjectFilesystem(projectFilesystem).setBuckEventBus(buckEventBus).setHttpWriteExecutorService(httpWriteExecutorService).setErrorTextTemplate(cacheDescription.getErrorMessageFormat()).setDistributedBuildModeEnabled(distributedBuildModeEnabled).build());
}
use of com.facebook.buck.log.CommandThreadFactory 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();
}
use of com.facebook.buck.log.CommandThreadFactory in project buck by facebook.
the class RageConfigTest method setUp.
@BeforeClass
public static void setUp() {
clock = new DefaultClock();
eventBus = BuckEventBusFactory.newInstance(clock);
threadFactory = new CommandThreadFactory("RageConfigTest.Unused");
}
Aggregations