def test_setup_app(self): assert_equals(self.settings.hostname, socket.getfqdn()) self.assertIsInstance(self.settings.config, dict) self.assertIsInstance(self.settings, Settings) # singleton test settings = RoboticeSettings("monitor") self.assertIsInstance(self.settings.sensors, list) assert_equals(self.settings, settings) settings = setup_app('monitor') assert_equals(self.settings, settings) # change role assert_equals(self.settings.worker, "monitor") self.worker = setup_app('reasoner').worker assert_equals(self.worker, "reasoner") self.assertIsInstance(self.settings.config.get("metering"), dict)
def main(): config = setup_app("reasoner") value = CONF.command.value try: value = json.loads(CONF.command.value) except Exception, e: pass
def main(): config = setup_app("reasoner") manager = getattr(config, CONF.command.config) value = CONF.command.value try: value = json.loads(CONF.command.value) except Exception, e: pass
def main(): config = setup_app("reasoner") manager = getattr(config, CONF.command.config) data = manager.get(CONF.command.key) try: pp(data) except Exception, e: print data
def init_reactors(sender, instance, **kwargs): """set default if specified """ config = setup_app('reasoner') for name, host in config.devices.iteritems(): for uuid, actuator in host.get('actuators').iteritems(): if 'default' in actuator: if actuator.get('default') == 'off': model_value = 0 real_value = 1 else: model_value = 1 real_value = 0 send_task('reactor.commit_action', [ config, actuator, str(model_value), str(real_value)], {})
def process_real_data(results, sensor): LOG = process_real_data.get_logger() config = setup_app('reasoner') for result in list(results): value = result[1] if isinstance(value, basestring): try: value = re.findall(NUMBER, value)[0] value = float(value) except Exception, e: pass if isinstance(value, (int, long, float, decimal.Decimal)): result_name = result[0].split('.')[0] result_metric = result[0].split('.')[1] system, plan_name = config.get_plan(result_name, result_metric) LOG.info("for result_name: {0} result_metric: {1} system: {2} plan: {3}".format( result_name, result_metric, system, plan_name)) if system != None: db_key = '.'.join([system.get('name'), 'sensors', plan_name, 'real']) try: config.metering.send(db_key, value) except Exception, e: LOG.error("Fail: send to metering %s " % e) try: redis_status = config.database.set(db_key, value) except Exception, er: raise er LOG.debug("%s: %s" % (db_key, value)) LOG.debug("metric was sent to database and statsd")
def main(): config = setup_app("reasoner") data = config.plan_manager.list() data.p() # print
def main(): config = setup_app("reasoner") data = config.plan_manager.get(CONF.command.uuid) print data
def setUp(self): self.config = setup_app('monitor')
def main(): config = setup_app("reasoner") manager = getattr(config, CONF.command.config) pp(manager.list())
def setUp(self): self.settings = setup_app('monitor')
import logging from kombu import Queue, Exchange from celery import Celery from robotice.conf import setup_app from robotice.conf.celery import * LOG = logging.getLogger(__name__) config = setup_app('reactor') BROKER_URL = config.broker if "amqp" in config.broker: default_exchange = Exchange('default') monitor_exchange = Exchange('monitor', type='fanout') reactor_exchange = Exchange('reactor', type='fanout') planner_exchange = Exchange('planner', type='fanout') CELERY_RESULT_BACKEND = "amqp" CELERY_QUEUES = ( Queue('default', default_exchange, routing_key='default'), Queue('monitor', monitor_exchange, routing_key='monitor.#'), Queue('planner', planner_exchange, routing_key='planner.#'), ) elif "redis" in config.broker: CELERY_RESULT_BACKEND = BROKER_URL #BROKER_TRANSPORT_OPTIONS = {
def process_real_data(results, sensor): LOG = process_real_data.get_logger() config = setup_app('reasoner') processed = 0 db_saved = 0 for result in list(results): value = result[1] if isinstance(value, basestring): try: value = re.findall(NUMBER, value)[0] value = float(value) except Exception, e: pass if isinstance(value, (int, long, float, decimal.Decimal)): result_name = result[0].split('.')[0] result_metric = result[0].split('.')[1] system, plan = config.get_plan(result_name, result_metric) """ key = ".".join([ "*", "*", result_name, "device" ]) keys = config.database.keys(key) for _key in keys: device = config.database.hgetall(_key) device = config.database.hgetall(key) if not device: raise Exception("%s not found in db" % key) """ if not plan: LOG.error("Missing plan for result %s and metric %s, value %s will be ignored. See log for more detail." % (result_name, result_metric, value)) continue if system != None: db_key = ':'.join([ str(system["name"]), str(plan["name"]), 'real']) try: config.metering.send(db_key, value) processed += 1 except Exception, e: LOG.error("Fail: send to metering %s " % e) try: redis_status = config.database.set(db_key, value) db_saved += 1 except Exception, er: raise er LOG.debug("%s: %s" % (db_key, value))
def setUp(self): self.config = setup_app('reactor')