def process_update(self, stream_name, updates, resync): """ Handle config updates. Resync is ignored since the entire config structure is passed in every update. Inputs: - updates - list of GatewayConfigs protobuf structures - resync - boolean indicating whether all database information will be resent (hence cached data can be discarded). This is ignored since config is contained in one DB element, hence all data is sent in every update. """ if len(updates) == 0: logging.info('No config update to process') return # We will only take the last update for update in updates[:-1]: logging.info('Ignoring config update %s', update.key) # Deserialize and store the last config update logging.info('Processing config update %s', updates[-1].key) mconfig_str = updates[-1].value.decode() mconfig = self._mconfig_manager.deserialize_mconfig( mconfig_str, self._allow_unknown_fields, ) if 'magmad' not in mconfig.configs_by_key: logging.error('Invalid config! Magmad service config missing') return self._mconfig_manager.update_stored_mconfig(mconfig_str) self._magmad_service.reload_mconfig() def did_mconfig_change(serv_name): return mconfig.configs_by_key.get(serv_name) != \ self._mconfig.configs_by_key.get(serv_name) # Reload magmad configs locally if did_mconfig_change('magmad'): self._loop.create_task( self._service_manager.update_dynamic_services( load_service_mconfig( 'magmad', mconfigs_pb2.MagmaD()).dynamic_services, ), ) services_to_restart = [ srv for srv in self._services if did_mconfig_change(srv) ] if services_to_restart: self._loop.create_task( self._service_manager.restart_services(services_to_restart), ) self._mconfig = mconfig configs_by_key = {} for srv in self._services: if srv in mconfig.configs_by_key: configs_by_key[srv] = mconfig.configs_by_key.get(srv) magmad_events.processed_updates(configs_by_key)
def process_update(self, stream_name, updates, resync): """ Handle config updates. Resync is ignored since the entire config structure is passed in every update. Inputs: - updates - list of GatewayConfigs protobuf structures - resync - boolean indicating whether all database information will be resent (hence cached data can be discarded). This is ignored since config is contained in one DB element, hence all data is sent in every update. """ if len(updates) == 0: logging.info('No config update to process') return # We will only take the last update for update in updates[:-1]: logging.info('Ignoring config update %s', update.key) # Deserialize and store the last config update logging.info('Processing config update %s', updates[-1].key) mconfig_str = updates[-1].value.decode() mconfig = self._mconfig_manager.deserialize_mconfig( mconfig_str, self._allow_unknown_fields, ) if MAGMAD not in mconfig.configs_by_key: logging.error('Invalid config! Magmad service config missing') return self._mconfig_manager.update_stored_mconfig(mconfig_str) self._magmad_service.reload_mconfig() def did_mconfig_change(serv_name): return mconfig.configs_by_key.get(serv_name) != \ self._mconfig.configs_by_key.get(serv_name) # Reload magmad configs locally if did_mconfig_change(MAGMAD) or ( SHARED_MCONFIG in mconfig.configs_by_key and did_mconfig_change(SHARED_MCONFIG)): logging.info("Restarting dynamic services due to config change") self._loop.create_task( self._service_manager.update_dynamic_services( load_service_mconfig( MAGMAD, mconfigs_pb2.MagmaD()).dynamic_services, ), ) services_to_restart = [] if SHARED_MCONFIG in mconfig.configs_by_key and did_mconfig_change( SHARED_MCONFIG): logging.info("Shared config changed. Restarting all services.") services_to_restart = self._services else: services_to_restart = [ srv for srv in self._services if did_mconfig_change(srv) ] if services_to_restart: self._loop.create_task( self._service_manager.restart_services(services_to_restart), ) self._mconfig = mconfig configs_by_key = {} for srv in self._services: if srv in mconfig.configs_by_key: configs_by_key[srv] = mconfig.configs_by_key.get(srv) agw_version = self._magmad_service.version unpacked_mconfig = mconfig.configs_by_key.get(MAGMAD) version_info = self._parse_versions_and_log_warning( agw_version, unpacked_mconfig) agw_version_parsed = version_info.agw_version orc8r_version_parsed = version_info.orc8r_version if agw_version_parsed and orc8r_version_parsed: agw_minor = int(agw_version_parsed.group('minor_version')) orc8r_minor = int(orc8r_version_parsed.group('minor_version')) if agw_minor - orc8r_minor <= -1: logging.warning( "Gateway is more than one minor version behind orc8r. Please consider updating it." ) magmad_events.processed_updates(configs_by_key)