예제 #1
0
파일: Job.py 프로젝트: vishalbelsare/kdvs
class JobGroupManager(object):
    r"""
Simple manager of groups of jobs. Can be used for finer execution control and
to facilitate reporting.
    """
    def __init__(self, **kwargs):
        r"""
Parameters
----------
kwargs : dict
    any keyworded arguments that may be used by the user for finer control (e.g.
    in sublass); currently, no arguments are used
        """
        self._jgmap = SetBDMap()

    def addJobIDToGroup(self, group_name, jobID):
        r"""
Add requested job to specified job group. If group was not defined before, it will
be created.

Parameters
----------
group_name : string
    name of the group

jobID : string
    job ID
        """
        self._jgmap[group_name] = jobID

    def addGroup(self, group_name, group_job_ids):
        r"""
Add series of jobs to specified job group (shortcut). If group was not defined before, it will
be created.

Parameters
----------
group_name : string
    name of the group

group_job_ids : iterable of string
    job IDs
        """
        for jid in group_job_ids:
            self.addJobIDToGroup(group_name, jid)

    def remGroup(self, group_name):
        r"""
Remove specified job group from this manager. All associated job IDs are removed as
well. NOTE: physical jobs are left intact.

Parameters
----------
group_name : string
    name of the group
        """
        del self._jgmap[group_name]

    def clear(self):
        r"""
Removes all job groups from this manager.
        """
        self._jgmap.clear()

    def getGroupJobsIDs(self, group_name):
        r"""
Get list of job IDs associated with specified job group name.

Parameters
----------
group_name : string
    name of the group

Returns
-------
jobIDs : iterable of string
    all job IDs from requested group, if exists
        """
        return list(self._jgmap.getFwdMap()[group_name])

    def findGroupByJobID(self, jobID):
        r"""
Identify job group of the requested job ID.

Parameters
----------
jobID : string
    job ID

Returns
-------
group_name : string
    name of the group with requested job, if exists

Raises
------
Error
    if jobID is found in more than one group
        """
        gr = self._jgmap.getBwdMap()[jobID]
        if len(gr) > 1:
            # should not happen with SetBDMap but to be safe...
            raise Error(
                'Job shall be internally assigned to single group! (got %s)' %
                gr)
        # return single element from the set
        return next(iter(gr))

    def getGroups(self):
        r"""
Get list of all job group names managed by this manager.
        """
        return self._jgmap.getFwdMap().keys()
예제 #2
0
 def test_init1(self):
     bd1 = SetBDMap()
     self.assertEqual(self.emptyFwdMap, bd1.getFwdMap())
     self.assertEqual(self.emptyBwdMap, bd1.getBwdMap())