Commit 36978514 authored by Adrian Rossouw's avatar Adrian Rossouw

just an in progress commit. this branch introduces some new dispatchers to...

just an in progress commit. this branch introduces some new dispatchers to handle some of the tricky logic we've found in classes.
parent 863579a1
......@@ -32,6 +32,15 @@ function db_drush_help($section) {
class provisionService_db extends provisionService {
protected $service = 'db';
/**
* Register the db handler for sites, based on the db_server option.
*/
static function subscribe_site($context) {
$context->setProperty('db_server', '@server_master');
$context->is_oid('db_server');
$context->service_subscribe('db', $context->db_server->name);
}
static function option_documentation() {
return array(
'--master_db' => 'server with db: Master database connection info, {type}://{user}:{password}@{host}',
......
......@@ -28,6 +28,15 @@ class provisionService_http extends provisionService {
$this->parse_configs();
}
/**
* Register the http handler for platforms, based on the web_server option.
*/
static function subscribe_platform($context) {
$context->setProperty('web_server', '@server_master');
$context->is_oid('web_server');
$context->service_subscribe('http', $context->web_server->name);
}
}
// Public http service , as in non-encrypted and listening on a port.
......@@ -104,25 +113,34 @@ class provisionService_http_public extends provisionService_http {
}
function verify() {
if ($this->context->type === 'server') {
if (!is_null($this->application_name)) {
provision_file()->create_dir($this->server->http_confd_path, dt("Webserver custom configuration"), 0700);
$this->sync($this->server->http_confd_path);
provision_file()->create_dir($this->server->http_platformd_path, dt("Webserver platform configuration"), 0700);
$this->sync($this->server->http_platformd_path, array(
'exclude' => $this->server->http_platformd_path . '/*', // Make sure remote directory is created
));
provision_file()->create_dir($this->server->http_vhostd_path , dt("Webserver virtual host configuration"), 0700);
$this->sync($this->server->http_vhostd_path, array(
'exclude' => $this->server->http_vhostd_path . '/*', // Make sure remote directory is created
));
}
}
function verify_server_cmd() {
if (!is_null($this->application_name)) {
provision_file()->create_dir($this->server->http_confd_path, dt("Webserver custom configuration"), 0700);
$this->sync($this->server->http_confd_path);
parent::verify();
provision_file()->create_dir($this->server->http_platformd_path, dt("Webserver platform configuration"), 0700);
$this->sync($this->server->http_platformd_path, array(
'exclude' => $this->server->http_platformd_path . '/*', // Make sure remote directory is created
));
provision_file()->create_dir($this->server->http_vhostd_path , dt("Webserver virtual host configuration"), 0700);
$this->sync($this->server->http_vhostd_path, array(
'exclude' => $this->server->http_vhostd_path . '/*', // Make sure remote directory is created
));
}
$this->create_config($this->context->type);
$this->parse_configs();
}
function verify_site_cmd() {
$this->create_config($this->context->type);
$this->parse_configs();
}
function verify_platform_cmd() {
$this->create_config($this->context->type);
$this->parse_configs();
}
/**
......
......@@ -220,13 +220,15 @@ function drush_provision_save($alias = null) {
$config->unlink();
}
else {
// trigger additional logic that should happen only on save.
d($alias)->type_invoke('save');
// create or update the record
d($alias)->write_alias();
}
}
function drush_provision_verify() {
d()->verify();
d()->command_invoke('verify');
}
function _provision_default_web_group() {
......
......@@ -39,7 +39,9 @@ function & d($name = NULL, $_root_object = FALSE) {
}
else {
$instances[$name] = provision_environment_factory($name);
$instances[$name]->init();
$instances[$name]->method_invoke('init');
$instances[$name]->type_invoke('init');
return $instances[$name];
}
}
......@@ -178,7 +180,63 @@ class provisionEnvironment {
elseif (property_exists($this, $name)) {
unset($this->$name);
}
}
/**
* Implement the __call magic method.
*
* This implementation is really simple. It simply return null if the
* method doesn't exist.
*
* This is used so that we can create methods for drush commands, and
* can fail safely.
*/
function __call($name, $args) {
$this->method_invoke($name, $args);
return false;
}
/**
* Execute a method on the object and all of it's associated
* services.
*/
function method_invoke($func, $args = array()) {
if (method_exists($this, $func)) {
call_user_func_array(array($this, $func), $args);
}
// Services will be invoked regardless of the existence of a
// implementation in the environment class.
$this->services_invoke($func, $args);
}
/**
* Execute the method for the current object type.
*
* This function is used to avoid having to conditionally
* check the context objects type to execute the correct code.
*
* This will generate a function call like : $method_$type,
* ie: $this->init_server().
*
* Additionally it will dispatch this function call to
* all the currently enabled services.
*/
function type_invoke($name, $args = array()) {
$this->method_invoke("{$name}_{$this->type}");
}
/**
* Allow a server to plug into a drush command that has been called.
*
* This method provides a general case for extending drush commands.
* This allows the developer to not have to conditionally check the
* context object type in all his methods, and reduces the need
* to define drush_hook_$command methods for a lot of cases.
*
* This will generate a function call like : $method_$type_cmd.
*/
function command_invoke($command, $args = array()) {
$this->method_invoke("{$command}_{$this->type}_cmd");
}
/**
......@@ -192,7 +250,18 @@ class provisionEnvironment {
* Init stub function.
*/
function init() {
dlm(__CLASS__);
$this->setProperty('context_type', 'server');
// Set up subscriptions for the available services.
$service_list = drush_command_invoke_all('provision_services');
foreach ($service_list as $service => $default) {
$class = "provisionService_{$service}";
$func = "subcribe_{$this->type}";
if (method_exists($class, $func)) {
call_user_func(array($class, $func), $this);
}
}
return true;
}
......@@ -261,6 +330,48 @@ class provisionEnvironment {
}
}
/**
* Call method $callback on each of the environment's service objects.
*
* @param $callback
* A provisionService method.
* @return
* An array of return values from method implementations.
*/
function services_invoke($callback) {
// fetch the merged list of services.
// These may be on different servers entirely.
$services = $this->get_services();
foreach (array_keys($services) as $service) {
$results[$service] = $this->service($service)->$callback();
}
return $results;
}
/**
* Return the merged list of services and the associated servers supplying them.
*
* This function will check with the parent_key to retrieve any service subscription
* it may have, and will add any additional subscriptions.
*
* Once the call chain reaches the @server_master object, it will provide the fallbacks
* if no subscriptions were available.
*/
function get_services() {
$services = array();
if (!is_null($this->parent_key)) {
$services = $this->{$this->parent_key}->get_services();
}
if (sizeof($this->service_subs)) {
foreach ($this->service_subs as $service => $server) {
$services[$service] = $server;
}
}
return $services;
}
/**
* Return environment-specific configuration options for help.
*
......@@ -387,21 +498,19 @@ class provisionServer extends provisionEnvironment {
}
/**
* Call method $callback on each of the environment's service objects.
*
* @param $callback
* A provisionService method.
* @return
* An array of return values from method implementations.
* Retrieve a list of service objects associated with this server.
*/
function services_invoke($callback) {
foreach (array_keys($this->services) as $service) {
$this->service($service)->$callback();
function get_services() {
$services = array();
foreach ($this->services as $service => $object) {
$services[$service] = $this->name;
}
return $services;
}
function verify() {
$this->services_invoke('verify');
$this->type_invoke('verify');
}
/**
......@@ -523,10 +632,6 @@ class provisionPlatform extends provisionEnvironment {
$this->setProperty('server', '@server_master');
$this->is_oid('server');
$this->setProperty('web_server', '@server_master');
$this->is_oid('web_server');
$this->service_subscribe('http', $this->web_server->name);
$this->setProperty('makefile', '');
}
......@@ -570,11 +675,6 @@ class provisionSite extends provisionEnvironment {
$this->setProperty('client_email');
$this->setProperty('aliases', array(), TRUE);
$this->setProperty('redirection', FALSE);
$this->setProperty('db_server', '@server_master');
$this->is_oid('db_server');
$this->service_subscribe('db', $this->db_server->name);
// TODO :: figure out how to put this into service classes.
$this->setProperty('ssl_enabled', 0);
......@@ -583,9 +683,4 @@ class provisionSite extends provisionEnvironment {
// this can potentially be handled by a Drupal sub class
$this->setProperty('profile', 'default');
}
function verify() {
$this->service('db')->verify();
$this->service('http')->verify();
}
}
......@@ -17,6 +17,25 @@ class provisionService extends provisionChainedState {
protected $configs = array();
/**
* Implement the __call magic method.
*
* This implementation is really simple. It simply return null if the
* method doesn't exist.
*
* This is used so that we can create methods for drush commands, and
* can fail safely.
*/
function __call($name, $args) {
if (method_exists($this, $name)) {
return call_user_func_array(array($this, $name), $args);
}
return false;
}
// All services have the ability to have an associated restart command and listen port.
function init() {
if (!is_null($this->service)) {
......
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