cluster.php

Classes

File

http/Provision/Service/http/cluster.php
View source
  1. <?php
  2. class Provision_Service_http_cluster extends Provision_Service_http {
  3. static function option_documentation() {
  4. return array(
  5. 'cluster_web_servers' => 'server with cluster: comma-separated list of web servers.'
  6. );
  7. }
  8. function init_server() {
  9. $this->server->setProperty('cluster_web_servers', array(), TRUE);
  10. }
  11. function init_site() {
  12. $this->_each_server(__FUNCTION__);
  13. }
  14. /**
  15. * Run a method on each server in the cluster.
  16. *
  17. * This function does a logical AND on the return status of each of the
  18. * methods, and returns TRUE only if they all returned something that
  19. * can be interpreted as TRUE.
  20. */
  21. function _each_server($method, $args = array()) {
  22. // Return True by default.
  23. $ret = TRUE;
  24. foreach ($this->server->cluster_web_servers as $server) {
  25. // If any methods return false, return false for the whole operation.
  26. $result = call_user_func_array(array(d($server)->service('http', $this->context), $method), $args);
  27. $ret = $ret && $result;
  28. }
  29. return $ret;
  30. }
  31. function parse_configs() {
  32. $this->_each_server(__FUNCTION__);
  33. }
  34. function create_config($config) {
  35. $this->_each_server(__FUNCTION__, array($config));
  36. }
  37. function delete_config($config) {
  38. $this->_each_server(__FUNCTION__, array($config));
  39. return $this;
  40. }
  41. function restart() {
  42. $this->_each_server(__FUNCTION__);
  43. }
  44. /**
  45. * Support the ability to cloak database credentials using environment variables.
  46. *
  47. * The cluster supports this functionality only if ALL the servers it maintains
  48. * supports this functionality.
  49. */
  50. function cloaked_db_creds() {
  51. return $this->_each_server(__FUNCTION__);
  52. }
  53. function sync() {
  54. $args = func_get_args();
  55. $this->_each_server(__FUNCTION__, $args);
  56. }
  57. function fetch() {
  58. drush_log('Skipping fetch from remote server(s), since master is authoritative in cluster service.');
  59. }
  60. function grant_server_list() {
  61. return array_merge(
  62. array_map('d', $this->server->cluster_web_servers),
  63. array($this->context->platform->server)
  64. );
  65. }
  66. }