You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vi...@apache.org on 2012/06/07 03:53:29 UTC
svn commit: r1347289 - in /incubator/ambari/branches/ambari-186: CHANGES.txt
hmc/php/db/HMCDBAccessor.php hmc/tests/php/db/test.php
Author: vikram
Date: Thu Jun 7 01:53:28 2012
New Revision: 1347289
URL: http://svn.apache.org/viewvc?rev=1347289&view=rev
Log:
AMBARI-472. Add api to find all unassigned hosts in a cluster (Contributed by Hitesh)
Modified:
incubator/ambari/branches/ambari-186/CHANGES.txt
incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php
incubator/ambari/branches/ambari-186/hmc/tests/php/db/test.php
Modified: incubator/ambari/branches/ambari-186/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/CHANGES.txt?rev=1347289&r1=1347288&r2=1347289&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/CHANGES.txt (original)
+++ incubator/ambari/branches/ambari-186/CHANGES.txt Thu Jun 7 01:53:28 2012
@@ -6,6 +6,8 @@ characters wide.
Release 0.1.x - unreleased
+ AMBARI-472. Add api to find all unassigned hosts in a cluster (Hitesh via Vikram)
+
AMBARI-470. Fix conflicting dashbord conf files in installer and dashboard. (Mahadev via Vikram)
AMBARI-469. Cap DataNode heap size. (Mahadev via Vikram)
Modified: incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php?rev=1347289&r1=1347288&r2=1347289&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php Thu Jun 7 01:53:28 2012
@@ -751,6 +751,7 @@ class HMCDBAccessor {
foreach ($hostsInfo as $hostInfo) {
if (!isset($hostInfo["hostName"])
+ || $hostInfo["hostName"] == ""
|| !isset($hostInfo["discoveryStatus"])) {
$response["result"] = 1;
$response["error"] = "Invalid arguments";
@@ -999,11 +1000,16 @@ class HMCDBAccessor {
LockAcquire();
$error = "";
$query = "SELECT "
- . " host_name, ip, total_mem, "
+ . " cluster_name, host_name, ip, total_mem, "
. " cpu_count, os_arch, os_type, os, disks_info, "
. " discovery_status, bad_health_reason, attributes "
- . " FROM Hosts WHERE cluster_name = "
- . $this->dbHandle->quote($clusterName);
+ . " FROM Hosts WHERE host_name != ''";
+
+ if ($clusterName != "") {
+ $query .= " AND cluster_name = "
+ . $this->dbHandle->quote($clusterName);
+ }
+
if (is_array($filter) && !empty($filter)) {
foreach ($filter as $operand => $cols) {
if ($operand == "=" || $operand == "!=") {
@@ -1137,9 +1143,12 @@ class HMCDBAccessor {
LockRelease(); return $response;
}
$result = $pdoStmt->fetchAll(PDO::FETCH_BOTH);
- $response["clusterName"] = $clusterName;
+ if ($clusterName != "") {
+ $response["clusterName"] = $clusterName;
+ }
if (isset($result) && is_array($result) && count($result) == 1) {
$entry = $result[0];
+ $response["clusterName"] = $entry["cluster_name"];
$response["hostName"] = $entry["host_name"];
$response["ip"] = $entry["ip"];
$response["totalMem"] = $entry["total_mem"];
@@ -3322,5 +3331,60 @@ class HMCDBAccessor {
$this->deleteAllInTable("ServiceInfo");
}
+
+ /**
+ * Returns all nodes that were successfully discovered but have no
+ * components/roles assigned to them within the given cluster
+ * Enter description here ...
+ * @param unknown_type $clusterName
+ */
+ public function getAllUnassignedHosts($clusterName) {
+ LockAcquire();
+ $error = "";
+ $query = "SELECT "
+ . " Hosts.host_name, Hosts.ip, Hosts.total_mem, "
+ . " Hosts.cpu_count, Hosts.os_arch, Hosts.os_type, Hosts.os, Hosts.disks_info, "
+ . " Hosts.discovery_status, Hosts.bad_health_reason, Hosts.attributes "
+ . " FROM Hosts LEFT JOIN HostRoles ON "
+ . " Hosts.cluster_name = HostRoles.cluster_name "
+ . " AND Hosts.host_name = HostRoles.host_name "
+ . " WHERE Hosts.cluster_name = "
+ . $this->dbHandle->quote($clusterName)
+ . " AND Hosts.discovery_status = 'SUCCESS'"
+ . " AND HostRoles.component_name ISNULL";
+
+ $response = array ( "result" => 0, "error" => "");
+ $this->logger->log_trace("Running query: $query");
+ $pdoStmt = $this->dbHandle->query($query);
+ if ($pdoStmt === FALSE) {
+ $error = $this->getLastDBErrorAsString();
+ $this->logger->log_error("Error when executing query"
+ . ", query=".$query
+ . ", error=".$error);
+ $response["result"] = 1;
+ $response["error"] = $error;
+ LockRelease(); return $response;
+ }
+ $result = $pdoStmt->fetchAll(PDO::FETCH_BOTH);
+ $response["hosts"] = array();
+ $response["clusterName"] = $clusterName;
+ foreach ($result as $entry) {
+ $host = array();
+ $host["hostName"] = $entry["host_name"];
+ $host["ip"] = $entry["ip"];
+ $host["totalMem"] = $entry["total_mem"];
+ $host["cpuCount"] = $entry["cpu_count"];
+ $host["osArch"] = $entry["os_arch"];
+ $host["osType"] = $entry["os_type"];
+ $host["os"] = $entry["os"];
+ $host["disksInfo"] = $entry["disks_info"];
+ $host["discoveryStatus"] = $entry["discovery_status"];
+ $host["badHealthReason"] = $entry["bad_health_reason"];
+ $host["attributes"] = json_decode($entry["attributes"], true);
+ array_push($response["hosts"], $host);
+ }
+ LockRelease(); return $response;
+ }
+
}
?>
Modified: incubator/ambari/branches/ambari-186/hmc/tests/php/db/test.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/tests/php/db/test.php?rev=1347289&r1=1347288&r2=1347289&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/tests/php/db/test.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/tests/php/db/test.php Thu Jun 7 01:53:28 2012
@@ -80,7 +80,7 @@ $hosts = array (
"osType" => "RHEL5",
"os" => "RHEL5 32-bit",
"disksInfo" => "foo",
- "discoveryStatus" => "success",
+ "discoveryStatus" => "SUCCESS",
"badHealthReason" => "no error",
"attributes" => array ( "foo" => "bar" )
),
@@ -116,7 +116,7 @@ $hosts2 = array (
"osType" => "RHEL5",
"os" => "RHEL5 32-bit",
"disksInfo" => "foo",
- "discoveryStatus" => "success",
+ "discoveryStatus" => "SUCCESS",
"badHealthReason" => "no error"
)
);
@@ -370,13 +370,13 @@ assert(is_array($result["components"]["N
&& $result["components"]["NAMENODE"]["componentName"] == "NAMENODE"
&& $result["components"]["NAMENODE"]["isMaster"] == true
&& $result["components"]["NAMENODE"]["isClient"] == false
- && $result["components"]["NAMENODE"]["displayName"] == "Namenode"
+ && $result["components"]["NAMENODE"]["displayName"] == "NameNode"
&& $result["components"]["NAMENODE"]["description"] != "");
assert(is_array($result["components"]["SNAMENODE"])
&& $result["components"]["SNAMENODE"]["componentName"] == "SNAMENODE"
&& $result["components"]["SNAMENODE"]["isMaster"] == true
&& $result["components"]["SNAMENODE"]["isClient"] == false
- && $result["components"]["SNAMENODE"]["displayName"] == "Secondary Namenode"
+ && $result["components"]["SNAMENODE"]["displayName"] == "Secondary NameNode"
&& $result["components"]["SNAMENODE"]["description"] != "");
assert(is_array($result["components"]["DATANODE"])
&& $result["components"]["DATANODE"]["componentName"] == "DATANODE"
@@ -896,14 +896,11 @@ assert($result["result"] == 0);
assert($result["error"] == "");
assert(is_array($result["componentMapping"]));
assert(is_array($result["nodes"])
- && count($result["nodes"]) == 2);
-assert($result["nodes"][0] == "localhost1"
- || $result["nodes"][0] == "localhost2");
-assert($result["nodes"][1] == "localhost1"
- || $result["nodes"][1] == "localhost2");
+ && count($result["nodes"]) == 1);
+assert($result["nodes"][0] == "localhost1");
print "Test getComponentNodes\n";
-$svcCompObj = new ServiceComponent($clusterName, "DATANODE", "HDFS", "", $odb, $puppet, FALSE);
+$svcCompObj = new ServiceComponent($clusterName, "DATANODE", "HDFS", "", $odb, $puppet, FALSE, "Datanode");
$result = $odb->getComponentNodes($svcCompObj);
assert(is_array($result));
assert($result["result"] == 0);
@@ -916,7 +913,7 @@ assert($result["nodes"][1] == "localhost
|| $result["nodes"][1] == "localhost2");
print "Test setServiceState\n";
-$svcObj = new Service($clusterName, "HDFS", 0, $odb, $puppet);
+$svcObj = new Service($clusterName, "HDFS", 0, $odb, $puppet, "HDFS");
$result = $odb->setServiceState($svcObj, 1);
assert(is_array($result));
assert($result["result"] == 0);
@@ -983,12 +980,11 @@ assert(is_array($result["serviceDependen
print "Test getRecursiveServiceDependency\n";
$result = $db->getRecursiveServiceDependency($result["serviceDependencies"],
- "HCATALOG");
+ "HIVE");
assert(is_array($result)
- && count($result) == 3
+ && count($result) == 2
&& in_array("HDFS", $result)
- && in_array("MAPREDUCE", $result)
- && in_array("HIVE", $result));
+ && in_array("MAPREDUCE", $result));
print "Test setHostsState\n";
$hostsToUpdate = array (
@@ -1157,4 +1153,53 @@ foreach ($result["configs"] as $key => $
assert(is_array($info["displayAttributes"]));
}
+print "Test getAllUnassignedHosts\n";
+
+$result = $db->getAllHostsInfo("", "", "");
+assert($result["result"] == 0);
+assert($result["error"] == "");
+assert(count($result["hosts"]) == 3);
+
+$hostsToAdd = array (
+array (
+ "hostName" => "localhost4",
+ "ip" => "127.0.0.4",
+ "totalMem" => 64,
+ "cpuCount" => 4,
+ "osArch" => "i386",
+ "osType" => "RHEL5",
+ "os" => "RHEL5 32-bit",
+ "disksInfo" => "foo",
+ "discoveryStatus" => "SUCCESS",
+ "badHealthReason" => "no error",
+ "attributes" => array ( "foo" => "bar" )
+),
+array (
+ "hostName" => "localhost5",
+ "ip" => "127.0.0.5",
+ "totalMem" => 32,
+ "cpuCount" => 8,
+ "osArch" => "x86_64",
+ "osType" => "RHEL6",
+ "os" => "RHEL6 64-bit",
+ "disksInfo" => "bar",
+ "discoveryStatus" => "error",
+ "badHealthReason" => "invalid ssh key"
+)
+);
+$result = $db->addHostsToCluster($clusterName, $hostsToAdd);
+assert(is_array($result));
+assert($result["clusterName"] == $clusterName);
+assert($result["result"] == 0);
+assert($result["error"] == "");
+
+$result = $db->getAllUnassignedHosts($clusterName);
+assert(is_array($result));
+assert($result["clusterName"] == $clusterName);
+assert($result["result"] == 0);
+assert($result["error"] == "");
+assert(count($result["hosts"]) == 1);
+assert($result["hosts"][0]["hostName"] == $hostsToAdd[0]["hostName"]);
+
+
?>