Skip to content
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
32 changes: 32 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.{js,py}]
charset = utf-8

[*.py]
indent_style = tab
tag_width = 4
; max_line_length = 79

[*.html]
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.css]
indent_style = space
indent_size = 2

[{.travis.yml}]
indent_style = space
indent_size = 2


14 changes: 6 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
:target: http://coalition.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. |badge-size| image:: https://reposs.herokuapp.com/?path=https://github.com/MercenariesEngineering/coalition
.. |badge-tests| image:: https://travis-ci.org/MercenariesEngineering/coalition.svg?branch=master

.. |badge-version| image:: https://badge.fury.io/gh/MercenariesEngineering%2Fcoalition.svg
:target: https://badge.fury.io/gh/MercenariesEngineering%2Fcoalition

.. |badge-size| image:: https://reposs.herokuapp.com/?path=https://github.com/MercenariesEngineering/coalition

.. |badge-coverage| image:: https://coveralls.io/repos/github/MercenariesEngineering/coalition/badge.svg?branch=development
:target: https://coveralls.io/github/MercenariesEngineering/coalition?branch=development

.. |badge-tests| image:: https://travis-ci.org/MercenariesEngineering/coalition.svg?branch=master

|badge-doc| |badge-size| |badge-version| |badge-coverage| |badge-tests|

`Full online documentation is availlble on ReadTheDocs <http://coalition.readthedocs.io/en/latest/>`_.
`Full online documentation is available on ReadTheDocs <http://coalition.readthedocs.io/en/latest/>`_.

Coalition
=========
Expand All @@ -40,9 +41,6 @@ The server waits for incoming workers connections. Workers ask the server for a
- **Unittests** of critical code parts;
- **Source code** and **documentation** on `the development platform <https://github.com/MercenariesEngineering/coalition>`_.

The current stable version are 3.8 and 3.10.

The development version is |current-version|.

.. |current-version| include:: version
The stable versions are 3.8 and 3.10. The current version is referenced in the file *version*, that is:

.. literalinclude:: ../../version
55 changes: 33 additions & 22 deletions db_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def _getLdapPermission(self, action):
if not hasattr(self, "ldap_user") or not self.ldap_user: # LDAP is not set up in configuration or ldapunsafeapi is set to True
return ""
if action == "addjob":
if self.permissions["ldaptemplateaddjobglobal"]:
if self.permissions["ldaptemplatecreatejobglobal"]:
return ""
elif self.permissions["ldaptemplateaddjob"]:
elif self.permissions["ldaptemplatecreatejob"]:
return "AND user='{user}'".format(user=self.ldap_user)
else:
raise LdapError("Action '{action}' is not permitted for user '{user}'".format(action=action, user=self.ldap_user))
Expand Down Expand Up @@ -207,7 +207,7 @@ def getAffinityMask (self, affinities):
aff = self.listAffinities ()
mask = 0L
cur = self.Conn.cursor ()
for affinity in affinities.split (","):
for affinity in [a.strip() for a in affinities.split (",")]:
if affinity != "":
m = re.match(r"^#(\d+)$", affinity)
if m:
Expand Down Expand Up @@ -236,15 +236,15 @@ def getAffinityString (self, affinity_bits):
self.AffinityBitsToName[affinity_bits] = result
return result

def newJob(self, parent, title, command, dir, environment, state, paused, timeout,
def newJob(self, parent, title, command, dir, environment, state, paused, timeout,
priority, affinity, user, url, progress_pattern, dependencies = None):
ldap_perm = self._getLdapPermission("addjob")
if ldap_perm is False:
return None
if ldap_perm != "": # User can add job owned by himself, force user value
user = self.ldap_user
cur = self.Conn.cursor()
self._execute(cur,
self._execute(cur,
"SELECT h_depth, h_affinity, h_priority, h_paused, command "
"FROM Jobs "
"WHERE id = {parent} {ldap_perm}".format(parent=parent, ldap_perm=ldap_perm))
Expand Down Expand Up @@ -354,16 +354,22 @@ def getJobDependencies(self, id):
rows = cur.fetchall()
return [self._rowAsDict (cur, row) for row in rows]

def getCountJobsWhere(self, where_clause=''):
def getCountJobsWhere(self, where_clause='', inner_join_table=''):
"""Get the number of matching jobs."""
cur = self.Conn.cursor()
self._execute(cur, "SELECT COUNT(*) FROM Jobs WHERE {}".format(where_clause[0]))
if not inner_join_table:
self._execute(cur, "SELECT COUNT(DISTINCT Jobs.id) FROM Jobs WHERE {}".format(where_clause))
else:
self._execute(cur, "SELECT COUNT(DISTINCT Jobs.id) FROM Jobs, {} WHERE {}".format(inner_join_table, where_clause))
return cur.fetchone()[0]

def getJobsWhere(self, where_clause='', index_min=0, index_max=1):
def getJobsWhere(self, where_clause='', inner_join_table='', index_min=0, index_max=1):
"""Get Jobs via a readonly SQL request."""
cur = self.Conn.cursor()
self._execute(cur, "SELECT * FROM Jobs WHERE {} LIMIT {},{}".format(where_clause, index_min, index_max))
if not inner_join_table:
self._execute(cur, "SELECT DISTINCT Jobs.* FROM Jobs WHERE {} LIMIT {},{}".format(where_clause, index_min, index_max))
else:
self._execute(cur, "SELECT DISTINCT Jobs.* FROM Jobs, {} WHERE {} LIMIT {},{}".format(inner_join_table, where_clause, index_min, index_max))
return [self._rowAsDict (cur, row) for row in cur.fetchall()]

def getJobsUsers(self):
Expand Down Expand Up @@ -396,12 +402,6 @@ def getJobsAffinities(self):
self._execute(cur, "SELECT DISTINCT affinity FROM Jobs")
return [self._rowAsDict (cur, row) for row in cur.fetchall()]

def getChildrenDependencyIds (self, id):
cur = self.Conn.cursor ()
self._execute (cur, "SELECT job.id AS id, dep.dependency AS dependency FROM Dependencies AS dep "
"INNER JOIN Jobs AS job ON job.id = dep.job_id "
" WHERE job.parent = %d" % id)

def getChildrenDependencyIds(self, id):
cur = self.Conn.cursor()
self._execute(cur, """
Expand All @@ -426,20 +426,18 @@ def getWorker (self, hostname):
worker['total_memory'] = info['total_memory']
except:
pass

self._execute (cur, "SELECT affinity FROM WorkerAffinities WHERE worker_name = '%s'" % ( hostname ) )
affinities = []

data = cur.fetchone()

if data is None:
worker['affinity'] = ""
return worker

for data in cur:
if data is None:
worker['affinity'] = ""
return worker
affinities.append( self.getAffinityString( data[0] ) )

worker['affinity'] = "\n".join( affinities )
worker['start_time'] = self.getWorkerStartTime(worker['name'])
return worker

def getWorkerStartTime(self, name):
Expand Down Expand Up @@ -481,6 +479,19 @@ def getWorkers (self):
workers.append (worker)
return workers

def getWorkersWhere(self, where_clause='', inner_join_table='', index_min=0, index_max=1):
"""Get WOrkers via readonly SQL requests."""
workers = list()
cur = self.Conn.cursor()
if not inner_join_table:
self._execute(cur, "SELECT DISTINCT Workers.name FROM Workers WHERE {} LIMIT {},{}".format(where_clause, index_min, index_max))
else:
self._execute(cur, "SELECT DISTINCT Workers.name FROM Workers, {} WHERE {} LIMIT {},{}".format(inner_join_table, where_clause, index_min, index_max))

for name in cur.fetchall():
workers.append(self.getWorker(name))
return workers

def getEvents (self, job, worker, howlong):
cur = self.Conn.cursor()
req = "SELECT * FROM Events WHERE start > %d" % (int(time.time())-howlong)
Expand Down
1 change: 1 addition & 0 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Using a `python virtual environment <https://virtualenv.pypa.io/en/stable/>`_ is

Logged as a priviledged user, in a shell prompt, run::

apt-get install libsasl2-dev libldap2-dev libmysqlclient-dev
cd /usr/local/bin
git clone https://github.com/MercenariesEngineering/coalition.git
cd coalition
Expand Down
2 changes: 1 addition & 1 deletion doc/source/python_api.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Python API
==========

.. automodule:: coalition
.. automodule:: api.coalition
:members:
:show-inheritance:
Loading