Esempio n. 1
0
def _normalize_user(user):
    for c in user['companies']:
        c['end_date'] = utils.date_to_timestamp(c['end_date'])

    # sort companies by end_date
    def end_date_comparator(x, y):
        if x["end_date"] == 0:
            return 1
        elif y["end_date"] == 0:
            return -1
        else:
            return cmp(x["end_date"], y["end_date"])

    user['companies'].sort(cmp=end_date_comparator)
    user['user_id'] = user.get('ldap_id')
Esempio n. 2
0
def _normalize_user(user):
    for c in user['companies']:
        c['end_date'] = utils.date_to_timestamp(c['end_date'])

    # sort companies by end_date
    def end_date_comparator(x, y):
        if x["end_date"] == 0:
            return 1
        elif y["end_date"] == 0:
            return -1
        else:
            return cmp(x["end_date"], y["end_date"])

    user['companies'].sort(cmp=end_date_comparator)
    user['user_id'] = user.get('ldap_id')
Esempio n. 3
0
def get_vault():
    vault = getattr(flask.current_app, 'spectrometer_vault', None)
    if not vault:
        try:
            vault = {}
            runtime_storage_inst = runtime_storage.get_runtime_storage(
                cfg.CONF.runtime_storage_uri)
            vault['runtime_storage'] = runtime_storage_inst
            vault['memory_storage'] = memory_storage.get_memory_storage(
                memory_storage.MEMORY_STORAGE_CACHED)

            flask.current_app.spectrometer_vault = vault
        except Exception as e:
            LOG.critical('Failed to initialize application: %s', e)
            LOG.exception(e)
            flask.abort(500)

    time_now = utils.date_to_timestamp('now')
    may_update_by_time = (time_now > vault.get('vault_update_time', 0) +
                          cfg.CONF.dashboard_update_interval)
    if (may_update_by_time and
            not getattr(flask.request, 'spectrometer_updated', None)):
        flask.request.spectrometer_updated = True
        vault['vault_update_time'] = time_now
        memory_storage_inst = vault['memory_storage']
        have_updates = memory_storage_inst.update(
            compact_records(vault['runtime_storage'].get_update(os.getpid())))
        vault['runtime_storage_update_time'] = (
            vault['runtime_storage'].get_by_key('runtime_storage_update_time'))

        if have_updates:
            vault['cache'] = {}
            vault['cache_size'] = 0
            _init_releases(vault)
            _init_module_groups(vault)
            _init_project_types(vault)
            _init_user_index(vault)

    return vault
Esempio n. 4
0
def get_vault():
    vault = getattr(flask.current_app, 'spectrometer_vault', None)
    if not vault:
        try:
            vault = {}
            runtime_storage_inst = runtime_storage.get_runtime_storage(
                cfg.CONF.runtime_storage_uri)
            vault['runtime_storage'] = runtime_storage_inst
            vault['memory_storage'] = memory_storage.get_memory_storage(
                memory_storage.MEMORY_STORAGE_CACHED)

            flask.current_app.spectrometer_vault = vault
        except Exception as e:
            LOG.critical('Failed to initialize application: %s', e)
            LOG.exception(e)
            flask.abort(500)

    time_now = utils.date_to_timestamp('now')
    may_update_by_time = (time_now > vault.get('vault_update_time', 0) +
                          cfg.CONF.dashboard_update_interval)
    if (may_update_by_time
            and not getattr(flask.request, 'spectrometer_updated', None)):
        flask.request.spectrometer_updated = True
        vault['vault_update_time'] = time_now
        memory_storage_inst = vault['memory_storage']
        have_updates = memory_storage_inst.update(
            compact_records(vault['runtime_storage'].get_update(os.getpid())))
        vault['runtime_storage_update_time'] = (
            vault['runtime_storage'].get_by_key('runtime_storage_update_time'))

        if have_updates:
            vault['cache'] = {}
            vault['cache_size'] = 0
            _init_releases(vault)
            _init_module_groups(vault)
            _init_project_types(vault)
            _init_user_index(vault)

    return vault
Esempio n. 5
0
def main():
    # init conf and logging
    conf = cfg.CONF
    conf.register_cli_opts(config.OPTS)
    conf.register_opts(config.OPTS)
    conf()

    logging.setup('spectrometer')
    LOG.info('Logging enabled')

    runtime_storage_inst = runtime_storage.get_runtime_storage(
        cfg.CONF.runtime_storage_uri)

    default_data = utils.read_json_from_uri(cfg.CONF.default_data_uri)
    if not default_data:
        LOG.critical('Unable to load default data')
        return not 0
    default_data_processor.process(runtime_storage_inst,
                                   default_data,
                                   cfg.CONF.sources_root,
                                   cfg.CONF.force_update)

    process_program_list(runtime_storage_inst, cfg.CONF.program_list_uri)

    update_pids(runtime_storage_inst)

    record_processor_inst = record_processor.RecordProcessor(
        runtime_storage_inst)

    update_records(runtime_storage_inst, record_processor_inst)

    apply_corrections(cfg.CONF.corrections_uri, runtime_storage_inst)

    # long operation should be the last
    update_members(runtime_storage_inst, record_processor_inst)

    runtime_storage_inst.set_by_key('runtime_storage_update_time',
                                    utils.date_to_timestamp('now'))
Esempio n. 6
0
def main():
    # init conf and logging
    conf = cfg.CONF
    conf.register_cli_opts(config.OPTS)
    conf.register_opts(config.OPTS)
    conf()

    logging.setup('spectrometer')
    LOG.info('Logging enabled')

    runtime_storage_inst = runtime_storage.get_runtime_storage(
        cfg.CONF.runtime_storage_uri)

    default_data = utils.read_json_from_uri(cfg.CONF.default_data_uri)
    if not default_data:
        LOG.critical('Unable to load default data')
        return not 0
    default_data_processor.process(runtime_storage_inst, default_data,
                                   cfg.CONF.sources_root,
                                   cfg.CONF.force_update)

    process_program_list(runtime_storage_inst, cfg.CONF.program_list_uri)

    update_pids(runtime_storage_inst)

    record_processor_inst = record_processor.RecordProcessor(
        runtime_storage_inst)

    update_records(runtime_storage_inst, record_processor_inst)

    apply_corrections(cfg.CONF.corrections_uri, runtime_storage_inst)

    # long operation should be the last
    update_members(runtime_storage_inst, record_processor_inst)

    runtime_storage_inst.set_by_key('runtime_storage_update_time',
                                    utils.date_to_timestamp('now'))
import itertools
import time

import mock
import six
import testtools

from spectrometer.processor import record_processor
from spectrometer.processor import runtime_storage
from spectrometer.processor import utils


RELEASES = [
    {
        'release_name': 'prehistory',
        'end_date': utils.date_to_timestamp('2011-Apr-21')
    },
    {
        'release_name': 'Diablo',
        'end_date': utils.date_to_timestamp('2011-Sep-08')
    },
    {
        'release_name': 'Zoo',
        'end_date': utils.date_to_timestamp('2035-Sep-08')
    },
]

REPOS = [
    {
        "branches": ["master"],
        "module": "stackalytics",
Esempio n. 8
0
def _normalize_releases(releases):
    for release in releases:
        release['release_name'] = release['release_name'].lower()
        release['end_date'] = utils.date_to_timestamp(release['end_date'])
    releases.sort(key=lambda x: x['end_date'])
Esempio n. 9
0
def _normalize_releases(releases):
    for release in releases:
        release['release_name'] = release['release_name'].lower()
        release['end_date'] = utils.date_to_timestamp(release['end_date'])
    releases.sort(key=lambda x: x['end_date'])
import itertools
import time

import mock
import six
import testtools

from spectrometer.processor import record_processor
from spectrometer.processor import runtime_storage
from spectrometer.processor import utils

RELEASES = [
    {
        'release_name': 'prehistory',
        'end_date': utils.date_to_timestamp('2011-Apr-21')
    },
    {
        'release_name': 'Diablo',
        'end_date': utils.date_to_timestamp('2011-Sep-08')
    },
    {
        'release_name': 'Zoo',
        'end_date': utils.date_to_timestamp('2035-Sep-08')
    },
]

REPOS = [{
    "branches": ["master"],
    "module": "stackalytics",
    "project_type": "stackforge",