def tagging_service(config_path, **kwargs): """ This method is called by the :py:func:`service.tagging.main` to parse the passed config file or configuration dictionary object, validate the configuration entries, and create an instance of SQLTaggingService :param config_path: could be a path to a configuration file or can be a dictionary object :param kwargs: additional keyword arguments if any :return: an instance of :py:class:`service.tagging.SQLTaggingService` """ _log.debug("kwargs before init: {}".format(kwargs)) if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) _log.debug("config_dict before init: {}".format(config_dict)) if not config_dict.get('connection') or \ not config_dict.get('connection').get('params') or \ not config_dict.get('connection').get('params').get('database'): raise ValueError("Missing database connection parameters. Agent " "configuration should contain database connection " "parameters with the details about type of database" "and name of database. Please refer to sample " "configuration file in Agent's source directory.") utils.update_kwargs_with_config(kwargs, config_dict) return SQLiteTaggingService(**kwargs)
def historian(config_path, **kwargs): """ This method is called by the :py:func:`influx.historian.main` to parse the passed config file or configuration dictionary object, validate the configuration entries, and create an instance of InfluxdbHistorian :param config_path: could be a path to a configuration file or can be a dictionary object :param kwargs: additional keyword arguments if any :return: an instance of :py:class:`InfluxdbHistorian` """ if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) connection = config_dict.pop('connection', {}) aggregations = config_dict.pop("aggregations", {}) # assert connection is not None # params = connection.get('params', None) # assert params is not None InfluxdbHistorian.__name__ = 'InfluxdbHistorian' utils.update_kwargs_with_config(kwargs, config_dict) _log.debug( "In influx historian before calling class kwargs is {}".format(kwargs)) return InfluxdbHistorian(connection, aggregations, **kwargs)
def historian(config_path, **kwargs): """ This method is called by the :py:func:`sqlhistorian.historian.main` to parse the passed config file or configuration dictionary object, validate the configuration entries, and create an instance of SQLHistorian :param config_path: could be a path to a configuration file or can be a dictionary object :param kwargs: additional keyword arguments if any :return: an instance of :py:class:`sqlhistorian.historian.SQLHistorian` """ if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) connection = config_dict.get('connection', None) assert connection is not None database_type = connection.get('type', None) assert database_type is not None params = connection.get('params', None) assert params is not None SQLHistorian.__name__ = 'SQLHistorian' utils.update_kwargs_with_config(kwargs, config_dict) _log.debug("In sql historian before calling class kwargs is {}".format( kwargs)) return SQLHistorian(**kwargs)
def tagging_service(config_path, **kwargs): """ This method is called by the :py:func:`service.tagging.main` to parse the passed config file or configuration dictionary object, validate the configuration entries, and create an instance of SQLTaggingService :param config_path: could be a path to a configuration file or can be a dictionary object :param kwargs: additional keyword arguments if any :return: an instance of :py:class:`service.tagging.SQLTaggingService` """ _log.debug("kwargs before init: {}".format(kwargs)) if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) _log.debug("config_dict before init: {}".format(config_dict)) if not config_dict.get('connection') or \ not config_dict.get('connection').get('params') or \ not config_dict.get('connection').get('params').get('database'): raise ValueError("Missing database connection parameters. Agent " "configuration should contain database connection " "parameters with the details about type of database" "and name of database. Please refer to sample " "configuration file in Agent's source directory.") utils.update_kwargs_with_config(kwargs,config_dict) return SQLiteTaggingService(**kwargs)
def historian(config_path, **kwargs): """ This method is called by the :py:func:`sqlhistorian.historian.main` to parse the passed config file or configuration dictionary object, validate the configuration entries, and create an instance of SQLHistorian :param config_path: could be a path to a configuration file or can be a dictionary object :param kwargs: additional keyword arguments if any :return: an instance of :py:class:`sqlhistorian.historian.SQLHistorian` """ if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) connection = config_dict.get('connection', None) assert connection is not None database_type = connection.get('type', None) assert database_type is not None params = connection.get('params', None) assert params is not None SQLHistorian.__name__ = 'SQLHistorian' utils.update_kwargs_with_config(kwargs, config_dict) _log.debug( "In sql historian before calling class kwargs is {}".format(kwargs)) return SQLHistorian(**kwargs)
def historian(config_path, **kwargs): """ This method is called by the :py:func:`influx.historian.main` to parse the passed config file or configuration dictionary object, validate the configuration entries, and create an instance of InfluxdbHistorian :param config_path: could be a path to a configuration file or can be a dictionary object :param kwargs: additional keyword arguments if any :return: an instance of :py:class:`InfluxdbHistorian` """ if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) connection = config_dict.pop('connection', {}) aggregations = config_dict.pop("aggregations", {}) # assert connection is not None # params = connection.get('params', None) # assert params is not None InfluxdbHistorian.__name__ = 'InfluxdbHistorian' utils.update_kwargs_with_config(kwargs, config_dict) _log.debug("In influx historian before calling class kwargs is {}".format( kwargs)) return InfluxdbHistorian(connection, aggregations, **kwargs)
def historian(config_path, **kwargs): config = utils.load_config(config_path) utils.update_kwargs_with_config(kwargs, config) class NullHistorian(BaseHistorian): '''This historian forwards data to another platform. ''' def __init__(self, **kwargs): super(NullHistorian, self).__init__(**kwargs) if self._gather_timing_data: self._turnaround_times = [] @Core.receiver("onstart") def starting(self, sender, **kwargs): _log.debug('Null historian started.') def publish_to_historian(self, to_publish_list): for item in to_publish_list: if self._gather_timing_data: turnaround_time = add_timing_data_to_header( item["headers"], self.core.agent_uuid or self.core.identity, "published") self._turnaround_times.append(turnaround_time) if len(self._turnaround_times) > 10000: # Test is now over. Button it up and shutdown. mean = math_utils.mean(self._turnaround_times) stdev = math_utils.stdev(self._turnaround_times) _log.info("Mean time from collection to publish: " + str(mean)) _log.info("Std dev time from collection to publish: " + str(stdev)) self._turnaround_times = [] #_log.debug("publishing {}".format(item)) _log.debug("recieved {} items to publish".format( len(to_publish_list))) self.report_all_handled() def query_historian(self, topic, start=None, end=None, agg_type=None, agg_period=None, skip=0, count=None, order="FIRST_TO_LAST"): """Not implemented """ raise NotImplemented( "query_historian not implimented for null historian") return NullHistorian(**kwargs)
def historian(config_path, **kwargs): config = utils.load_config(config_path) custom_topic_list = config.pop('custom_topic_list', []) topic_replace_list = config.pop('topic_replace_list', []) destination_vip = config.pop('destination-vip', None) service_topic_list = config.pop('service_topic_list', None) destination_serverkey = None try: destination_address = config.pop('destination-address') except KeyError: destination_address = None if service_topic_list is not None: w = "Deprecated service_topic_list. Use capture_device_data " \ "capture_log_data, capture_analysis_data or capture_record_data " \ "instead!" _log.warning(w) # Populate the new values for the kwargs based upon the old data. kwargs['capture_device_data'] = True if ( "device" in service_topic_list or "all" in service_topic_list) else False kwargs['capture_log_data'] = True if ( "datalogger" in service_topic_list or "all" in service_topic_list) else False kwargs['capture_record_data'] = True if ( "record" in service_topic_list or "all" in service_topic_list) else False kwargs['capture_analysis_data'] = True if ( "analysis" in service_topic_list or "all" in service_topic_list) else False if destination_vip: hosts = KnownHostsStore() destination_serverkey = hosts.serverkey(destination_vip) if destination_serverkey is None: _log.info( "Destination serverkey not found in known hosts file, using config" ) destination_serverkey = config.pop('destination-serverkey') else: config.pop('destination-serverkey', None) destination_messagebus = 'zmq' required_target_agents = config.pop('required_target_agents', []) cache_only = config.pop('cache_only', False) utils.update_kwargs_with_config(kwargs, config) return ForwardHistorian(destination_vip, destination_serverkey, custom_topic_list=custom_topic_list, topic_replace_list=topic_replace_list, required_target_agents=required_target_agents, cache_only=cache_only, destination_address=destination_address, **kwargs)
def historian(config_path, **kwargs): if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) connection = config_dict.get('connection', None) assert connection is not None utils.update_kwargs_with_config(kwargs, config_dict) return MQTTHistorian(**kwargs)
def historian(config_path, **kwargs): config = utils.load_config(config_path) utils.update_kwargs_with_config(kwargs, config) class NullHistorian(BaseHistorian): '''This historian forwards data to another platform. ''' def __init__(self, **kwargs): super(NullHistorian, self).__init__(**kwargs) if self._gather_timing_data: self._turnaround_times = [] @Core.receiver("onstart") def starting(self, sender, **kwargs): _log.debug('Null historian started.') def publish_to_historian(self, to_publish_list): for item in to_publish_list: if self._gather_timing_data: turnaround_time = add_timing_data_to_header(item["headers"], self.core.agent_uuid or self.core.identity, "published") self._turnaround_times.append(turnaround_time) if len(self._turnaround_times) > 10000: # Test is now over. Button it up and shutdown. mean = math_utils.mean(self._turnaround_times) stdev = math_utils.stdev(self._turnaround_times) _log.info("Mean time from collection to publish: " + str(mean)) _log.info("Std dev time from collection to publish: " + str(stdev)) self._turnaround_times = [] #_log.debug("publishing {}".format(item)) _log.debug("recieved {} items to publish" .format(len(to_publish_list))) self.report_all_handled() def query_historian(self, topic, start=None, end=None, agg_type=None, agg_period=None, skip=0, count=None, order="FIRST_TO_LAST"): """Not implemented """ raise NotImplemented("query_historian not implimented for null historian") return NullHistorian(**kwargs)
def weather_agent(config_path, **kwargs): """ Used for instantiating the WeatherDotGov agent. :param config_path: string formatted file path to use for configuring the agent. :param kwargs: keyword arguments passed during instantiation. :return: an instance of the WeatherDotGov Agent """ if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) _log.debug("config_dict before init: {}".format(config_dict)) utils.update_kwargs_with_config(kwargs, config_dict) return WeatherDotGovAgent(**kwargs)
def historian(config_path, **kwargs): config = utils.load_config(config_path) destination_vip = config.get('destination-vip', None) assert destination_vip is not None hosts = KnownHostsStore() destination_serverkey = hosts.serverkey(destination_vip) if destination_serverkey is not None: config['destination-serverkey'] = destination_serverkey else: assert config.get('destination-serverkey') is not None _log.info("Destination serverkey not found in known hosts file, using config") utils.update_kwargs_with_config(kwargs, config) return DataMover(**kwargs)
def historian(config_path, **kwargs): config = utils.load_config(config_path) destination_vip = config.get('destination-vip', None) assert destination_vip is not None hosts = KnownHostsStore() serverkey = hosts.serverkey(destination_vip) if serverkey is not None: config['destination-serverkey'] = serverkey else: assert config.get('destination-serverkey') is not None _log.info("Destination serverkey not found in known hosts file, " "using config") utils.update_kwargs_with_config(kwargs, config) return DataMover(**kwargs)
def security_agent(config_path, **kwargs): """Parses the Agent configuration and returns an instance of the agent created using that configuration. :param config_path: Path to a configuration file. :type config_path: str :returns: TestSecureAgents :rtype: TestSecureAgents """ config = {} _log.debug("config_dict before init: {}".format(config)) utils.update_kwargs_with_config(kwargs, config) return SecurityAgent(**kwargs)
def historian(config_path, **kwargs): """ This method is called by the :py:func:`crate_historian.historian.main` to parse the passed config file or configuration dictionary object, validate the configuration entries, and create an instance of MongodbHistorian :param config_path: could be a path to a configuration file or can be a dictionary object :param kwargs: additional keyword arguments if any :return: an instance of :py:class:`CrateHistorian` """ if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) cn_node = config_dict.pop('connection', {}) CrateHistorian.__name__ = 'CrateHistorian' utils.update_kwargs_with_config(kwargs, config_dict) return CrateHistorian(cn_node, **kwargs)
def CsvDriverAgent(config_path, **kwargs): """Parses the Agent configuration and returns an instance of the agent created using that configuration. :param config_path: Path to a configuration file. :type config_path: String path to the agent's configuration in the Volttron config store :returns: Csvdriveragent instance :rtype: Csvdriveragent """ # Load the configuration into keyword arguments to be used by the agent, creating an empty configuration if # parsing goes wrong _log.debug("Config path: {}".format(config_path)) try: config = utils.load_config(config_path) except Exception: config = {} if not config: _log.info("Using Agent defaults for starting configuration.") _log.debug("config_dict before init: {}".format(config)) utils.update_kwargs_with_config(kwargs, config) # Create an instance of the agent return Csvdriveragent(**kwargs)
def historian(config_path, **kwargs): """ Parses the Agent configuration and returns an instance of the agent created using that configuration. :param config_path: Path to a configuration file. :type config_path: str :returns: `FactsService` :rtype: `FactsService` """ if isinstance(config_path, dict): config_dict = config_path else: config_dict = utils.load_config(config_path) # Gather all settings from configuration into kwargs. # This ensures that settings common to all historians # are passed to BaseHistorian. utils.update_kwargs_with_config(kwargs, config_dict) return FactsService(**kwargs)
def ambient(config_path, **kwargs): """ Parses the Agent configuration and returns an instance of the agent created using that configuration. :param config_path: Path to a configuration file. :type config_path: str :returns: Ambient :rtype: Ambient """ try: config = utils.load_config(config_path) except Exception: config = {} if not config: _log.error("Ambient agent configuration: ".format(config)) for key in ["api_key", "application_key"]: if not config.get(key) or not isinstance(config.get(key), str): raise RuntimeError( "Ambient agent must be configured with '{}' key.".format(key)) _log.debug("config_dict before init: {}".format(config)) utils.update_kwargs_with_config(kwargs, config) return Ambient(**kwargs)
def darksky(config_path, **kwargs): """Parses the Agent configuration and returns an instance of the agent created using that configuration. :param config_path: Path to a configuration file. :type config_path: str :returns: Darksky :rtype: Darksky """ try: config = utils.load_config(config_path) except Exception: config = {} if not config: _log.error("Darksky agent configuration: ".format(config)) if "api_key" not in config: raise RuntimeError("Darksky agent must be configured with an api key.") _log.debug("config_dict before init: {}".format(config)) utils.update_kwargs_with_config(kwargs, config) return Darksky(**kwargs)
def historian(config_path, **kwargs): config = utils.load_config(config_path) custom_topic_list = config.pop('custom_topic_list', []) topic_replace_list = config.pop('topic_replace_list', []) destination_vip = config.pop('destination-vip', None) service_topic_list = config.pop('service_topic_list', None) if service_topic_list is not None: w = "Deprecated service_topic_list. Use capture_device_data " \ "capture_log_data, capture_analysis_data or capture_record_data " \ "instead!" _log.warning(w) # Populate the new values for the kwargs based upon the old data. kwargs['capture_device_data'] = True if ("device" in service_topic_list or "all" in service_topic_list) else False kwargs['capture_log_data'] = True if ("datalogger" in service_topic_list or "all" in service_topic_list) else False kwargs['capture_record_data'] = True if ("record" in service_topic_list or "all" in service_topic_list) else False kwargs['capture_analysis_data'] = True if ("analysis" in service_topic_list or "all" in service_topic_list) else False hosts = KnownHostsStore() destination_serverkey = hosts.serverkey(destination_vip) if destination_serverkey is None: _log.info("Destination serverkey not found in known hosts file, using config") destination_serverkey = config.pop('destination-serverkey') else: config.pop('destination-serverkey', None) required_target_agents = config.pop('required_target_agents', []) cache_only = config.pop('cache_only', False) utils.update_kwargs_with_config(kwargs, config) return ForwardHistorian(destination_vip, destination_serverkey, custom_topic_list=custom_topic_list, topic_replace_list=topic_replace_list, required_target_agents=required_target_agents, cache_only=cache_only, **kwargs)