Ejemplo n.º 1
0
def cleanup_after_job(job_id):
    """
    Release the resources used by an openquake job.

    :param job_id: the job id
    :type job_id: int
    """
    logging.debug('Cleaning up after job %s', job_id)

    kvs.cache_gc(job_id)
Ejemplo n.º 2
0
def clear_job_data(job_id):
    """
    Clear KVS cache data for the given job. This is done by searching in the
    KVS for keys matching a job key (derived from the job_id) and deleting each
    result.

    Invoked by the -j or --job command line arg.

    :param job_id: job ID as an integer
    """

    try:
        job_id = int(job_id)
    except ValueError:
        print 'Job ID should be an integer.'
        print 'Use the --list option to show current jobs.'
        raise

    LOG.info('Attempting to clear cache data for job %s...' % job_id)

    result = kvs.cache_gc(job_id)

    if result is None:
        LOG.info('Job %s not found.' % job_id)
    else:
        LOG.info('Removed %s keys.' % result)
Ejemplo n.º 3
0
def clear_job_data(job_id):
    """
    Clear KVS cache data for the given job. This is done by searching in the
    KVS for keys matching a job key (derived from the job_id) and deleting each
    result.

    Invoked by the -j or --job command line arg.

    :param job_id: job ID as an integer
    """

    try:
        job_id = int(job_id)
    except ValueError:
        print 'Job ID should be an integer.'
        print 'Use the --list option to show current jobs.'
        raise

    LOG.info('Attempting to clear cache data for job %s...' % job_id)

    result = kvs.cache_gc(job_id)

    if result is None:
        LOG.info('Job %s not found.' % job_id)
    else:
        LOG.info('Removed %s keys.' % result)
Ejemplo n.º 4
0
def cleanup_after_job(job_id):
    """
    Release the resources used by an openquake job.

    :param job_id: the job id
    :type job_id: int
    """
    logging.debug('Cleaning up after job %s', job_id)

    kvs.cache_gc(job_id)

    # Using the celery API, terminate and revoke and terminate any running
    # tasks associated with the current job.
    task_ids = _get_task_ids(job_id)
    if not task_ids:  # this is normal when OQ_NO_DISTRIBUTE=1
        logs.LOG.debug('No task to revoke')
    for tid in task_ids:
        celery.task.control.revoke(tid, terminate=True)
        logs.LOG.debug('Revoked task %s', tid)
Ejemplo n.º 5
0
    def test_gc_nonexistent_job(self):
        """
        If we try to run garbage collection on a nonexistent job, the result of
        :py:function:`openquake.engine.kvs.cache_gc` should be None.
        """
        nonexist_job = '1234nonexistent'

        result = kvs.cache_gc(nonexist_job)

        self.assertTrue(result is None)
Ejemplo n.º 6
0
    def test_gc_nonexistent_job(self):
        """
        If we try to run garbage collection on a nonexistent job, the result of
        :py:function:`openquake.engine.kvs.cache_gc` should be None.
        """
        nonexist_job = '1234nonexistent'

        result = kvs.cache_gc(nonexist_job)

        self.assertTrue(result is None)
Ejemplo n.º 7
0
def cleanup_after_job(job_id, terminate):
    """
    Release the resources used by an openquake job.

    :param int job_id: the job id
    :param bool terminate: the celery revoke command terminate flag
    """
    logging.debug('Cleaning up after job %s', job_id)

    kvs.cache_gc(job_id)

    # Using the celery API, terminate and revoke and terminate any running
    # tasks associated with the current job.
    task_ids = _get_task_ids(job_id)
    if task_ids:
        logs.LOG.warn('Revoking %d tasks', len(task_ids))
    else:  # this is normal when OQ_NO_DISTRIBUTE=1
        logs.LOG.debug('No task to revoke')
    for tid in task_ids:
        celery.task.control.revoke(tid, terminate=terminate)
        logs.LOG.debug('Revoked task %s', tid)
Ejemplo n.º 8
0
def cleanup_after_job(job_id, terminate):
    """
    Release the resources used by an openquake job.

    :param int job_id: the job id
    :param bool terminate: the celery revoke command terminate flag
    """
    logging.debug('Cleaning up after job %s', job_id)

    kvs.cache_gc(job_id)

    # Using the celery API, terminate and revoke and terminate any running
    # tasks associated with the current job.
    task_ids = _get_task_ids(job_id)
    if task_ids:
        logs.LOG.warn('Revoking %d tasks', len(task_ids))
    else:  # this is normal when OQ_NO_DISTRIBUTE=1
        logs.LOG.debug('No task to revoke')
    for tid in task_ids:
        celery.task.control.revoke(tid, terminate=terminate)
        logs.LOG.debug('Revoked task %s', tid)
Ejemplo n.º 9
0
    def test_gc_dataless_job(self):
        """
        Test that :py:function:`openquake.engine.kvs.cache_gc` returns 0
        (to indicate that the job existed but there was nothing to delete).

        The job key should key should be removed from CURRENT_JOBS.
        """
        self.assertTrue(
            self.client.sismember(kvs.tokens.CURRENT_JOBS, self.dataless_job))

        result = kvs.cache_gc(self.dataless_job)

        self.assertEqual(0, result)

        # make sure the job was deleted from CURRENT_JOBS
        self.assertFalse(
            self.client.sismember(kvs.tokens.CURRENT_JOBS, self.dataless_job))
Ejemplo n.º 10
0
    def test_gc_some_job_data(self):
        """
        Test that all job data is cleared and the job key is removed from
        CURRENT_JOBS.
        """
        result = kvs.cache_gc(self.test_job)

        # 3 things should have been deleted
        self.assertEqual(3, result)

        # make sure each piece of data was deleted
        for key in (self.gmf1_key, self.gmf2_key, self.vuln_key):
            self.assertFalse(self.client.exists(key))

        # make sure the job was deleted from CURRENT_JOBS
        self.assertFalse(
            self.client.sismember(kvs.tokens.CURRENT_JOBS, self.test_job))
Ejemplo n.º 11
0
    def test_gc_dataless_job(self):
        """
        Test that :py:function:`openquake.engine.kvs.cache_gc` returns 0
        (to indicate that the job existed but there was nothing to delete).

        The job key should key should be removed from CURRENT_JOBS.
        """
        self.assertTrue(
            self.client.sismember(kvs.tokens.CURRENT_JOBS, self.dataless_job))

        result = kvs.cache_gc(self.dataless_job)

        self.assertEqual(0, result)

        # make sure the job was deleted from CURRENT_JOBS
        self.assertFalse(
            self.client.sismember(kvs.tokens.CURRENT_JOBS, self.dataless_job))
Ejemplo n.º 12
0
    def test_gc_some_job_data(self):
        """
        Test that all job data is cleared and the job key is removed from
        CURRENT_JOBS.
        """
        result = kvs.cache_gc(self.test_job)

        # 3 things should have been deleted
        self.assertEqual(3, result)

        # make sure each piece of data was deleted
        for key in (self.gmf1_key, self.gmf2_key, self.vuln_key):
            self.assertFalse(self.client.exists(key))

        # make sure the job was deleted from CURRENT_JOBS
        self.assertFalse(
            self.client.sismember(kvs.tokens.CURRENT_JOBS, self.test_job))
Ejemplo n.º 13
0
    def test_gc_clears_stats(self):
        # redis garbage collection should clear stats counters as well
        stats.pk_set(self.test_job, 'nhzrd_total', 10)
        stats.pk_set(self.test_job, 'nhzrd_done', 7)
        stats.pk_set(self.test_job, 'nhzrd_failed', 3)

        # Sanity check:
        self.assertEqual(10, stats.pk_get(self.test_job, 'nhzrd_total'))
        self.assertEqual(7, stats.pk_get(self.test_job, 'nhzrd_done'))
        self.assertEqual(3, stats.pk_get(self.test_job, 'nhzrd_failed'))

        result = kvs.cache_gc(self.test_job)

        # 6 keys should be deleted, including the stats keys:
        self.assertEqual(6, result)

        # explicitly test that the stats keys are deleted
        self.assertIsNone(stats.pk_get(self.test_job, 'nhzrd_total'))
        self.assertIsNone(stats.pk_get(self.test_job, 'nhzrd_done'))
        self.assertIsNone(stats.pk_get(self.test_job, 'nhzrd_failed'))
Ejemplo n.º 14
0
    def test_gc_clears_stats(self):
        # redis garbage collection should clear stats counters as well
        stats.pk_set(self.test_job, 'nhzrd_total', 10)
        stats.pk_set(self.test_job, 'nhzrd_done', 7)
        stats.pk_set(self.test_job, 'nhzrd_failed', 3)

        # Sanity check:
        self.assertEqual(10, stats.pk_get(self.test_job, 'nhzrd_total'))
        self.assertEqual(7, stats.pk_get(self.test_job, 'nhzrd_done'))
        self.assertEqual(3, stats.pk_get(self.test_job, 'nhzrd_failed'))

        result = kvs.cache_gc(self.test_job)

        # 6 keys should be deleted, including the stats keys:
        self.assertEqual(6, result)

        # explicitly test that the stats keys are deleted
        self.assertIsNone(stats.pk_get(self.test_job, 'nhzrd_total'))
        self.assertIsNone(stats.pk_get(self.test_job, 'nhzrd_done'))
        self.assertIsNone(stats.pk_get(self.test_job, 'nhzrd_failed'))