X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_policy_module%2Fcmd%2Fpolicy_module_agent.py;h=43dbc343c54b8b5e7d6eedc00c445b1b7dc405aa;hb=cb5642a2af495af4319beb1dba2d417b78f3200a;hp=c82f0063c6e92b558c8d23409ddf91dad631812d;hpb=48af3094153dcbef3bf03f72f9d20a3c49d50678;p=osm%2FPOL.git diff --git a/osm_policy_module/cmd/policy_module_agent.py b/osm_policy_module/cmd/policy_module_agent.py index c82f006..43dbc34 100644 --- a/osm_policy_module/cmd/policy_module_agent.py +++ b/osm_policy_module/cmd/policy_module_agent.py @@ -22,8 +22,10 @@ # contact: bdiaz@whitestack.com or glavado@whitestack.com ## import argparse +import asyncio import logging import sys +import os from osm_policy_module.core.agent import PolicyModuleAgent from osm_policy_module.core.config import Config @@ -31,33 +33,36 @@ from osm_policy_module.core.database import DatabaseManager def main(): - cfg = Config.instance() - parser = argparse.ArgumentParser(prog='pm-scaling-config-agent') - parser.add_argument('--config-file', nargs='?', help='Policy module agent configuration file') + # Cleanup old temp health file + if os.path.exists("/tmp/osm_pol_agent_health_flag"): + os.remove("/tmp/osm_pol_agent_health_flag") + + parser = argparse.ArgumentParser(prog="osm-policy-agent") + parser.add_argument("--config-file", nargs="?", help="POL configuration file") args = parser.parse_args() - if args.config_file: - cfg.load_file(args.config_file) - log_formatter_str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' - logging.basicConfig(stream=sys.stdout, - format=log_formatter_str, - datefmt='%m/%d/%Y %I:%M:%S %p', - level=logging.getLevelName(cfg.OSMPOL_LOG_LEVEL)) - kafka_logger = logging.getLogger('kafka') - kafka_logger.setLevel(logging.getLevelName(cfg.OSMPOL_KAFKA_LOG_LEVEL)) - kafka_formatter = logging.Formatter(log_formatter_str) - kafka_handler = logging.StreamHandler(sys.stdout) - kafka_handler.setFormatter(kafka_formatter) - kafka_logger.addHandler(kafka_handler) + cfg = Config(args.config_file) + + root = logging.getLogger() + root.setLevel(logging.getLevelName(cfg.get("global", "loglevel"))) + ch = logging.StreamHandler(sys.stdout) + ch.setLevel(logging.getLevelName(cfg.get("global", "loglevel"))) + formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s", "%m/%d/%Y %I:%M:%S %p" + ) + ch.setFormatter(formatter) + root.addHandler(ch) + log = logging.getLogger(__name__) - log.info("Config: %s", vars(cfg)) - log.info("Syncing database...") - db_manager = DatabaseManager() + log.debug("Config: %s", cfg.conf) + log.info("Initializing database...") + db_manager = DatabaseManager(cfg) db_manager.create_tables() - log.info("Database synced correctly.") + log.info("Database initialized correctly.") log.info("Starting policy module agent...") - agent = PolicyModuleAgent() + loop = asyncio.get_event_loop() + agent = PolicyModuleAgent(cfg, loop) agent.run() -if __name__ == '__main__': +if __name__ == "__main__": main()