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); $logger->log_debug("Components are ".json_encode($components)); $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 = $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; } } $deployAddedNodesResult = $hmc->deployNodes($goodHosts); $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 = $clusterState['context']['txnId']; } /* Create the output data... */ $jsonOutput = array( 'clusterName' => $clusterName, 'txnId' => $txnId ); /* ...and spit it out. */ header("Content-type: application/json"); print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput))); ?>