Commit 94efd9e3 authored by Paul Rich's avatar Paul Rich
Browse files

Merge branch 'develop'

parents b0c2f30e 7a2679a9
.TH "cweb" 8
.SH NAME
cweb \- Cobalt realtime job data agent
.SH SYNOPSIS
.B cweb
[\fB\-id\fR]
[\fB\-p\fR \fIPORT\fR]
[\fB\-\-job\-fields\fR \fIfield1:field2:...:fieldN\fR]
[\fB\-\-reservation\-fields\fR \fIfield1:field2:...:fieldN\fR]
.SH DESCRIPTION
.B cweb
Queries the cobalt queue-manager, scheduler, and active system component for
job, reservation, and node/partition data for a running Cobalt instance. This
data is presented as a JSON-encoded string. If run interactively, \fBcweb\fR
will query once, write results to \fIstdout\fR and exit. If run as a daemon,
then this data will be presented via a web-interface at the specified port to a
HTTP get request. Data will be returned once per request. By default, cweb
will run a webserver, and will direct all status and error messages to
stdout/stderr.
.SH OPTIONS
.TP
.B \-d
Run as a daemon. This will expect a pidfile to be set and will be expected to
run as a service.
.TP
.B \-g \-\-debug
Run a debugging ping-pong server, as opposed to serving JSON data.
.TP
.B \-h
Print help and exit.
.TP
.B \-i \-\-immediage
Run interacively. Fetch current job/reservation/resource status, print JSON and
exit.
.TP
.B \-p PORT \-\-port PORT
Port to respond to. This is ignored with the \fI\-i\fR flag.
.TP
.B \-\-job\-fields field1:field2:...:fieldN
Fetch additional data fields for job data. See
.BR cqm(8)
for additional fields. Additional fields are ':'-delimited
.TP
.B \-\-reservation\-fields field1:field2:...:fieldN
Fetch additional data fields for job data. See
.BR bgsched (8)
for additional fields. Additional fields are ':'-delimited
.SH NOTES
.SH SEE ALSO
.BR cqm (8)
.BR bgsched (8)
.BR bgqsystem (8)
.BR alpssystem (8)
.BR cluster_system (8)
Summary: Cobalt System Software Suite
Name: cobalt
Version: $Version$
Release: 1
License: CPL
Group: System Software
URL: http://www.mcs.anl.gov/cobalt
Prefix: /usr
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires: python >= 2.6
%package -n cobalt-clients
Version: %{version}
Summary: Cobalt Resource Management System clients
Group: Applications/System
Requires: %{requires}
%description -n cobalt-clients
Cobalt Resource Management clients.
%description
The Cobalt Resource Management System
%prep
%setup -q
python2.6 setup.py build
%define client_wrapper_dir /usr/libexec/cobalt
%define python_wrapper_dir %{client_wrapper_dir}/bin
%build
cd src/clients && make PROGPREFIX=%{client_wrapper_dir}
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}
mkdir -p ${RPM_BUILD_ROOT}%{_bindir}
mkdir -p ${RPM_BUILD_ROOT}%{client_wrapper_dir}
python2.6 setup.py install --prefix=${RPM_BUILD_ROOT}%{client_wrapper_dir} --install-lib ${RPM_BUILD_ROOT}/usr/lib64/python2.6/site-packages
install -m 755 src/clients/wrapper ${RPM_BUILD_ROOT}%{python_wrapper_dir}
install -m 755 src/clients/cobalt-admin ${RPM_BUILD_ROOT}%{_sbindir$}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/slp.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bgsched.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/user_script_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cqm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bg_mpirun_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bg_runjob_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/system_script_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/gravina.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/partadm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/setres.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/releaseres.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cqadm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bgsystem.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bgqsystem.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/schedctl.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cluster_system.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cluster_simulator.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/nodeadm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/perfdata.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/prologue_helper.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cdbwriter.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cweb.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/test*
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/brun.py
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bstat.py
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/pmrun.py
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cdump.py
mkdir -p ${RPM_BUILD_ROOT}%{_initrddir}
mkdir -p ${RPM_BUILD_ROOT}/etc/init.d
mkdir -p ${RPM_BUILD_ROOT}/etc/sysconfig
%{__mv} misc/cweb.init ${RPM_BUILD_ROOT}/etc/init.d/cweb
%{__mv} misc/cweb.sysconfig ${RPM_BUILD_ROOT}/etc/sysconfig/cweb
#install -m 644 misc/cobalt ${RPM_BUILD_ROOT}/etc/init.d
#mkdir ${RPM_BUILD_ROOT}%{_sysconfdir}
install -m 644 misc/cobalt.conf ${RPM_BUILD_ROOT}/etc
cd ${RPM_BUILD_ROOT}%{_sbindir}
#for file in `find . -name \*.py | sed -e 's/\.py//' ` ; do ln -s cobalt-admin $file ; done
cd ${RPM_BUILD_ROOT}%{python_wrapper_dir}
for file in `find . -name \*.py | sed -e 's/\.py//' |grep -v fake` ; do ln -sf %{python_wrapper_dir}/wrapper ${RPM_BUILD_ROOT}%{_bindir}/$file ; done
find . -wholename "./Parser" -prune -o -name '*.py' -type f -print0 | xargs -0 grep -lE '^#! *(/usr/.*bin/(env +)?) ?python' | xargs sed -r -i -e '1s@^#![[:space:]]*(/usr/(local/)?bin/(env +)?)?python@#!/usr/bin/python@'
#cd ${RPM_BUILD_ROOT}%{python_wrapper_dir} ; for file in `find . -name \*.py -print` ; do ln -sf wrapper `echo ${RPM_BUILD_ROOT}%{_bindir}/$file|sed -e 's/.py//'` ; done
cd ${RPM_BUILD_ROOT}/usr/sbin ; for file in `find . -name \*.py -print` ; do ln -sf $file `echo $file|sed -e 's/.py//'` ; done
#put manpages back in the right place
%{__mv} ${RPM_BUILD_ROOT}%{client_wrapper_dir}/share ${RPM_BUILD_ROOT}/usr/share
%clean
rm -rf $RPM_BUILD_ROOT
%pre
if ! /usr/bin/getent group cobalt &>/dev/null
then
groupadd cobalt
fi
%post -n cobalt
if test ! -d /var/spool/cobalt ; then
mkdir -p /var/spool/cobalt
chmod 700 /var/spool/cobalt
fi
if test ! -d /var/spool/cobalt/overflow ; then
mkdir -p /var/spool/cobalt/overflow
chmod 700 /var/spool/cobalt/overflow
fi
if [ ! -d /var/log/cobalt ]; then
mkdir -p /var/log/cobalt
chmod 755 /var/log/cobalt
chgrp cobalt /var/log/cobalt
fi
%files -n cobalt
/usr/sbin/*
/etc/init.d/cweb
/etc/sysconfig/cweb
%config (noreplace) %attr(640,root,cobalt) /etc/cobalt.conf
#%config(noreplace) /etc/init.d/cobalt
/usr/share/man/man5/*
/usr/share/man/man8/*
%files -n cobalt-clients
%{python_wrapper_dir}/*
/usr/bin/*
%attr(2755,root,cobalt) %{python_wrapper_dir}/wrapper
/usr/lib*/python2.6/site-packages/Cobalt/*
/usr/lib*/python2.6/site-packages/Cobalt-*egg-info*
/usr/share/man/man1/*.1*
%defattr(-,root,root,-)
%doc
%changelog
* Tue Oct 4 2005 Narayan Desai <desai@mcs.anl.gov> -
- Initial build.
Summary: Cobalt System Software Suite
Name: cobalt
Version: $Version$
Release: 1
License: CPL
Group: System Software
URL: http://www.mcs.anl.gov/cobalt
Prefix: /usr
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: systemd-rpm-macros
Requires: python >= 2.7
Requires: python-lockfile
Requires: python-python-daemon
%package -n cobalt-clients
Version: %{version}
Summary: Cobalt Resource Management System clients
Group: Applications/System
Requires: %{requires}
%description -n cobalt-clients
Cobalt Resource Management clients.
%description
The Cobalt Resource Management System
%prep
%setup -q
%define python python2.7
%{python} setup.py build
%define client_wrapper_dir /usr/libexec/cobalt
%define python_wrapper_dir %{client_wrapper_dir}/bin
%define python_site_packages %{_libdir}%{python}/site-packages
%build
cd src/clients && make PROGPREFIX=%{client_wrapper_dir}
%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}
mkdir -p ${RPM_BUILD_ROOT}%{_bindir}
mkdir -p ${RPM_BUILD_ROOT}%{client_wrapper_dir}
%{python} setup.py install --prefix=${RPM_BUILD_ROOT}%{client_wrapper_dir} --install-lib ${RPM_BUILD_ROOT}%{python_site_packages}
install -m 755 src/clients/wrapper ${RPM_BUILD_ROOT}%{python_wrapper_dir}
install -m 755 src/clients/cobalt-admin ${RPM_BUILD_ROOT}%{_sbindir$}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/slp.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bgsched.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/user_script_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cqm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bg_mpirun_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bg_runjob_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/system_script_forker.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/gravina.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/partadm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/setres.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/releaseres.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cqadm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bgsystem.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bgqsystem.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/schedctl.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cluster_system.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cluster_simulator.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/nodeadm.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/perfdata.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/prologue_helper.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cdbwriter.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__mv} ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cweb.py ${RPM_BUILD_ROOT}%{_sbindir}
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/test*
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/brun.py
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/bstat.py
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/pmrun.py
%{__rm} -f ${RPM_BUILD_ROOT}%{python_wrapper_dir}/cdump.py
mkdir -p ${RPM_BUILD_ROOT}%{_initrddir}
%{__mv} misc/cobalt.init.cray ${RPM_BUILD_ROOT}/etc/init.d/cobalt
install -m 644 misc/cobalt.conf ${RPM_BUILD_ROOT}/etc
mkdir -p ${RPM_BUILD_ROOT}/%{_unitdir}
install -m 640 misc/cweb.service ${RPM_BUILD_ROOT}%{_unitdir}
cd ${RPM_BUILD_ROOT}%{_sbindir}
#for file in `find . -name \*.py | sed -e 's/\.py//' ` ; do ln -s cobalt-admin $file ; done
cd ${RPM_BUILD_ROOT}%{python_wrapper_dir}
for file in `find . -name \*.py | sed -e 's/\.py//' |grep -v fake` ; do ln -sf %{python_wrapper_dir}/wrapper ${RPM_BUILD_ROOT}%{_bindir}/$file ; done
find . -wholename "./Parser" -prune -o -name '*.py' -type f -print0 | xargs -0 grep -lE '^#! *(/usr/.*bin/(env +)?) ?python' | xargs sed -r -i -e '1s@^#![[:space:]]*(/usr/(local/)?bin/(env +)?)?python@#!/usr/bin/python@'
#cd ${RPM_BUILD_ROOT}%{python_wrapper_dir} ; for file in `find . -name \*.py -print` ; do ln -sf wrapper `echo ${RPM_BUILD_ROOT}%{_bindir}/$file|sed -e 's/.py//'` ; done
cd ${RPM_BUILD_ROOT}%{_sbindir} ; for file in `find . -name \*.py -print` ; do ln -sf $file `echo $file|sed -e 's/.py//'` ; done
#put manpages back in the right place
%{__mv} ${RPM_BUILD_ROOT}%{client_wrapper_dir}/share ${RPM_BUILD_ROOT}/usr/share
%clean
rm -rf ${RPM_BUILD_ROOT}
%pre
if ! /usr/bin/getent group cobalt &>/dev/null
then
groupadd cobalt
fi
%post -n cobalt
if test ! -d /var/spool/cobalt ; then
mkdir -p /var/spool/cobalt
chmod 700 /var/spool/cobalt
fi
if test ! -d /var/spool/cobalt/overflow ; then
mkdir -p /var/spool/cobalt/overflow
chmod 700 /var/spool/cobalt/overflow
fi
if [ ! -d /var/log/cobalt ]; then
mkdir -p /var/log/cobalt
chmod 755 /var/log/cobalt
chgrp cobalt /var/log/cobalt
fi
%files -n cobalt
%{_sbindir}/*
%config (noreplace) %attr(640,root,cobalt) /etc/cobalt.conf
%config (noreplace) /etc/init.d/cobalt
# On SLES systems we're running this through systemd
%config (noreplace) %attr(640,root,cobalt)
%{_unitdir}/cweb.service
%{_mandir}/man5/*.5*
%{_mandir}/man8/*.8*
%files -n cobalt-clients
%{python_wrapper_dir}/*
%{_bindir}/*
%attr(2755,root,cobalt) %{python_wrapper_dir}/wrapper
%{python_site_packages}/Cobalt/*
%{python_site_packages}/Cobalt-*egg-info*
%{_mandir}/man1/*.1*
%defattr(-,root,root,-)
%doc
%changelog
* Fri Feb 17 2017 Paul Rich <richp@alcf.anl.gov>
- SLES-Cray specfile updates.
* Tue Oct 4 2005 Narayan Desai <desai@mcs.anl.gov> -
- Initial build.
#!/bin/sh
#
# cweb
#
# chkconfig: 345 90 60
# description: provides cobalt information to the gronkulator web application
### BEGIN INIT INFO
# Provides: cweb
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 345
# Default-Stop: 90
# Short-Description:
# Description:
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
prog="cweb"
config="/etc/sysconfig/${prog}"
python="$(which python2.6)"
CWEB_USER='root'
CWEB_PORT=5050
CWEB_ARGS=''
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
exec=/usr/sbin/cweb
pidfile=/var/run/${prog}.pid
lockfile=${pidfile}.lock
args="-d -p $CWEB_PORT -f $pidfile $CWEB_ARGS"
start() {
[ -f $exec ] || exit 5
[ -f $config ] || exit 6
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
daemon --user $CWEB_USER --pidfile $pidfile "$python $exec $args"
retval=$?
echo
return $retval
}
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
killproc -p $pidfile -TERM $python
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
killproc -p $pidfile $prog -HUP
}
rh_status() {
# run checks to determine if the service is running or use generic status
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
exit $?
[Unit]
Description=Daemon for serving Cobalt information via web service.
[Service]
Type=simple
PIDFile=/var/run/cweb.pid
StandardOutput=syslog
StandardError=syslog
Environment=COBALT_CONFIG_FILES=/etc/cobalt.conf
Environment=cweb_path=/usr/sbin/cweb
Environment=cweb_port=5050
Environment=cweb_pidfile=/var/run/cweb.pid
EnvironmentFile=-/usr/lib/systemd/system/cweb.env
ExecStart=/usr/bin/python2.7 $cweb_path -p $cweb_port -d -f $cweb_pidfile
CWEB_USER=root
CWEB_PORT=5050
......@@ -60,6 +60,7 @@ import os
import sys
import signal
import socket
import ast
from Cobalt import client_utils
from Cobalt.client_utils import \
cb_debug, cb_env, cb_nodes, cb_time, cb_umask, cb_path, cb_dep, \
......@@ -275,7 +276,7 @@ def update_spec(parser, opts, spec, opt2spec):
This function will update the appropriate spec values with the opts values
"""
# Get the key validated values into spec dictionary
for opt in ['mode', 'proccount', 'nodecount']:
for opt in ['mode', 'proccount', 'nodecount', 'attrs']:
spec[opt2spec[opt]] = opts[opt]
# Hack until the Cluster Systems get re-written.
......@@ -591,8 +592,10 @@ def main():
filters = client_utils.get_filters()
client_utils.process_filters(filters, spec)
# Attrs needs special handling filter won't set otherwise
if spec.get('attrs', None) is not None:
opts['attrs'].update(ast.literal_eval(str(spec['attrs'])))
update_spec(parser, opts, spec, opt2spec)
run_job(parser, user, spec, opts)
if __name__ == '__main__':
......
#!/usr/bin/env python
'''cweb: Cobalt client for serving json-encoded job and system status
required by the gornkulator.
cweb queries a running Cobalt instance to obtain system configuration
information, pending and active reservations, queued jobs and running jobs.
This client is intended to run as a daemon and provides the system status as a
REST-ish service.
'''
import logging
import sys
import time
import traceback
from collections import deque, defaultdict
from logging.handlers import SysLogHandler
from optparse import OptionParser
from random import shuffle
from socket import getfqdn
from wsgiref.simple_server import make_server, WSGIRequestHandler
try:
import json
except ImportError:
import simplejson as json
import daemon #python-daemon
try:
# works for python-daemon 1.5.5 or earlier, needed for 2.6 compat.
from daemon.pidlockfile import PIDLockFile
except (ImportError, TypeError):
# We are in the 2.7 or later world
from daemon.pidfile import PIDLockFile
from Cobalt.Proxy import ComponentProxy
from Cobalt.Util import merge_nodelist
class GronkdRequestHandler(WSGIRequestHandler):
"""subclass of WSGIRequestHandler so I can override the default logging
mechanism."""
def log_message(self, format, *args):
msg = '%s - ' % self.client_address[0] + format % args
logger.info(msg)
# Set up some basic logging information
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
formatter = logging.Formatter('cweb[%(process)d]: %(message)s')
syslog_handler = SysLogHandler(address='/dev/log', facility='daemon')
syslog_handler.setFormatter(formatter)
logger.addHandler(syslog_handler)
# Artifact of how this was put together and this ends up being an efficient way
# to get data into the wsgi server app.
system_type = None
system_types = ['bgsystem', 'bgqsystem', 'cluster_system', 'alps_system']
bg_types = ['bgsystem', 'bgqsystem']
cluster_types = ['cluster_system']
cray_types = ['alps_system']
hostname = getfqdn()
partition_table = {}
node_state = {}
indexes = {}
alps_system_query_fields = ['Node_id', 'Name', 'Queues', 'Status', 'Backfill']
job_query_fields = ['jobid', 'walltime', 'nodes', 'mode', 'queue', 'starttime',
'submittime', 'project']
reservation_query_fields = ['name', 'start', 'duration', 'partitions', 'queue']
# Maps colors to nodes and partitions
color_map = {}
# A queue containing the currently running colors
color_queue = deque(['#028F5C', '#051EB8', '#70AE14', '#0A3D70', '#0CCCCC',
'#0F5C28', '#11EB84', '#147AE0', '#170A3C', '#199998',
'#1C28F4', '#1EB850', '#2147AC', '#23D708', '#266664',
'#28F5C0', '#2B851C', '#2E1478', '#30A3D4', '#333330',
'#35C28C', '#3851E8', '#3AE144', '#3D70A0', '#3FFFFC',
'#428F58', '#451EB4', '#47AE10', '#4A3D6C', '#4CCCC8',
'#4F5C24', '#51EB80', '#547ADC', '#570A38', '#599994',
'#5C28F0', '#5EB84C', '#6147A8', '#63D704', '#666660',
'#68F5BC', '#6B8518', '#6E1474', '#70A3D0', '#73332C',
'#75C288', '#7851E4', '#7AE140', '#7D709C', '#7FFFF8',
'#828F54', '#851EB0', '#87AE0C', '#8A3D68', '#8CCCC4',
'#8F5C20', '#91EB7C', '#947AD8', '#970A34', '#999990',
'#9C28EC', '#9EB848', '#A147A4', '#A3D700', '#A6665C',
'#A8F5B8', '#AB8514', '#AE1470', '#B0A3CC', '#B33328',
'#B5C284', '#B851E0', '#BAE13C', '#BD7098', '#BFFFF4',
'#C28F50', '#C51EAC', '#C7AE08', '#CA3D64', '#CCCCC0',
'#CF5C1C', '#D1EB78', '#D47AD4', '#D70A30', '#D9998C',
'#DC28E8', '#DEB844', '#E147A0', '#E3D6FC', '#E66658',
'#E8F5B4', '#EB8510', '#EE146C', '#F0A3C8', '#F33324',
'#F5C280', '#F851DC', '#FAE138', '#FD7094'])
shuffle(color_queue)
def tdformat(seconds):
'''Convert from an integer representing seconds to an #d HH:MM:SS format'''
days, remainder = divmod(int(seconds), 86400)
hours, remainder = divmod(int(remainder), 3600)
minutes, seconds = divmod(remainder, 60)
out = ''
if days: out += '%dd ' % days
out += ':'.join('%02d' % x for x in (hours, minutes, seconds))
return out
def check_finished(run_jobs):
'''checks if the job has finished running and removes from color map'''
for job_id, color in color_map.items():
if job_id not in run_jobs:
color_queue.appendleft(color)
del(color_map[job_id])
def cobalt_query(state):
cqm = ComponentProxy('queue-manager', defer=True)
scheduler = ComponentProxy('scheduler', defer=True)
if state not in ('running', 'queued', 'reservation'):
return None
# Templates for queries to coblat
query_job = dict.fromkeys(job_query_fields, '*')
query_res = dict.fromkeys(reservation_query_fields, '*')
if state == 'reservation':
return scheduler.get_reservations([query_res])
if state == 'running' or state == 'starting':
query_job['state'] = 'running'
query_job['location'] = '*'
if state == 'queued':
query_job['state'] = 'queued'
query_job['score'] = '*'
return cqm.get_jobs([query_job])
def get_job_data():
# Import this here to bypass problems with daemonization
global partition_table
global node_state
global system_type
now = time.time()
jobs = {'lastUpdated': int(now),
'nodeinfo': defaultdict(dict),
'indexes': indexes,
'running': cobalt_query('running'),
'queued': cobalt_query('queued'),