210 |
210 |
211 def init_cnxset_pool(self): |
211 def init_cnxset_pool(self): |
212 """should be called bootstrap_repository, as this is what it does""" |
212 """should be called bootstrap_repository, as this is what it does""" |
213 config = self.config |
213 config = self.config |
214 self._cnxsets_pool = Queue.Queue() |
214 self._cnxsets_pool = Queue.Queue() |
|
215 # 0. init a cnxset that will be used to fetch bootstrap information from |
|
216 # the database |
215 self._cnxsets_pool.put_nowait(pool.ConnectionsSet(self.sources)) |
217 self._cnxsets_pool.put_nowait(pool.ConnectionsSet(self.sources)) |
|
218 # 1. set used cubes |
|
219 if config.creating or not config.read_instance_schema: |
|
220 config.bootstrap_cubes() |
|
221 else: |
|
222 self.set_schema(self.config.load_bootstrap_schema(), resetvreg=False) |
|
223 config.init_cubes(self.get_cubes()) |
|
224 # 2. load schema |
216 if config.quick_start: |
225 if config.quick_start: |
217 # quick start: only to get a minimal repository to get cubes |
226 # quick start: only to get a minimal repository to get cubes |
218 # information (eg dump/restore/...) |
227 # information (eg dump/restore/...) |
219 config._cubes = () |
228 # |
220 # only load hooks and entity classes in the registry |
229 # restrict appobject_path to only load hooks and entity classes in |
|
230 # the registry |
221 config.cube_appobject_path = set(('hooks', 'entities')) |
231 config.cube_appobject_path = set(('hooks', 'entities')) |
222 config.cubicweb_appobject_path = set(('hooks', 'entities')) |
232 config.cubicweb_appobject_path = set(('hooks', 'entities')) |
223 self.set_schema(config.load_schema()) |
233 # limit connections pool to 1 |
224 config['connections-pool-size'] = 1 |
234 config['connections-pool-size'] = 1 |
225 # will be reinitialized later from cubes found in the database |
235 if config.quick_start or config.creating or not config.read_instance_schema: |
226 config._cubes = None |
236 # load schema from the file system |
227 elif config.creating or not config.read_instance_schema: |
|
228 if not config.creating: |
237 if not config.creating: |
229 # test start: use the file system schema (quicker) |
|
230 self.warning("set fs instance'schema") |
238 self.warning("set fs instance'schema") |
231 config.bootstrap_cubes() |
|
232 self.set_schema(config.load_schema()) |
239 self.set_schema(config.load_schema()) |
233 else: |
240 else: |
234 # normal start: load the instance schema from the database |
241 # normal start: load the instance schema from the database |
235 self.fill_schema() |
242 self.info('loading schema from the repository') |
236 if not config.creating: |
243 self.set_schema(self.deserialize_schema()) |
237 self.init_sources_from_database() |
244 # 3. initialize data sources |
238 if 'CWProperty' in self.schema: |
245 if config.creating: |
239 self.vreg.init_properties(self.properties()) |
|
240 else: |
|
241 # call init_creating so that for instance native source can |
246 # call init_creating so that for instance native source can |
242 # configurate tsearch according to postgres version |
247 # configurate tsearch according to postgres version |
243 for source in self.sources: |
248 for source in self.sources: |
244 source.init_creating() |
249 source.init_creating() |
245 # close initialization connetions set and reopen fresh ones for proper |
250 else: |
246 # initialization now that we know cubes |
251 self.init_sources_from_database() |
|
252 if 'CWProperty' in self.schema: |
|
253 self.vreg.init_properties(self.properties()) |
|
254 # 4. close initialization connection set and reopen fresh ones for |
|
255 # proper initialization |
247 self._get_cnxset().close(True) |
256 self._get_cnxset().close(True) |
248 self.cnxsets = [] # list of available cnxsets (can't iterate on a Queue) |
257 self.cnxsets = [] # list of available cnxsets (can't iterate on a Queue) |
249 for i in xrange(config['connections-pool-size']): |
258 for i in xrange(config['connections-pool-size']): |
250 self.cnxsets.append(pool.ConnectionsSet(self.sources)) |
259 self.cnxsets.append(pool.ConnectionsSet(self.sources)) |
251 self._cnxsets_pool.put_nowait(self.cnxsets[-1]) |
260 self._cnxsets_pool.put_nowait(self.cnxsets[-1]) |
252 if config.quick_start: |
|
253 config.init_cubes(self.get_cubes()) |
|
254 |
261 |
255 # internals ############################################################### |
262 # internals ############################################################### |
256 |
263 |
257 def init_sources_from_database(self): |
264 def init_sources_from_database(self): |
258 self.sources_by_eid = {} |
265 self.sources_by_eid = {} |
316 return sources.get_source(type, source_config, self, eid) |
323 return sources.get_source(type, source_config, self, eid) |
317 |
324 |
318 def set_schema(self, schema, resetvreg=True): |
325 def set_schema(self, schema, resetvreg=True): |
319 self.info('set schema %s %#x', schema.name, id(schema)) |
326 self.info('set schema %s %#x', schema.name, id(schema)) |
320 if resetvreg: |
327 if resetvreg: |
321 if self.config._cubes is None: |
|
322 self.config.init_cubes(self.get_cubes()) |
|
323 # trigger full reload of all appobjects |
328 # trigger full reload of all appobjects |
324 self.vreg.set_schema(schema) |
329 self.vreg.set_schema(schema) |
325 else: |
330 else: |
326 self.vreg._set_schema(schema) |
331 self.vreg._set_schema(schema) |
327 self.querier.set_schema(schema) |
332 self.querier.set_schema(schema) |
329 # sources |
334 # sources |
330 for source in self.sources_by_uri.itervalues(): |
335 for source in self.sources_by_uri.itervalues(): |
331 source.set_schema(schema) |
336 source.set_schema(schema) |
332 self.schema = schema |
337 self.schema = schema |
333 |
338 |
334 def fill_schema(self): |
339 def deserialize_schema(self): |
335 """load schema from the repository""" |
340 """load schema from the database""" |
336 from cubicweb.server.schemaserial import deserialize_schema |
341 from cubicweb.server.schemaserial import deserialize_schema |
337 self.info('loading schema from the repository') |
|
338 appschema = schema.CubicWebSchema(self.config.appid) |
342 appschema = schema.CubicWebSchema(self.config.appid) |
339 self.set_schema(self.config.load_bootstrap_schema(), resetvreg=False) |
|
340 self.debug('deserializing db schema into %s %#x', appschema.name, id(appschema)) |
343 self.debug('deserializing db schema into %s %#x', appschema.name, id(appschema)) |
341 with self.internal_session() as session: |
344 with self.internal_session() as session: |
342 try: |
345 try: |
343 deserialize_schema(appschema, session) |
346 deserialize_schema(appschema, session) |
344 except BadSchemaDefinition: |
347 except BadSchemaDefinition: |