15
15
16
16
import static com .google .common .util .concurrent .Futures .immediateFuture ;
17
17
import static com .google .common .util .concurrent .MoreExecutors .directExecutor ;
18
- import static com .google .devtools .build .lib .remote .common .ProgressStatusListener .NO_ACTION ;
19
- import static com .google .devtools .build .lib .remote .util .Utils .bytesCountToDisplayString ;
20
18
import static com .google .devtools .build .lib .remote .util .Utils .getFromFuture ;
21
19
22
20
import build .bazel .remote .execution .v2 .Action ;
52
50
import com .google .devtools .build .lib .actions .UserExecException ;
53
51
import com .google .devtools .build .lib .actions .cache .MetadataInjector ;
54
52
import com .google .devtools .build .lib .concurrent .ThreadSafety ;
55
- import com .google .devtools .build .lib .exec .SpawnProgressEvent ;
56
53
import com .google .devtools .build .lib .exec .SpawnRunner .SpawnExecutionContext ;
57
54
import com .google .devtools .build .lib .profiler .Profiler ;
58
55
import com .google .devtools .build .lib .profiler .SilentCloseable ;
61
58
import com .google .devtools .build .lib .remote .RemoteCache .ActionResultMetadata .SymlinkMetadata ;
62
59
import com .google .devtools .build .lib .remote .common .LazyFileOutputStream ;
63
60
import com .google .devtools .build .lib .remote .common .OutputDigestMismatchException ;
64
- import com .google .devtools .build .lib .remote .common .ProgressStatusListener ;
65
61
import com .google .devtools .build .lib .remote .common .RemoteActionExecutionContext ;
66
62
import com .google .devtools .build .lib .remote .common .RemoteActionFileArtifactValue ;
67
63
import com .google .devtools .build .lib .remote .common .RemoteCacheClient ;
95
91
import java .util .List ;
96
92
import java .util .Map ;
97
93
import java .util .Map .Entry ;
98
- import java .util .concurrent .atomic .AtomicLong ;
99
- import java .util .regex .Matcher ;
100
- import java .util .regex .Pattern ;
101
94
import java .util .stream .Collectors ;
102
95
import java .util .stream .Stream ;
103
96
import javax .annotation .Nullable ;
@@ -362,50 +355,6 @@ private static Path toTmpDownloadPath(Path actualPath) {
362
355
return actualPath .getParentDirectory ().getRelative (actualPath .getBaseName () + ".tmp" );
363
356
}
364
357
365
- static class DownloadProgressReporter {
366
- private static final Pattern PATTERN = Pattern .compile ("^bazel-out/[^/]+/[^/]+/" );
367
- private final ProgressStatusListener listener ;
368
- private final String id ;
369
- private final String file ;
370
- private final String totalSize ;
371
- private final AtomicLong downloadedBytes = new AtomicLong (0 );
372
-
373
- DownloadProgressReporter (ProgressStatusListener listener , String file , long totalSize ) {
374
- this .listener = listener ;
375
- this .id = file ;
376
- this .totalSize = bytesCountToDisplayString (totalSize );
377
-
378
- Matcher matcher = PATTERN .matcher (file );
379
- this .file = matcher .replaceFirst ("" );
380
- }
381
-
382
- void started () {
383
- reportProgress (false , false );
384
- }
385
-
386
- void downloadedBytes (int count ) {
387
- downloadedBytes .addAndGet (count );
388
- reportProgress (true , false );
389
- }
390
-
391
- void finished () {
392
- reportProgress (true , true );
393
- }
394
-
395
- private void reportProgress (boolean includeBytes , boolean finished ) {
396
- String progress ;
397
- if (includeBytes ) {
398
- progress =
399
- String .format (
400
- "Downloading %s, %s / %s" ,
401
- file , bytesCountToDisplayString (downloadedBytes .get ()), totalSize );
402
- } else {
403
- progress = String .format ("Downloading %s" , file );
404
- }
405
- listener .onProgressStatus (SpawnProgressEvent .create (id , progress , finished ));
406
- }
407
- }
408
-
409
358
/**
410
359
* Download the output files and directory trees of a remotely executed action to the local
411
360
* machine, as well stdin / stdout to the given files.
@@ -422,8 +371,7 @@ public void download(
422
371
RemotePathResolver remotePathResolver ,
423
372
ActionResult result ,
424
373
FileOutErr origOutErr ,
425
- OutputFilesLocker outputFilesLocker ,
426
- ProgressStatusListener progressStatusListener )
374
+ OutputFilesLocker outputFilesLocker )
427
375
throws ExecException , IOException , InterruptedException {
428
376
ActionResultMetadata metadata = parseActionResultMetadata (context , remotePathResolver , result );
429
377
@@ -440,11 +388,7 @@ public void download(
440
388
context ,
441
389
remotePathResolver .localPathToOutputPath (file .path ()),
442
390
toTmpDownloadPath (file .path ()),
443
- file .digest (),
444
- new DownloadProgressReporter (
445
- progressStatusListener ,
446
- remotePathResolver .localPathToOutputPath (file .path ()),
447
- file .digest ().getSizeBytes ()));
391
+ file .digest ());
448
392
return Futures .transform (download , (d ) -> file , directExecutor ());
449
393
} catch (IOException e ) {
450
394
return Futures .<FileMetadata >immediateFailedFuture (e );
@@ -596,14 +540,10 @@ private void createSymlinks(Iterable<SymlinkMetadata> symlinks) throws IOExcepti
596
540
}
597
541
598
542
public ListenableFuture <Void > downloadFile (
599
- RemoteActionExecutionContext context ,
600
- String outputPath ,
601
- Path localPath ,
602
- Digest digest ,
603
- DownloadProgressReporter reporter )
543
+ RemoteActionExecutionContext context , String outputPath , Path localPath , Digest digest )
604
544
throws IOException {
605
545
SettableFuture <Void > outerF = SettableFuture .create ();
606
- ListenableFuture <Void > f = downloadFile (context , localPath , digest , reporter );
546
+ ListenableFuture <Void > f = downloadFile (context , localPath , digest );
607
547
Futures .addCallback (
608
548
f ,
609
549
new FutureCallback <Void >() {
@@ -630,16 +570,6 @@ public void onFailure(Throwable throwable) {
630
570
/** Downloads a file (that is not a directory). The content is fetched from the digest. */
631
571
public ListenableFuture <Void > downloadFile (
632
572
RemoteActionExecutionContext context , Path path , Digest digest ) throws IOException {
633
- return downloadFile (context , path , digest , new DownloadProgressReporter (NO_ACTION , "" , 0 ));
634
- }
635
-
636
- /** Downloads a file (that is not a directory). The content is fetched from the digest. */
637
- public ListenableFuture <Void > downloadFile (
638
- RemoteActionExecutionContext context ,
639
- Path path ,
640
- Digest digest ,
641
- DownloadProgressReporter reporter )
642
- throws IOException {
643
573
Preconditions .checkNotNull (path .getParentDirectory ()).createDirectoryAndParents ();
644
574
if (digest .getSizeBytes () == 0 ) {
645
575
// Handle empty file locally.
@@ -660,9 +590,7 @@ public ListenableFuture<Void> downloadFile(
660
590
return COMPLETED_SUCCESS ;
661
591
}
662
592
663
- reporter .started ();
664
- OutputStream out = new ReportingOutputStream (new LazyFileOutputStream (path ), reporter );
665
-
593
+ OutputStream out = new LazyFileOutputStream (path );
666
594
SettableFuture <Void > outerF = SettableFuture .create ();
667
595
ListenableFuture <Void > f = cacheProtocol .downloadBlob (context , digest , out );
668
596
Futures .addCallback (
@@ -673,7 +601,6 @@ public void onSuccess(Void result) {
673
601
try {
674
602
out .close ();
675
603
outerF .set (null );
676
- reporter .finished ();
677
604
} catch (IOException e ) {
678
605
outerF .setException (e );
679
606
} catch (RuntimeException e ) {
@@ -686,7 +613,6 @@ public void onSuccess(Void result) {
686
613
public void onFailure (Throwable t ) {
687
614
try {
688
615
out .close ();
689
- reporter .finished ();
690
616
} catch (IOException e ) {
691
617
if (t != e ) {
692
618
t .addSuppressed (e );
@@ -1220,49 +1146,6 @@ private static FailureDetail createFailureDetail(String message, Code detailedCo
1220
1146
.build ();
1221
1147
}
1222
1148
1223
- /**
1224
- * An {@link OutputStream} that reports all the write operations with {@link
1225
- * DownloadProgressReporter}.
1226
- */
1227
- private static class ReportingOutputStream extends OutputStream {
1228
-
1229
- private final OutputStream out ;
1230
- private final DownloadProgressReporter reporter ;
1231
-
1232
- ReportingOutputStream (OutputStream out , DownloadProgressReporter reporter ) {
1233
- this .out = out ;
1234
- this .reporter = reporter ;
1235
- }
1236
-
1237
- @ Override
1238
- public void write (byte [] b ) throws IOException {
1239
- out .write (b );
1240
- reporter .downloadedBytes (b .length );
1241
- }
1242
-
1243
- @ Override
1244
- public void write (byte [] b , int off , int len ) throws IOException {
1245
- out .write (b , off , len );
1246
- reporter .downloadedBytes (len );
1247
- }
1248
-
1249
- @ Override
1250
- public void write (int b ) throws IOException {
1251
- out .write (b );
1252
- reporter .downloadedBytes (1 );
1253
- }
1254
-
1255
- @ Override
1256
- public void flush () throws IOException {
1257
- out .flush ();
1258
- }
1259
-
1260
- @ Override
1261
- public void close () throws IOException {
1262
- out .close ();
1263
- }
1264
- }
1265
-
1266
1149
/** In-memory representation of action result metadata. */
1267
1150
static class ActionResultMetadata {
1268
1151
0 commit comments