Skip to content

Commit cbab4d7

Browse files
authored
Add staged package hashes (#38311)
1 parent a32774a commit cbab4d7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/util/PackageUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ public static PackageAttributes forFileToStage(
438438
.toString();
439439
destination.setLocation(resourcePath);
440440
destination.setName(dest);
441+
destination.setSha256(hash);
441442
return new AutoValue_PackageUtil_PackageAttributes(
442443
file, null, destination, file.length(), hash);
443444
}
@@ -456,6 +457,7 @@ public static PackageAttributes forBytesToStage(
456457
DataflowPackage targetPackage = new DataflowPackage();
457458
targetPackage.setName(target);
458459
targetPackage.setLocation(resourcePath);
460+
targetPackage.setSha256(hashCode.toString());
459461

460462
return new AutoValue_PackageUtil_PackageAttributes(
461463
null, bytes, targetPackage, size, hashCode.toString());
@@ -465,6 +467,7 @@ public PackageAttributes withPackageName(String overridePackageName) {
465467
DataflowPackage newDestination = new DataflowPackage();
466468
newDestination.setName(overridePackageName);
467469
newDestination.setLocation(getDestination().getLocation());
470+
newDestination.setSha256(getHash());
468471

469472
return new AutoValue_PackageUtil_PackageAttributes(
470473
getSource(), getBytes(), newDestination, getSize(), getHash());

runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/util/PackageUtilTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ public void testFileWithExtensionPackageNamingAndSize() throws Exception {
191191
assertThat(target.getName(), endsWith(".txt"));
192192
assertThat(target.getLocation(), equalTo(STAGING_PATH + target.getName()));
193193
assertThat(attr.getSize(), equalTo((long) contents.length()));
194+
String expectedHash = Files.asByteSource(tmpFile).hash(Hashing.sha256()).toString();
195+
assertThat(target.getSha256(), equalTo(expectedHash));
194196
}
195197

196198
@Test
@@ -299,6 +301,8 @@ public void testPackageUploadWithFileSucceeds() throws Exception {
299301

300302
assertThat(target.getName(), endsWith(".txt"));
301303
assertThat(target.getLocation(), equalTo(STAGING_PATH + target.getName()));
304+
String expectedHash = Files.asByteSource(tmpFile).hash(Hashing.sha256()).toString();
305+
assertThat(target.getSha256(), equalTo(expectedHash));
302306
assertThat(
303307
new LineReader(Channels.newReader(pipe.source(), StandardCharsets.UTF_8.name())).readLine(),
304308
equalTo(contents));

0 commit comments

Comments
 (0)