$txnStatus, 'txnId' => $txnId ); LockAcquire(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX); $retval = updateClusterState($clusterName, $state, $displayName, $context); LockRelease(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX); return $retval; } /////// launch the stages in the background. $stagesFile = "./uninstall/stages.php"; $logger->log_info("ClusterName: $clusterName\n"); $logger->log_info("Deploy User: $deployUser\n"); $status = ""; $createTxResult = HMCTxnUtils::createNewTransaction($dbAccessor, $clusterName, $status); if ($createTxResult == FALSE) { $msg = "SETUP: Failed to create new transaction in background: $createTxResult\n"; $logger->log_error($msg); return array("result" => 1, "error" => "$msg"); } $rootTxnId = $createTxResult; $logger->log_info("Root Txn Id = $rootTxnId\n"); $cmd = $GLOBALS["PHP_EXEC_PATH"] . " " . "../util/sequentialScriptRunner.php"; // $cmd = $GLOBALS["PHP_EXEC_PATH"] . " " . "./addNodes/addNodesOrchestrator.php"; $hostsFile = getHostsFilePath($clusterName); $args = "$clusterName $deployUser $rootTxnId $hostsFile $stagesFile"; $execBackgroundResult = HMCTxnUtils::execBackgroundProcess($dbAccessor, $clusterName, $rootTxnId, $cmd, $args, ""); if ($execBackgroundResult == FALSE) { $msg = "Failed to execute addNodesOrchestrator in background: $execBackgroundResult\n"; $logger->log_error($msg); return array("result" => 1, "error" => "$msg"); } /////// done launching stages /////// now monitor the stages $allDone = false; while ($allDone == false) { // use the txn id for finding the status to pass back to the user // the orchestrator txn id could potentially return an error because // there is a potential race condition before the orchestrator txnId has // been committed to the db by the backgrounded process. $dbHandle = new HMCDBAccessor($GLOBALS["DB_PATH"]); $orchestratorTxnId = $dbHandle->getAllSubTransactionsInfo( $clusterName, $rootTxnId); if ($orchestratorTxnId['result'] != 0) { // encountered error $logger->log_error("Empty orchestrator txn id " . json_encode($orchestratorTxnId)); // Check if this should return error FIXME // $jsonOutput['encounteredError'] = true; return (array('result' => 1, 'error' => $orchestratorTxnId['error'])); } // as soon as DB is read, sleep for 2 seconds because we want to // avoid continuous polling of the db sleep(2); //$logger->log_error(" ==== subTxns info is " . json_encode($orchestratorTxnId)); $keys = array_keys($orchestratorTxnId['subTxns']); if (count($keys) == 0) { $logger->log_debug("No keys found in orchestrator's child transactions"); continue; } $firstKey = $keys[0]; if ($firstKey == '') { continue; } $allSubTxns = $dbHandle->getAllSubTransactionsInfo( $clusterName, $firstKey); // the all sub txn ids could potentially return an error because // there is a potential race condition before the orchestrator's subTxnId has // been committed to the db by the backgrounded process. if ($allSubTxns['result'] != 0) { $logger->log_error("Empty orchestrator txn id " . json_encode($allSubTxns)); return ($jsonOutput); } $logger->log_debug("allsubtxn count is ".json_encode(count($allSubTxns['subTxns']))); $logger->log_debug("stages count is ".json_encode(count($stagesInfo))); $logger->log_debug("subtxns ".json_encode($allSubTxns)); // allDone must be set once the processes launched have completed running if ((count($allSubTxns['subTxns']) == count($stagesInfo))) { $lastTxn = end($allSubTxns['subTxns']); if (($lastTxn['opStatus'] == "SUCCESS")) { $allDone = true; $result = 0; $error = ""; } else if (($lastTxn['opStatus'] == "FAILED") || ($lastTxn['opStatus'] == "TOTALFAILURE")) { $logger->log_debug(""); $allDone = true; $error = json_encode($lastTxn['state']); $result = 1; } } } /////// done monitoring return back to the uninstall if ($result != 0) { return array('result' => $result, 'error' => $error); } // need to cleanup db for this cluster $dbAccessor->cleanupCluster($clusterName); LockAcquire(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX); $clusterStateResponse = $dbAccessor->getClusterState($clusterName); if ($clusterStateResponse['result'] != 0) { LockRelease(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX); return $clusterStateResponse; } $clusterState = json_decode($clusterStateResponse['state'], true); // set cluster state to not configured $state = "NOT_CONFIGURED"; $displayName = "Uninstall succeeded"; $retval = updateClusterState($clusterName, $state, $displayName, $clusterState['context']); LockRelease(HMC_CLUSTER_STATE_LOCK_FILE_SUFFIX); return $retval; } ?>