281 if sourceent.name == 'system': |
281 if sourceent.name == 'system': |
282 self.system_source.eid = sourceent.eid |
282 self.system_source.eid = sourceent.eid |
283 self.sources_by_eid[sourceent.eid] = self.system_source |
283 self.sources_by_eid[sourceent.eid] = self.system_source |
284 self.system_source.init(True, sourceent) |
284 self.system_source.init(True, sourceent) |
285 continue |
285 continue |
286 self.add_source(sourceent, add_to_cnxsets=False) |
286 self.add_source(sourceent) |
287 |
287 |
288 def _clear_planning_caches(self): |
288 def _clear_planning_caches(self): |
289 for cache in ('source_defs', 'is_multi_sources_relation', |
289 for cache in ('source_defs', 'is_multi_sources_relation', |
290 'can_cross_relation', 'rel_type_sources'): |
290 'can_cross_relation', 'rel_type_sources'): |
291 clear_cache(self, cache) |
291 clear_cache(self, cache) |
292 |
292 |
293 def add_source(self, sourceent, add_to_cnxsets=True): |
293 def add_source(self, sourceent): |
294 source = self.get_source(sourceent.type, sourceent.name, |
294 source = self.get_source(sourceent.type, sourceent.name, |
295 sourceent.host_config, sourceent.eid) |
295 sourceent.host_config, sourceent.eid) |
296 self.sources_by_eid[sourceent.eid] = source |
296 self.sources_by_eid[sourceent.eid] = source |
297 self.sources_by_uri[sourceent.name] = source |
297 self.sources_by_uri[sourceent.name] = source |
298 if self.config.source_enabled(source): |
298 if self.config.source_enabled(source): |
299 # call source's init method to complete their initialisation if |
299 # call source's init method to complete their initialisation if |
300 # needed (for instance looking for persistent configuration using an |
300 # needed (for instance looking for persistent configuration using an |
301 # internal session, which is not possible until connections sets have been |
301 # internal session, which is not possible until connections sets have been |
302 # initialized) |
302 # initialized) |
303 source.init(True, sourceent) |
303 source.init(True, sourceent) |
304 if not source.copy_based_source: |
|
305 warn('[3.18] old multi-source system will go away in the next version', |
|
306 DeprecationWarning) |
|
307 self.sources.append(source) |
|
308 self.querier.set_planner() |
|
309 if add_to_cnxsets: |
|
310 for cnxset in self.cnxsets: |
|
311 cnxset.add_source(source) |
|
312 else: |
304 else: |
313 source.init(False, sourceent) |
305 source.init(False, sourceent) |
314 self._clear_planning_caches() |
306 self._clear_planning_caches() |
315 |
307 |
316 def remove_source(self, uri): |
308 def remove_source(self, uri): |
317 source = self.sources_by_uri.pop(uri) |
309 source = self.sources_by_uri.pop(uri) |
318 del self.sources_by_eid[source.eid] |
310 del self.sources_by_eid[source.eid] |
319 if self.config.source_enabled(source) and not source.copy_based_source: |
|
320 self.sources.remove(source) |
|
321 self.querier.set_planner() |
|
322 for cnxset in self.cnxsets: |
|
323 cnxset.remove_source(source) |
|
324 self._clear_planning_caches() |
311 self._clear_planning_caches() |
325 |
312 |
326 def get_source(self, type, uri, source_config, eid=None): |
313 def get_source(self, type, uri, source_config, eid=None): |
327 # set uri and type in source config so it's available through |
314 # set uri and type in source config so it's available through |
328 # source_defs() |
315 # source_defs() |