manageServicesPostProcess.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/clusterState.php';
  28. include_once 'commandUtils.php';
  29. include_once "../util/HMCTxnUtils.php";
  30. function manageServicesPostProcess($clusterName, $user, $txnId, $progress)
  31. {
  32. $logger = new HMCLogger("ManageServicesPostProcess");
  33. $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  34. $result = 0;
  35. $error = "";
  36. /* Safe fallbacks, in case the call to getClusterState() below fails. */
  37. $state = "DEPLOYED";
  38. $displayName = "Deployed successfully";
  39. $context = array (
  40. 'status' => TRUE
  41. );
  42. $clusterStateResponse = $dbAccessor->getClusterState($clusterName);
  43. if ($clusterStateResponse['result'] != 0) {
  44. $logger->log_error("Failed to fetch cluster state (for restoration of stashed state)");
  45. $result = $clusterStateResponse["result"];
  46. $error = $clusterStateResponse["error"];
  47. }
  48. else {
  49. $clusterState = json_decode($clusterStateResponse['state'], true);
  50. $stashedDeployState = $clusterState["context"]["stashedDeployState"];
  51. /* Restore the cluster's state to that stashed at the time of beginning the
  52. * service management.
  53. */
  54. $state = $stashedDeployState["state"];
  55. $displayName = $stashedDeployState["displayName"];
  56. $context = $stashedDeployState["context"];
  57. }
  58. // update state of the cluster
  59. $retval = updateClusterState($clusterName, $state, $displayName, $context);
  60. if ($retval['result'] != 0) {
  61. $logger->log_error("Update cluster state failed");
  62. $result = $retval['result'];
  63. $error = $retval['error'];
  64. }
  65. return (array("result" => $result, "error" => $error));
  66. }
  67. ?>