Beispiel #1
0
 def __init__(self, conf):
     super(DciControlServer, self).__init__(__name__)
     self.config.update(conf)
     self.url_map.strict_slashes = False
     self.engine = dci_config.get_engine(conf)
     self.sender = self._get_zmq_sender(conf['ZMQ_CONN'])
     engine = dci_config.get_engine(self.config)
     self.team_admin_id = self._get_team_id(engine, 'admin')
     self.team_redhat_id = self._get_team_id(engine, 'Red Hat')
     self.team_epm_id = self._get_team_id(engine, 'EPM')
Beispiel #2
0
 def __init__(self, conf):
     super(DciControlServer, self).__init__(__name__)
     self.config.update(conf)
     self.url_map.strict_slashes = False
     self.engine = dci_config.get_engine(conf)
     self.es_engine = es_engine.DCIESEngine(conf)
     self.sender = self._get_zmq_sender(conf['ZMQ_CONN'])
Beispiel #3
0
 def __init__(self, conf, elastic_engine=None):
     super(DciControlServer, self).__init__(__name__)
     self.config.update(conf)
     self.url_map.strict_slashes = False
     self.engine = dci_config.get_engine(conf)
     self.es_engine = elastic_engine
     if not self.es_engine:
         self.es_engine = es_engine.DCIESEngine(es_host=conf['ES_HOST'],
                                                es_port=conf['ES_PORT'])
     self.sender = self._get_zmq_sender(conf['ZMQ_CONN'])
Beispiel #4
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    app_conf = dci_config.generate_conf()
    connectable = dci_config.get_engine(app_conf)
    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
        )

        with context.begin_transaction():
            context.run_migrations()
Beispiel #5
0
def get_trends_of_topics(user):
    engine = get_engine()
    sql = text("""
SELECT jobs.id,
    jobs.status,
    jobs.created_at,
    jobs.topic_id
FROM jobs
LEFT JOIN teams ON jobs.team_id = teams.id
LEFT JOIN topics ON jobs.topic_id = topics.id
WHERE
    (jobs.status = 'failure' OR jobs.status = 'success') AND
    teams.external = true
ORDER BY jobs.created_at DESC;
    """)  # noqa

    jobs = engine.execute(sql)
    return flask.jsonify({'topics': get_trends_from_jobs(jobs)})
Beispiel #6
0
def get_global_status(user):
    conf = generate_conf()
    engine = get_engine(conf)
    sql = text("""
SELECT DISTINCT ON (components.id, jobs.remoteci_id)
    jobs.id,
    jobs.status,
    jobs.created_at,
    jobs.remoteci_id,
    components.id as component_id,
    components.name as component_name,
    topics.id as topic_id,
    topics.name as topic_name,
    products.id as product_id,
    products.name as product_name,
    remotecis.name as remoteci_name,
    teams.name as team_name
FROM jobs
LEFT JOIN remotecis ON jobs.remoteci_id = remotecis.id
LEFT JOIN teams ON remotecis.team_id = teams.id
LEFT JOIN topics ON jobs.topic_id = topics.id
LEFT JOIN jobs_components ON jobs.id = jobs_components.job_id
LEFT JOIN components ON components.id = jobs_components.component_id
LEFT JOIN products ON topics.product_id = products.id
WHERE
    teams.external = '1' AND
    (jobs.status = 'failure' OR jobs.status = 'success') AND
    remotecis.state = 'active' AND
    components.id IN (SELECT DISTINCT ON (topic_id) id
                      FROM components
                      WHERE state = 'active'
                      ORDER BY topic_id, created_at DESC)
ORDER BY
    components.id,
    jobs.remoteci_id,
    jobs.created_at DESC;
""")  # noqa

    jobs = engine.execute(sql)
    global_status = format_global_status(jobs)
    global_status = insert_component_with_no_job(
        global_status, v1_components._get_latest_components())
    return flask.jsonify(
        {'globalStatus': add_percentage_of_success(global_status)})
Beispiel #7
0
#!/usr/bin/env python

import os
import io
import tqdm
from dci import dci_config
from dci.db import models
from sqlalchemy import sql

conf = dci_config.CONFIG
swift = dci_config.get_store('files')
engine = dci_config.get_engine(conf).connect()

_TABLE = models.FILES

# Calculate the total files to sync
file_list = os.walk(conf['FILES_UPLOAD_FOLDER'])

with tqdm.tqdm(total=sum(1 for _ in file_list)) as pbar:
    for dirname, dirnames, filenames in os.walk(conf['FILES_UPLOAD_FOLDER']):
        if not filenames:
            pbar.update(1)
            continue
        for filename in filenames:
            # Check if file exist in the DB
            query = sql.select([_TABLE]).where(_TABLE.c.id == filename)
            result = engine.execute(query)

            # If not, do not sync, that's an orphan file
            if result.rowcount == 0:
                tqdm.tqdm.write("File %s not found, do not sync" % filename)