Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Start All / Stop All functionality. #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion circusweb/circushttpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import json
from base64 import b64encode, b64decode
from datetime import datetime
from zmq.eventloop import ioloop
import socket

Expand Down Expand Up @@ -98,6 +99,7 @@ def render_template(self, template_path, **data):
server = '%s://%s/' % (self.request.protocol, self.request.host)
namespace.update({'controller': get_controller(),
'version': __version__,
'now': datetime.now,
'b64encode': b64encode,
'dumps': json.dumps,
'session': self.session, 'messages': messages,
Expand Down Expand Up @@ -242,7 +244,6 @@ def get(self, endpoint, name):
redirect_url=self.reverse_url('index'))
self.redirect(url)


class KillProcessHandler(BaseHandler):

@require_logged_user
Expand Down Expand Up @@ -333,6 +334,34 @@ def get(self, endpoint):
self.redirect(url)


class StartAllHandler(BaseHandler):

@require_logged_user
@tornado.web.asynchronous
@gen.coroutine
def get(self, endpoint):
url = yield self.run_command(command='start_all',
message='starting all watchers',
endpoint=b64decode(endpoint),
args=[],
redirect_url=self.reverse_url('index'))
self.redirect(url)


class StopAllHandler(BaseHandler):

@require_logged_user
@tornado.web.asynchronous
@gen.coroutine
def get(self, endpoint):
url = yield self.run_command(command='stop_all',
message='stopping all watchers',
endpoint=b64decode(endpoint),
args=[],
redirect_url=self.reverse_url('index'))
self.redirect(url)


class Application(tornado.web.Application):

def __init__(self):
Expand All @@ -349,6 +378,10 @@ def __init__(self):
WatcherAddHandler, name="add_watcher"),
URLSpec(r'/([^/]+)/watcher/([^/]+)/',
WatcherHandler, name="watcher"),
URLSpec(r'/([^/]+)/start_all/',
StartAllHandler, name="start_all"),
URLSpec(r'/([^/]+)/stop_all/',
StopAllHandler, name="stop_all"),
URLSpec(r'/([^/]+)/watcher/([^/]+)/switch_status/',
WatcherSwitchStatusHandler, name="switch_status"),
URLSpec(r'/([^/]+)/watcher/([^/]+)/process/kill/([^/]+)/',
Expand Down
16 changes: 16 additions & 0 deletions circusweb/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ def switch_status(self, name, endpoint):

raise gen.Return(res)

@gen.coroutine
def start_all(self, endpoint):
client = self.get_client(endpoint)
msg = cmds['start'].make_message(name='*')
res = yield gen.Task(client.call, msg)

raise gen.Return(res)

@gen.coroutine
def stop_all(self, endpoint):
client = self.get_client(endpoint)
msg = cmds['stop'].make_message(name='*')
res = yield gen.Task(client.call, msg)

raise gen.Return(res)

@gen.coroutine
def reloadconfig(self, endpoint):
client = self.get_client(endpoint)
Expand Down
6 changes: 5 additions & 1 deletion circusweb/media/circus.css
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ footer {
box-shadow: 0 0 5px #757575;
}

.reloadconfig, .add_watcher, .add_endpoint {
.reloadconfig, .add_watcher, .add_endpoint, .watchers_start_all, .watchers_stop_all {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
Expand All @@ -312,6 +312,10 @@ footer {
text-decoration: none;
}

.watchers_start_all, .watchers_stop_all {
width: auto;
}

.add_watcher:active {
-webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.1);
-moz-box-shadow: inset 0 1px 2px rgba(0,0,0,.1);
Expand Down
4 changes: 2 additions & 2 deletions circusweb/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright" content="Copyright 2012, Circus Team" />
<meta name="copyright" content="Copyright ${now().year}, Circus Team" />
<meta name="description" content="Control panel for the Circus Process Watcher" />
<title>Circus Control Panel</title>

Expand Down Expand Up @@ -111,7 +111,7 @@ <h3>Add Watcher</h3>
</section>

<footer>
&copy; Copyright 2012, The Mozilla Foundation - circushttpd v.${version}
&copy; Copyright ${now().year}, The Mozilla Foundation - circushttpd v.${version}
</footer>

</body>
Expand Down
4 changes: 3 additions & 1 deletion circusweb/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
% for endpoint, stat_endpoint in endpoints.items():
<div class="title" style="background-color: #D6D6FF;">
<div style="float: left;" class="watcher_name">${endpoint} Watchers</div>
<div style="float: right;"><a class="watchers_start_all" href="${reverse_url('start_all', b64encode(endpoint))}">Start All </a></div>
<div style="float: right;"><a class="watchers_stop_all" href="${reverse_url('stop_all', b64encode(endpoint))}">Stop All</a></div>
<div style="float: right;"><a class="reloadconfig" href="${reverse_url('reloadconfig', b64encode(endpoint))}">Reload config</a></div>
<div style="float: right;"><a href="#" class="add_watcher" data-add-url="${reverse_url('add_watcher', b64encode(endpoint))}">Add Watcher</a></div>

Expand Down Expand Up @@ -31,7 +33,7 @@
<div style="width: 50px;">${options['shell']}</div>
<div style="width: 50px;">${options['uid']}</div>
<div style="width: 50px;">${options['gid']}</div>
<div style="width: 50px;"><a class="watcher-status watcher-status-${controller.get_status(watcher, endpoint)}" title="${controller.get_status(watcher, endpoint)}" href="${reverse_url('switch_status', b64encode(endpoint), watcher)}"></a></div>
<div style="width: 50px;"><a class="watcher-status watcher-status-${controller.get_status(watcher, endpoint)}" title="${controller.get_status(watcher, endpoint)}, click to switch" href="${reverse_url('switch_status', b64encode(endpoint), watcher)}"></a></div>
</div>
% endif
% endfor
Expand Down