Commit b42197b8 authored by anarcat's avatar anarcat

rewrite the cluster module as a dumbcluster module

this mostly consists of adding a slave server list
parent bfbef9fc
<?php
/**
* @file
* Expose the web cluster feature to hostmaster.
* Expose the web dumbcluster feature to hostmaster.
*/
/**
* Implementation of hook_hosting_feature().
*/
function hosting_web_cluster_hosting_feature() {
$features['web_cluster'] = array(
'title' => t('Web clusters'),
'description' => t('Provides a service to expose a site across multiple web front ends.'),
function hosting_web_dumbcluster_hosting_feature() {
$features['web_dumbcluster'] = array(
'title' => t('Web dumbclusters'),
'description' => t('Provides a service to expose a site across multiple web front ends. This adds to the base cluster class the capability of having "light" servers which do not have files copied around.'),
'status' => HOSTING_FEATURE_DISABLED,
'module' => 'hosting_web_cluster',
'module' => 'hosting_web_dumbcluster',
'group' => 'experimental',
);
return $features;
......
name = Web Cluster
description = Allow hostmaster to configure web clusters.
name = Web Dumbcluster
description = Allow hostmaster to configure web dumbclusters, which have masters and slaves.
package = Hosting
dependencies[] = hosting_web_server
......
<?php
function hosting_web_cluster_schema() {
function hosting_web_dumbcluster_schema() {
return array(
'hosting_web_cluster' => array(
'hosting_web_dumbcluster' => array(
'fields' => array(
'vid' => array(
'type' => 'int',
......@@ -22,16 +22,21 @@ function hosting_web_cluster_schema() {
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => 'slave', // can also be 'master'
),
'primary key' => array('vid', 'web_server_nid'),
),
);
}
function hosting_web_cluster_install() {
drupal_install_schema('hosting_web_cluster');
function hosting_web_dumbcluster_install() {
drupal_install_schema('hosting_web_dumbcluster');
}
function hosting_web_cluster_uninstall() {
drupal_uninstall_schema('hosting_web_cluster');
function hosting_web_dumbcluster_uninstall() {
drupal_uninstall_schema('hosting_web_dumbcluster');
}
<?php
function hosting_web_cluster_hosting_service() {
function hosting_web_dumbcluster_hosting_service() {
return array(
'cluster' => 'http',
'dumbcluster' => 'http',
);
}
......@@ -2,14 +2,19 @@
module_load_include('service.inc', 'hosting_web_server');
class hostingService_http_cluster extends hostingService_http {
public $type = 'cluster';
class hostingService_http_dumbcluster extends hostingService_http {
public $type = 'dumbcluster';
function view(&$render) {
$render['web_servers'] = array(
$render['master_servers'] = array(
'#type' => 'item',
'#title' => t('Web servers'),
'#value' => theme('item_list', array_map('_hosting_node_link', array_intersect_key($this->web_servers, hosting_get_servers('http')))),
'#title' => t('Master web servers'),
'#value' => theme('item_list', array_map('_hosting_node_link', array_intersect_key($this->master_servers, hosting_get_servers('http')))),
);
$render['slave_servers'] = array(
'#type' => 'item',
'#title' => t('Slave web servers'),
'#value' => theme('item_list', array_map('_hosting_node_link', array_intersect_key($this->slave_servers, hosting_get_servers('http')))),
);
}
......@@ -19,11 +24,17 @@ class hostingService_http_cluster extends hostingService_http {
$servers = hosting_get_servers('http');
unset($servers[$this->server->nid]);
$form['web_servers'] = array(
'#title' => t('Servers'),
$form['master_servers'] = array(
'#title' => t('Master servers'),
'#type' => 'checkboxes',
'#options' => $servers,
'#default_value' => isset($this->master_servers) ? $this->master_servers : array(),
);
$form['slave_servers'] = array(
'#title' => t('Slave servers'),
'#type' => 'checkboxes',
'#options' => $servers,
'#default_value' => isset($this->web_servers) ? $this->web_servers : array(),
'#default_value' => isset($this->slave_servers) ? $this->slave_servers : array(),
);
}
......@@ -32,43 +43,59 @@ class hostingService_http_cluster extends hostingService_http {
$ssl_enabled = TRUE;
$web_servers = array();
$result = db_query('SELECT web_server_nid FROM {hosting_web_cluster} WHERE vid = %d', $this->server->vid);
$master_servers = array();
$result = db_query('SELECT web_server_nid, type FROM {hosting_web_dumbcluster} WHERE vid = %d', $this->server->vid);
while ($web_server = db_fetch_object($result)) {
$web_servers[] = $web_server->web_server_nid;
if ($web_server->type == 'master') {
$master_servers[] = $web_server->web_server_nid;
}
else {
$slave_servers[] = $web_server->web_server_nid;
}
$server = node_load($web_server->web_server_nid);
$ssl_enabled = $ssl_enabled && $server->services['http']->ssl_enabled;
}
$this->ssl_enabled = $ssl_enabled;
$this->setValues(array('web_servers' => drupal_map_assoc($web_servers)));
$this->setValues(array('master_servers' => drupal_map_assoc($master_servers)));
}
function insert() {
parent::insert();
foreach (array_filter($this->web_servers) as $web_server) {
foreach (array_filter($this->master_servers) as $web_server) {
$record = array(
'nid' => $this->server->nid,
'vid' => $this->server->vid,
'web_server_nid' => $web_server,
'type' => 'master',
);
drupal_write_record('hosting_web_dumbcluster', $record);
}
foreach (array_filter($this->slave_servers) as $web_server) {
$record = array(
'nid' => $this->server->nid,
'vid' => $this->server->vid,
'web_server_nid' => $web_server,
'type' => 'slave',
);
drupal_write_record('hosting_web_cluster', $record);
drupal_write_record('hosting_web_dumbcluster', $record);
}
}
function delete() {
parent::delete();
db_query('DELETE FROM {hosting_web_cluster} WHERE nid = %d', $this->server->nid);
db_query('DELETE FROM {hosting_web_dumbcluster} WHERE nid = %d', $this->server->nid);
}
function delete_revision() {
parent::delete_revision();
db_query('DELETE FROM {hosting_web_cluster} WHERE vid = %d', $this->server->vid);
db_query('DELETE FROM {hosting_web_dumbcluster} WHERE vid = %d', $this->server->vid);
}
function context_options($task_type, $ref_type, &$task) {
parent::context_options($task_type, $ref_type, $task);
$task->context_options['cluster_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->web_servers, hosting_get_servers('http')))));
$task->context_options['master_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->master_servers, hosting_get_servers('http')))));
$task->context_options['slave_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->slave_servers, hosting_get_servers('http')))));
}
}
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