2017-11-10 1 views
0

Java 응용 프로그램은 런타임시 hadoop xml의 폴더를 정의해야합니다 (단순화를 위해 프로그램 명령 행 인수에서 가져옵니다).프로그래밍 방식으로 hadoop * -site.xml의 디렉토리를 설정하는 방법

import org.apache.hadoop.conf.Configuration() 

.... 

Configuration = new Configuration 
config.addResource(new Path(String.format("%s/core-site.xml", hadoopLocation))); 
config.addResource(new Path(String.format("%s/hdfs-site.xml", hadoopLocation))); 
config.addResource(new Path(String.format("%s/tez-site.xml", hadoopLocation))); 
config.addResource(new Path(String.format("%s/yarn-site.xml", hadoopLocation))); 
config.addResource(new Path(String.format("%s/mapred-site.xml", hadoopLocation))); 
config.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()); 
config.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName()); 

try { 
    FileSystem dfs = FileSystem.get(config); 
} catch (IOException e) { 
    LOGGER.error("Failed to process hadoop file system"); 
} 

그러나, 나는 내 프로그램에서 호출 할 때마다 new Configuration() 그것을 반복하거나 일부 지속적인 사전 baseConfiguration 객체를 사용하고 new Configuration(baseConfiguration)처럼 사용한다 : 나는 다음과 같은 코드를 사용할 수 같아요. 이 모든 방법들은 꽤 서투르게 보입니다. 더 우아한 해결책이 있습니까? 정적 메서드 호출과 같은 무언가를 한 번 수행 할 수 있습니다. 다음 코드는 설명 용으로 만 제공됩니다.

Configuration.setBaseXmlsDir(); 

답변

1

Hadoop 응용 프로그램은 classpath에서 이러한 파일을 찾습니다. hadoop classpath을 실행하면 목록의 구성 디렉토리를 볼 수 있습니다.

따라서 위치를 수정하려면 애플리케이션을 실행하기 전에 클래스 경로를 수정하면됩니다. 가장 쉬운 방법은 다음과 같이 응용 프로그램을 시작하기 전에 환경 변수 HADOOP_CONF_DIR을 정의하는 것입니다.

export HADOOP_CONF_DIR=/your/path/to/xmls 
hadoop jar ... 
관련 문제