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:00:39 UTC

svn commit: r1347240 - in /incubator/ambari/branches/ambari-186: CHANGES.txt hmc/html/showUninstallProgress.php hmc/js/showUninstallProgress.js hmc/js/uninstallProgress.js hmc/php/frontend/deploy.php hmc/php/frontend/uninstall.php

Author: vikram
Date: Thu Jun  7 01:00:39 2012
New Revision: 1347240

URL: http://svn.apache.org/viewvc?rev=1347240&view=rev
Log:
AMBARI-436. Support Resume For Uninstall (Contributed by Varun)

Added:
    incubator/ambari/branches/ambari-186/hmc/html/showUninstallProgress.php
    incubator/ambari/branches/ambari-186/hmc/js/showUninstallProgress.js
Modified:
    incubator/ambari/branches/ambari-186/CHANGES.txt
    incubator/ambari/branches/ambari-186/hmc/js/uninstallProgress.js
    incubator/ambari/branches/ambari-186/hmc/php/frontend/deploy.php
    incubator/ambari/branches/ambari-186/hmc/php/frontend/uninstall.php

Modified: incubator/ambari/branches/ambari-186/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/CHANGES.txt?rev=1347240&r1=1347239&r2=1347240&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/CHANGES.txt (original)
+++ incubator/ambari/branches/ambari-186/CHANGES.txt Thu Jun  7 01:00:39 2012
@@ -6,6 +6,8 @@ characters wide.
 
 Release 0.1.x - unreleased
 
+  AMBARI-436. Support Resume For Uninstall (Varun via Vikram)
+
   AMBARI-435. Uninstall needs to update status for failure. (Vikram)
 
   AMBARI-434. fix display name in smoke test progress description (Hitesh via Vikram)

Added: incubator/ambari/branches/ambari-186/hmc/html/showUninstallProgress.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/html/showUninstallProgress.php?rev=1347240&view=auto
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/html/showUninstallProgress.php (added)
+++ incubator/ambari/branches/ambari-186/hmc/html/showUninstallProgress.php Thu Jun  7 01:00:39 2012
@@ -0,0 +1,45 @@
+<?php require_once "./head.inc" ?>
+<html>
+  <head>
+    <title id="pageTitleId"><?php echo $RES['page.title'] ?></title>
+
+    <!-- CSS -->
+    <link type="text/css" rel="stylesheet" href="../yui-3.5.1/build/cssreset/cssreset-min.css">
+    <link type="text/css" rel="stylesheet" href="../css/bootstrap.css" media="screen"/>
+    <link type="text/css" rel="stylesheet" href="../css/common.css" media="screen"/>
+    <link type="text/css" rel="stylesheet" href="../css/common2.css" media="screen"/>
+    <link type="text/css" rel="stylesheet" href="../css/common3.css" media="screen"/>
+    <link rel="shortcut icon" href="../images/logo-micro.gif">
+    <!-- End CSS -->
+  </head>
+
+  <body class="yui3-skin-sam">
+    <?php require "./topnav.htmli"; ?>
+
+    <div id="contentDivId"> 
+
+      <?php require "./utils.htmli"; ?>
+      <?php require "./txnUtils.htmli"; ?>
+
+    </div>
+    <!-- End of contentDivId -->
+
+    <?php require "./footer.htmli"; ?>
+
+    <!-- Javascript Scaffolding -->
+    <script type="text/javascript">
+      /* Minimal data required to bootstrap clusters.js. */
+      var clusterName = '<?php echo $clusterName; ?>';
+
+      var jsFilesToLoad = [ 
+        '../js/utils.js',
+        '../js/txnUtils.js',
+        '../js/uninstallProgress.js',
+        '../js/showUninstallProgress.js' 
+      ];
+    </script>
+
+    <?php require "./bootstrapJs.htmli"; ?>
+    <!-- End of Javascript Scaffolding -->
+  </body>
+</html> 

Added: incubator/ambari/branches/ambari-186/hmc/js/showUninstallProgress.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/js/showUninstallProgress.js?rev=1347240&view=auto
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/js/showUninstallProgress.js (added)
+++ incubator/ambari/branches/ambari-186/hmc/js/showUninstallProgress.js Thu Jun  7 01:00:39 2012
@@ -0,0 +1,2 @@
+/* Main() */
+executeStage( '../php/frontend/uninstall.php?clusterName=' + clusterName, renderUninstallProgress );

Modified: incubator/ambari/branches/ambari-186/hmc/js/uninstallProgress.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/js/uninstallProgress.js?rev=1347240&r1=1347239&r2=1347240&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/js/uninstallProgress.js (original)
+++ incubator/ambari/branches/ambari-186/hmc/js/uninstallProgress.js Thu Jun  7 01:00:39 2012
@@ -64,30 +64,19 @@ function renderUninstallProgress (uninst
 
   hideLoadingImg();
 
-  var hmcRestartMsg = '';
-  if (uninstallProgressInfo.nagiosGangliaCoHosted != null
-      && uninstallProgressInfo.nagiosGangliaCoHosted) {
-    hmcRestartMsg = '<strong>Note:</strong> We detected that you need to restart HMC as'
-        + ' Nagios/Ganglia are co-hosted on this server. <br/>Please restart'
-        + ' HMC using \"service hmc restart\". ';
-  } else {
-    hmcRestartMsg = '';
-  }
-
-  hmcRestartMsg += '' +
-      '<a href="javascript:void(null)" id=clustersListLinkId>' +
-        'Continue' +
-      '</a>';
 
   var uninstallProgressStatusMessage = {
 
     success:
       '<p style=\"text-align:center\">' +
-        'Uninstalled the cluster successfully.<br/>' + hmcRestartMsg +
+        'Uninstalled the cluster successfully.<br/>' +
+        '<a href="javascript:void(null)" id=clustersListLinkId>' +
+          'Continue' +
+        '</a>' +
       '</p>',
     failure:
       '<p>' +
-        'There was a problem with uninstall.  Take a look at ' +
+        'There was a problem with uninstall. Take a look at ' +
           '<a href="javascript:void(null)" id=showUninstallTxnLogsLinkId>Uninstall Logs</a>' +
         ' to see what might have happened.' +
       '</p>'

Modified: incubator/ambari/branches/ambari-186/hmc/php/frontend/deploy.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/frontend/deploy.php?rev=1347240&r1=1347239&r2=1347240&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/frontend/deploy.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/frontend/deploy.php Thu Jun  7 01:00:39 2012
@@ -14,7 +14,6 @@ include_once "../util/clusterState.php";
 $dbPath = $GLOBALS["DB_PATH"];
 $clusterName = $_GET['clusterName'];
 
-$startTime = time();
 $hmc = new HMC($dbPath, $clusterName);
 
 /* For returning in our JSON at the very end. */
@@ -53,7 +52,9 @@ if (($clusterState['state'] == 'CONFIGUR
 
   $txnId = $deployResult["txnId"];
 
-  /* (And when we kick off the deploy is the only time to update the state of the cluster) */
+  /* (And when we kick off the deploy is the only time to update the state of 
+   * the cluster).
+   */
   $state = "DEPLOYMENT_IN_PROGRESS";
   $displayName = "Deployment in progress";
   $context = array (
@@ -102,7 +103,6 @@ if (!$nagiosGangliaCoHosted) {
 
 /* Create the output data... */
 $jsonOutput = array(
-    'startTime' => $startTime,
     'clusterName' => $clusterName,
     'txnId' => $txnId,
     'nagiosGangliaCoHosted' => $nagiosGangliaCoHosted);

Modified: incubator/ambari/branches/ambari-186/hmc/php/frontend/uninstall.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/frontend/uninstall.php?rev=1347240&r1=1347239&r2=1347240&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/frontend/uninstall.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/frontend/uninstall.php Thu Jun  7 01:00:39 2012
@@ -9,73 +9,123 @@ include_once "../orchestrator/HMC.php";
 include_once "../db/OrchestratorDB.php";
 include_once "../puppet/DBReader.php";
 include_once "../puppet/PuppetInvoker.php";
+include_once "../util/clusterState.php";
 
-
-$logger = new HMCLogger("Uninstall");
-$dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
-
-$logger->log_debug("Uninstall invoked");
+$dbPath = $GLOBALS["DB_PATH"];
 $clusterName = $_GET['clusterName'];
-$action = $_GET['action'];
-$deployUser = $_GET['clusterDeployUser'];
 
-$wipeout = FALSE;
-if ($action == "wipeOut") {
-  $wipeout = TRUE;
-} else {
-  $wipeout = FALSE;
-}
+/* For returning in our JSON at the very end. */
+$result = 0;
+$error = "";
 
-////// need to generate the hosts.txt file with all the good nodes in the cluster
-$allHostsInfo = $dbAccessor->getAllHostsInfo($clusterName, 
-  array("=" => array ( "discoveryStatus" => "SUCCESS")));
-if ($allHostsInfo["result"] != 0 ) {
-  $logger->log_error("Got error while getting hostsInfo ".$allHostsInfo["error"]);
-  print json_encode($allHostsInfo);
-  return;
-}
+$txnId = -1;
+$deployUser = "";
 
-$hostFileName = getHostsFilePath($clusterName);
+$logger = new HMCLogger("Uninstall");
 
-$hostFileHdl = fopen($hostFileName, "w");
+$dbAccessor = new HMCDBAccessor($dbPath);
+$clusterStateResponse = $dbAccessor->getClusterState($clusterName);
 
-foreach ($allHostsInfo["hosts"] as $hostInfo) {
-  fwrite($hostFileHdl, $hostInfo["hostName"]."\n");
+if ($clusterStateResponse['result'] != 0) {
+  print json_encode($clusterStateResponse);
+  return;
 }
 
-fclose($hostFileHdl);
-////// end of generating new file
+$clusterState = json_decode($clusterStateResponse['state'], true);
 
-$logger->log_debug("Uninstall got wipeout value $wipeout");
+/* Run an actual uninstall only if this cluster is in a deployed state 
+ * (regardless of whether the deploy was a success or failure). 
+ */
+if ($clusterState['state'] == 'DEPLOYED') {
 
-$dbPath = $GLOBALS["DB_PATH"];
+  $logger->log_debug("Uninstall invoked");
 
-// call the wipeout script and return the transaction id
-$hmc = new HMC($dbPath, $clusterName);
+  $action = $_GET['action'];
+  $deployUser = $_GET['clusterDeployUser'];
 
-$startTime = time();
-$result = $hmc->uninstallHDP($wipeout);
-if ($result["result"] != 0) {
-  print json_encode($result);
-  return;
-}
-
-if (!isset($result["txnId"])) {
-  print json_encode ( array("result" => 1, "error" => "Could not obtain txn info for triggered command"));
+  $wipeout = FALSE;
+  if ($action == "wipeOut") {
+    $wipeout = TRUE;
+  } else {
+    $wipeout = FALSE;
+  }
+
+  ////// need to generate the hosts.txt file with all the good nodes in the cluster
+  $allHostsInfo = $dbAccessor->getAllHostsInfo($clusterName, 
+    array("=" => array ( "discoveryStatus" => "SUCCESS")));
+  if ($allHostsInfo["result"] != 0 ) {
+    $logger->log_error("Got error while getting hostsInfo ".$allHostsInfo["error"]);
+    print json_encode($allHostsInfo);
+    return;
+  }
+
+  $hostFileName = getHostsFilePath($clusterName);
+
+  $hostFileHdl = fopen($hostFileName, "w");
+
+  foreach ($allHostsInfo["hosts"] as $hostInfo) {
+    fwrite($hostFileHdl, $hostInfo["hostName"]."\n");
+  }
+
+  fclose($hostFileHdl);
+  ////// end of generating new file
+
+  $logger->log_debug("Uninstall got wipeout value $wipeout");
+
+  // call the wipeout script and return the transaction id
+  $hmc = new HMC($dbPath, $clusterName);
+
+  $uninstallResult = $hmc->uninstallHDP($wipeout);
+  if ($uninstallResult["result"] != 0) {
+    print json_encode($uninstallResult);
+    return;
+  }
+
+  if (!isset($uninstallResult["txnId"])) {
+    print json_encode ( array("result" => 1, "error" => "Could not obtain txn info for triggered command"));
+
+    return;
+  }
+
+  $txnId = $uninstallResult["txnId"];
+
+  /* (And when we kick off the uninstall is the only time to update the state 
+   * of the cluster). 
+   */
+  $state = "UNINSTALLATION_IN_PROGRESS";
+  $displayName = "Uninstallation in progress";
+  $context = array (
+    'txnId' => $txnId,
+    'deployUser' => $deployUser
+  );
 
-  return;
+  $retval = updateClusterState($clusterName, $state, $displayName, $context);
+  if ($retval['result'] != 0) {
+    $result = $retval['result'];
+    $error = $retval['error'];
+  }
 }
+/* In case the uninstall is already running or has ended, just return the txnId 
+ * and deployUser from the DB instead of kicking off a fresh uninstall - this 
+ * is so we can use this entrypoint to show the cluster's uninstall progress at 
+ * any time in the future, not just during a live uninstall. 
+ */
+elseif ($clusterState['state'] == 'UNINSTALLATION_IN_PROGRESS') {
 
-$txnId = $result["txnId"];
+  $txnId = $clusterState['context']['txnId'];
+  $deployUser = $clusterState['context']['deployUser'];
+}
 
+/* Create the output data... */
 $jsonOutput = array(
-    'startTime' => $startTime,
     'clusterName' => $clusterName,
-    'deployUser' => $deployUser,
     'txnId' => $txnId,
+    'deployUser' => $deployUser
   );
 
+/* ...and spit it out. */
 header("Content-type: application/json");
-print (json_encode(array("result" => 0, "error" => 0, "response" => $jsonOutput)));
+
+print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput)));
 
 ?>