Permalink
Browse files

added node db support

  • Loading branch information...
tarekziade committed Aug 8, 2012
1 parent 1fad869 commit 7b6a371be496b11a69828369e6367ce4abdcaa19
Showing with 114 additions and 11 deletions.
  1. +31 −3 marteau/media/marteau.css
  2. +14 −0 marteau/queue.py
  3. +21 −2 marteau/server.py
  4. +16 −1 marteau/templates/index.mako
  5. +32 −5 marteau/templates/nodes.mako
View
@@ -45,23 +45,29 @@ a:hover {
}
+p {
+ font-style: italic;
+ color: grey;
+ font-size: 20px;
+}
+
#right {
float:right;
}
-#workers {
+div.resource {
margin-right: 5px;
padding: 12px;
border: 1px dotted rgb(203, 200, 185);
background: none repeat scroll 0% 0% rgb(246, 246, 242);
}
-#workers span {
+div.resource span {
font-weight: bold;
font-size: 20px;
}
-#workers div {
+div.resource div {
font-style: italic;
margin-top: 6px;
}
@@ -72,12 +78,34 @@ a:hover {
min-width: 300px;
}
+#workers {
+ margin-bottom: 10px;
+}
+
#running {
float: left;
min-width: 300px;
margin-left: 15px;
}
+div.resource a {
+ float: right;
+}
+
+div.smallform {
+ width: 400px;
+ float: right;
+ margin-top: 10px;
+ border: 1px dotted rgb(203, 200, 185);
+ background: none repeat scroll 0% 0% rgb(246, 246, 242);
+ padding: 12px;
+ margin-right: 5px;
+}
+
+div.smallform input[type="text"] {
+ width: 300px;
+}
+
#form {
margin-top: 10px;
border: 1px dotted rgb(203, 200, 185);
View
@@ -2,6 +2,7 @@
import json
from retools.queue import QueueManager, Worker, Job
+from marteau.node import Node
_QM = None
@@ -23,6 +24,19 @@ def append_console(job_id, data):
_QM.redis.set(key, data)
+def get_nodes():
+ names = _QM.redis.smembers('retools:nodes')
+ for name in names:
+ node = _QM.redis.get('retools:node:%s' % name)
+ yield Node(**json.loads(node))
+
+def save_node(node):
+ names = _QM.redis.smembers('retools:nodes')
+ if node.name not in names:
+ _QM.redis.sadd('retools:nodes', node.name)
+ _QM.redis.set('retools:node:%s' % node.name, node.to_json())
+
+
def purge_console(job_id):
key = 'retools:jobconsole:%s' % job_id
try:
View
@@ -4,6 +4,7 @@
from marteau import queue
from marteau.job import reportsdir
+from marteau.node import Node
CURDIR = os.path.dirname(__file__)
@@ -19,6 +20,7 @@ def index():
index = TMPLS.get_template('index.mako')
return index.render(jobs=queue.get_jobs(),
workers=queue.get_workers(),
+ nodes=list(queue.get_nodes()),
failures=queue.get_failures(),
successes=queue.get_successes(),
get_result=queue.get_result,
@@ -74,11 +76,28 @@ def _get_result(jobid):
return res.render(status=status, console=console, report=report)
-
@route('/nodes', method='GET')
def _nodes():
res = TMPLS.get_template('nodes.mako')
- return res.render()
+ return res.render(nodes=list(queue.get_nodes()))
+
+
+@route('/nodes', method='POST')
+def add_node():
+ """Adds a run into Marteau"""
+ node = request.forms.get('name')
+ if node is None:
+ node = request.body.read()
+ rest = True
+ else:
+ rest = False
+
+ node = Node(name=node)
+ queue.save_node(node)
+ if not rest:
+ return redirect('/nodes')
+
+ return location
@route('/media/<filename:path>')
@@ -1,16 +1,31 @@
<%inherit file="base.mako"/>
<div id="right">
-<div id="workers">
+<div id="workers" class="resource">
<span>Workers</span>
%for worker in workers:
<div>${worker.worker_id} - Queues: ${", ".join(worker.queues)}</div>
%endfor
%if not workers:
+<div>
Dude. No workers, no chocolate.
+</div>
%endif
</div>
+<div id="#nodes" class="resource">
+<span>Nodes</span> <a href="/nodes">manage</a>
+%for node in nodes:
+<div>${node.name} (${node.status})</div>
+%endfor
+%if not nodes:
+<div>
+C'mon, I need some boxes.
+</div>
+%endif
+</div>
+
+
<div id="form">
<form action="/test" method="POST">
Add a job. Repo: <input type="text" name="repo"/>
@@ -1,16 +1,43 @@
<%inherit file="base.mako"/>
- <p>Manage here all nodes used for the tests</p>
+
+<div class="smallform resource">
+<form action="/nodes" method="POST">
+ <span>Add a node.</span>
+ <div>
+ <input type="text" name="name"/>
+ <input type="submit"/>
+ </div>
+</form>
+</div>
+
+ <p>Manage here all nodes used for the tests</p>
+ <div>
+ %if not nodes:
+ Nooooo.... No nodes!
+ %endif
+ %if nodes:
<table>
<tr>
<th>Name</th>
<th>Enabled</th>
<th>Status</th>
</tr>
+ %for node in nodes:
<tr>
- <td>locahost</td>
- <td>Yup.</td>
- <td>Active. Ping it</td>
-
+ <td>${node.name}</td>
+ <td>
+ %if node.enabled:
+ Enabled.
+ %endif
+ %if not node.enabled:
+ Disabled.
+ %endif
+ </td>
+ <td>${node.status}</td>
</tr>
+ %endfor
</table>
+%endif
+
+</div>

0 comments on commit 7b6a371

Please sign in to comment.