Commit 75729269 authored by Jamie Carl's avatar Jamie Carl

Merge branch 'master'

Conflicts:
	libs/Warlock/controlpanel.phtml
parents 850e8d35 29b411be
......@@ -266,7 +266,6 @@
<Compile Include="src\Application\Request\Loader.php" />
<Compile Include="src\Application\Request\_Interface.php" />
<Compile Include="src\Application\Router.php" />
<Compile Include="src\Application\Runner.php" />
<Compile Include="src\Application\Url.php" />
<Compile Include="src\Closure.php" />
<Compile Include="src\Controller.php" />
......
......@@ -22,8 +22,8 @@ var HazaarWarlock = function (sid, host, useWebSockets, websocketsAutoReconnect)
this.encoded = false;
this.sid = sid;
this.host = host;
this.useWebSockets = false;
this.websocketsAutoReconnect = false;
this.useWebSockets = useWebSockets || true;
this.websocketsAutoReconnect = websocketsAutoReconnect || true;
this.messageQueue = [];
this.subscribeQueue = {};
this.callbacks = {};
......@@ -60,7 +60,7 @@ var HazaarWarlock = function (sid, host, useWebSockets, websocketsAutoReconnect)
o.reconnectDelay = 0;
o.reconnectRetries = 0;
if (o.admin_key) {
o._send(p.sync, {'admin_key': o.admin_key}, true);
o._send(p.sync, { 'admin_key': o.admin_key }, true);
}
if (Object.keys(o.subscribeQueue).length > 0) {
for (event_id in o.subscribeQueue) {
......@@ -113,13 +113,13 @@ var HazaarWarlock = function (sid, host, useWebSockets, websocketsAutoReconnect)
return result;
}
}).fail(function (jqXHR) {
o._closeHandler({data: {'id': event_id, 'callback': callback, 'filter': filter}});
o._closeHandler({ data: { 'id': event_id, 'callback': callback, 'filter': filter } });
}).always(function () {
o._unlongpoll();
});
this.sockets.push(socket);
if (this.admin_key && this.sockets.length == 1) {
this._send(p.sync, {'admin_key': this.admin_key});
this._send(p.sync, { 'admin_key': this.admin_key });
}
};
this._unlongpoll = function (xhr) {
......@@ -165,7 +165,7 @@ var HazaarWarlock = function (sid, host, useWebSockets, websocketsAutoReconnect)
switch (packet.TYP) {
case p.event:
var event = packet.PLD;
if (this.subscribeQueue[event.id]) this.subscribeQueue[event.id].callback(event);
if (this.subscribeQueue[event.id]) this.subscribeQueue[event.id].callback(event.data, event);
break;
case p.error:
alert('ERROR\n\nCommand:\t' + packet.PLD.command + '\n\nReason:\t\t' + packet.PLD.reason);
......@@ -228,7 +228,7 @@ var HazaarWarlock = function (sid, host, useWebSockets, websocketsAutoReconnect)
}
} else {
packet.CID = this.guid;
$.post(this.longPollingUrl, {CID: this.guid, P: this._encode(packet)}).done(function (data) {
$.post(this.longPollingUrl, { CID: this.guid, P: this._encode(packet) }).done(function (data) {
var packet = o._decode(data);
if (packet.TYP == p.ok) {
} else {
......
......@@ -98,36 +98,36 @@ function removePanel(parent, id) {
parent.find('#panel_' + id).remove();
}
function handleTrigger(event) {
switch (event.data.args.type) {
function handleTrigger(data, event) {
switch (data.args.type) {
case 'job':
var job = event.data.args.job;
var job = data.args.job;
var parent = $('#joblist');
if (event.data.command == 'add') {
var data = {
if (data.command == 'add') {
var info = {
'Status': String(job.status_text).toUpperCase(),
'ID': job.id,
'Start': (new Date(job.start * 1000)).toLocaleString(),
'Environment': job.application.env,
'Retries': job.retries
};
displayPanel(parent, event.data.args.id, (job.tag ? job.tag : job.id), data);
} else if (event.data.command == 'update') {
var data = {
displayPanel(parent, data.args.id, (job.tag ? job.tag : job.id), info);
} else if (data.command == 'update') {
var info = {
'Status': String(job.status_text).toUpperCase(),
'Started': (new Date(job.start * 1000)).toLocaleString(),
'Retries': job.retries
};
updatePanel(parent, event.data.args.id, data);
} else if (event.data.command == 'remove') {
removePanel(parent, event.data.args.id);
updatePanel(parent, data.args.id, info);
} else if (data.command == 'remove') {
removePanel(parent, data.args.id);
}
break;
case 'process':
var parent = $('#processlist');
var proc = event.data.args.process;
if (event.data.command == 'add') {
var data = {
var proc = data.args.process;
if (data.command == 'add') {
var info = {
'State': 'Starting',
'PID': proc.pid,
'Started': (new Date(proc.start)).toLocaleString(),
......@@ -135,62 +135,62 @@ function handleTrigger(event) {
'Memory': '0 MB',
'Peak': '0 MB'
};
displayPanel(parent, event.data.args.id, event.data.args.process.tag, data);
} else if (event.data.command == 'update') {
var data = {
displayPanel(parent, data.args.id, data.args.process.tag, info);
} else if (data.command == 'update') {
var info = {
'State': proc.status.state,
'PID': proc.status.pid,
'Memory': mem(proc.status.mem) + ' MB',
'Peak': mem(proc.status.peak) + ' MB'
};
updatePanel(parent, event.data.args.id, data);
} else if (event.data.command == 'remove') {
removePanel(parent, event.data.args.id);
updatePanel(parent, data.args.id, info);
} else if (data.command == 'remove') {
removePanel(parent, data.args.id);
}
break;
case 'client':
var parent = $('#clientlist');
var client = event.data.args.client;
if (event.data.command == 'add') {
var client = data.args.client;
if (data.command == 'add') {
var host = client.ip ? client.ip + ':' + client.port : 'Internal';
var label = client.username ? client.username : host;
var since = new Date(client.since * 1000);
var data = {
var dinfoata = {
'ID': client.id,
'Host': host,
'User': (client.username ? client.username : 'None'),
'Since': formatDate(since)
};
displayPanel(parent, client.id, label, data)
displayPanel(parent, client.id, label, info)
.toggleClass('client-admin', client.admin)
.toggleClass('client-system', client.system);
} else if (event.data.command == 'update') {
} else if (data.command == 'update') {
updatePanel(parent, client.id, client).toggleClass('client-admin', client.admin);
} else if (event.data.command == 'remove') {
removePanel(parent, event.data.args.client);
} else if (data.command == 'remove') {
removePanel(parent, data.args.client);
}
break;
case 'event':
var parent = $('#eventlist');
var e = event.data.args.event;
if (event.data.command == 'add') {
var data = {
var e = data.args.event;
if (data.command == 'add') {
var info = {
'ID': e.trigger,
'When': (new Date(e.when * 1000)).toLocaleString(),
'Data': JSON.stringify(e.data)
};
displayPanel(parent, e.trigger, e.id, data);
} else if (event.data.command = 'remove') {
removePanel(parent, event.data.args.id);
displayPanel(parent, e.trigger, e.id, info);
} else if (data.command = 'remove') {
removePanel(parent, data.args.id);
}
break;
case 'service':
var parent = $('#servicelist');
var service = event.data.args.service;
var service = data.args.service;
if (!service.name)
break;
if (event.data.command == 'update') {
var data = {
if (data.command == 'update') {
var info = {
'Status': service.status,
'Restarts': service.restarts,
'Heartbeats': service.heartbeats,
......@@ -199,17 +199,17 @@ function handleTrigger(event) {
var panel = parent.find('#panel_' + service.name);
if (panel.length == 0) {
var button = $('<button class="btnToggleService">').html((service.enabled) ? 'Disable' : 'Enable');
displayPanel(parent, service.name, service.name, data, button);
displayPanel(parent, service.name, service.name, info, button);
} else {
updatePanel(parent, service.name, data);
updatePanel(parent, service.name, info);
}
}
break;
default:
console.log("Event type '" + event.data.args.type + "' not implemented yet!");
console.log("Event type '" + data.args.type + "' not implemented yet!");
break;
}
updateStatus(event.data.status);
updateStatus(data.status);
}
$.fn.dialog = function (params) {
......
This diff is collapsed.
......@@ -74,6 +74,8 @@ class Application {
private static $instance;
private $protocol;
/**
* @brief The main application constructor
*
......@@ -544,11 +546,7 @@ class Application {
/**
* @brief Execute code from standard input in the application context
*
* @detail This method is part of the background code execution scheduler, Bulletin. Code can be scheduled to
* execute in the background at a later time. This code is stored in the schedulars memory and when
* it's time to execute it, Bulletin will launch a new application context, bootstrap it, but
* instead of calling the run() method like normal it will call this runStdin() method to execute the
* stored code that was passed via stdin.
* @detail This method is will accept Hazaar Protocol commands from STDIN and execute them.
*
* @since 1.0.0
*/
......@@ -565,19 +563,22 @@ class Application {
)
);
$warlock = new \Hazaar\Application\Config('warlock.ini', NULL, $defaults);
$warlock = new \Hazaar\Application\Config('warlock', APPLICATION_ENV, $defaults);
define('RESPONSE_ENCODED', $warlock->server->encoded);
$protocol = new \Hazaar\Application\Protocol($warlock->sys->id, $warlock->server->encoded);
$this->protocol = new \Hazaar\Application\Protocol($warlock->sys->id, $warlock->server->encoded);
//Execution should wait here until we get a command
$line = fgets(STDIN);
$type = $protocol->decode($line, $payload);
$type = $this->protocol->decode($line, $payload);
$type_name = $this->protocol->getTypeName($type);
switch ($type) {
switch ($type_name) {
case $protocol->getType('exec') :
case 'EXEC' :
$params = (array_key_exists('params', $payload) ? $payload['params'] : array());
......@@ -587,20 +588,17 @@ class Application {
$result = call_user_func_array($_function, $params);
if($result === TRUE){
//Any of these are considered an OK response.
if($result === NULL
|| $result === TRUE
|| $result == 0){
$code = 0;
} elseif(is_int($result)) {
} else { //Anything else is an error and we display it.
$code = $result;
} else {
$code = 0;
echo $protocol->encode('OK', $result);
}
} else {
......@@ -611,7 +609,7 @@ class Application {
break;
case $protocol->getType('SERVICE') :
case 'SERVICE' :
if(!array_key_exists('name', $payload)) {
......@@ -627,7 +625,7 @@ class Application {
if(class_exists($serviceClass)) {
$service = new $serviceClass($this, $protocol);
$service = new $serviceClass($this, $this->protocol);
$code = call_user_func_array(array($service, 'main'), $params);
......@@ -645,6 +643,26 @@ class Application {
}
private function trigger($event, $data){
if(!$this->protocol instanceof \Hazaar\Application\Protocol)
return false;
$packet = array(
'id' => $event
);
if($data)
$packet['data'] = $data;
echo $this->protocol->encode('trigger', $packet) . "\n";
flush();
return true;
}
/**
* @brief Return the requested path in the current application
*
......
......@@ -4,7 +4,7 @@
* Author: Jamie Carl
* Date: 25/09/14
* Time: 9:21 AM
*
*
* @package Core
*/
......@@ -14,8 +14,8 @@ namespace Hazaar\Application;
* @brief Hazaar Application Protocol Class
*
* @detail The Application Protocol is a simple protocol developed to allow communication between
* parts of the Hazaar framework over the wire or other IO interfaces. It allows common information
* to be encoded/decoded between endpoints.
* parts of the Hazaar framework over the wire or other IO interfaces. It allows common information
* to be encoded/decoded between endpoints.
*
* @since 2.0.0
*
......
......@@ -336,7 +336,7 @@ class Error extends \Hazaar\Controller {
'line' => $this->errline
);
echo $protocol->encode('error', $error) . "\n";
$protocol->stream($protocol->encode('error', $error));
exit($this->errno);
......
......@@ -40,7 +40,7 @@ class File extends \Hazaar\Logger\Backend {
public function write($tag, $message, $level = E_NOTICE) {
$remote = $_SERVER['REMOTE_ADDR'];
$remote = ake($_SERVER, 'REMOTE_ADDR', '--');
$line = array();
......@@ -53,7 +53,7 @@ class File extends \Hazaar\Logger\Backend {
$line[] = str_pad(strtoupper($this->getLogLevelId($level)), 6, ' ', STR_PAD_RIGHT);
if($this->getOption('write_uri'))
$line[] = $_SERVER['REQUEST_URI'];
$line[] = ake($_SERVER, 'REQUEST_URI');
$line[] = $tag;
......@@ -79,4 +79,3 @@ class File extends \Hazaar\Logger\Backend {
}
}
......@@ -143,4 +143,3 @@ class Frontend {
}
}
......@@ -45,40 +45,34 @@ class Warlock extends \Hazaar\View\Helper {
'pid' => 'warlock.pid'
),
'server' => array(
'listen' => $_SERVER['HTTP_HOST'],
'listen' => $_SERVER['SERVER_NAME'],
'port' => 8000,
'encoded' => TRUE
),
'websockets' => array(
'enabled' => TRUE,
'autoReconnect' => TRUE
'enabled' => true,
'autoReconnect' => true
)
);
$config = new \Hazaar\Application\Config('warlock.ini', NULL, $defaults);
if(trim($config->server->listen) == '0.0.0.0') {
$config = new \Hazaar\Application\Config('warlock', APPLICATION_ENV, $defaults);
if(trim($config->server->listen) == '0.0.0.0')
$host = $_SERVER['HTTP_HOST'] . ':' . $config->server->port . '/' . APPLICATION_NAME;
} else {
else
$host = $config->server->listen . ':' . $config->server->port . '/' . APPLICATION_NAME;
}
$view->script("{$this->js_varname} = new HazaarWarlock('{$config->sys->id}', '$host');");
$wsEnabled = strbool($config->websockets->enabled === true);
$wsAutoReconnect = (($config->websockets->autoReconnect === TRUE) ? 'true' : 'false');
$wsAutoReconnect = strbool($config->websockets->autoReconnect === true);
if($config->websockets->enabled === TRUE)
$view->script("{$this->js_varname}.enableWebsockets($wsAutoReconnect);");
$view->script("{$this->js_varname} = new HazaarWarlock('{$config->sys->id}', '$host', $wsEnabled, $wsAutoReconnect);");
if($config->server->encoded === TRUE)
if($config->server->encoded === true)
$view->script("{$this->js_varname}.enableEncoding();");
if(array_key_exists('REMOTE_USER', $_SERVER))
$view->script("{$this->js_varname}.setUser('{$_SERVER['REMOTE_USER']}');");
if(($user = ake($_SERVER, 'REMOTE_USER')))
$view->script("{$this->js_varname}.setUser('$user');");
}
......
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