updateSubTransactionOpStatus($clusterName, $parentSubTxnId, $mySubTxnId, $opStatus); if ($subTransactionReturnValue["result"] != 0 ) { $logger->log_error("Got error while updating subTxn: ".$subTransactionReturnValue["error"]); print json_encode($subTransactionReturnValue); return; } $stageName = "findSshableNodes"; $cmdLine = getCommandLine(); // $hosts = explode(",", $hostsStr); runPdsh($clusterName, $stageName, $deployUser, $readFromFile, $cmdLine); ////////////// now read the per-host output files to get ssh-able information about each node //////////////// $clusterDir = getClusterDir($clusterName); $commandOutputDir = $clusterDir . $stageName . "/"; $allHosts = array(); $finalOpStatus = "SUCCESS"; $numTotalNodes = 0; $numNodesSucceeded = 0; $numNodesFailed = 0; if ($dirHandle = opendir($commandOutputDir)) { while (false !== ($entry = readdir($dirHandle))) { if ($entry == "." || $entry == "..") { continue; } $nodeStatus = "SUCCESS"; // Only consider .out files if(!preg_match("/.out/", $entry)) { continue; } $nodeName = basename($entry, ".out"); $nodeStatus = "SUCCESS"; $doneFile = $commandOutputDir . $nodeName . ".done"; if (file_exists($doneFile)) { // Read the contents of the done-file $doneFileContents = file_get_contents($doneFile); if (trim($doneFileContents) != "0") { $numNodesFailed += 1; $nodeStatus = "FAILED"; $finalOpStatus = "FAILED"; $logger->log_debug( "Contents of done file for $clusterName : $doneFileContents"); } } else { $numNodesFailed += 1; $nodeStatus = "FAILED"; $finalOpStatus = "FAILED"; } // Initialize this host's array $thisHostArray = array(); $thisHostArray["hostName"] = strtolower($nodeName); $thisHostArray["totalMem"] = 0; $thisHostArray["cpuCount"] = 0; $thisHostArray["osArch"] = ""; $thisHostArray["disksInfo"] = json_encode(array()); $thisHostArray["osType"] = ""; $thisHostArray["os"] = ""; $thisHostArray["ip"] = $nodeName; // To be unique if ($nodeStatus != "FAILED") { $sshContents = file_get_contents($commandOutputDir.$entry); if ($sshContents == "") { $numNodesFailed += 1; $finalOpStatus = "FAILED"; $nodeStatus = "FAILED"; } } // since node status can be updated in the above block as well. if ($nodeStatus != "FAILED") { $numNodesSucceeded += 1; } else { $thisHostArray["badHealthReason"] = rtrim(file_get_contents($commandOutputDir.$nodeName . ".err")); } $thisHostArray["discoveryStatus"] = $nodeStatus; array_push($allHosts, $thisHostArray); } closedir($dirHandle); } // Perisist the data to the db. $logger->log_info("Going to persist information sshAble nodes"); $returnValue = $dbAccessor->addHostsToCluster($clusterName, $allHosts); if ($returnValue["result"] != 0 ) { $logger->log_error("Got error while adding hosts: ".$returnValue["error"]); print json_encode($returnValue); return; } if ($numNodesSucceeded == 0) { $finalOpStatus = "TOTALFAILURE"; } $nodeFileOut = fopen($readFromFile, "w"); if ($nodeFileOut == FALSE) { $subTransactionReturnValue = $dbAccessor->updateSubTransactionOpStatus($clusterName, $parentSubTxnId, $mySubTxnId, "TOTALFAILURE"); $logger->log_error("Got error while trying to rewrite hosts file"); return; } // foreach successfully discovered host write the host list to the readFromFile foreach ($allHosts as $hostInfo) { if ($hostInfo["discoveryStatus"] == "FAILED") { continue; } // write the nodename to the readFromFile file. fwrite($nodeFileOut, $hostInfo["hostName"]."\n"); } fclose($nodeFileOut); $subTransactionReturnValue = $dbAccessor->updateSubTransactionOpStatus($clusterName, $parentSubTxnId, $mySubTxnId, $finalOpStatus); if ($subTransactionReturnValue["result"] != 0 ) { $logger->log_error("Got error while updating subTxn: ".$subTransactionReturnValue["error"]); print json_encode($subTransactionReturnValue); return; } ?>