Pārlūkot izejas kodu

AMBARI-277. API for getting cluster status. Contributed by Vikram

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/ambari-186@1339983 13f79535-47bb-0310-9956-ffa450edef68
Hitesh Shah 13 gadi atpakaļ
vecāks
revīzija
16b63c0952
3 mainītis faili ar 60 papildinājumiem un 0 dzēšanām
  1. 2 0
      CHANGES.txt
  2. 39 0
      hmc/php/db/HMCDBAccessor.php
  3. 19 0
      hmc/php/util/clusterState.php

+ 2 - 0
CHANGES.txt

@@ -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)

+ 39 - 0
hmc/php/db/HMCDBAccessor.php

@@ -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

+ 19 - 0
hmc/php/util/clusterState.php

@@ -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;
+}
+
+?>