123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?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 '../util/selectNodes.php';
- // include_once 'install_puppet.php';
- $logger = new HMCLogger("InitializeCluster");
- $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
- $selectNodes = new SelectNodes();
- header("Content-type: application/json");
- $clusterName = $_GET['clusterName'];
- // Validate clusterId: TODO; FIXME
- // We need to clean up prior instances for this cluster name
- $dbAccessor->cleanupServices($clusterName);
- // Read from the input
- $requestdata = file_get_contents('php://input');
- $requestObj = json_decode($requestdata, true);
- $deployUser = $requestObj['ClusterDeployUser'];
- // Persist the services enabled stuff
- $servicesCheckList = $requestObj["services"];
- // create local copy for easy lookup
- $tempLocalServicesCopy = array();
- foreach($servicesCheckList as $serviceInfo) {
- $tempLocalServicesCopy[$serviceInfo["serviceName"]] = array("isEnabled" => $serviceInfo["isEnabled"]);
- }
- $logger->log_debug("temp local".json_encode($tempLocalServicesCopy)."========");
- $svcDepsListArr = $dbAccessor->getAllServiceDependencies();
- if ($svcDepsListArr["result"] != 0) {
- $logger->log_error("Got error while getting service dependencies: ".$svcDepsListArr["error"]);
- print json_encode($svcDepsListArr);
- return;
- }
- $svcDepsList = $svcDepsListArr["serviceDependencies"];
- // generate full svc list based on dep tree
- $localServicesCopy = array();
- foreach ($tempLocalServicesCopy as $svcName => $svcInfo) {
- if (!$svcInfo["isEnabled"]
- && !isset($localServicesCopy[$svcName])) {
- $localServicesCopy[$svcName] = $svcInfo;
- continue;
- }
- $localServicesCopy[$svcName] = array("isEnabled" => TRUE);
- $svcDeps = $dbAccessor->getRecursiveServiceDependency(
- $svcDepsList, $svcName);
- if (is_array($svcDeps)) {
- foreach ($svcDeps as $svcDep) {
- $localServicesCopy[$svcDep] = array("isEnabled" => TRUE);
- }
- }
- }
- $servicesCheckList = array();
- foreach ($localServicesCopy as $svcName => $svcInfo) {
- $svcInfo["serviceName"] = $svcName;
- array_push($servicesCheckList, $svcInfo);
- }
- $logger->log_debug("svc list".json_encode($servicesCheckList)."========");
- $dbResponse = $dbAccessor->addServicesToCluster($clusterName, $servicesCheckList);
- if ($dbResponse["result"] != 0) {
- $logger->log_error("Got error while adding service: ".$dbResponse["error"]);
- print json_encode($dbResponse);
- return;
- }
- $jsonOutput["clusterName"] = $clusterName;
- // Populate all hosts for the UI
- $jsonOutput["allHosts"] = array();
- /*
- * FIXME need to get all hosts from select Nodes script
- */
- $allHostsInfo = $dbAccessor->getAllHostsInfo($clusterName,
- array("=" => array ( "discoveryStatus" => "SUCCESS")),
- array(
- array("sortColumn" => "totalMem", "sortOrder" => "DESC"),
- array("sortColumn" => "cpuCount", "sortOrder" => "DESC"),
- array("sortColumn" => "hostName", "sortOrder" => "ASC")
- )
- );
- if ($allHostsInfo["result"] != 0 ) {
- $logger->log_error("Got error while getting hostsInfo ".$allHostsInfo["error"]);
- print json_encode($allHostsInfo);
- return;
- }
- $logger->log_debug("HOSTS_INFO: ".json_encode($allHostsInfo["hosts"]));
- foreach($allHostsInfo["hosts"] as $hostInfo) {
- $logger->log_debug("HOST: ".json_encode($hostInfo));
- array_push($jsonOutput["allHosts"], $hostInfo);
- }
- // bootstrap($jsonOutput["allHosts"], getSshKeyFilePath($clusterName));
- $suggestedNodes = $selectNodes->selectNodes($clusterName,
- $dbAccessor);
- //////////////////// Populate service masters for the UI ///////////////////////////
- $jsonOutput["services"] = array();
- $allServicesArray = $dbAccessor->getAllServicesList();
- if ($allServicesArray["result"] != 0 ) {
- $logger->log_error("Got error while getting all services list ".$allServicesArray["error"]);
- print json_encode($allServicesArray);
- return;
- }
- $allServicesInfo = $dbAccessor->getAllServicesInfo($clusterName);
- if ($allServicesInfo["result"] != 0 ) {
- $logger->log_error("Got error while getting all services list ".$allServicesInfo["error"]);
- print json_encode($allServicesInfo);
- return;
- }
- foreach($allServicesArray["services"] as $service) {
- $thisService = array();
- $serviceName = $service["serviceName"];
- $thisService["enabled"] = $allServicesInfo["services"][$serviceName]["isEnabled"];
- $thisService["masters"] = array();
- $allServiceComponents = $dbAccessor->getAllServiceComponents($serviceName);
- if ($allServiceComponents["result"] != 0 ) {
- $logger->log_error("Got error while getting all service compoenents:".$allServiceComponents["error"]);
- print json_encode($allServiceComponents);
- return;
- }
- foreach($allServiceComponents["components"] as $componentName => $component) {
- if($component["isMaster"] == 0) {
- continue;
- }
- $thisMaster = array();
- $hosts = $suggestedNodes["mastersToHosts"][$componentName]["hostNames"];
- $thisMaster["name"] = $component["componentName"];
- $thisMaster["displayName"] = $component["displayName"];
- $thisMaster["description"] = $component["description"];
- $thisMaster["hostNames"] =
- $hosts;
- array_push($thisService["masters"], $thisMaster);
- }
- array_push($jsonOutput["services"], $thisService);
- }
- //////////////////// End of populate service masters for the UI ///////////////////////////
- // Update the state of the cluster.
- $result = 0;
- $error = "";
- $state = "CONFIGURATION_IN_PROGRESS";
- $displayName = "Configuration in progress";
- $context = array (
- 'stage' => "SELECT_SERVICES"
- );
- $retval = updateClusterState($clusterName, $state, $displayName, $context);
- if ($retval['result'] != 0) {
- $result = $retval['result'];
- $error = $retval['error'];
- }
- print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput)));
- ?>
|