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

Commit

Permalink
Load hdfs config files and set key-value pairs in SmartConf (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE authored Feb 9, 2018
1 parent f575d47 commit 8ab5215
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
9 changes: 6 additions & 3 deletions smart-agent/src/main/java/org/smartdata/agent/SmartAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static void main(String[] args) throws IOException {
SmartAgent agent = new SmartAgent();

SmartConf conf = (SmartConf) new GenericOptionsParser(new SmartConf(), args).getConfiguration();

String[] masters = AgentUtils.getMasterAddress(conf);
if (masters == null) {
throw new IOException("No master address found!");
Expand All @@ -82,27 +83,29 @@ public static void main(String[] args) throws IOException {
String agentAddress = AgentUtils.getAgentAddress(conf);
LOG.info("Agent address: " + agentAddress);

HadoopUtil.setSmartConfByHadoop(conf);
agent.authentication(conf);

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

//TODO: remove loadHadoopConf
private void authentication(SmartConf conf) throws IOException {
if (!SecurityUtil.isSecurityEnabled(conf)) {
return;
}

// Load Hadoop configuration files
String hadoopConfPath = conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY);
try {
HadoopUtil.loadHadoopConf(hadoopConfPath, conf);
HadoopUtil.loadHadoopConf(conf);
} catch (IOException e) {
LOG.info("Running in secure mode, but cannot find Hadoop configuration file. "
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
conf.set("hadoop.security.authentication", "kerberos");
conf.set("hadoop.security.authorization", "true");
}

UserGroupInformation.setConfiguration(conf);

String keytabFilename = conf.get(SmartConfKeys.SMART_AGENT_KEYTAB_FILE_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ public static void loadHadoopConf(String hadoopConfPath, Configuration conf)
}
}

/**
* Load hadoop configure files from path configured in conf and override same key's value.
*
* @param conf
*/
public static void loadHadoopConf(Configuration conf) throws IOException {
String hadoopConfPath = conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY);
HdfsConfiguration hadoopConf = getHadoopConf(hadoopConfPath);
if (hadoopConf != null) {
for (Map.Entry<String, String> entry : hadoopConf) {
String key = entry.getKey();
conf.set(key, entry.getValue());
}
}
}

public static void setSmartConfByHadoop(SmartConf conf) {
try {
if (conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY) != null) {
HadoopUtil.loadHadoopConf(conf);
URI nnUri = HadoopUtil.getNameNodeUri(conf);
if (nnUri != null) {
conf.set(SmartConfKeys.SMART_DFS_NAMENODE_RPCSERVER_KEY,
nnUri.toString());
}
}
} catch (IOException ex) {
LOG.error("Load hadoop conf in {} error", conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY));
}
}

/**
* Get hadoop configuration from the configure files in the given directory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public HdfsStatesUpdateService(SmartContext context, MetaStore metaStore) {
*
* @return true if initialized successfully
*/
//@TODO: remove loadHadoopConf because it is done in Smart Server
@Override
public void init() throws IOException {
LOG.info("Initializing ...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.hazelcast.core.HazelcastInstance;
import org.smartdata.SmartContext;
import org.smartdata.conf.SmartConf;
import org.smartdata.hdfs.HadoopUtil;
import org.smartdata.server.cluster.ClusterMembershipListener;
import org.smartdata.server.cluster.HazelcastInstanceProvider;
import org.smartdata.server.cluster.HazelcastWorker;
Expand All @@ -43,7 +44,11 @@ public void start() throws IOException, InterruptedException {
SmartServer.main(args);
} else {
instance.getCluster().addMembershipListener(new ClusterMembershipListener(this));
this.hazelcastWorker = new HazelcastWorker(new SmartContext(new SmartConf()));

SmartConf conf = new SmartConf();
HadoopUtil.setSmartConfByHadoop(conf);

this.hazelcastWorker = new HazelcastWorker(new SmartContext(conf));
this.hazelcastWorker.start();
}
}
Expand Down
13 changes: 7 additions & 6 deletions smart-server/src/main/java/org/smartdata/server/SmartServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public SmartServer(SmartConf conf) {
public void initWith() throws Exception {
LOG.info("Start Init Smart Server");

HadoopUtil.setSmartConfByHadoop(conf);
authentication();
MetaStore metaStore = MetaStoreUtils.getDBAdapter(conf);
context = new ServerContext(conf, metaStore);
Expand Down Expand Up @@ -270,15 +271,15 @@ private void authentication() throws IOException {
if (!SecurityUtil.isSecurityEnabled(conf)) {
return;
}

// Load Hadoop configuration files
String hadoopConfPath = conf.get(SmartConfKeys.SMART_HADOOP_CONF_DIR_KEY);
try {
HadoopUtil.loadHadoopConf(hadoopConfPath, conf);
HadoopUtil.loadHadoopConf(conf);
} catch (IOException e) {
LOG.info("Running in secure mode, but cannot find Hadoop configuration file. "
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
conf.set("hadoop.security.authentication", "kerberos");
conf.set("hadoop.security.authorization", "true");
LOG.info("Running in secure mode, but cannot find Hadoop configuration file. "
+ "Please config smart.hadoop.conf.path property in smart-site.xml.");
conf.set("hadoop.security.authentication", "kerberos");
conf.set("hadoop.security.authorization", "true");
}

UserGroupInformation.setConfiguration(conf);
Expand Down

0 comments on commit 8ab5215

Please sign in to comment.