server/repository.py
branchstable
changeset 5043 fe52dd3936cf
parent 5032 e3fa27fc0d9a
child 5067 adc2122eed03
equal deleted inserted replaced
5042:cc062bb09abb 5043:fe52dd3936cf
   163         self._extid_cache = {}
   163         self._extid_cache = {}
   164         # open some connections pools
   164         # open some connections pools
   165         if config.open_connections_pools:
   165         if config.open_connections_pools:
   166             self.open_connections_pools()
   166             self.open_connections_pools()
   167 
   167 
   168     def _boostrap_hook_registry(self):
   168     def _bootstrap_hook_registry(self):
   169         """called during bootstrap since we need the metadata hooks"""
   169         """called during bootstrap since we need the metadata hooks"""
   170         hooksdirectory = join(CW_SOFTWARE_ROOT, 'hooks')
   170         hooksdirectory = join(CW_SOFTWARE_ROOT, 'hooks')
   171         self.vreg.init_registration([hooksdirectory])
   171         self.vreg.init_registration([hooksdirectory])
   172         self.vreg.load_file(join(hooksdirectory, 'metadata.py'),
   172         self.vreg.load_file(join(hooksdirectory, 'metadata.py'),
   173                             'cubicweb.hooks.metadata')
   173                             'cubicweb.hooks.metadata')
   174 
   174 
   175     def open_connections_pools(self):
   175     def open_connections_pools(self):
   176         config = self.config
   176         config = self.config
   177         self._available_pools = Queue.Queue()
   177         self._available_pools = Queue.Queue()
   178         self._available_pools.put_nowait(pool.ConnectionsPool(self.sources))
   178         self._available_pools.put_nowait(pool.ConnectionsPool(self.sources))
   179         if config.read_instance_schema:
   179         if config.quick_start:
   180             # normal start: load the instance schema from the database
   180             # quick start, usually only to get a minimal repository to get cubes
   181             self.fill_schema()
   181             # information (eg dump/restore/
   182         elif config.bootstrap_schema:
   182             config._cubes = ()
   183             # usually during repository creation
   183             self.set_schema(config.load_schema(), resetvreg=False)
   184             self.warning("set fs instance'schema as bootstrap schema")
   184             config['connections-pool-size'] = 1
       
   185             config._cubes = None
       
   186         elif config.creating:
       
   187             # repository creation
   185             config.bootstrap_cubes()
   188             config.bootstrap_cubes()
   186             self.set_schema(config.load_schema(), resetvreg=False)
   189             self.set_schema(config.load_schema(), resetvreg=False)
   187             # need to load the Any and CWUser entity types
   190             # need to load the Any and CWUser entity types
   188             etdirectory = join(CW_SOFTWARE_ROOT, 'entities')
   191             etdirectory = join(CW_SOFTWARE_ROOT, 'entities')
   189             self.vreg.init_registration([etdirectory])
   192             self.vreg.init_registration([etdirectory])
   190             for modname in ('__init__', 'authobjs', 'wfobjs'):
   193             for modname in ('__init__', 'authobjs', 'wfobjs'):
   191                 self.vreg.load_file(join(etdirectory, '%s.py' % modname),
   194                 self.vreg.load_file(join(etdirectory, '%s.py' % modname),
   192                                 'cubicweb.entities.%s' % modname)
   195                                     'cubicweb.entities.%s' % modname)
   193             self._boostrap_hook_registry()
   196             self._bootstrap_hook_registry()
       
   197         elif config.read_instance_schema:
       
   198             # normal start: load the instance schema from the database
       
   199             self.fill_schema()
   194         else:
   200         else:
   195             # test start: use the file system schema (quicker)
   201             # test start: use the file system schema (quicker)
   196             self.warning("set fs instance'schema")
   202             self.warning("set fs instance'schema")
   197             config.bootstrap_cubes()
   203             config.bootstrap_cubes()
   198             self.set_schema(config.load_schema())
   204             self.set_schema(config.load_schema())
   217         self.pools = []
   223         self.pools = []
   218         for i in xrange(config['connections-pool-size']):
   224         for i in xrange(config['connections-pool-size']):
   219             self.pools.append(pool.ConnectionsPool(self.sources))
   225             self.pools.append(pool.ConnectionsPool(self.sources))
   220             self._available_pools.put_nowait(self.pools[-1])
   226             self._available_pools.put_nowait(self.pools[-1])
   221         self._shutting_down = False
   227         self._shutting_down = False
   222         self.hm = self.vreg['hooks']
   228         if config.quick_start:
       
   229             config.init_cubes(self.get_cubes())
       
   230         else:
       
   231             self.hm = self.vreg['hooks']
   223 
   232 
   224     # internals ###############################################################
   233     # internals ###############################################################
   225 
   234 
   226     def get_source(self, uri, source_config):
   235     def get_source(self, uri, source_config):
   227         source_config['uri'] = uri
   236         source_config['uri'] = uri
   266         finally:
   275         finally:
   267             session.close()
   276             session.close()
   268         self.set_schema(appschema)
   277         self.set_schema(appschema)
   269 
   278 
   270     def start_looping_tasks(self):
   279     def start_looping_tasks(self):
   271         if not (self.config.creating or self.config.repairing):
   280         if not (self.config.creating or self.config.repairing
       
   281                 or self.config.quick_start):
   272             # call instance level initialisation hooks
   282             # call instance level initialisation hooks
   273             self.hm.call_hooks('server_startup', repo=self)
   283             self.hm.call_hooks('server_startup', repo=self)
   274             # register a task to cleanup expired session
   284             # register a task to cleanup expired session
   275             self.looping_task(self.config['session-time']/3., self.clean_sessions)
   285             self.looping_task(self.config['session-time']/3., self.clean_sessions)
   276         assert isinstance(self._looping_tasks, list), 'already started'
   286         assert isinstance(self._looping_tasks, list), 'already started'
   334                 self.info('task %s finished', looptask.name)
   344                 self.info('task %s finished', looptask.name)
   335         for thread in self._running_threads:
   345         for thread in self._running_threads:
   336             self.info('waiting thread %s...', thread.name)
   346             self.info('waiting thread %s...', thread.name)
   337             thread.join()
   347             thread.join()
   338             self.info('thread %s finished', thread.name)
   348             self.info('thread %s finished', thread.name)
   339         if not (self.config.creating or self.config.repairing):
   349         if not (self.config.creating or self.config.repairing
       
   350                 or self.config.quick_start):
   340             self.hm.call_hooks('server_shutdown', repo=self)
   351             self.hm.call_hooks('server_shutdown', repo=self)
   341         self.close_sessions()
   352         self.close_sessions()
   342         while not self._available_pools.empty():
   353         while not self._available_pools.empty():
   343             pool = self._available_pools.get_nowait()
   354             pool = self._available_pools.get_nowait()
   344             try:
   355             try:
   446         """return the list of cubes used by this instance. This is a
   457         """return the list of cubes used by this instance. This is a
   447         public method, not requiring a session id.
   458         public method, not requiring a session id.
   448         """
   459         """
   449         versions = self.get_versions(not (self.config.creating
   460         versions = self.get_versions(not (self.config.creating
   450                                           or self.config.repairing
   461                                           or self.config.repairing
       
   462                                           or self.config.quick_start
   451                                           or self.config.mode == 'test'))
   463                                           or self.config.mode == 'test'))
   452         cubes = list(versions)
   464         cubes = list(versions)
   453         cubes.remove('cubicweb')
   465         cubes.remove('cubicweb')
   454         return cubes
   466         return cubes
   455 
   467