def update_input(self, _input, _input_setting, forwarder): """ Update input. """ assert _input.split(self.SEP)[0] in \ self._dispatch_schema_manager.get_input_schemas(), \ SnapshotManagerException("Wrong input: {}.".format(_input)) with self._rwlock.writer_lock: try: if not forwarder: if not _input_setting: # Delete input del self._dispatch_snapshot[_input] else: new_md5 = md5_of_dict(_input_setting) self._dispatch_snapshot[_input][self.CHECKSUM] = \ new_md5 else: new_md5 = md5_of_dict(_input_setting) self._dispatch_snapshot[_input] = { self.FORWARDER: forwarder, self.CHECKSUM: new_md5 } except KeyError: raise SnapshotManagerException( "Non exits input: {}.".format(_input)) except Exception as e: raise SnapshotManagerException(e)
def setting_is_changed(self, name, setting): """ Check if setting of name is changed, it will compare the md5 between old and new setting. @name: setting name. @setting: new setting. @return: True if changed else False. """ assert name.split(self.SEP)[0] in \ self._dispatch_schema_manager.get_global_setting_schemas() or \ name.split(self.SEP)[0] in \ self._dispatch_schema_manager.get_input_schemas(), \ SnapshotManagerException("Wrong setting: {}.".format(name)) new_md5 = md5_of_dict(setting) with self._rwlock.reader_lock: try: return not new_md5 == \ self._dispatch_snapshot[name][self.CHECKSUM] except KeyError: raise SnapshotManagerException( "Non exits setting: {}.".format(name)) except Exception as e: raise SnapshotManagerException(e)
def update_global_setting(self, global_setting, global_setting_setting, forwarder): """ Update global setting. """ assert global_setting.split(self.SEP)[0] in \ self._dispatch_schema_manager.get_global_setting_schemas(), \ SnapshotManagerException( "Wrong global setting: {}.".format(global_setting)) new_md5 = md5_of_dict(global_setting_setting) with self._rwlock.writer_lock: if global_setting in self._dispatch_snapshot and \ self._dispatch_snapshot[global_setting][self.CHECKSUM] == new_md5 and \ forwarder not in \ self._dispatch_snapshot[global_setting][self.FORWARDER_LIST]: self._dispatch_snapshot[global_setting][ self.FORWARDER_LIST].append(forwarder) else: self._dispatch_snapshot[global_setting] = \ {self.FORWARDER_LIST: [forwarder], self.CHECKSUM: new_md5}