incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vik...@apache.org
Subject svn commit: r1347356 - in /incubator/ambari/branches/ambari-186: ./ hmc/html/ hmc/js/ hmc/php/frontend/
Date Thu, 07 Jun 2012 03:29:19 GMT
Author: vikram
Date: Thu Jun  7 03:29:18 2012
New Revision: 1347356

URL: http://svn.apache.org/viewvc?rev=1347356&view=rev
Log:
AMBARI-508. Support Resume For Add Nodes (Contributed by Varun)

Added:
    incubator/ambari/branches/ambari-186/hmc/html/showDeployAddedNodesProgress.php
    incubator/ambari/branches/ambari-186/hmc/js/showDeployAddedNodesProgress.js
    incubator/ambari/branches/ambari-186/hmc/php/frontend/restoreDeployedStatePostProcess.php
Modified:
    incubator/ambari/branches/ambari-186/CHANGES.txt
    incubator/ambari/branches/ambari-186/hmc/js/deployAddedNodesProgress.js
    incubator/ambari/branches/ambari-186/hmc/js/reviewAndDeploy.js
    incubator/ambari/branches/ambari-186/hmc/js/selectComponents.js
    incubator/ambari/branches/ambari-186/hmc/php/frontend/deployAddedNodes.php
    incubator/ambari/branches/ambari-186/hmc/php/frontend/fetchTxnProgress.php

Modified: incubator/ambari/branches/ambari-186/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/CHANGES.txt?rev=1347356&r1=1347355&r2=1347356&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/CHANGES.txt (original)
+++ incubator/ambari/branches/ambari-186/CHANGES.txt Thu Jun  7 03:29:18 2012
@@ -6,6 +6,8 @@ characters wide.
 
 Release 0.1.x - unreleased
 
+  AMBARI-508. Support Resume For Add Nodes (Varun via Vikram)
+
   AMBARI-506. Do not use epel in local yum repo installs (Hitesh via Vikram)
 
   AMBARI-507. Install rpms instead of tar.gz downloads (Ramya via Vikram)

Added: incubator/ambari/branches/ambari-186/hmc/html/showDeployAddedNodesProgress.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/html/showDeployAddedNodesProgress.php?rev=1347356&view=auto
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/html/showDeployAddedNodesProgress.php (added)
+++ incubator/ambari/branches/ambari-186/hmc/html/showDeployAddedNodesProgress.php Thu Jun
 7 03:29:18 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/deployAddedNodesProgress.js',
+        'js/showDeployAddedNodesProgress.js' 
+      ];
+    </script>
+
+    <?php require "./bootstrapJs.htmli"; ?>
+    <!-- End of Javascript Scaffolding -->
+  </body>
+</html> 

Modified: incubator/ambari/branches/ambari-186/hmc/js/deployAddedNodesProgress.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/js/deployAddedNodesProgress.js?rev=1347356&r1=1347355&r2=1347356&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/js/deployAddedNodesProgress.js (original)
+++ incubator/ambari/branches/ambari-186/hmc/js/deployAddedNodesProgress.js Thu Jun  7 03:29:18
2012
@@ -1,112 +1,106 @@
-function DeployAddedNodes() {
+function generateLogsContent(errorInfoJson) {
+  return '<pre>' +
+           globalYui.JSON.stringify( errorInfoJson.logs, null, 4 ) +
+         '</pre>';
+}
+  
+function renderDeployAddedNodesProgress(progressInfo) {
+
+  hideLoadingImg();
+
+  /* At this point, our users are done with the installation wizard
+   * and have asked for a deploy, so there's no going back - remove
+   * all traces of #installationWizardProgressBarDivId.
+   */
+  var installationWizardProgressBarDiv = globalYui.one('#installationWizardProgressBarDivId');
 
-  function generateLogsContent(errorInfoJson) {
-    return '<pre>' +
-             globalYui.JSON.stringify( errorInfoJson.logs, null, 4 ) +
-           '</pre>';
+  /* But be safe and perform this removal only if #installationWizardProgressBarDivId 
+   * actually exists on the page - this .js file is now being used in more 
+   * than one place, so this robustness is needed.
+   */
+  if (installationWizardProgressBarDiv) {
+    installationWizardProgressBarDiv.setStyle('display', 'none')
   }
-    
-  this.renderProgress = function(progressInfo) {
-  
-    hideLoadingImg();
-  
-    /* At this point, our users are done with the installation wizard
-     * and have asked for a deploy, so there's no going back - remove
-     * all traces of #installationWizardProgressBarDivId.
-     */
-    var installationWizardProgressBarDiv = globalYui.one('#installationWizardProgressBarDivId');
-  
-    /* But be safe and perform this removal only if #installationWizardProgressBarDivId 
-     * actually exists on the page - this .js file is now being used in more 
-     * than one place, so this robustness is needed.
-     */
-    if (installationWizardProgressBarDiv) {
-      installationWizardProgressBarDiv.setStyle('display', 'none')
-    }
-  
-    var progressStatusMessage = {
-  
-      success:
-        '<p>' +
-          'Successfully added new nodes to your cluster.<br><a href="index.php"
id="addMoreNodesSuccessLink" style="margin-top:10px" class="btn btn-large">Continue</a>'
+ 
-        '</p>',
-      failure:
-        '<p>' +
-          'Failed to add new nodes to the cluster.<br>Take a look at the ' +
-            '<a href="javascript:void(null)" id="showDeployTxnLogsLinkId">deploy logs</a>'
+
-          ' to find out what might have gone wrong.' +
-          '<a href="index.php" class="btn btn-large" style="margin-top:10px" id="addMoreNodesFailedLink">'
+ 
-          'Continue' +
-          '</a>' +
-        '</p>'
-    };
-  
-    var postCompletionFixup = {
-  
-      success: function(txnProgressWidget) {  
-      },
-  
-      failure: function(txnProgressWidget) {
-  
-        /* Create the panel that'll display our error info. */
-        var errorInfoPanel = 
-          createInformationalPanel( '#informationalPanelContainerDivId', 'Deploy Logs' );
-  
-        /* Prime the panel to start off showing our stock loading image. */
-        var errorInfoPanelBodyContent = 
-          '<img id="errorInfoPanelLoadingImgId" class="loadingImg" src="../images/loading.gif"
/>';
-  
-        /* Make the call to our backend to fetch the report for this txnId. */
-        globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' + 
-          txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId,
{
-            
-            timeout: 10000,
-            on: {
-              success: function (x,o) {
-  
-                globalYui.log("RAW JSON DATA: " + o.responseText);
-  
-                var errorInfoJson = null;
-  
-                // Process the JSON data returned from the server
-                try {
-                  errorInfoJson = globalYui.JSON.parse(o.responseText);
-                }
-                catch (e) {
-                  alert("JSON Parse failed!");
-                  return;
-                }
-  
-                /* TODO XXX Remove some of the noise from this to allow
-                 * for better corelation - for now, just dump a 
-                 * pretty-printed version of the returned JSON.
-                 */
-                errorInfoPanelBodyContent = generateLogsContent(errorInfoJson);
-  
-                /* Update the contents of errorInfoPanel (which was, till
-                 * now, showing the loading image). 
-                 */
-                errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
-              },
-              failure: function (x,o) {
-                alert("Async call failed!");
+
+  var progressStatusMessage = {
+
+    success:
+      '<p>' +
+        'Successfully added new nodes to your cluster.<br><a href="index.php" id="addMoreNodesSuccessLink"
style="margin-top:10px" class="btn btn-large">Continue</a>' + 
+      '</p>',
+    failure:
+      '<p>' +
+        'Failed to add new nodes to the cluster.<br>Take a look at the ' +
+          '<a href="javascript:void(null)" id="showDeployTxnLogsLinkId">deploy logs</a>'
+
+        ' to find out what might have gone wrong.' +
+        '<a href="index.php" class="btn btn-large" style="margin-top:10px" id="addMoreNodesFailedLink">'
+ 
+        'Continue' +
+        '</a>' +
+      '</p>'
+  };
+
+  var postCompletionFixup = {
+
+    failure: function(txnProgressWidget) {
+
+      /* Create the panel that'll display our error info. */
+      var errorInfoPanel = 
+        createInformationalPanel( '#informationalPanelContainerDivId', 'Deploy Logs' );
+
+      /* Prime the panel to start off showing our stock loading image. */
+      var errorInfoPanelBodyContent = 
+        '<img id="errorInfoPanelLoadingImgId" class="loadingImg" src="../images/loading.gif"
/>';
+
+      /* Make the call to our backend to fetch the report for this txnId. */
+      globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' + 
+        txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId,
{
+          
+          timeout: 10000,
+          on: {
+            success: function (x,o) {
+
+              globalYui.log("RAW JSON DATA: " + o.responseText);
+
+              var errorInfoJson = null;
+
+              // Process the JSON data returned from the server
+              try {
+                errorInfoJson = globalYui.JSON.parse(o.responseText);
               }
-          }
-        });
-  
-        /* Register a click-handler for #showDeployTxnLogsLinkId to render 
-         * the contents inside errorInfoPanel (and make it visible). 
-         */
-        globalYui.one("#showDeployTxnLogsLinkId").on( "click", function(e) {
-          errorInfoPanel.set('bodyContent', errorInfoPanelBodyContent);
-          errorInfoPanel.show();
-  
-        });
-      }
-    };
+              catch (e) {
+                alert("JSON Parse failed!");
+                return;
+              }
+
+              /* TODO XXX Remove some of the noise from this to allow
+               * for better corelation - for now, just dump a 
+               * pretty-printed version of the returned JSON.
+               */
+              errorInfoPanelBodyContent = generateLogsContent(errorInfoJson);
+
+              /* Update the contents of errorInfoPanel (which was, till
+               * now, showing the loading image). 
+               */
+              errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
+            },
+            failure: function (x,o) {
+              alert("Async call failed!");
+            }
+        }
+      });
+
+      /* Register a click-handler for #showDeployTxnLogsLinkId to render 
+       * the contents inside errorInfoPanel (and make it visible). 
+       */
+      globalYui.one("#showDeployTxnLogsLinkId").on( "click", function(e) {
+        errorInfoPanel.set('bodyContent', errorInfoPanelBodyContent);
+        errorInfoPanel.show();
+
+      });
+    }
+  };
+
+  var progressWidget = new TxnProgressWidget(progressInfo, 'Add Nodes Progress', progressStatusMessage,
postCompletionFixup);
   
-    var progressWidget = new TxnProgressWidget(progressInfo, 'Add Nodes', progressStatusMessage,
postCompletionFixup);
-    
-    progressWidget.show();
-  } 
-};
+  progressWidget.show();
+} 

Modified: incubator/ambari/branches/ambari-186/hmc/js/reviewAndDeploy.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/js/reviewAndDeploy.js?rev=1347356&r1=1347355&r2=1347356&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/js/reviewAndDeploy.js (original)
+++ incubator/ambari/branches/ambari-186/hmc/js/reviewAndDeploy.js Thu Jun  7 03:29:18 2012
@@ -44,7 +44,7 @@ function renderDeploySummary (deployInfo
         if (type == "checkbox") {
           readOnlyAttr = 'disabled="disabled"';
           var checkVal = perServiceInfo.properties[mPropertiesKey].value;
-          if (checkVal) {
+          if (checkVal == 'true') {
             valueAttr = 'checked=yes';
           } else {
             valueAttr = '';
@@ -95,7 +95,6 @@ globalYui.one('#deploySubmitButtonId').o
     submitDataAndProgressToNextScreen(url, requestData, submitButton, thisScreenId, nextScreenId,
nextScreenRenderFunction);
 });
 
-
 function renderDeploy (deployInfo) {
   globalDeployInfo = deployInfo;
   var inputUrl = "../php/frontend/fetchClusterServices.php?clusterName=" + deployInfo.clusterName
+ "&getConfigs=true&getComponents=true";

Modified: incubator/ambari/branches/ambari-186/hmc/js/selectComponents.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/js/selectComponents.js?rev=1347356&r1=1347355&r2=1347356&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/js/selectComponents.js (original)
+++ incubator/ambari/branches/ambari-186/hmc/js/selectComponents.js Thu Jun  7 03:29:18 2012
@@ -99,46 +99,12 @@ globalYui.one('#deployAddedNodesSubmitBu
     e.target.set('disabled', true);
 
     var deployRequestData = getSelectedComponents();
-    var deployAddedNodes = new DeployAddedNodes();
-    
-    globalYui.io("../php/frontend/deployAddedNodes.php?clusterName="+ InstallationWizard.SelectServicesForNewNodes.renderData.clusterName,
{
-      method: 'POST',
-      data: globalYui.JSON.stringify(deployRequestData),
-      timeout : 10000,
-      on: {
-        start: function(x, o) {
-          e.target.set('disabled', false);
-          showLoadingImg();
-        },
-        complete: function(x, o) {
-          e.target.set('disabled', false);
-          hideLoadingImg();
-        },
-        success: function (x,o) {
-          globalYui.log("RAW DEPLOY DATA: " + o.responseText);
 
-          try {
-            deployProgressInfoJson = globalYui.JSON.parse(o.responseText);
-          } catch (e) {
-            alert("JSON Parse failed!");
-            return;
-          }
-
-          globalYui.log("PARSED DATA: " + globalYui.Lang.dump(deployProgressInfoJson));
-
-          /* Done with this stage, transition to the next. */
-          transitionToNextStage( "#selectServicesCoreDivId", deployRequestData, "#txnProgressCoreDivId",
deployProgressInfoJson, deployAddedNodes.renderProgress);
-
-          /* At this point, our users are done with the installation wizard
-          * and have asked for a deploy, so there's no going back - remove
-          * all traces of #installationWizardProgressBarDivId.
-          */
-          globalYui.one('#installationWizardProgressBarDivId').setStyle('display', 'none');
-        },
-      failure: function (x,o) {
-        e.target.set('disabled', false);
-        alert("Async call failed!");
-      }
-    }
-  });
+    var url = "../php/frontend/deployAddedNodes.php?clusterName=" + InstallationWizard.SelectServicesForNewNodes.renderData.clusterName;
+    var requestData = deployRequestData;
+    var submitButton = e.target;
+    var thisScreenId = "#selectServicesCoreDivId";
+    var nextScreenId = "#txnProgressCoreDivId";
+    var nextScreenRenderFunction = renderDeployAddedNodesProgress;
+    submitDataAndProgressToNextScreen(url, requestData, submitButton, thisScreenId, nextScreenId,
nextScreenRenderFunction);
 });

Added: incubator/ambari/branches/ambari-186/hmc/js/showDeployAddedNodesProgress.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/js/showDeployAddedNodesProgress.js?rev=1347356&view=auto
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/js/showDeployAddedNodesProgress.js (added)
+++ incubator/ambari/branches/ambari-186/hmc/js/showDeployAddedNodesProgress.js Thu Jun  7
03:29:18 2012
@@ -0,0 +1,2 @@
+/* Main() */
+executeStage( '../php/frontend/deployAddedNodes.php?clusterName=' + clusterName, renderDeployAddedNodesProgress
);

Modified: incubator/ambari/branches/ambari-186/hmc/php/frontend/deployAddedNodes.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/frontend/deployAddedNodes.php?rev=1347356&r1=1347355&r2=1347356&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/frontend/deployAddedNodes.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/frontend/deployAddedNodes.php Thu Jun  7
03:29:18 2012
@@ -12,103 +12,102 @@ 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";
 
-/* Now comes in from Config.inc
-$GLOBALS["HMC_LOG_LEVEL"] = HMCLogger::DEBUG;
-$GLOBALS["HMC_LOG_FILE"] = "/tmp/orchestrator-test.log";
-$GLOBALS["BACKGROUND_EXECUTOR_PATH"] = "../util/BackgroundExecutor.php";
-$GLOBALS["PHP_EXEC_PATH"] = "/usr/bin/php";
-$GLOBALS["CLUSTERMAIN_PATH"] = "../orchestrator/ClusterMain.php";
-$GLOBALS["puppetManifestDir"] = "/etc/puppet/master/manifests/";
-$GLOBALS["puppetKickVersionFile"] = "/tmp/puppet_kick_version.txt";
-$GLOBALS["puppetReportsDir"] = "/usr/local/rvm/gems/ruby-1.8.7-p358/gems/puppet-2.7.9/lib/puppet/reports/";
-$GLOBALS["puppetKickTimeout"] = 60;
-$GLOBALS["puppetMaxParallelKicks"] = 10;
-$GLOBALS["DRYRUN"] = FALSE;
-*/
-
-/* vinodkv
-system("mkdir -p ".$GLOBALS["puppetManifestDir"]);
-system("mkdir -p ".$GLOBALS["puppetReportsDir"]);
-*/
+$dbPath = $GLOBALS["DB_PATH"];
+$clusterName = $_GET['clusterName'];
+
+/* For returning in our JSON at the very end. */
+$result = 0;
+$error = "";
 
+$txnId = -1;
 
 $logger = new HMCLogger("deployAddedNodes");
-$dbHandle = new HMCDBAccessor($GLOBALS["DB_PATH"]);
 
-$dbPath = $GLOBALS["DB_PATH"];
-$clusterName = $_GET['clusterName'];
-$readFromFile = getHostsFilePath($clusterName);
+$dbAccessor = new HMCDBAccessor($dbPath);
+$clusterStateResponse = $dbAccessor->getClusterState($clusterName);
+
+if ($clusterStateResponse['result'] != 0) {
+  print json_encode($clusterStateResponse);
+  return;
+}
+
+$clusterState = json_decode($clusterStateResponse['state'], true);
+
+/* Perform the actual addition of nodes only if this cluster is in a 
+ * deployed state (regardless of whether the deploy was a success or failure). 
+ */
+if ($clusterState['state'] == 'DEPLOYED') {
+
+  $readFromFile = getHostsFilePath($clusterName);
+
+  $requestData = file_get_contents('php://input');
+  $components = json_decode($requestData, true);
 
-$requestData = file_get_contents('php://input');
-$components = json_decode($requestData, true);
+  $logger->log_debug("Components are ".json_encode($components));
 
-$logger->log_debug("Components are ".json_encode($components));
+  $hmc = new HMC($dbPath, $clusterName);
 
-$startTime = time();
-$hmc = new HMC($dbPath, $clusterName);
-
-// Get info about all nodes from hosts file 
-// the host file has been pruned by the previous stage of addNodes
-$goodHosts = readHostsFile($readFromFile);
-$goodHosts = convertToLowerCase($goodHosts);
-
-$logger->log_debug("goodHosts: ".json_encode($goodHosts));
-
-/////// Insert roles for these nodes ////////
-foreach ($components as $componentName) {
-  $addHostsToComponentResult = $dbHandle->addHostsToComponent($clusterName, $componentName,
$goodHosts, "UNKNOWN", "UNKNOWN");
-  if ($addHostsToComponentResult["result"] != 0 ) {
-    $logger->log_error("Got error adding component $componentName :" .$addHostsToComponentResult["error"]);
-    print json_encode($addHostsToComponentResult);
-    return false;
+  // Get info about all nodes from hosts file 
+  // the host file has been pruned by the previous stage of addNodes
+  $goodHosts = readHostsFile($readFromFile);
+  $goodHosts = convertToLowerCase($goodHosts);
+
+  $logger->log_debug("goodHosts: ".json_encode($goodHosts));
+
+  /////// Insert roles for these nodes ////////
+  foreach ($components as $componentName) {
+    $addHostsToComponentResult = $dbAccessor->addHostsToComponent($clusterName, $componentName,
$goodHosts, "UNKNOWN", "UNKNOWN");
+    if ($addHostsToComponentResult["result"] != 0 ) {
+      $logger->log_error("Got error adding component $componentName :" .$addHostsToComponentResult["error"]);
+      print json_encode($addHostsToComponentResult);
+      return;
+    }
   }
-}
 
-$result = $hmc->deployNodes($goodHosts);
-//print_r($result);
+  $deployAddedNodesResult = $hmc->deployNodes($goodHosts);
 
-//assert($result["result"] == 0);
-assert(isset($result["txnId"]));
+  $txnId = $deployAddedNodesResult["txnId"];
+
+  /* (And when we kick off the node addition is the only time to update the 
+   * state of the cluster). 
+   */
+  $state = "NODE_ADDITION_IN_PROGRESS";
+  $displayName = "Node addition in progress";
+  $context = array (
+    'txnId' => $txnId,
+    /* We've come here only if the cluster is in the "DEPLOYED" state, so the 
+     * state we stash is the state at the end of the deploy - we'll restore 
+     * this state at the end of the service management action.
+     */
+    'stashedDeployState' => $clusterState
+  );
+
+  $retval = updateClusterState($clusterName, $state, $displayName, $context);
+  if ($retval['result'] != 0) {
+    $result = $retval['result'];
+    $error = $retval['error'];
+  }
+}
+/* In case a node addition is already running, just return the txnId 
+ * from the DB instead of kicking off a fresh action - this is so 
+ * we can try and preclude multiple additions occurring in parallel.
+ */
+elseif ($clusterState['state'] == 'NODE_ADDITION_IN_PROGRESS') {
 
-$txnId = $result["txnId"];
+  $txnId = $clusterState['context']['txnId'];
+}
 
 /* Create the output data... */
 $jsonOutput = array(
     'clusterName' => $clusterName,
-    'txnId' => $txnId );
+    'txnId' => $txnId
+  );
 
 /* ...and spit it out. */
 header("Content-type: application/json");
 
-print (json_encode($jsonOutput));
-
-/*
-do {
-  $curTime = time();
-  $progress = $hmc->getProgress($txnId);
-
-  print "Elapsed: " . ($curTime - $startTime) . " seconds \n";
-  print "Progress: \n";
-  print_r($progress);
-
-  print "======================";
-  print(file_get_contents($GLOBALS["puppetManifestDir"]."site.pp"));
-  print "======================";
-
-  if (!is_array($progress)
-      || $progress["result"] != 0
-      || !$progress["processRunning"]) {
-    print "Breaking loop now. Action completed \n";
-    break;
-  }
-} while ( 1 );
-
-print "======================\n";
-print "Getting puppet logs\n";
-print "======================\n";
-$logs = $hmc->getLogs($txnId);
-print_r($logs);
-*/
+print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput)));
 
 ?>

Modified: incubator/ambari/branches/ambari-186/hmc/php/frontend/fetchTxnProgress.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/frontend/fetchTxnProgress.php?rev=1347356&r1=1347355&r2=1347356&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/frontend/fetchTxnProgress.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/frontend/fetchTxnProgress.php Thu Jun  7
03:29:18 2012
@@ -7,7 +7,7 @@ include_once '../util/clusterState.php';
 include_once "uninstallCleanup.php";
 include_once "deployPostProcess.php";
 include_once "uninstallCleanup.php";
-include_once "manageServicesPostProcess.php";
+include_once "restoreDeployedStatePostProcess.php";
 
 $dbPath = $GLOBALS["DB_PATH"];
 
@@ -21,23 +21,26 @@ $map = array(
   "HMC::deployHDP" => array (
       "deployPostProcess"
   ),
+  "HMC::deployNodes" => array (
+      "restoreDeployedStatePostProcess"
+  ),
   "HMC::uninstallHDP" => array (
       "deBootStrap"
   ),
   "HMC::startAllServices" => array (
-      "manageServicesPostProcess"
+      "restoreDeployedStatePostProcess"
   ),
   "HMC::stopAllServices" => array (
-      "manageServicesPostProcess"
+      "restoreDeployedStatePostProcess"
   ),
   "HMC::startServices" => array (
-      "manageServicesPostProcess"
+      "restoreDeployedStatePostProcess"
   ),
   "HMC::stopServices" => array (
-      "manageServicesPostProcess"
+      "restoreDeployedStatePostProcess"
   ),
   "HMC::reconfigureServices" => array (
-      "manageServicesPostProcess"
+      "restoreDeployedStatePostProcess"
   )
 );
 

Added: incubator/ambari/branches/ambari-186/hmc/php/frontend/restoreDeployedStatePostProcess.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/frontend/restoreDeployedStatePostProcess.php?rev=1347356&view=auto
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/frontend/restoreDeployedStatePostProcess.php
(added)
+++ incubator/ambari/branches/ambari-186/hmc/php/frontend/restoreDeployedStatePostProcess.php
Thu Jun  7 03:29:18 2012
@@ -0,0 +1,67 @@
+<?php
+
+include_once '../util/Logger.php';
+include_once '../conf/Config.inc';
+include_once 'localDirs.php';
+include_once "../util/lock.php";
+include_once '../db/HMCDBAccessor.php';
+include_once '../util/clusterState.php';
+
+include_once 'commandUtils.php';
+include_once "../util/HMCTxnUtils.php";
+
+// common post process function for manage services, post deploy add nodes
+// Updates state back to DEPLOYED and associated success/failure
+function restoreDeployedStatePostProcess($clusterName, $user, $txnId, $progress)
+{
+  $logger = new HMCLogger("ManageServicesPostProcess");
+  $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
+
+  $result = 0;
+  $error = "";
+
+  /* Safe fallbacks, in case the call to getClusterState() below fails. */
+  $state = "DEPLOYED";
+  $displayName = "Deployed successfully";
+  $context = array (
+    'status' => TRUE
+  );
+
+
+  LockAcquire(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX);
+  $clusterStateResponse = $dbAccessor->getClusterState($clusterName);
+  LockRelease(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX);
+
+  if ($clusterStateResponse['result'] != 0) {
+    $logger->log_error("Failed to fetch cluster state (for restoration of stashed state)");
+
+    $result = $clusterStateResponse["result"];
+    $error = $clusterStateResponse["error"];
+  }
+  else {
+    $clusterState = json_decode($clusterStateResponse['state'], true);
+
+    $stashedDeployState = $clusterState["context"]["stashedDeployState"]; 
+    /* Restore the cluster's state to that stashed at the time of beginning the
+     * service management. 
+     */
+    $state = $stashedDeployState["state"];
+    $displayName = $stashedDeployState["displayName"];
+    $context = $stashedDeployState["context"];
+  }
+
+  // update state of the cluster 
+  LockAcquire(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX);
+  $retval = updateClusterState($clusterName, $state, $displayName, $context);
+  LockRelease(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX);
+
+  if ($retval['result'] != 0) {
+    $logger->log_error("Update cluster state failed");
+    $result = $retval['result'];
+    $error = $retval['error'];
+  }
+
+  return (array("result" => $result, "error" => $error));
+}
+
+?>



Mime
View raw message