Ejemplo n.º 1
0
class AnalyzeDBSync(object):
    def __init__(self):
        self._env_init()
        self._conf_init()

    def _env_init(self):
        self.env = Env()

    def _conf_init(self):
        conf_file = "/".join(
            [self.env.basic_conf_dir(),
             self.env.basic_conf_file()])
        self.conf = AnalyzeConf(conf_file)

    def main(self):
        group = re.match("mysql://(.*):(.*)@.*/(.*)",
                         self.conf.db_connection())
        if len(group.groups()) < 3:
            print "invalid database connect:", self.conf.db_connection()
            return

        user = group.groups()[0]
        password = group.groups()[1]
        db = group.groups()[2]

        sql_cmd = "create database %s;" % (db)
        sql_cmd += "grant all privileges on %s.* to '%s'@'localhost' identified by '%s';" % (
            db, user, password)
        sql_cmd += "grant all privileges on %s.* to '%s'@" % (db, user)
        sql_cmd += "'%' identified by "
        sql_cmd += "'%s';" % (password)

        os.system('mysql -u root -p -e "%s"' % (sql_cmd))
Ejemplo n.º 2
0
class Analyze(object):
    def __init__(self):
        self._env_init()
        self._log_init()
        self._conf_init()
        self._db_init()
        self.se_mgr = SearchEngineMgr(self.conf, self.db)
        self._rabbitmq_init()
        self.scheduler = Scheduler(self.conf, self.se_mgr, self.db)
        self.se_mgr.set_scheduler(self.scheduler)
        self.se_mgr.set_mq(self.analyze_mq)
        self.rest_server = RestServer(self.conf, self.db, self.analyze_mq,
                                      self.se_mgr, self.scheduler)
        self.analyze_mq.set_rest_server(self.rest_server)

    def _db_init(self):
        self.db = AnalyzeDB(self.conf)

    def _log_init(self):
        id = "analyze"
        LOG.set_log_id(id)
        LOG.set_log_level('info')

        log_file = self.env.log_dir() + "/" + id + ".log"
        LOG.set_log_file(log_file)

    def _env_init(self):
        self.env = Env()
        self.env.check()

    def _conf_init(self):
        conf_file = "/".join(
            [self.env.basic_conf_dir(),
             self.env.basic_conf_file()])
        self.conf = AnalyzeConf(conf_file)

        LOG.set_log_level(self.conf.log_level())

    def _rabbitmq_init(self):
        self.analyze_mq = AnalyzeMQ(self.conf, self.se_mgr)
        self.se_mgr.register_notifier(self.analyze_mq.del_queue)

    def main(self):
        mq_task = gevent.spawn(self.analyze_mq.run)
        rest_task = gevent.spawn(self.rest_server.run)

        gevent.wait([mq_task, rest_task])