|
19 | 19 |
|
20 | 20 | package org.apache.spark.k8s.operator; |
21 | 21 |
|
| 22 | +import static java.nio.charset.StandardCharsets.UTF_8; |
| 23 | + |
22 | 24 | import java.math.BigInteger; |
| 25 | +import java.security.MessageDigest; |
| 26 | +import java.security.NoSuchAlgorithmException; |
23 | 27 | import java.util.List; |
24 | 28 | import java.util.Map; |
25 | 29 |
|
26 | 30 | import scala.Option; |
27 | 31 |
|
28 | 32 | import io.fabric8.kubernetes.client.KubernetesClient; |
29 | | -import org.apache.commons.codec.digest.DigestUtils; |
30 | 33 | import org.apache.commons.collections4.MapUtils; |
31 | 34 |
|
32 | 35 | import org.apache.spark.SparkConf; |
@@ -68,6 +71,17 @@ public class SparkAppSubmissionWorker { |
68 | 71 | /** Property name for the Spark master URL prefix. */ |
69 | 72 | public static final String MASTER_URL_PREFIX_PROPS_NAME = "spark.master.url.prefix"; |
70 | 73 |
|
| 74 | + /** SHA256 Message Digest when generating hash-based identifier. */ |
| 75 | + private static final ThreadLocal<MessageDigest> SHA_256_THREAD_LOCAL = |
| 76 | + ThreadLocal.withInitial( |
| 77 | + () -> { |
| 78 | + try { |
| 79 | + return MessageDigest.getInstance("SHA-256"); |
| 80 | + } catch (NoSuchAlgorithmException e) { |
| 81 | + throw new UnsupportedOperationException(e); |
| 82 | + } |
| 83 | + }); |
| 84 | + |
71 | 85 | /** |
72 | 86 | * Build secondary resource spec for given app with Spark developer API, with defaults / overrides |
73 | 87 | * as: |
@@ -202,8 +216,9 @@ public static String generateSparkAppId(final SparkApplication app) { |
202 | 216 | * @return The generated hash-based ID. |
203 | 217 | */ |
204 | 218 | public static String generateHashBasedId(final String prefix, final String... identifiers) { |
| 219 | + final MessageDigest sha256 = SHA_256_THREAD_LOCAL.get(); |
205 | 220 | String sha256Hash = |
206 | | - new BigInteger(1, DigestUtils.sha256(String.join("/", identifiers))) |
| 221 | + new BigInteger(1, sha256.digest(String.join("/", identifiers).getBytes(UTF_8))) |
207 | 222 | .toString(DEFAULT_ENCODE_BASE); |
208 | 223 | String truncatedIdentifiersHash = |
209 | 224 | sha256Hash.substring(0, DEFAULT_HASH_BASED_IDENTIFIER_LENGTH_LIMIT); |
|
0 commit comments