def startup(args: argparse.Namespace, **kwargs: Dict[str, Any]) -> None: global announce, dispatcher, group, httpServer, notification, validator global registration, remote, security, statistics, storage, event global rootDirectory global aeStatistics rootDirectory = os.getcwd() # get the root directory os.environ[ "FLASK_ENV"] = "development" # get rid if the warning message from flask. # Hopefully it is clear at this point that this is not a production CSE # Handle command line arguments and load the configuration if args is None: args = argparse.Namespace( ) # In case args is None create a new args object and populate it args.configfile = None args.resetdb = False args.loglevel = None for key, value in kwargs.items(): args.__setattr__(key, value) if not Configuration.init(args): return # init Logging Logging.init() Logging.log('============') Logging.log('Starting CSE') Logging.log('CSE-Type: %s' % C.cseTypes[Configuration.get('cse.type')]) Logging.log(Configuration.print()) # Initiatlize the resource storage storage = Storage() # Initialize the event manager event = EventManager() # Initialize the statistics system statistics = Statistics() # Initialize the registration manager registration = RegistrationManager() # Initialize the resource validator validator = Validator() # Initialize the resource dispatcher dispatcher = Dispatcher() # Initialize the security manager security = SecurityManager() # Initialize the HTTP server httpServer = HttpServer() # Initialize the notification manager notification = NotificationManager() # Initialize the announcement manager announce = AnnouncementManager() # Initialize the group manager group = GroupManager() # Import a default set of resources, e.g. the CSE, first ACP or resource structure importer = Importer() if not importer.importResources(): return # Initialize the remote CSE manager remote = RemoteCSEManager() remote.start() # Start AEs startAppsDelayed( ) # the Apps are actually started after the CSE finished the startup # Start the HTTP server event.cseStartup() # type: ignore Logging.log('CSE started') httpServer.run() # This does NOT return
def startup(args: argparse.Namespace, **kwargs: Dict[str, Any]) -> None: global announce, dispatcher, group, httpServer, notification, validator global registration, remote, request, security, statistics, storage, event global rootDirectory global aeStatistics global supportedReleaseVersions, cseType, defaultSerialization, cseCsi, cseRi, cseRn global cseOriginator global isHeadless rootDirectory = os.getcwd() # get the root directory os.environ[ "FLASK_ENV"] = "development" # get rid if the warning message from flask. # Hopefully it is clear at this point that this is not a production CSE # Handle command line arguments and load the configuration if args is None: args = argparse.Namespace( ) # In case args is None create a new args object and populate it args.configfile = None args.resetdb = False args.loglevel = None args.headless = False for key, value in kwargs.items(): args.__setattr__(key, value) isHeadless = args.headless if not Configuration.init(args): return # Initialize configurable constants supportedReleaseVersions = Configuration.get( 'cse.supportedReleaseVersions') cseType = Configuration.get('cse.type') cseCsi = Configuration.get('cse.csi') cseRi = Configuration.get('cse.ri') cseRn = Configuration.get('cse.rn') cseOriginator = Configuration.get('cse.originator') defaultSerialization = Configuration.get('cse.defaultSerialization') # init Logging Logging.init() if not args.headless: Logging.console('Press ? for help') Logging.log('============') Logging.log('Starting CSE') Logging.log(f'CSE-Type: {cseType.name}') Logging.log('Configuration:') Logging.log(Configuration.print()) # Initiatlize the resource storage storage = Storage() # Initialize the event manager event = EventManager() # Initialize the statistics system statistics = Statistics() # Initialize the registration manager registration = RegistrationManager() # Initialize the resource validator validator = Validator() # Initialize the resource dispatcher dispatcher = Dispatcher() # Initialize the request manager request = RequestManager() # Initialize the security manager security = SecurityManager() # Initialize the HTTP server httpServer = HttpServer() # Initialize the notification manager notification = NotificationManager() # Initialize the group manager group = GroupManager() # Import a default set of resources, e.g. the CSE, first ACP or resource structure # Import extra attribute policies for specializations first importer = Importer() if not importer.importAttributePolicies() or not importer.importResources( ): return # Initialize the remote CSE manager remote = RemoteCSEManager() # Initialize the announcement manager announce = AnnouncementManager() # Start AEs startAppsDelayed( ) # the Apps are actually started after the CSE finished the startup # Start the HTTP server event.cseStartup() # type: ignore httpServer.run() # This does return (!) Logging.log('CSE started') if isHeadless: # when in headless mode give the CSE a moment (2s) to experience fatal errors before printing the start message BackgroundWorkerPool.newActor( delay=2, workerCallback=lambda: Logging.console('CSE started') if not shuttingDown else None).start() # # Enter an endless loop. # Execute keyboard commands in the keyboardHandler's loop() function. # commands = { '?': _keyHelp, 'h': _keyHelp, '\n': lambda c: print(), # 1 empty line '\x03': _keyShutdownCSE, # See handler below 'c': _keyConfiguration, 'C': _keyClearScreen, 'D': _keyDeleteResource, 'i': _keyInspectResource, 'l': _keyToggleLogging, 'Q': _keyShutdownCSE, # See handler below 'r': _keyCSERegistrations, 's': _keyStatistics, 't': _keyResourceTree, 'T': _keyChildResourceTree, 'w': _keyWorkers, } # Endless runtime loop. This handles key input & commands # The CSE's shutdown happens in one of the key handlers below loop(commands, catchKeyboardInterrupt=True, headless=args.headless) shutdown()