getClusterState($clusterName); if ($clusterStateResponse['result'] != 0) { print json_encode($clusterStateResponse); return; } $clusterState = json_decode($clusterStateResponse['state'], true); $freshInstall = ($clusterState['state'] == 'CONFIGURATION_IN_PROGRESS') ? true : false; $clusterDir = getClusterDir($clusterName); $logString = "Cluster Name: $clusterName Cleanup required? $freshInstall and type: ".gettype($freshInstall); $logger->log_info($logString); // Validate clusterName: TODO; FIXME // We need to clean up prior instances for this // cluster name if this is a fresh install if ($freshInstall) { $dbAccessor->cleanupHosts($clusterName); } // Read from the input $deployUser = $_POST['ClusterDeployUser']; /////// Remove the cluster directory before copying the files $clusterDir = getClusterDir($clusterName); rrmdir($clusterDir); if (!is_dir($clusterDir) && !mkdir($clusterDir, 0700, true)) { print json_encode(array( "result" => 1, "error" => 'Failed to create directory...')); return; } ////// end of directory removal $identityFileDestination = getSshKeyFilePath($clusterName); $hostsFileDestination = getHostsFilePath($clusterName); // TODO: FIXME: Change echos to return error codes. //echo '
'; if (move_uploaded_file($_FILES['clusterDeployUserIdentityFile']['tmp_name'], $identityFileDestination)) { //echo "File is valid, and was successfully uploaded.\n"; // Set the permissions chmod($identityFileDestination, 0400);// TODO: Error conditions } else { $logger->log_error("Identity file copy to loc ".$identityFileDestination." failed"); //echo "Possible file upload attack!\n"; } if (move_uploaded_file($_FILES['clusterHostsFile']['tmp_name'], $hostsFileDestination)) { //echo "File is valid, and was successfully uploaded.\n"; } else { $logger->log_error("Hosts file copy to loc ".$hostsFileDestination." failed"); //echo "Possible file upload attack!\n"; } removeCarriageReturn($hostsFileDestination); header("Content-type: application/json"); // Validate that there are no nodes that are already in use in case of addNodesWizard $logger->log_info("Doing a fresh install: $freshInstall"); if (!$freshInstall) { // Get the list of current nodes $allHostsInfoResult = $dbAccessor->getAllHostsInfo("", array()); if ($allHostsInfoResult["result"] != 0 ) { $logger->log_error("Got error while getting hostInfo for $host :" .$allHostsInfoResult["error"]); print json_encode($allHostsInfoResult); return; } $unassignedHostResult = $dbAccessor->getAllUnassignedHosts($clusterName); if ($unassignedHostResult["result"] != 0) { print json_encode($unassignedHostResult); return; } $unassignedHostList = $unassignedHostResult["hosts"]; // See if they are duplicates $newHosts = readHostsFile($hostsFileDestination); $duplicateHosts = array(); $logger->log_debug("Checking for Duplicate Hosts."); foreach ($allHostsInfoResult["hosts"] as $hostInfo) { $logger->log_debug("Checking for Duplicate Hosts. hostname = ". $hostInfo["hostName"]. " key does not exist? " . array_key_exists($hostInfo["hostName"], $unassignedHostList). " incoming cluster name: $clusterName, host is part of cluster " .$hostInfo["clusterName"]); if (in_array($hostInfo["hostName"], $newHosts) && (!(array_key_exists($hostInfo["hostName"], $unassignedHostList)) || ($hostInfo["clusterName"] != $clusterName))) { if (!array_key_exists($hostInfo["clusterName"], $duplicateHosts)) { $duplicateHosts[$hostInfo["clusterName"]] = array(); } array_push($duplicateHosts[$hostInfo["clusterName"]], $hostInfo["hostName"]); } } $numDupHosts = count($duplicateHosts); $numNewHosts = count($newHosts); if ($numDupHosts != 0) { $logger->log_warn("Trying to add duplicate nodes to the cluster, dups=" . print_r($duplicateHosts, true)); print (json_encode(array("result" => 3, "error" => "Some hosts in the given file are already being used in cluster", "hosts" => $duplicateHosts))); return; } } else { // Update the state of the cluster. $state = "CONFIGURATION_IN_PROGRESS"; $displayName = "Configuration in progress"; $context = array ( 'stage' => "ADD_NODES" ); $retval = updateClusterState($clusterName, $state, $displayName, $context); } print (json_encode(array("result" => 0))); /* $outjson = array( "errorCode"=> $retval['result'], // "clusterName" => $clusterName, // "finalDestination" => $identityFileDestination, // "fileToBeMoved" => $_FILES['clusterDeployUserIdentityFile']['tmp_name'], ); */ // TODO: FIXME: Check file lengths. ?>