def __init__(self, name=None): from liota.entities.edge_systems.dell5k_edge_system import Dell5KEdgeSystem Thread.__init__(self, name=name) # cmd related obj self.cmd_messenger_thread = None self.cmd_messenger_pipe = None # simulator related obj self.simulator_lock = None # simulator related configuration self.endpoint_list = {} # simulator list: (comm type, ip:port or folder) self.type_dcc_map = {} # Device Type to DCC mapping: (device type, dcc package name list (e.g., iotcc, iotcc_mqtt)) self.type_key_map = {} # Device Type to Unique Key mapping: (device type, unique key) self.type_tuple_key_dcc_pkg = {} # Device Type to Tuple of (unique key, dcc_pkg) self._config = {} #key: cfg type, value: cfg list/info self._get_config_from_file() # extract configuration from liota.conf first self._executable_check() # check based on configuration, simulator thread is executable or not self._save_config() # create an edge system instance config_path = self._config['package_path'] config = read_user_config(config_path + '/sampleProp.conf') self.edge_system_object = Dell5KEdgeSystem(config['EdgeSystemName']) # Initialization of simulator messenger queue and lock global cmd_message_queue cmd_message_queue = Queue() self.simulator_lock = Lock() self._simulators = {} # key: beacon type, value: thread ref self.flag_alive = True self.start()
def run(self, registry): import copy from liota.dccs.opentsdb import opentsdb from liota.dcc_comms.socket_comms import SocketDccComms from liota.lib.utilities.offline_buffering import BufferingParams # Acquire resources from registry # Creating a copy of system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Initialize DCC object with transport offline_buffering = BufferingParams(persistent_storage=True, queue_size=-1, data_drain_size=10, draining_frequency=1) self.opentsdb = opentsdb( SocketDccComms(ip=config['opentsdbIP'], port=config['opentsdbPort']), buffering_params=offline_buffering ) # Register gateway system opentsdb_edge_system = self.opentsdb.register(edge_system) registry.register("opentsdb", self.opentsdb) registry.register("opentsdb_edge_system", opentsdb_edge_system)
def clean_up(self): # Get values from configuration file config = read_user_config(self.config_path + '/sampleProp.conf') # Unregister edge system if config['ShouldUnregisterOnUnload'] == "True": self.iotcc.unregister(self.iotcc_edge_system) self.iotcc.comms.client.close()
def run(self, registry): import copy from liota.entities.metrics.metric import Metric # Acquire resources from registry edge_system = copy.copy(registry.get("graphite_edge_system")) graphite = registry.get("graphite") reg_edge_system = graphite.register(edge_system) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Create metrics self.metrics = [] metric_name = "EdgeSystem.CPU_Utilization" metric_cpu_utilization = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_utilization ) reg_metric_cpu_utilization = graphite.register(metric_cpu_utilization) graphite.create_relationship(reg_edge_system, reg_metric_cpu_utilization) reg_metric_cpu_utilization.start_collecting() self.metrics.append(reg_metric_cpu_utilization) metric_name = "EdgeSystem.CPU_Process" metric_cpu_procs = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_procs ) reg_metric_cpu_procs = graphite.register(metric_cpu_procs) graphite.create_relationship(reg_edge_system, reg_metric_cpu_procs) reg_metric_cpu_procs.start_collecting() self.metrics.append(reg_metric_cpu_procs) metric_name = "EdgeSystem.Disk_Busy_Stats" metric_disk_busy_stats = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_disk_usage_stats ) reg_metric_disk_busy_stats = graphite.register(metric_disk_busy_stats) graphite.create_relationship(reg_edge_system, reg_metric_disk_busy_stats) reg_metric_disk_busy_stats.start_collecting() self.metrics.append(reg_metric_disk_busy_stats) metric_name = "EdgeSystem.Network_Bytes_Received" metric_network_bytes_received = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_network_bytes_received ) reg_metric_network_bytes_received = graphite.register(metric_network_bytes_received) graphite.create_relationship(reg_edge_system, reg_metric_network_bytes_received) reg_metric_network_bytes_received.start_collecting() self.metrics.append(reg_metric_network_bytes_received)
def run(self, registry): import copy from liota.entities.metrics.metric import Metric # Acquire resources from registry iotcc_edge_system = copy.copy(registry.get("iotcc_edge_system")) iotcc = registry.get("iotcc") # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Create metrics self.metrics = [] metric_name = "CPU Utilization" metric_cpu_utilization = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_utilization ) reg_metric_cpu_utilization = iotcc.register(metric_cpu_utilization) iotcc.create_relationship(iotcc_edge_system, reg_metric_cpu_utilization) reg_metric_cpu_utilization.start_collecting() self.metrics.append(reg_metric_cpu_utilization) metric_name = "CPU Process" metric_cpu_procs = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_procs ) reg_metric_cpu_procs = iotcc.register(metric_cpu_procs) iotcc.create_relationship(iotcc_edge_system, reg_metric_cpu_procs) reg_metric_cpu_procs.start_collecting() self.metrics.append(reg_metric_cpu_procs) metric_name = "Disk Usage Stats" metric_disk_usage_stats = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_disk_usage_stats ) reg_metric_disk_usage_stats = iotcc.register(metric_disk_usage_stats) iotcc.create_relationship(iotcc_edge_system, reg_metric_disk_usage_stats) reg_metric_disk_usage_stats.start_collecting() self.metrics.append(reg_metric_disk_usage_stats) metric_name = "Network Bytes Received" metric_network_bytes_received = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_network_bytes_received ) reg_metric_network_bytes_received = iotcc.register(metric_network_bytes_received) iotcc.create_relationship(iotcc_edge_system, reg_metric_network_bytes_received) reg_metric_network_bytes_received.start_collecting() self.metrics.append(reg_metric_network_bytes_received)
def run(self, registry): import copy from liota.dccs.wavefront import Wavefront from liota.dcc_comms.mqtt_dcc_comms import MqttDccComms from liota.lib.transports.mqtt import MqttMessagingAttributes from liota.lib.transports.mqtt import QoSDetails from liota.lib.utilities.identity import Identity from liota.lib.utilities.tls_conf import TLSConf from liota.lib.utilities.offline_buffering import BufferingParams from liota.lib.utilities.utility import systemUUID # Acquire resources from registry # Creating a copy of system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Initialize DCC object with transport offline_buffering = BufferingParams(persistent_storage=True, queue_size=-1, data_drain_size=10, draining_frequency=1) identity = Identity(root_ca_cert=config['broker_root_ca_cert'], username=config['broker_username'], password=['broker_password'], cert_file=None, key_file=None) # Encapsulate TLS parameters tls_conf = TLSConf(config['cert_required'], config['tls_version'], config['cipher']) # Encapsulate QoS related parameters qos_details = QoSDetails(config['in_flight'], config['queue_size'], config['retry']) # Connecting to emqtt broker client_id = systemUUID().get_uuid(edge_system.name) self.wavefront = Wavefront(MqttDccComms( edge_system_name=edge_system.name, url=config['BrokerIP'], port=config['BrokerPort'], identity=identity, tls_conf=tls_conf, qos_details=qos_details, client_id=client_id, clean_session=True, protocol=config['protocol'], transport=['transport'], conn_disconn_timeout=config['ConnectDisconnectTimeout']), buffering_params=offline_buffering) # Register gateway system wavefront_edge_system = self.wavefront.register(edge_system) registry.register("wavefront", self.wavefront) registry.register("wavefront_edge_system", wavefront_edge_system)
def run(self, registry): from liota.entities.edge_systems.dell5k_edge_system import Dell5KEdgeSystem # getting values from conf file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Initialize edgesystem edge_system = Dell5KEdgeSystem(config['EdgeSystemName']) registry.register("edge_system", edge_system)
def clean_up(self): # Get values from configuration file config = read_user_config(self.config_path + '/sampleProp.conf') for metric in self.metrics: metric.stop_collecting() #Unregister iotcc device if config['ShouldUnregisterOnUnload'] == "True": self.iotcc.unregister(self.iotcc_bike)
def run(self, registry): """ The execution function of a liota package. Establishes connection with IoTControlCenter DCC using MqttDccComms :param registry: the instance of ResourceRegistryPerPackage of the package :return: """ import copy from liota.lib.utilities.identity import Identity from liota.dccs.iotcc import IotControlCenter from liota.dcc_comms.mqtt_dcc_comms import MqttDccComms from liota.dccs.dcc import RegistrationFailure from liota.lib.utilities.tls_conf import TLSConf # Get values from configuration file self.config_path = registry.get("package_conf") config = read_user_config(self.config_path + '/sampleProp.conf') # Acquire resources from registry # Creating a copy of edge_system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Encapsulates Identity identity = Identity(root_ca_cert=config['broker_root_ca_cert'], username=config['broker_username'], password=config['broker_password'], cert_file=config['edge_system_cert_file'], key_file=config['edge_system_key_file']) # Encapsulate TLS parameters tls_conf = TLSConf(config['cert_required'], config['tls_version'], config['cipher']) # Initialize DCC object with MQTT transport self.iotcc = IotControlCenter(MqttDccComms(edge_system_name=edge_system.name, url=config['BrokerIP'], port=config['BrokerPort'], identity=identity, tls_conf=tls_conf, enable_authentication=True)) try: # Register edge system (gateway) self.iotcc_edge_system = self.iotcc.register(edge_system) """ Use iotcc & iotcc_edge_system as common identifiers in the registry to easily refer the objects in other packages """ registry.register("iotcc_mqtt", self.iotcc) registry.register("iotcc_mqtt_edge_system", self.iotcc_edge_system) except RegistrationFailure: print "EdgeSystem registration to IOTCC failed" self.iotcc.set_properties(self.iotcc_edge_system, config['SystemPropList'])
def run(self, registry): from liota.entities.devices.bike_simulated import BikeSimulated import pint # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # create a pint unit registry ureg = pint.UnitRegistry() # initialize and run the physical model (simulated device) bike_simulator = BikeSimulated(name=config['DeviceName'], ureg=ureg) registry.register("bike_simulator", bike_simulator)
def run(self, registry): import copy from liota.dccs.influx import influx from liota.dcc_comms.mqtt_dcc_comms import MqttDccComms from liota.lib.transports.mqtt import MqttMessagingAttributes from liota.lib.transports.mqtt import QoSDetails from liota.lib.utilities.identity import Identity from liota.lib.utilities.tls_conf import TLSConf # Acquire resources from registry # Creating a copy of system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Initialize DCC object with transport identity = Identity(root_ca_cert=config['broker_root_ca_cert'], username=config['broker_username'], password=['broker_password'], cert_file=None, key_file=None) # Encapsulate TLS parameters tls_conf = TLSConf(config['cert_required'], config['tls_version'], config['cipher']) # Encapsulate QoS related parameters qos_details = QoSDetails(config['in_flight'], config['queue_size'], config['retry']) # Connecting to emqtt broker self.influx = influx( MqttDccComms( edge_system_name=edge_system.name, url=config['BrokerIP'], port=config['BrokerPort'], identity=identity, tls_conf=tls_conf, qos_details=qos_details, clean_session=True, protocol=config['protocol'], transport=['transport'], conn_disconn_timeout=config['ConnectDisconnectTimeout'])) # Register gateway system influx_edge_system = self.influx.register(edge_system) registry.register("influx", self.influx) registry.register("influx_edge_system", influx_edge_system)
def run(self, registry): import copy from liota.dccs.aws_iot import AWSIoT from liota.dcc_comms.mqtt_dcc_comms import MqttDccComms from liota.lib.transports.mqtt import QoSDetails from liota.lib.utilities.identity import Identity from liota.lib.utilities.tls_conf import TLSConf # Acquire resources from registry # Creating a copy of edge_system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Encapsulates Identity identity = Identity(root_ca_cert=config['broker_root_ca_cert'], username=None, password=None, cert_file=config['edge_system_cert_file'], key_file=config['edge_system_key_file']) # Encapsulate TLS parameters tls_conf = TLSConf(config['cert_required'], config['tls_version'], config['cipher']) # Encapsulate QoS related parameters qos_details = QoSDetails(config['in_flight'], config['queue_size'], config['retry']) # Connecting to AWSIoT # Publish topic for all Metrics will be 'liota/generated_local_uuid_of_edge_system/request' # Create and pass custom MqttMessagingAttributes object to MqttDccComms to have custom topic self.aws_iot = AWSIoT(MqttDccComms( edge_system_name=edge_system.name, url=config['BrokerIP'], port=config['BrokerPort'], identity=identity, tls_conf=tls_conf, qos_details=qos_details, clean_session=True, protocol=config['protocol'], transport=['transport'], conn_disconn_timeout=config['ConnectDisconnectTimeout']), enclose_metadata=True) # Register edge system (gateway) aws_iot_edge_system = self.aws_iot.register(edge_system) registry.register("aws_iot", self.aws_iot) registry.register("aws_iot_edge_system", aws_iot_edge_system)
def run(self, registry): import copy from liota.lib.utilities.identity import Identity from liota.dccs.iotcc import IotControlCenter from liota.dcc_comms.mqtt_dcc_comms import MqttDccComms from liota.dccs.dcc import RegistrationFailure from liota.lib.utilities.tls_conf import TLSConf # Get values from configuration file self.config_path = registry.get("package_conf") config = read_user_config(self.config_path + '/sampleProp.conf') # Acquire resources from registry # Creating a copy of edge_system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Encapsulates Identity identity = Identity(root_ca_cert=config['broker_root_ca_cert'], username=config['broker_username'], password=config['broker_password'], cert_file=config['edge_system_cert_file'], key_file=config['edge_system_key_file']) # Encapsulate TLS parameters tls_conf = TLSConf(config['cert_required'], config['tls_version'], config['cipher']) # Initialize DCC object with MQTT transport self.iotcc = IotControlCenter( MqttDccComms(edge_system_name=edge_system.name, url=config['BrokerIP'], port=config['BrokerPort'], identity=identity, tls_conf=tls_conf, enable_authentication=True)) try: # Register edge system (gateway) self.iotcc_edge_system = self.iotcc.register(edge_system) """ Use iotcc & iotcc_edge_system as common identifiers in the registry to easily refer the objects in other packages """ registry.register("iotcc_mqtt", self.iotcc) registry.register("iotcc_mqtt_edge_system", self.iotcc_edge_system) except RegistrationFailure: print "EdgeSystem registration to IOTCC failed" self.iotcc.set_properties(self.iotcc_edge_system, config['SystemPropList'])
def clean_up(self): """ The clean up function of a liota package. Disconnects from IoTControlCenter DCC and un-registers the edge-system if specified in configuration. :return: """ # Get values from configuration file config = read_user_config(self.config_path + '/sampleProp.conf') # Un-register edge system if config['ShouldUnregisterOnUnload'] == "True": self.iotcc.unregister(self.iotcc_edge_system) self.iotcc.comms.client.disconnect()
def run(self, registry): """ The execution function of a liota package. Establishes connection with AWSIoT DCC using MqttDccComms :param registry: the instance of ResourceRegistryPerPackage of the package :return: """ import copy from liota.dccs.aws_iot import AWSIoT from liota.dcc_comms.mqtt_dcc_comms import MqttDccComms from liota.lib.transports.mqtt import QoSDetails from liota.lib.utilities.identity import Identity from liota.lib.utilities.tls_conf import TLSConf # Acquire resources from registry # Creating a copy of edge_system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Encapsulates Identity identity = Identity(root_ca_cert=config['broker_root_ca_cert'], username=None, password=None, cert_file=config['edge_system_cert_file'], key_file=config['edge_system_key_file']) # Encapsulate TLS parameters tls_conf = TLSConf(config['cert_required'], config['tls_version'], config['cipher']) # Encapsulate QoS related parameters qos_details = QoSDetails(config['in_flight'], config['queue_size'], config['retry']) # Connecting to AWSIoT # Publish topic for all Metrics will be 'liota/generated_local_uuid_of_edge_system/request' # Create and pass custom MqttMessagingAttributes object to MqttDccComms to have custom topic self.aws_iot = AWSIoT(MqttDccComms(edge_system_name=edge_system.name, url=config['BrokerIP'], port=config['BrokerPort'], identity=identity, tls_conf=tls_conf, qos_details=qos_details, clean_session=True, protocol=config['protocol'], transport=['transport'], conn_disconn_timeout=config['ConnectDisconnectTimeout']), enclose_metadata=True) # Register edge system (gateway) aws_iot_edge_system = self.aws_iot.register(edge_system) registry.register("aws_iot", self.aws_iot) registry.register("aws_iot_edge_system", aws_iot_edge_system)
def run(self, registry): from liota.entities.devices.bike_simulated import BikeSimulated import pint # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # create a pint unit registry ureg = pint.UnitRegistry() # initialize and run the physical model (simulated device) bike_simulator = BikeSimulated( name=config['DeviceName'], ureg=ureg ) registry.register("bike_simulator", bike_simulator)
def run(self, registry): """ The execution function of a liota package. Registers Dell5KEdgeSystem as "edge_system" in package manager's resource registry. :param registry: the instance of ResourceRegistryPerPackage of the package :return: """ from liota.entities.edge_systems.dell5k_edge_system import Dell5KEdgeSystem # getting values from conf file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Initialize edgesystem edge_system = Dell5KEdgeSystem(config['EdgeSystemName']) registry.register("edge_system", edge_system)
def run(self, registry): from liota.entities.metrics.metric import Metric from liota.lib.transports.mqtt import MqttMessagingAttributes import copy # Acquire resources from registry wavefront_edge_system = copy.copy( registry.get("wavefront_edge_system")) wavefront = registry.get("wavefront") bike_simulator = registry.get("bike_simulator") wavefront_bike = wavefront.register(bike_simulator) wavefront.create_relationship(wavefront_edge_system, wavefront_bike) config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') ureg = bike_simulator.ureg self.create_udm(bike_model=bike_simulator) # Create metrics self.metrics = [] metric_name = "speed" bike_speed = Metric(name=metric_name, unit=(ureg.m / ureg.sec), interval=2, sampling_function=self.get_bike_speed) reg_bike_speed = wavefront.register(bike_speed) wavefront.create_relationship(wavefront_bike, reg_bike_speed) reg_bike_speed.start_collecting() self.metrics.append(reg_bike_speed) metric_name = "power" bike_power = Metric(name=metric_name, unit=ureg.watt, interval=2, sampling_function=self.get_bike_power) reg_bike_power = wavefront.register(bike_power) wavefront.create_relationship(wavefront_bike, reg_bike_power) reg_bike_power.start_collecting() self.metrics.append(reg_bike_power)
def run(self, registry): import copy from liota.lib.utilities.identity import Identity from liota.dccs.iotcc import IotControlCenter from liota.dcc_comms.websocket_dcc_comms import WebSocketDccComms from liota.dccs.dcc import RegistrationFailure # Acquire resources from registry # Creating a copy of edge_system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file self.config_path = registry.get("package_conf") config = read_user_config(self.config_path + '/sampleProp.conf') identity = Identity(root_ca_cert=config['WebsocketCaCertFile'], username=config['IotCCUID'], password=config['IotCCPassword'], cert_file=config['ClientCertFile'], key_file=config['ClientKeyFile']) # Initialize DCC object with transport self.iotcc = IotControlCenter( WebSocketDccComms(url=config['WebSocketUrl'], verify_cert=config['VerifyServerCert'], identity=identity)) try: # Register edge system (gateway) self.iotcc_edge_system = self.iotcc.register(edge_system) """ Use iotcc & iotcc_edge_system as common identifiers in the registry to easily refer the objects in other packages """ registry.register("iotcc", self.iotcc) registry.register("iotcc_edge_system", self.iotcc_edge_system) except RegistrationFailure: print "EdgeSystem registration to IOTCC failed" self.iotcc.set_properties(self.iotcc_edge_system, config['SystemPropList'])
def __init__(self, name=None): from liota.entities.edge_systems.dell5k_edge_system import Dell5KEdgeSystem Thread.__init__(self, name=name) # cmd related obj self.cmd_messenger_thread = None self.cmd_messenger_pipe = None # simulator related obj self.simulator_lock = None # simulator related configuration self.endpoint_list = { } # simulator list: (comm type, ip:port or folder) self.type_dcc_map = { } # Device Type to DCC mapping: (device type, dcc package name list (e.g., iotcc, iotcc_mqtt)) self.type_key_map = { } # Device Type to Unique Key mapping: (device type, unique key) self.type_tuple_key_dcc_pkg = { } # Device Type to Tuple of (unique key, dcc_pkg) self._config = {} #key: cfg type, value: cfg list/info self._get_config_from_file( ) # extract configuration from liota.conf first self._executable_check( ) # check based on configuration, simulator thread is executable or not self._save_config() # create an edge system instance config_path = self._config['package_path'] config = read_user_config(config_path + '/sampleProp.conf') self.edge_system_object = Dell5KEdgeSystem(config['EdgeSystemName']) # Initialization of simulator messenger queue and lock global cmd_message_queue cmd_message_queue = Queue() self.simulator_lock = Lock() self._simulators = {} # key: beacon type, value: thread ref self.flag_alive = True self.start()
def run(self, registry): import copy from liota.dccs.graphite import Graphite from liota.dcc_comms.socket_comms import SocketDccComms # Acquire resources from registry # Creating a copy of system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Initialize DCC object with transport self.graphite = Graphite( SocketDccComms(ip=config['GraphiteIP'], port=config['GraphitePort'])) # Register gateway system graphite_edge_system = self.graphite.register(edge_system) registry.register("graphite", self.graphite) registry.register("graphite_edge_system", graphite_edge_system)
def run(self, registry): from liota.entities.devices.simulated_device import SimulatedDevice from liota.entities.metrics.metric import Metric import copy # Acquire resources from registry self.iotcc = registry.get("iotcc_mqtt") # Creating a copy of edge_system object to keep original object "clean" self.iotcc_edge_system = copy.copy(registry.get("iotcc_mqtt_edge_system")) # Get values from configuration file config_path = registry.get("package_conf") self.config = read_user_config(config_path + '/sampleProp.conf') # Register device ram_device = SimulatedDevice(self.config['DeviceName'], "Device-RAM") self.reg_ram_device = self.iotcc.register(ram_device) self.iotcc.set_properties(self.reg_ram_device, self.config['DevicePropList']) self.iotcc.create_relationship(self.iotcc_edge_system, self.reg_ram_device) # Create metrics self.metrics = [] mem_free_metric = Metric( name="Memory Free", unit=None, interval=10, sampling_function=read_mem_free ) reg_mem_free_metric = self.iotcc.register(mem_free_metric) self.iotcc.create_relationship(self.reg_ram_device, reg_mem_free_metric) reg_mem_free_metric.start_collecting() self.metrics.append(reg_mem_free_metric) # Use the iotcc_device_name as identifier in the registry to easily refer the device in other packages registry.register("reg_ram_device_mqtt", self.reg_ram_device)
def run(self, registry): import copy from liota.lib.utilities.identity import Identity from liota.dccs.iotcc import IotControlCenter from liota.dcc_comms.websocket_dcc_comms import WebSocketDccComms from liota.dccs.dcc import RegistrationFailure # Acquire resources from registry # Creating a copy of edge_system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file self.config_path = registry.get("package_conf") config = read_user_config(self.config_path + '/sampleProp.conf') identity = Identity(root_ca_cert=config['WebsocketCaCertFile'], username=config['IotCCUID'], password=config['IotCCPassword'], cert_file=config['ClientCertFile'], key_file=config['ClientKeyFile']) # Initialize DCC object with transport self.iotcc = IotControlCenter( WebSocketDccComms(url=config['WebSocketUrl'], verify_cert=config['VerifyServerCert'], identity=identity) ) try: # Register edge system (gateway) self.iotcc_edge_system = self.iotcc.register(edge_system) """ Use iotcc & iotcc_edge_system as common identifiers in the registry to easily refer the objects in other packages """ registry.register("iotcc", self.iotcc) registry.register("iotcc_edge_system", self.iotcc_edge_system) except RegistrationFailure: print "EdgeSystem registration to IOTCC failed" self.iotcc.set_properties(self.iotcc_edge_system, config['SystemPropList'])
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # # THE POSSIBILITY OF SUCH DAMAGE. # # ----------------------------------------------------------------------------# from pint import UnitRegistry from temperusb import TemperHandler from liota.dcc_comms.socket_comms import SocketDccComms from liota.dccs.graphite import Graphite from liota.entities.metrics.metric import Metric from liota.entities.edge_systems.dk300_edge_system import Dk300EdgeSystem from liota.lib.utilities.utility import read_user_config # getting values from conf file config = read_user_config('sampleProp.conf') ureg = UnitRegistry() quantity = ureg.Quantity # --------------------------------------------------------------------------- # Below we showcase how easily SI units can be used in the code with help of # Pint library which is part of Liota and how easily conversion of the units # can be done such as Celsius to Fahrenheit or Kelvin as shown below with # help of this library. def getTemp(): th = TemperHandler() devs = th.get_devices() t = devs[0].get_temperatures() temp = quantity(t[0]['temperature_c'], ureg.degC) return temp
# THE POSSIBILITY OF SUCH DAMAGE. # # ----------------------------------------------------------------------------# from linux_metrics import cpu_stat, disk_stat, net_stat, mem_stat from liota.dccs.iotcc import IotControlCenter from liota.lib.utilities.identity import Identity from liota.entities.metrics.metric import Metric from liota.entities.devices.simulated_device import SimulatedDevice from liota.entities.edge_systems.dell5k_edge_system import Dell5KEdgeSystem from liota.dcc_comms.websocket_dcc_comms import WebSocketDccComms from liota.dccs.dcc import RegistrationFailure from liota.lib.utilities.utility import get_default_network_interface, get_disk_name, read_user_config # getting values from conf file config = read_user_config('sampleProp.conf') # Getting edge_system's network interface and disk name # There are situations where route may not actually return a default route in the # main routing table, as the default route might be kept in another table. # Such cases should be handled manually. network_interface = get_default_network_interface() # If edge_system has multiple disks, only first disk will be returned. # Such cases should be handled manually. disk_name = get_disk_name() # some standard metrics for Linux systems # agent classes for different IoT system # agent classes for different data center components # agent classes for different kinds of of devices, connected to the IoT System
def run(self, registry): import copy import pint from liota.lib.transports.mqtt import MqttMessagingAttributes from liota.entities.metrics.metric import Metric from liota.entities.devices.simulated_device import SimulatedDevice # create a pint unit registry ureg = pint.UnitRegistry() # Acquire resources from registry aws_iot = registry.get("aws_iot") aws_iot_edge_system = copy.copy(registry.get("aws_iot_edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Create metrics self.metrics = [] # Creating CPU Metric cpu_utilization = Metric(name="CPUUtilization", unit=None, interval=10, aggregation_size=2, sampling_function=read_cpu_utilization) # Registering Metric and creating Parent-Child relationship reg_cpu_utilization = aws_iot.register(cpu_utilization) aws_iot.create_relationship(aws_iot_edge_system, reg_cpu_utilization) # Publish topic for this Metric reg_cpu_utilization.msg_attr = MqttMessagingAttributes( pub_topic=config['CustomPubTopic']) # Publishing Registered CPU Utilization Metric to AWSIoT Dcc reg_cpu_utilization.start_collecting() self.metrics.append(reg_cpu_utilization) # Creating Simulated Device dht_sensor = SimulatedDevice("SimulatedDHTSensor") # Registering Device and creating Parent-Child relationship reg_dht_sensor = aws_iot.register(dht_sensor) aws_iot.create_relationship(aws_iot_edge_system, reg_dht_sensor) # Creating Temperature Metric temp_metric = Metric(name="LivingRoomTemperature", entity_type="Metric", unit=ureg.degC, interval=1, aggregation_size=5, sampling_function=get_living_room_temperature) # Registering Metric and creating Parent-Child relationship reg_temp_metric = aws_iot.register(temp_metric) aws_iot.create_relationship(reg_dht_sensor, reg_temp_metric) # Publish topic for this Metric reg_temp_metric.msg_attr = MqttMessagingAttributes( pub_topic=config['LivingRoomTemperatureTopic']) # Publishing Registered Temperature Metric to AWSIoT Dcc reg_temp_metric.start_collecting() self.metrics.append(reg_temp_metric) # Creating Humidity Metric hum_metric = Metric(name="LivingRoomHumidity", entity_type="Metric", unit=None, interval=1, aggregation_size=5, sampling_function=get_living_room_humidity) # Registering Metric and creating Parent-Child relationship reg_hum_metric = aws_iot.register(hum_metric) aws_iot.create_relationship(reg_dht_sensor, reg_hum_metric) # Publish topic for this Metric reg_hum_metric.msg_attr = MqttMessagingAttributes( pub_topic=config['LivingRoomHumidityTopic']) # Publishing Registered Humidity Metric to AWSIoT Dcc reg_hum_metric.start_collecting() self.metrics.append(reg_hum_metric) # Creating Simulated Device light_sensor = SimulatedDevice("SimDigLightSensor") # Registering Device and creating Parent-Child relationship reg_light_sensor = aws_iot.register(light_sensor) aws_iot.create_relationship(aws_iot_edge_system, reg_light_sensor) # Creating Light Metric light_metric = Metric(name="LivingRoomLight", entity_type="Metric", unit=None, interval=10, aggregation_size=1, sampling_function=get_living_room_luminance) # Registering Metric and creating Parent-Child relationship reg_light_metric = aws_iot.register(light_metric) aws_iot.create_relationship(reg_light_sensor, reg_light_metric) # Publish topic for this Metric reg_light_metric.msg_attr = MqttMessagingAttributes( pub_topic=config['LivingRoomLightTopic']) # Publishing Registered Light Metric to AWSIoT DCC reg_light_metric.start_collecting() self.metrics.append(reg_light_metric)
from liota.core.package_manager import LiotaPackage from liota.lib.utilities.utility import read_user_config config = read_user_config('/tmp/cti_Prop.conf') class PackageClass(LiotaPackage): def run(self, registry): from liota.entities.edge_systems.general_edge_system import GeneralEdgeSystem edge_system = GeneralEdgeSystem(config['EdgeSystemName']) registry.register("edge_system", edge_system) def clean_up(self): pass