def register_web_service_controllers(self): """ Register web service controllers for this kit. """ # # If another kit of the same name already exists, and has loaded # the ws controllers, then we don't need to do it a second time # for ki in get_all_kit_installers(): if ki.spec[0] == self.spec[0] and ki.ws_controllers_loaded: self.__class__.ws_controllers_loaded = True return kit_pkg_name = inspect.getmodule(self).__package__ ws_pkg_name = '{}.web_service.controllers'.format(kit_pkg_name) logger.debug( 'Searching for web service controllers in package: %s', ws_pkg_name ) try: importlib.import_module(ws_pkg_name) self.__class__.ws_controllers_loaded = True except ModuleNotFoundError: logger.debug( 'No web service controllers found for kit: %s', self.spec )
def setup_routes(): """ Used to setup RESTFul resources. """ # # Ensure all kits are loaded, and their web services are registered # for kit_installer_class in get_all_kit_installers(): kit_installer = kit_installer_class() kit_installer.register_web_service_controllers() kit_installer.register_event_listeners() dispatcher = cherrypy.dispatch.RoutesDispatcher() dispatcher.mapper.explicit = False for controller_class in get_all_ws_controllers(): controller = controller_class(app) for action in controller.actions: dispatcher.connect( action['name'], action['path'], action=action['action'], controller=controller, conditions=dict(method=action['method']) ) return dispatcher
def register_database_tables(self): """ Register database table mappers for this kit. """ # # If another kit of the same name already exists, and has loaded # the database tables, then we don't need to do it a second time # for ki in get_all_kit_installers(): if ki.spec[0] == self.spec[0] and ki.db_tables_loaded: self.__class__.db_tables_loaded = True return kit_pkg_name = inspect.getmodule(self).__package__ db_table_pkg_name = '{}.db.models'.format(kit_pkg_name) logger.debug( 'Searching for database table mappers in package: %s', db_table_pkg_name ) try: importlib.import_module(db_table_pkg_name) self.__class__.db_tables_loaded = True except ModuleNotFoundError: logger.debug( 'No database table mappers found for kit: %s', self.spec )
def __get_uge_kit(self) -> Optional[KitInstallerBase]: """ Return KitInstallerBase for first found UGE kit """ for kit_installer in get_all_kit_installers(): if kit_installer.name == 'uge': return kit_installer return None
def _map_db_tables(self): # # Make sure all kit table mappers have been registered # load_kits() for kit_installer_class in get_all_kit_installers(): kit_installer = kit_installer_class() kit_installer.register_database_table_mappers() # # Map all tables that haven't yet been mapped # for table_mapper in get_all_table_mappers(): key = table_mapper.__name__ if key not in self._mapped_tables.keys(): logger.debug('Mapping table: {}'.format(key)) self._mapped_tables[key] = table_mapper() self._mapped_tables[key].map(self)
def _load_kits(self, base_kit_order='any'): """ Return a list of all KitInstaller objects in the system """ all_kit_installers = get_all_kit_installers() if base_kit_order in ['first', 'last']: base_kit_installer = None for kit in all_kit_installers: if kit.name == 'base': base_kit_installer = kit if base_kit_installer: all_kit_installers.remove(base_kit_installer) if base_kit_order == 'first': all_kit_installers.insert(0, base_kit_installer) else: all_kit_installers.append(base_kit_installer) return all_kit_installers
def start(self): self.bus.log('[{0}] Initializing thread manager'.format( self.__class__.__name__)) # # Ensure that all kit worker actions are loaded # load_kits() for kit_installer_class in get_all_kit_installers(): kit_installer = kit_installer_class() kit_installer.register_web_service_worker_actions() # Create 8 worker threads num_worker_threads = 8 self.bus.log('[{0}] Initializing {1} worker threads'.format( self.__class__.__name__, num_worker_threads)) for thread_id in range(num_worker_threads): t = threading.Thread(target=worker_thread, args=(thread_id, threadManager)) t.setDaemon(True) t.start()
if 'TORTUGA_TEST' in os.environ: app = TestApp(include=[ 'tortuga.events.tasks', 'tortuga.resourceAdapter.tasks', ]) app.app = Application() app.dbm = DbManager() # # In regular mode, we also want to load the kits, and include any tasks # they may have as well. # else: load_kits() kits_task_modules: List[str] = [] for kit_installer_class in get_all_kit_installers(): kit_installer = kit_installer_class() kit_installer.register_event_listeners() kits_task_modules += kit_installer.task_modules config_manager = ConfigManager() redis_password = config_manager.getRedisPassword() app = TortugaCeleryApp( 'tortuga.tasks.queue', broker='redis://:{}@localhost:6379/0'.format(redis_password), backend='redis://:{}@localhost:6379/0'.format(redis_password), include=[ 'tortuga.events.tasks', 'tortuga.resourceAdapter.tasks', ] + kits_task_modules)
def _register_database_tables(self): for kit_installer_class in get_all_kit_installers(): kit_installer = kit_installer_class() kit_installer.register_database_tables()