def __init__(self, config_path): """Initialise node instance. Sets up signal handling to deal with interrupts. Loads configuration file, checks validity and creates sensible defaults if values missing. Starts loaded modules. Initialises logger to handle output durring running. Creates and binds socket for inter-process communications with server instances. Allocates potential ports for server instances. Starts continuous communication with controller. Starts JSON server ready to receive commands from the controller. """ self._setup_signal_handling() self._option_check(config_path) parser = configparser.ConfigParser(delimiters='=') parser.read(config_path) self.config = self._create_config_defaults() self.config = lib.load_config(self.config, parser) lib.create_directory(self.config["cache_path"] + 'shared') self._logger = lib.setup_logger(self.config["log_path"], TAG, self.config["verbosity"]) self.database = database.State(self) self._allocate_ports(self.config["port_range"]) context = zmq.Context() self.ipc_socket = context.socket(zmq.PUB) self.ipc_socket.bind("ipc://oc") self._controller_communication = ControllerCommunication(self) self._json_server = JSONServer(self)
def __init__(self, node, expr, port): """Initialise server instance. Creates new connection manager. Creates new HTTP server. Passes objects to the server to facilitate callbacks. Sets server status to 'start'. Runs server until terminated. """ self._setup_signal_handling() self._database = node.database self._node = node self._expr = expr self._port = port self._load_data = collections.deque(maxlen=int(self._node.config["stat_refresh"])) self._set_path(expr) lib.create_directory(self._server_path) self._server = self.ThreadedHTTPServer(('', self._port), self.HandlerClass) #self._server = self.ThreadedHTTPServer((self._node.config["node_host"], self._port), self.HandlerClass) self._server._setup_signal_handling() self._server._server = self self._server._node = self._node self._server._expr = self._expr self._server._server_path = self._server_path threading.Thread(target=self._conn_manager, args=(expr, )).start() threading.Thread(target=self._load_monitor, args=()).start() threading.Thread(target=self._stat_reporter, args=()).start() self._start() self._server.serve_forever()
def __init__(self, config_path): """Initialise node instance. Sets up signal handling to deal with interrupts. Loads configuration file, checks validity and creates sensible defaults if values missing. Starts loaded modules. Initialises logger to handle output durring running. Creates and binds socket for inter-process communications with server instances. Allocates potential ports for server instances. Starts continuous communication with controller. Starts JSON server ready to receive commands from the controller. """ self._setup_signal_handling() self._option_check(config_path) parser = configparser.ConfigParser(delimiters='=') parser.read(config_path) self.config = self._create_config_defaults() self.config = lib.load_config(self.config, parser) lib.create_directory(self.config["cache_path"] + 'shared') self._logger = lib.setup_logger(self.config["log_path"], TAG, self.config["verbosity"]) self.database = database.State(self) self._allocate_ports(self.config["port_range"]) context = zmq.Context() self.ipc_socket = context.socket(zmq.PUB) self.ipc_socket.bind("ipc://oc") self._controller_communication = ControllerCommunication(self) self._json_server = JSONServer(self)