configureCluster.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. */
  22. include_once '../util/Logger.php';
  23. include_once '../conf/Config.inc';
  24. include_once 'localDirs.php';
  25. include_once "../util/lock.php";
  26. include_once '../db/HMCDBAccessor.php';
  27. include_once '../util/suggestProperties.php';
  28. include_once '../util/clusterState.php';
  29. $logger = new HMCLogger("ConfigureCluster");
  30. $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  31. header("Content-type: application/json");
  32. $clusterName = $_GET['clusterName'];
  33. // TODO: Validate clusterName
  34. $requestData = file_get_contents('php://input');
  35. $requestObj = json_decode($requestData, true);
  36. // persist the user entered mount points *******
  37. foreach ($requestObj["clusterConfig"] as $serviceName=>$objects) {
  38. $dbAccessor->updateServiceConfigs($clusterName, $objects);
  39. }
  40. // finished persisting the mount point info *******
  41. // logic for next stage *******
  42. // trigger script to do advanced config recommendations
  43. $suggestProperties = new SuggestProperties();
  44. $ret = $suggestProperties->suggestProperties($clusterName, $dbAccessor, TRUE);
  45. if ($ret["result"] != 0) {
  46. $logger->log_error("Failed to run advanced properties suggestion, error=".$ret["error"]);
  47. print (json_encode($ret));
  48. return;
  49. }
  50. // logic for next stage ends here *******
  51. // give back json data for the advanced cluster properties *******
  52. // Return a valid response
  53. $jsonOutput = array();
  54. $jsonOutput["clusterName"] = $clusterName;
  55. // Update the state of the cluster.
  56. $result = 0;
  57. $error = "";
  58. $state = "CONFIGURATION_IN_PROGRESS";
  59. $displayName = "Configuration in progress";
  60. $context = array (
  61. 'stage' => "CONFIGURE_CLUSTER"
  62. );
  63. $retval = updateClusterState($clusterName, $state, $displayName, $context);
  64. if ($retval['result'] != 0) {
  65. $result = $retval['result'];
  66. $error = $retval['error'];
  67. }
  68. print(json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput)));
  69. ?>