liyinan926 commented on a change in pull request #23546: [SPARK-23153][K8s] 
Support client dependencies with a HCFS
URL: https://github.com/apache/spark/pull/23546#discussion_r249117347
 
 

 ##########
 File path: 
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesUtils.scala
 ##########
 @@ -71,17 +75,64 @@ private[spark] object KubernetesUtils extends Logging {
    * - File URIs with scheme local:// resolve to just the path of the URI.
    * - Otherwise, the URIs are returned as-is.
    */
-  def resolveFileUrisAndPath(fileUris: Iterable[String]): Iterable[String] = {
+  def resolveFileUrisAndPath(fileUris: Iterable[String], conf: 
Option[SparkConf] = None)
+  : Iterable[String] = {
     fileUris.map { uri =>
-      resolveFileUri(uri)
+      resolveFileUri(uri, conf)
     }
   }
 
-  def resolveFileUri(uri: String): String = {
+  /**
+   * Get the final path for a client file, if not return the uri as is.
+   *
+   */
+  def getDestPathIfClientFile(uri: String, conf: SparkConf): String = {
+    val fileUri = Utils.resolveURI(uri)
+    val fileScheme = Option(fileUri.getScheme).getOrElse("file")
+    if (fileScheme == "client") {
+      if (conf.get(KUBERNETES_FILE_UPLOAD_PATH).isDefined) {
+        val uploadPath = conf.get(KUBERNETES_FILE_UPLOAD_PATH).get
+        s"${uploadPath}/${fileUri.getPath.split("/").last}"
+      } else {
+        throw new SparkException("Please specify " +
+          "spark.kubernetes.file.upload.path property...")
+      }
+    } else {
+      uri
+    }
+  }
+
+  /**
+   *  Resolves a uri according to its scheme. If scheme is client
+   *  then uploads the file to the HCFS.
+   */
+  def resolveFileUri(uri: String, conf: Option[SparkConf] = None): String = {
     val fileUri = Utils.resolveURI(uri)
     val fileScheme = Option(fileUri.getScheme).getOrElse("file")
     fileScheme match {
       case "local" => fileUri.getPath
+      case KUBERNETES_FILE_UPLOAD_SCHEME =>
+        conf match {
+          case Some(sConf) =>
+            if (sConf.get(KUBERNETES_FILE_UPLOAD_PATH).isDefined) {
+              try {
+                val hadoopConf = SparkHadoopUtil.get.newConfiguration(sConf)
+                val uploadPath = sConf.get(KUBERNETES_FILE_UPLOAD_PATH).get
+                val fs = getHadoopFileSystem(Utils.resolveURI(uploadPath), 
hadoopConf)
+                val storePath = new 
Path(s"${uploadPath}/${fileUri.getPath.split("/").last}")
+                log.info(s"Uploading file: ${fileUri.getPath}...")
 
 Review comment:
   We should also mention the destination path in the log message.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to