복붙노트

[HADOOP] spark-submit (클러스터 모드) 할 HDFS에있는 typesafe 구성 파일을 추가하는 방법은 무엇입니까?

HADOOP

spark-submit (클러스터 모드) 할 HDFS에있는 typesafe 구성 파일을 추가하는 방법은 무엇입니까?

Kafka에서 HDFS로 데이터를 스트리밍하는 Spark (Spark 1.5.2) 응용 프로그램이 있습니다. 내 응용 프로그램에는 Kafka 주제와 같은 특정 항목을 구성하는 두 가지 유형 안전 설정 파일이 있습니다.

이제 클러스터에서 spark-submit (클러스터 모드)로 애플리케이션을 실행하고 싶습니다. 내 프로젝트의 모든 종속성이있는 jar 파일은 HDFS에 저장됩니다. 나의 구성 파일이 jar 파일에 포함되어있는 한 모든 것이 정상적으로 작동합니다. 그러나 항아리를 항상 재구성해야하기 때문에 이것은 테스트 목적으로는 비현실적입니다.

따라서 내 프로젝트의 설정 파일을 제외하고 "driver-class-path"를 통해 추가했습니다. 이것은 클라이언트 모드에서 작동했지만, 이제 config 파일을 HDFS로 옮기고 클러스터 모드에서 내 애플리케이션을 실행하면 설정을 찾을 수 없습니다. 아래에서 내 spark-submit 명령을 찾을 수 있습니다.

/usr/local/spark/bin/spark-submit \
    --total-executor-cores 10 \
    --executor-memory 15g \
    --verbose \
    --deploy-mode cluster\
    --class com.hdp.speedlayer.SpeedLayerApp \
    --driver-class-path hdfs://iot-master:8020/user/spark/config \
    --master spark://spark-master:6066 \
    hdfs://iot-master:8020/user/spark/speed-layer-CONFIG.jar

이미 --file 매개 변수로 시도했지만 작동하지 않습니다. 아무도 내가 이것을 고칠 수있는 방법을 알고 있니?

최신 정보:

좀 더 연구를 해봤는데 HDFS 경로와 관련이있을 수 있다고 생각했습니다. 나는 HDFS 경로를 "hdfs : /// iot-master : 8020 // user // spark // config"로 변경했습니다.하지만 불행하게도 그것은 작동하지 않습니다.하지만 아마도 이것이 도움이 될 수 있습니다.

아래에서 클러스터 모드로 드라이버 프로그램을 실행할 때 나타나는 오류를 볼 수도 있습니다.

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.spark.deploy.worker.DriverWrapper$.main(DriverWrapper.scala:58)
    at org.apache.spark.deploy.worker.DriverWrapper.main(DriverWrapper.scala)
Caused by: java.lang.ExceptionInInitializerError
    at com.speedlayer.SpeedLayerApp.main(SpeedLayerApp.scala)
    ... 6 more
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'application'
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:145)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
...

해결법

  1. ==============================

    1.같은 결과를 얻으려고하면 다음과 같은 결과가 나왔습니다.

    같은 결과를 얻으려고하면 다음과 같은 결과가 나왔습니다.

    그래서 내가 아는 한은 hdfs에서 설정 파일을 읽어 들이기위한 어려운 방법이 없다.

    내 접근 방식은 내 애플 리케이션에 경로를 전달하고 구성 파일을 읽고 참조 파일에 병합했다 :

    private val HDFS_IMPL_KEY = "fs.hdfs.impl"
    def loadConf(pathToConf: String): Config = {
       val path = new Path(pathToConf)
       val confFile = File.createTempFile(path.getName, "tmp")
       confFile.deleteOnExit()
       getFileSystemByUri(path.toUri).copyToLocalFile(path, new Path(confFile.getAbsolutePath))
    
       ConfigFactory.load(ConfigFactory.parseFile(confFile))
    }
    
    def getFileSystemByUri(uri: URI) : FileSystem  = {
       val hdfsConf = new Configuration()
       hdfsConf.set(HDFS_IMPL_KEY, classOf[org.apache.hadoop.hdfs.DistributedFileSystem].getName)
    FileSystem.get(uri, hdfsConf)
    }
    

    이 오류는 ConfigFactory가 구성 파일을 찾지 못했음을 의미하므로 찾고자하는 속성을 찾을 수 없습니다.

  2. ==============================

    2.하나의 옵션은 --files 플래그와 HDFS 위치를 사용하고 -Dconfig.file과 함께 spark.executor.extraClassPath 플래그를 사용하여 실행 프로그램 클래스 경로에 추가해야합니다.

    하나의 옵션은 --files 플래그와 HDFS 위치를 사용하고 -Dconfig.file과 함께 spark.executor.extraClassPath 플래그를 사용하여 실행 프로그램 클래스 경로에 추가해야합니다.

    또한 spark-submit에 대한 도움말 문서를 보면 다음과 같이 볼 수 있습니다.

    --files FILES           Comma-separated list of files to be placed in the working
                            directory of each executor.
    

    스파크 제출으로 실행 :

    /usr/local/spark/bin/spark-submit \
    --total-executor-cores 10 \
    --executor-memory 15g \
    --conf "spark.executor.extraClassPath=-Dconfig.file=application.conf"
    --verbose \
    --deploy-mode cluster\
    --class com.hdp.speedlayer.SpeedLayerApp \
    --driver-class-path hdfs://iot-master:8020/user/spark/config \
    --files hdfs:/path/to/conf \
    --master spark://spark-master:6066 \
    hdfs://iot-master:8020/user/spark/speed-layer-CONFIG.jar
    
  3. from https://stackoverflow.com/questions/35509510/how-to-add-a-typesafe-config-file-which-is-located-on-hdfs-to-spark-submit-clus by cc-by-sa and MIT license