Commit 46d5a27a authored by anarcat's avatar anarcat

first implementation of the dumbcluster, pretty dumb, based on cluster.php

parent a537781f
<?php
class Provision_Service_http_cluster extends Provision_Service_http {
class Provision_Service_http_dumbcluster extends Provision_Service_http {
static function option_documentation() {
return array(
'--cluster_web_servers' => 'server with cluster: comma-separated list of web servers.'
'--slave_web_servers' => 'server with dumbcluster: comma-separated list of slave web servers.'
'--master_web_server' => 'server with dumbcluster: the master web server.'
);
}
function init_server() {
$this->server->setProperty('cluster_web_servers', array(), TRUE);
$this->server->setProperty('slave_web_servers', array(), TRUE);
$this->server->setProperty('master_web_server', array(), TRUE);
}
/**
* Run a method on each server in the cluster.
* Run a method on each server in the dumbcluster.
*
* This function does a logical AND on the return status of each of the
* methods, and returns TRUE only if they all returned something that
* can be interpreted as TRUE.
*/
function _each_server($method, $args = array()) {
function _each_server($servers, $method, $args = array()) {
// Return True by default.
$ret = TRUE;
foreach ($this->server->cluster_web_servers as $server) {
foreach ($servers as $server) {
// If any methods return false, return false for the whole operation.
$result = call_user_func_array(array(d($server)->service('http', $this->context), $method), $args);
$ret = $ret && $result;
......@@ -30,44 +32,46 @@ class Provision_Service_http_cluster extends Provision_Service_http {
}
function parse_configs() {
$this->_each_server(__FUNCTION__);
$this->_each_server($this->server->master_web_servers, __FUNCTION__);
}
function create_config($config) {
$this->_each_server(__FUNCTION__, array($config));
$this->_each_server($this->server->master_web_servers, __FUNCTION__);
}
function delete_config($config) {
$this->_each_server(__FUNCTION__, array($config));
function delete_config($config) {
$this->_each_server($this->server->master_web_servers, __FUNCTION__);
}
function restart() {
$this->_each_server(__FUNCTION__);
$this->_each_server($this->server->master_web_servers, __FUNCTION__);
$this->_each_server($this->server->slave_web_servers, __FUNCTION__);
}
/**
* Support the ability to cloak database credentials using environment variables.
*
* The cluster supports this functionality only if ALL the servers it maintains
* The dumbcluster supports this functionality only if ALL the servers it maintains
* supports this functionality.
*/
function cloaked_db_creds() {
return $this->_each_server(__FUNCTION__);
return $this->_each_server($this->server->master_web_servers, __FUNCTION__) &&
$this->_each_server($this->server->slave_web_servers, __FUNCTION__);
}
function sync() {
$args = func_get_args();
$this->_each_server(__FUNCTION__, $args);
$this->_each_server($this->server->master_web_servers, __FUNCTION__, $args);
}
function fetch() {
$args = func_get_args();
$this->_each_server(__FUNCTION__, $args);
$this->_each_server($this->server->master_web_servers, __FUNCTION__, $args);
}
function grant_server_list() {
return array_merge(
array_map('d', $this->server->cluster_web_servers),
array_map('d', $this->server->slave_web_servers),
array($this->context->platform->server)
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment