configureServices.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 './configUtils.php';
  28. include_once '../util/suggestProperties.php';
  29. include_once "../util/clusterState.php";
  30. $logger = new HMCLogger("Options");
  31. $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  32. // Read from the input
  33. $requestdata = file_get_contents('php://input');
  34. $requestObj = json_decode($requestdata, true);
  35. $clusterName = $_GET['clusterName'];
  36. // TODO: Validate clusterName
  37. $result = validateAndPersistConfigsFromUser($dbAccessor, $logger, $clusterName, $requestObj);
  38. if ($result['result'] != 0) {
  39. $logger->log_error("Failed to validate configs from user, error=" . $result["error"]);
  40. print json_encode($result);
  41. return;
  42. }
  43. $jsonOutput = array();
  44. $jsonOutput['clusterName'] = $clusterName;
  45. // Update the state of the cluster.
  46. $result = 0;
  47. $error = "";
  48. $state = "CONFIGURATION_IN_PROGRESS";
  49. $displayName = "Configuration in progress";
  50. $context = array (
  51. 'stage' => "CONFIGURE_SERVICES"
  52. );
  53. $retval = updateClusterState($clusterName, $state, $displayName, $context);
  54. if ($retval['result'] != 0) {
  55. $result = $retval['result'];
  56. $error = $retval['error'];
  57. }
  58. print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput)));
  59. ?>