You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/05/18 07:52:07 UTC

svn commit: r1339983 - in /incubator/ambari/branches/ambari-186: CHANGES.txt hmc/php/db/HMCDBAccessor.php hmc/php/util/clusterState.php

Author: hitesh
Date: Fri May 18 05:52:07 2012
New Revision: 1339983

URL: http://svn.apache.org/viewvc?rev=1339983&view=rev
Log:
AMBARI-277. API for getting cluster status. Contributed by Vikram

Added:
    incubator/ambari/branches/ambari-186/hmc/php/util/clusterState.php   (with props)
Modified:
    incubator/ambari/branches/ambari-186/CHANGES.txt
    incubator/ambari/branches/ambari-186/hmc/php/db/HMCDBAccessor.php

Modified: incubator/ambari/branches/ambari-186/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/CHANGES.txt?rev=1339983&r1=1339982&r2=1339983&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/CHANGES.txt (original)
+++ incubator/ambari/branches/ambari-186/CHANGES.txt Fri May 18 05:52:07 2012
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.x.x - unreleased
 
+  AMBARI-277. API for getting cluster status. (Vikram via hitesh)
+
   AMBARI-274. Templeton data on hdfs needs to be readable by all users (Ramya via hitesh)
 
   AMBARI-272. Remove occurrences of repo_url to support local yum repo (Ramya via hitesh)

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=1339983&r1=1339982&r2=1339983&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 18 05:52:07 2012
@@ -78,6 +78,45 @@ class HMCDBAccessor {
     LockRelease(); return $response;
   }
 
+  public function getClusterState ($clusterName) {
+    LockAcquire();
+    $response = array ( "clusterName" => $clusterName,
+        "result" => 0, "error" => "");
+    $ret = $this->dbHandle->beginTransaction();
+    if (!$ret) {
+      $error = $this->getLastDBErrorAsString();
+      $response["result"] = 1;
+      $response["error"] = "Failed to start DB transaction, error=".$error;
+      LockRelease(); return $response;
+    }
+    $query = "SELECT state FROM Clusters WHERE cluster_name = "
+        . $this->dbHandle->quote($clusterName);
+    $this->logger->log_trace("Running query: $query");
+    $pdoStmt = $this->dbHandle->query($query);
+    if ($pdoStmt === FALSE) {
+      $error = $this->getLastDBErrorAsString();
+      $this->dbHandle->rollBack();
+      $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);
+
+    LockRelease();
+
+    if (isset($result) && is_array($result) && count($result) == 1) {
+      $response[$clusterName] = $result[0]["state"];
+      return $response;
+    }
+
+    $response["result"] = 1;
+    $response["error"] = "Result is not set or not array or count is not 1 ".json_encode($result);
+    return $response;
+  }
+
   /**
    * Update cluster state for a given clusterName
    * @param string $clusterName Cluster Name

Added: incubator/ambari/branches/ambari-186/hmc/php/util/clusterState.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/util/clusterState.php?rev=1339983&view=auto
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/util/clusterState.php (added)
+++ incubator/ambari/branches/ambari-186/hmc/php/util/clusterState.php Fri May 18 05:52:07 2012
@@ -0,0 +1,19 @@
+<?php
+
+include_once '../php/util/Logger.php';
+include_once '../php/conf/Config.inc';
+include_once '../php/frontend/localDirs.php';
+include_once "../php/util/lock.php";
+include_once '../php/db/HMCDBAccessor.php';
+
+// initial setup
+$logger = new HMCLogger("sequentialScriptExecutor");
+$dbHandle = new HMCDBAccessor($GLOBALS["DB_PATH"]);
+
+function needWipeOut ($clusterName) {
+  global $logger, $dbHandle;
+  $clusterStatus = $dbHandle->getClusterStatus($clusterName);
+  return $clusterStatus;
+}
+
+?>

Propchange: incubator/ambari/branches/ambari-186/hmc/php/util/clusterState.php
------------------------------------------------------------------------------
    svn:eol-style = native