Skip to content

Commit 67719f5

Browse files
sluongngbazel-io
authored andcommitted
Add digest func to Remote Asset Downloader
A follow up from bazelbuild/remote-apis#286 Closes bazelbuild#21996. PiperOrigin-RevId: 628100606 Change-Id: Ib37a013d704dcfd14556f7914d90c1393ef73d38
1 parent 17e0a93 commit 67719f5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
714714
Optional.ofNullable(callCredentials),
715715
retrier,
716716
cacheClient,
717+
digestUtil.getDigestFunction(),
717718
remoteOptions,
718719
verboseFailures,
719720
fallbackDownloader));

src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import build.bazel.remote.asset.v1.FetchGrpc.FetchBlockingStub;
2121
import build.bazel.remote.asset.v1.Qualifier;
2222
import build.bazel.remote.execution.v2.Digest;
23+
import build.bazel.remote.execution.v2.DigestFunction;
2324
import build.bazel.remote.execution.v2.RequestMetadata;
2425
import com.google.auth.Credentials;
2526
import com.google.common.annotations.VisibleForTesting;
@@ -65,6 +66,7 @@ public class GrpcRemoteDownloader implements AutoCloseable, Downloader {
6566
private final Optional<CallCredentials> credentials;
6667
private final RemoteRetrier retrier;
6768
private final RemoteCacheClient cacheClient;
69+
private final DigestFunction.Value digestFunction;
6870
private final RemoteOptions options;
6971
private final boolean verboseFailures;
7072
@Nullable private final Downloader fallbackDownloader;
@@ -89,6 +91,7 @@ public GrpcRemoteDownloader(
8991
Optional<CallCredentials> credentials,
9092
RemoteRetrier retrier,
9193
RemoteCacheClient cacheClient,
94+
DigestFunction.Value digestFunction,
9295
RemoteOptions options,
9396
boolean verboseFailures,
9497
@Nullable Downloader fallbackDownloader) {
@@ -98,6 +101,7 @@ public GrpcRemoteDownloader(
98101
this.credentials = credentials;
99102
this.retrier = retrier;
100103
this.cacheClient = cacheClient;
104+
this.digestFunction = digestFunction;
101105
this.options = options;
102106
this.verboseFailures = verboseFailures;
103107
this.fallbackDownloader = fallbackDownloader;
@@ -130,7 +134,8 @@ public void download(
130134
RemoteActionExecutionContext.create(metadata);
131135

132136
final FetchBlobRequest request =
133-
newFetchBlobRequest(options.remoteInstanceName, urls, checksum, canonicalId, headers);
137+
newFetchBlobRequest(
138+
options.remoteInstanceName, urls, checksum, canonicalId, digestFunction, headers);
134139
try {
135140
FetchBlobResponse response =
136141
retrier.execute(
@@ -178,9 +183,12 @@ static FetchBlobRequest newFetchBlobRequest(
178183
List<URL> urls,
179184
Optional<Checksum> checksum,
180185
String canonicalId,
186+
DigestFunction.Value digestFunction,
181187
Map<String, List<String>> headers) {
182188
FetchBlobRequest.Builder requestBuilder =
183-
FetchBlobRequest.newBuilder().setInstanceName(instanceName);
189+
FetchBlobRequest.newBuilder()
190+
.setInstanceName(instanceName)
191+
.setDigestFunction(digestFunction);
184192
for (URL url : urls) {
185193
requestBuilder.addUris(url.toString());
186194
}

src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public int maxConcurrency() {
160160
Optional.<CallCredentials>empty(),
161161
retrier,
162162
cacheClient,
163+
DIGEST_UTIL.getDigestFunction(),
163164
remoteOptions,
164165
/* verboseFailures= */ false,
165166
fallbackDownloader);
@@ -205,6 +206,7 @@ public void fetchBlob(
205206
assertThat(request)
206207
.isEqualTo(
207208
FetchBlobRequest.newBuilder()
209+
.setDigestFunction(DIGEST_UTIL.getDigestFunction())
208210
.addUris("http://example.com/content.txt")
209211
.build());
210212
responseObserver.onNext(
@@ -270,6 +272,7 @@ public void fetchBlob(
270272
assertThat(request)
271273
.isEqualTo(
272274
FetchBlobRequest.newBuilder()
275+
.setDigestFunction(DIGEST_UTIL.getDigestFunction())
273276
.addUris("http://example.com/content.txt")
274277
.addQualifiers(
275278
Qualifier.newBuilder()
@@ -308,6 +311,7 @@ public void fetchBlob(
308311
assertThat(request)
309312
.isEqualTo(
310313
FetchBlobRequest.newBuilder()
314+
.setDigestFunction(DIGEST_UTIL.getDigestFunction())
311315
.addUris("http://example.com/content.txt")
312316
.addQualifiers(
313317
Qualifier.newBuilder()
@@ -352,6 +356,7 @@ public void testFetchBlobRequest() throws Exception {
352356
Checksum.fromSubresourceIntegrity(
353357
"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")),
354358
"canonical ID",
359+
DIGEST_UTIL.getDigestFunction(),
355360
ImmutableMap.of(
356361
"Authorization", ImmutableList.of("Basic Zm9vOmJhcg=="),
357362
"X-Custom-Token", ImmutableList.of("foo", "bar")));
@@ -360,6 +365,7 @@ public void testFetchBlobRequest() throws Exception {
360365
.isEqualTo(
361366
FetchBlobRequest.newBuilder()
362367
.setInstanceName("instance name")
368+
.setDigestFunction(DIGEST_UTIL.getDigestFunction())
363369
.addUris("http://example.com/a")
364370
.addUris("http://example.com/b")
365371
.addUris("file:/not/limited/to/http")

0 commit comments

Comments
 (0)