Skip to content

Commit 21bd61a

Browse files
committed
[SPARK-53825] Use Java MessageDigest instead of org.apache.commons.codec
### What changes were proposed in this pull request? This PR aims to use Java `MessageDigest` instead of `org.apache.commons.codec`. ### Why are the changes needed? To reduce 3rd-party library dependency. ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. This patch had conflicts when merged, resolved by Committer: Dongjoon Hyun <[email protected]> Closes #373 from dongjoon-hyun/SPARK-53825. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent cd8789c commit 21bd61a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

spark-submission-worker/src/main/java/org/apache/spark/k8s/operator/SparkAppSubmissionWorker.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919

2020
package org.apache.spark.k8s.operator;
2121

22+
import static java.nio.charset.StandardCharsets.UTF_8;
23+
2224
import java.math.BigInteger;
25+
import java.security.MessageDigest;
26+
import java.security.NoSuchAlgorithmException;
2327
import java.util.List;
2428
import java.util.Map;
2529

2630
import scala.Option;
2731

2832
import io.fabric8.kubernetes.client.KubernetesClient;
29-
import org.apache.commons.codec.digest.DigestUtils;
3033

3134
import org.apache.spark.SparkConf;
3235
import org.apache.spark.deploy.k8s.KubernetesDriverSpec;
@@ -67,6 +70,17 @@ public class SparkAppSubmissionWorker {
6770
/** Property name for the Spark master URL prefix. */
6871
public static final String MASTER_URL_PREFIX_PROPS_NAME = "spark.master.url.prefix";
6972

73+
/** SHA256 Message Digest when generating hash-based identifier. */
74+
private static final ThreadLocal<MessageDigest> SHA_256_THREAD_LOCAL =
75+
ThreadLocal.withInitial(
76+
() -> {
77+
try {
78+
return MessageDigest.getInstance("SHA-256");
79+
} catch (NoSuchAlgorithmException e) {
80+
throw new UnsupportedOperationException(e);
81+
}
82+
});
83+
7084
/**
7185
* Build secondary resource spec for given app with Spark developer API, with defaults / overrides
7286
* as:
@@ -201,8 +215,9 @@ public static String generateSparkAppId(final SparkApplication app) {
201215
* @return The generated hash-based ID.
202216
*/
203217
public static String generateHashBasedId(final String prefix, final String... identifiers) {
218+
final MessageDigest sha256 = SHA_256_THREAD_LOCAL.get();
204219
String sha256Hash =
205-
new BigInteger(1, DigestUtils.sha256(String.join("/", identifiers)))
220+
new BigInteger(1, sha256.digest(String.join("/", identifiers).getBytes(UTF_8)))
206221
.toString(DEFAULT_ENCODE_BASE);
207222
String truncatedIdentifiersHash =
208223
sha256Hash.substring(0, DEFAULT_HASH_BASED_IDENTIFIER_LENGTH_LIMIT);

0 commit comments

Comments
 (0)