You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by om...@apache.org on 2012/05/11 16:58:45 UTC

svn commit: r1337197 - in /incubator/ambari/branches/ambari-186: CHANGES.txt hmc/php/db/HMCDBAccessor.php hmc/php/db/test.php

Author: omalley
Date: Fri May 11 14:58:45 2012
New Revision: 1337197

URL: http://svn.apache.org/viewvc?rev=1337197&view=rev
Log:
AMBARI-208. Support filtering hosts based on discovery status. (hitesh
via omalley)

Modified:
    incubator/ambari/branches/ambari-186/CHANGES.txt
    incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php
    incubator/ambari/branches/ambari-186/hmc/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=1337197&r1=1337196&r2=1337197&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/CHANGES.txt (original)
+++ incubator/ambari/branches/ambari-186/CHANGES.txt Fri May 11 14:58:45 2012
@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.x.x - unreleased
 
+  AMBARI-208. Support filtering hosts based on discovery status. (hitesh
+  via omalley)
+
   AMBARI-207. Fix for undefined variable manifest. (jitendra via omalley)
 
   AMBARI-204. Use the host that runs Ambari for running slaves & masters.

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=1337197&r1=1337196&r2=1337197&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php Fri May 11 14:58:45 2012
@@ -919,7 +919,14 @@ class HMCDBAccessor {
   /**
    * Get information on all hosts
    * @param string $clusterName
-   * @param mixed $filter TBD
+   * @param mixed $filter
+   *   - only supports equal operand
+   *   - only supports discoveryStatus filter
+   *   - array (
+   *      "=" => array ( "discoveryStatus" => "SUCCESS" )
+   *      )
+   *   - format
+   *     "$operand" => array ( "$column1" => "$value1", ... )
    * @param mixed $order order by particular column
    *   - only supports hostName, ip, totalMem, cpuCount, osArch, osType
    *    array (
@@ -959,6 +966,18 @@ class HMCDBAccessor {
         . " discovery_status, bad_health_reason, attributes "
         . " FROM Hosts WHERE cluster_name = "
         . $this->dbHandle->quote($clusterName);
+    if (is_array($filter) && !empty($filter)) {
+      foreach ($filter as $operand => $cols) {
+        if ($operand == "=" || $operand == "!=") {
+          foreach ($cols as $columnName => $value) {
+            if ($columnName == "discoveryStatus") {
+              $query .= " AND discovery_status " . $operand . " "
+                  . $this->dbHandle->quote($value);
+            }
+          }
+        }
+      }
+    }
     $using_sort = FALSE;
     if (isset($order) && is_array($order)
         && isset($order["sortColumn"])) {

Modified: incubator/ambari/branches/ambari-186/hmc/php/db/test.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/db/test.php?rev=1337197&r1=1337196&r2=1337197&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/db/test.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/db/test.php Fri May 11 14:58:45 2012
@@ -171,6 +171,20 @@ foreach ($result["hosts"] as $tmpHost) {
   assert(is_array($tmpHost["attributes"]));
 }
 
+print "Test getAllHostsInfo with filter\n";
+$result = $db->getAllHostsInfo($clusterName, array ( "=" => array ( "discoveryStatus" => "error")), "");
+assert($result["result"] == 0);
+assert($result["error"] == "");
+assert(is_array($result) && is_array($result["hosts"])
+       && count($result["hosts"]) == 1);
+assert($result["hosts"][0]["ip"] == "127.0.0.2");
+
+$result = $db->getAllHostsInfo($clusterName, array ( "!=" => array ( "discoveryStatus" => "errorfoo")), "");
+assert($result["result"] == 0);
+assert($result["error"] == "");
+assert(is_array($result) && is_array($result["hosts"])
+       && count($result["hosts"]) == 2);
+
 $result = $db->getAllHostsInfo($clusterName, "", array("sortColumn" => "totalMem", "sortOrder" => "DESC"));
 assert($result["result"] == 0);
 assert($result["error"] == "");