Return-Path: X-Original-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 145E9C13E for ; Fri, 11 May 2012 14:59:10 +0000 (UTC) Received: (qmail 44293 invoked by uid 500); 11 May 2012 14:59:10 -0000 Delivered-To: apmail-incubator-ambari-commits-archive@incubator.apache.org Received: (qmail 44269 invoked by uid 500); 11 May 2012 14:59:10 -0000 Mailing-List: contact ambari-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@incubator.apache.org Delivered-To: mailing list ambari-commits@incubator.apache.org Received: (qmail 44212 invoked by uid 99); 11 May 2012 14:59:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 May 2012 14:59:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 May 2012 14:59:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BF6A62388847; Fri, 11 May 2012 14:58:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1337197 - in /incubator/ambari/branches/ambari-186: CHANGES.txt hmc/php/db/HMCDBAccessor.php hmc/php/db/test.php Date: Fri, 11 May 2012 14:58:45 -0000 To: ambari-commits@incubator.apache.org From: omalley@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120511145845.BF6A62388847@eris.apache.org> 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"] == "");