Github user wengyanqing commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/828#discussion_r73454751
  
    --- Diff: src/test/feature/lib/hdfs_config.cpp ---
    @@ -0,0 +1,293 @@
    +#include <fstream>
    +#include <string>
    +#include <vector>
    +#include <unordered_set>
    +
    +#include "hdfs_config.h"
    +#include "command.h"
    +#include "psql.h"
    +#include "xml_parser.h"
    +#include "string_util.h"
    +
    +using std::string;
    +
    +namespace hawq {
    +namespace test {
    +
    +string HdfsConfig::getHdfsUser() {
    +  string cmd = "ps aux|grep hdfs.server|grep -v grep";
    +  Command c(cmd);
    +  string result = c.run().getResultOutput();
    +  auto lines = hawq::test::split(result, '\n');
    +  if (lines.size() >= 1) {
    +    return hawq::test::trim(hawq::test::split(lines[lines.size()-1], ' 
')[0]);
    +  } 
    +  return "hdfs";
    +}
    +
    +bool HdfsConfig::LoadFromHawqConfigFile() {
    +  const char *env = getenv("GPHOME");
    +  string confPath = env ? env : "";
    +  if (confPath != "") {
    +    confPath.append("/etc/hdfs-client.xml");
    +  } else {
    +    return false;
    +  }
    +
    +  hawqxmlconf.reset(new XmlConfig(confPath));
    +  hawqxmlconf->parse();
    +  return true;
    +}
    +
    +bool HdfsConfig::LoadFromHdfsConfigFile() {
    +  string confPath=getHadoopHome();
    +  if (confPath == "") {
    +    return false;
    +  }
    +  confPath.append("/etc/hadoop/hdfs-site.xml");
    +  hdfsxmlconf.reset(new XmlConfig(confPath));
    +  hdfsxmlconf->parse();
    +  return true;
    +}
    +
    +bool HdfsConfig::isHA() {
    +  const hawq::test::PSQLQueryResult &result = psql.getQueryResult(
    +       "SELECT substring(fselocation from length('hdfs:// ') for 
(position('/' in substring(fselocation from length('hdfs:// ')))-1)::int) "
    +       "FROM pg_filespace pgfs, pg_filespace_entry pgfse "
    +       "WHERE pgfs.fsname = 'dfs_system' AND pgfse.fsefsoid=pgfs.oid ;");
    +  std::vector<std::vector<string>> table = result.getRows();
    +  if (table.size() > 0) {
    +    int find = table[0][0].find(":");
    +    if (find < 0) {
    +      return true;
    +    } else {
    +      return false;
    +    }
    +  }
    +  return false;
    +}
    +
    +bool HdfsConfig::isConfigKerberos() {
    +  bool ret = LoadFromHawqConfigFile();
    +  if (!ret) {
    +    throw GetHawqHomeException();
    +  }
    +  string authentication = 
hawqxmlconf->getString("hadoop.security.authentication");
    +  if (authentication == "kerberos") {
    +    return true;
    +  } else {
    +    return false;
    +  }
    +}
    +
    +bool HdfsConfig::isTruncate() {
    +  string cmd = "hadoop fs -truncate";
    +  Command c(cmd);
    +  string result = c.run().getResultOutput();
    +  auto lines = hawq::test::split(result, '\n');
    +  if (lines.size() >= 1) {
    +    string valueLine = lines[0];
    +    int find = valueLine.find("-truncate: Unknown command");
    +    if (find < 0) {
    +      return true;
    +    }
    +  }
    +  return false;
    +}
    +
    +string HdfsConfig::getHadoopHome() {
    +  string cmd = "ps -ef|grep hadoop";
    --- End diff --
    
    I see lots of places have the same logic. 
    1. run command
    2. get command result by lines
    3. process lines result
    It's better to extract the common logic into function. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to