Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 8ab5215

Browse files
authored
Load hdfs config files and set key-value pairs in SmartConf (#1593)
1 parent f575d47 commit 8ab5215

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

smart-agent/src/main/java/org/smartdata/agent/SmartAgent.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static void main(String[] args) throws IOException {
7272
SmartAgent agent = new SmartAgent();
7373

7474
SmartConf conf = (SmartConf) new GenericOptionsParser(new SmartConf(), args).getConfiguration();
75+
7576
String[] masters = AgentUtils.getMasterAddress(conf);
7677
if (masters == null) {
7778
throw new IOException("No master address found!");
@@ -82,27 +83,29 @@ public static void main(String[] args) throws IOException {
8283
String agentAddress = AgentUtils.getAgentAddress(conf);
8384
LOG.info("Agent address: " + agentAddress);
8485

86+
HadoopUtil.setSmartConfByHadoop(conf);
8587
agent.authentication(conf);
8688

8789
agent.start(AgentUtils.overrideRemoteAddress(ConfigFactory.load(AgentConstants.AKKA_CONF_FILE),
8890
agentAddress), AgentUtils.getMasterActorPaths(masters), conf);
8991
}
9092

93+
//TODO: remove loadHadoopConf
9194
private void authentication(SmartConf conf) throws IOException {
9295
if (!SecurityUtil.isSecurityEnabled(conf)) {
9396
return;
9497
}
9598

9699
// Load Hadoop configuration files
97-
String hadoopConfPath = conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY);
98100
try {
99-
HadoopUtil.loadHadoopConf(hadoopConfPath, conf);
101+
HadoopUtil.loadHadoopConf(conf);
100102
} catch (IOException e) {
101103
LOG.info("Running in secure mode, but cannot find Hadoop configuration file. "
102-
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
104+
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
103105
conf.set("hadoop.security.authentication", "kerberos");
104106
conf.set("hadoop.security.authorization", "true");
105107
}
108+
106109
UserGroupInformation.setConfiguration(conf);
107110

108111
String keytabFilename = conf.get(SmartConfKeys.SMART_AGENT_KEYTAB_FILE_KEY);

smart-hadoop-support/smart-hadoop/src/main/java/org/smartdata/hdfs/HadoopUtil.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,37 @@ public static void loadHadoopConf(String hadoopConfPath, Configuration conf)
102102
}
103103
}
104104

105+
/**
106+
* Load hadoop configure files from path configured in conf and override same key's value.
107+
*
108+
* @param conf
109+
*/
110+
public static void loadHadoopConf(Configuration conf) throws IOException {
111+
String hadoopConfPath = conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY);
112+
HdfsConfiguration hadoopConf = getHadoopConf(hadoopConfPath);
113+
if (hadoopConf != null) {
114+
for (Map.Entry<String, String> entry : hadoopConf) {
115+
String key = entry.getKey();
116+
conf.set(key, entry.getValue());
117+
}
118+
}
119+
}
120+
121+
public static void setSmartConfByHadoop(SmartConf conf) {
122+
try {
123+
if (conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY) != null) {
124+
HadoopUtil.loadHadoopConf(conf);
125+
URI nnUri = HadoopUtil.getNameNodeUri(conf);
126+
if (nnUri != null) {
127+
conf.set(SmartConfKeys.SMART_DFS_NAMENODE_RPCSERVER_KEY,
128+
nnUri.toString());
129+
}
130+
}
131+
} catch (IOException ex) {
132+
LOG.error("Load hadoop conf in {} error", conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY));
133+
}
134+
}
135+
105136
/**
106137
* Get hadoop configuration from the configure files in the given directory.
107138
*

smart-hadoop-support/smart-hadoop/src/main/java/org/smartdata/hdfs/HdfsStatesUpdateService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public HdfsStatesUpdateService(SmartContext context, MetaStore metaStore) {
7373
*
7474
* @return true if initialized successfully
7575
*/
76+
//@TODO: remove loadHadoopConf because it is done in Smart Server
7677
@Override
7778
public void init() throws IOException {
7879
LOG.info("Initializing ...");

smart-server/src/main/java/org/smartdata/server/SmartDaemon.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.hazelcast.core.HazelcastInstance;
2121
import org.smartdata.SmartContext;
2222
import org.smartdata.conf.SmartConf;
23+
import org.smartdata.hdfs.HadoopUtil;
2324
import org.smartdata.server.cluster.ClusterMembershipListener;
2425
import org.smartdata.server.cluster.HazelcastInstanceProvider;
2526
import org.smartdata.server.cluster.HazelcastWorker;
@@ -43,7 +44,11 @@ public void start() throws IOException, InterruptedException {
4344
SmartServer.main(args);
4445
} else {
4546
instance.getCluster().addMembershipListener(new ClusterMembershipListener(this));
46-
this.hazelcastWorker = new HazelcastWorker(new SmartContext(new SmartConf()));
47+
48+
SmartConf conf = new SmartConf();
49+
HadoopUtil.setSmartConfByHadoop(conf);
50+
51+
this.hazelcastWorker = new HazelcastWorker(new SmartContext(conf));
4752
this.hazelcastWorker.start();
4853
}
4954
}

smart-server/src/main/java/org/smartdata/server/SmartServer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public SmartServer(SmartConf conf) {
8686
public void initWith() throws Exception {
8787
LOG.info("Start Init Smart Server");
8888

89+
HadoopUtil.setSmartConfByHadoop(conf);
8990
authentication();
9091
MetaStore metaStore = MetaStoreUtils.getDBAdapter(conf);
9192
context = new ServerContext(conf, metaStore);
@@ -270,15 +271,15 @@ private void authentication() throws IOException {
270271
if (!SecurityUtil.isSecurityEnabled(conf)) {
271272
return;
272273
}
274+
273275
// Load Hadoop configuration files
274-
String hadoopConfPath = conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY);
275276
try {
276-
HadoopUtil.loadHadoopConf(hadoopConfPath, conf);
277+
HadoopUtil.loadHadoopConf(conf);
277278
} catch (IOException e) {
278-
LOG.info("Running in secure mode, but cannot find Hadoop configuration file. "
279-
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
280-
conf.set("hadoop.security.authentication", "kerberos");
281-
conf.set("hadoop.security.authorization", "true");
279+
LOG.info("Running in secure mode, but cannot find Hadoop configuration file. "
280+
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
281+
conf.set("hadoop.security.authentication", "kerberos");
282+
conf.set("hadoop.security.authorization", "true");
282283
}
283284

284285
UserGroupInformation.setConfiguration(conf);

0 commit comments

Comments
 (0)