Skip to content

Commit

Permalink
2.0.1, still experimental but looks good
Browse files Browse the repository at this point in the history
  • Loading branch information
niphlod committed Nov 2, 2014
1 parent 156c22c commit abc284d
Show file tree
Hide file tree
Showing 16 changed files with 1,052 additions and 194 deletions.
98 changes: 85 additions & 13 deletions controllers/plugin_cs_monitor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf8
from datetime import timedelta as timed
import datetime
import time
from gluon.storage import Storage
from gluon import current
from gluon.serializers import json as dumps
Expand All @@ -9,6 +10,7 @@
from plugin_cs_monitor.html_helpers import nice_worker_stats, nice_task_status, mybootstrap
from plugin_cs_monitor.html_helpers import fixup_bs3_widgets
from plugin_cs_monitor.scheduler_helpers import requeue_task
from gluon.scheduler import JobGraph
from collections import defaultdict

response.files.append(URL('static', 'plugin_cs_monitor/js/stupidtable/stupidtable.min.js'))
Expand All @@ -25,6 +27,9 @@

response.files.append(URL('static', 'plugin_cs_monitor/js/dagre/dagre-d3.min.js'))

response.files.append(URL('static', 'plugin_cs_monitor/js/select2/select2.min.js'))
response.files.append(URL('static', 'plugin_cs_monitor/js/select2/select2-bootstrap.css'))

response.files.append(URL('static', 'plugin_cs_monitor/js/app.js'))

##Configure start
Expand All @@ -48,7 +53,7 @@
'cacheable': True}

TASKS_SUMMARY_KWARGS = {
'cache': (cache.with_prefix(sc_cache, "plugin_cs_monitor"),TASKS_SUMMARY_CACHE_TIME),
'cache': (cache.with_prefix(sc_cache, "plugin_cs_monitor"), TASKS_SUMMARY_CACHE_TIME),
'cacheable' : True}

response.meta.author = 'Niphlod <niphlod@gmail.com>'
Expand Down Expand Up @@ -100,12 +105,12 @@ def wactions():
r = [request.vars.w_records]
else:
r = request.vars.w_records
for w in r:
s.set_worker_status(action=request.vars.action, worker_name=w)
rtn = dbs(sw.worker_name.belongs(r)).validate_and_update(status=request.vars.action)
if rtn.errors:
session.flash = "Not a valid action"
elif rtn.updated:
session.flash = "%s workers updated correctly" % rtn.updated
redirect(default)
session.flash = "%s workers updated correctly" % len(r)
redirect(default)


@auth.requires_signature()
def tactions():
Expand Down Expand Up @@ -168,13 +173,15 @@ def tactions():

redirect(default)


@auth.requires_signature()
def tasks():
session.forget(response)
c = cache_tasks_counts(st)

return dict(c=c)


def cache_tasks_counts(t):

if GROUPING_MODE == 'python':
Expand Down Expand Up @@ -202,6 +209,7 @@ def cache_tasks_counts(t):

return rtn


@auth.requires_signature()
def task_group():
session.forget(response)
Expand Down Expand Up @@ -243,6 +251,7 @@ def task_group():
BASEURL = URL("plugin_cs_monitor", "tactions", user_signature=True)
return dict(tasks=tasks, paginate=paginate, total=total, page=page, BASEURL=BASEURL)


@auth.requires_signature()
def task_details():
session.forget(response)
Expand All @@ -255,6 +264,7 @@ def task_details():
deps = [row.job_name for row in deps]
return dict(task=task, st=st, deps=deps)


@auth.requires_signature()
def run_details():
session.forget(response)
Expand Down Expand Up @@ -288,6 +298,7 @@ def run_details():
row.elapsed_seconds_ = td
return dict(runs=runs, paginate=paginate, total=total, page=page)


@auth.requires_signature()
def run_traceback():
session.forget(response)
Expand All @@ -299,6 +310,7 @@ def run_traceback():
return ''
return dict(traceback=rtn.traceback)


@auth.requires_signature()
def edit_task():
task_id = request.args(0)
Expand Down Expand Up @@ -359,6 +371,7 @@ def edit_task():
response.flash = 'Errors detected'
return dict(form=form, task=task)


def gb_duration(q):
#byduration
count_ = sr.id.count()
Expand Down Expand Up @@ -398,6 +411,7 @@ def gb_duration(q):

return gb_duration_rows, jgb_duration_series


def gb_status(q, mode='runs'):
#bystatus
if GROUPING_MODE == 'python':
Expand Down Expand Up @@ -441,6 +455,7 @@ def gb_status(q, mode='runs'):

return gb_status_rows, jgb_status_series


def bydate(q, mode):
#by period

Expand Down Expand Up @@ -503,6 +518,7 @@ def bydate(q, mode):

return gb_when_rows, jgb_when_series


def byday(q, day, mode):
#by period
if GROUPING_MODE == 'python':
Expand Down Expand Up @@ -648,6 +664,7 @@ def clear_cache():
session.flash = 'Cache Cleared'
redirect(URL("index"), client_side=True)


@auth.requires_signature()
def delete_tasks():
session.forget(response)
Expand Down Expand Up @@ -677,16 +694,26 @@ def delete_tasks():
limit = limit.strftime('%Y-%m-%d %H:%M:%S')
return dict(limit=limit)

@auth.requires_signature()

@auth.requires_signature(hash_vars=False)
def jobs():
return dict()


@auth.requires_signature(hash_vars=False)
def jobs_render():
session.forget(response)
q = sd.id > 0
if request.vars.job_name:
q = sd.job_name == request.vars.job_name
all_jobs = dbs(q).select(sd.job_name, groupby=sd.job_name)
all_jobs = dict([(row.job_name, "a_%s" % k) for k, row in enumerate(all_jobs)])
all_deps = dbs(q).select()
all_jobs = {request.vars.job_name : 'a_0'}
newjob = None
else:
q = sd.id > 0
all_jobs = dbs(q).select(sd.job_name, groupby=sd.job_name)
all_jobs = dict([(row.job_name, "a_%s" % k) for k, row in enumerate(all_jobs)])
newjob = str(int(time.mktime(datetime.datetime.utcnow().timetuple())))

all_deps = dbs(q).select()
all_nodes = {}
all_edges = {}
for row in all_deps:
Expand All @@ -705,7 +732,9 @@ def jobs():
for id in v.keys():
all_tasks_ids[id] = None

all_tasks_labels = dbs(st.id.belongs(all_tasks_ids.keys())).select().as_dict()
all_tasks_labels = dbs(st.id.belongs(all_tasks_ids.keys())).select(
st.id, st.function_name, st.task_name, st.status
).as_dict()

for k, v in all_nodes.iteritems():
for id in v.keys():
Expand All @@ -714,5 +743,48 @@ def jobs():
title="%(id)s (%(function_name)s): %(status)s" % all_tasks_labels[id],
linkto=URL('task_details', args=id, user_signature=True))

return dict(all_jobs=all_jobs, all_edges=dumps(all_edges), all_nodes=dumps(all_nodes))
return dict(all_jobs=all_jobs, all_edges=dumps(all_edges), all_nodes=dumps(all_nodes), newjob=newjob)

@auth.requires_signature(hash_vars=False)
def edit_job():
posted = request.post_vars
if posted:
if ',' in posted.task_child and ',' in posted.task_parent:
session.flash = 'Only one multiple value allowed'
return dict()
if ',' in posted.task_child:
posted.task_child = posted.task_child.split(',')
else:
posted.task_child = [posted.task_child]
if ',' in posted.task_parent:
posted.task_parent = posted.task_parent.split(',')
else:
posted.task_parent = [posted.task_parent]
myjob = JobGraph(dbs, posted.job_name)
for child in posted.task_child:
for parent in posted.task_parent:
myjob.add_deps(parent, child)
rtn = myjob.validate(posted.job_name)
if rtn is None:
session.flash = "No task added, validation failed"
else:
session.flash = "Dependency correctly added"
return dict()

@auth.requires_signature(hash_vars=False)
def tasks_dropdown_helper():
session.forget(response)
if not request.get_vars.q:
raise HTTP(404)
q = request.get_vars.q
all_tasks = dbs(
(st.task_name.ilike('%' + q + '%')) |
(st.id.ilike('%' + q + '%'))
).select(
st.id, st.task_name
)
rtn = []
for row in all_tasks:
rtn.append(dict(id=row.id, text='%(id)s - %(task_name)s' % row))

return dumps(dict(results=rtn))
2 changes: 1 addition & 1 deletion modules/plugin_cs_monitor/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'STOPPED' : ('#B94A48', SPAN('STOPPED', _class="label label-danger")),
'EXPIRED' : ('#F89406', SPAN('EXPIRED', _class="label label-warning")),
'ASSIGNED' : ('#FAA732', SPAN('ASSIGNED', _class="label label-warning")),
'TIMEOUT' : ('#FAA732', SPAN('TIMEOUT', _class="label label-warning")),
'TIMEOUT' : ('#B94A48', SPAN('TIMEOUT', _class="label label-warning")),
}

WORKER_STATUS = {
Expand Down
13 changes: 13 additions & 0 deletions static/plugin_cs_monitor/js/instantclick.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions static/plugin_cs_monitor/js/select2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright 2014 Igor Vaynberg

Version: @@ver@@ Timestamp: @@timestamp@@

This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
General Public License version 2 (the "GPL License"). You may choose either license to govern your
use of this software only upon the condition that you accept all of the terms of either the Apache
License or the GPL License.

You may obtain a copy of the Apache License and the GPL License at:

http://www.apache.org/licenses/LICENSE-2.0
http://www.gnu.org/licenses/gpl-2.0.html

Unless required by applicable law or agreed to in writing, software distributed under the Apache License
or the GPL Licesnse is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the Apache License and the GPL License for the specific language governing
permissions and limitations under the Apache License and the GPL License.
Loading

0 comments on commit abc284d

Please sign in to comment.