Repository: incubator-hawq
Updated Branches:
  refs/heads/master 51cf8634d -> 85000f34d


HAWQ-1037. Add get OS user in hdfs_config when  is not set


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/85000f34
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/85000f34
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/85000f34

Branch: refs/heads/master
Commit: 85000f34dc226d4b5f5a16232136b173206aeae9
Parents: 65b0e27
Author: Chunling Wang <[email protected]>
Authored: Thu Sep 8 09:56:37 2016 +0800
Committer: ivan <[email protected]>
Committed: Fri Sep 9 10:00:14 2016 +0800

----------------------------------------------------------------------
 src/test/feature/lib/hdfs_config.cpp | 19 ++++++++++++++++---
 src/test/feature/lib/hdfs_config.h   |  7 ++-----
 2 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/85000f34/src/test/feature/lib/hdfs_config.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/hdfs_config.cpp 
b/src/test/feature/lib/hdfs_config.cpp
index 8a8ed81..b09c2d4 100644
--- a/src/test/feature/lib/hdfs_config.cpp
+++ b/src/test/feature/lib/hdfs_config.cpp
@@ -2,10 +2,10 @@
 #include <string>
 #include <vector>
 #include <unordered_set>
+#include <pwd.h>
 
 #include "hdfs_config.h"
 #include "command.h"
-#include "psql.h"
 #include "xml_parser.h"
 #include "string_util.h"
 
@@ -14,6 +14,19 @@ using std::string;
 namespace hawq {
 namespace test {
 
+HdfsConfig::HdfsConfig() {
+  std::string user = HAWQ_USER;
+  if(user.empty()) {
+    struct passwd *pw;
+    uid_t uid = geteuid();
+    pw = getpwuid(uid);
+    user.assign(pw->pw_name);
+  }
+  conn.reset(new hawq::test::PSQL(HAWQ_DB, HAWQ_HOST, HAWQ_PORT, user, 
HAWQ_PASSWORD));
+  isLoadFromHawqConfigFile = false;
+  isLoadFromHdfsConfigFile = false;
+}
+
 void HdfsConfig::runCommand(const string &command, 
                             bool ishdfsuser, 
                             string &result) {
@@ -115,7 +128,7 @@ bool HdfsConfig::LoadFromHdfsConfigFile() {
 }
 
 int HdfsConfig::isHA() {
-  const hawq::test::PSQLQueryResult &result = psql.getQueryResult(
+  const hawq::test::PSQLQueryResult &result = conn->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 ;");
@@ -173,7 +186,7 @@ string HdfsConfig::getHadoopHome() {
 }
 
 bool HdfsConfig::getNamenodeHost(string &namenodehost) {
-  const hawq::test::PSQLQueryResult &result = psql.getQueryResult(
+  const hawq::test::PSQLQueryResult &result = conn->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 ;");

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/85000f34/src/test/feature/lib/hdfs_config.h
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/hdfs_config.h 
b/src/test/feature/lib/hdfs_config.h
index 6b57588..c339c83 100644
--- a/src/test/feature/lib/hdfs_config.h
+++ b/src/test/feature/lib/hdfs_config.h
@@ -21,10 +21,7 @@ class HdfsConfig {
     /**
      * HdfsConfig constructor
      */
-    HdfsConfig(): psql(HAWQ_DB, HAWQ_HOST, HAWQ_PORT, HAWQ_USER, 
HAWQ_PASSWORD) {
-      isLoadFromHawqConfigFile = false;
-      isLoadFromHdfsConfigFile = false;
-    }
+    HdfsConfig();
 
     /**
      * HdfsConfig destructor
@@ -180,7 +177,7 @@ class HdfsConfig {
     std::unique_ptr<XmlConfig> hdfsxmlconf;
     bool isLoadFromHawqConfigFile;
     bool isLoadFromHdfsConfigFile;
-    hawq::test::PSQL psql;
+    std::unique_ptr<hawq::test::PSQL> conn;
 };
 
 } // namespace test

Reply via email to