def list_expired_reservations(self, expiration_time): expiration_timestamp = time.mktime(expiration_time.timetuple()) + expiration_time.microsecond / 1e6 client = self._redis_maker() # This is not a problem in SQL, since we say "retrieve only those that have expired" # However, I simply don't know how to say that in redis, even using expire or expireat. # The only way I can think of is to check the whole table of reservations. So we have # established a mechanism based on expiration to avoid performing this more than once per # second acquired = client.hset(WEBLAB_RESERVATIONS_LOCK, "locked", 1) if not acquired and not is_testing(): # When testing, we want to avoid that two calls return different results, so # we ignore the mechanism return [] client.expire(WEBLAB_RESERVATIONS_LOCK, 1) # Every second reservation_ids = client.smembers(WEBLAB_RESERVATIONS) pipeline = client.pipeline() for reservation_id in reservation_ids: weblab_reservation_status = WEBLAB_RESERVATION_STATUS % reservation_id pipeline.hget(weblab_reservation_status, LATEST_ACCESS) expired_reservation_ids = [] for reservation_id, latest_access_str in zip(reservation_ids, pipeline.execute()): if latest_access_str is None: continue latest_access = float(latest_access_str) if latest_access is not None and latest_access < expiration_timestamp: expired_reservation_ids.append(reservation_id) return expired_reservation_ids
def __init__(self, application, port, instance): super(InternalFlaskServer, self).__init__(instance) self.application = application self.port = port self.instance = instance if is_testing(): @application.route('/_shutdown') def shutdown_func(): func = request.environ.get('werkzeug.server.shutdown') if func: func() return "Shutting down" else: return "Shutdown not available" self._thread = threading.Thread(target=self.application.run, kwargs={ 'port': self.port, 'debug': False, 'host': '', 'threaded': True }) self._thread.setDaemon(True) self._thread.setName(next_counter('InternalFlaskServer'))
def __init__(self, config, application): the_server_route = config[configuration_doc.CORE_FACADE_SERVER_ROUTE] core_server_url = config[configuration_doc.CORE_SERVER_URL] core_server_url_parsed = urlparse.urlparse(core_server_url) if core_server_url.startswith('http://') or core_server_url.startswith('https://'): the_location = core_server_url_parsed.path else: the_location = '/weblab' class NewWsgiHttpHandler(WrappedWSGIRequestHandler): server_route = the_server_route location = the_location script_name = core_server_url_parsed.path.split('/weblab')[0] timeout = config[configuration_doc.FACADE_TIMEOUT] listen = config[configuration_doc.CORE_FACADE_BIND] port = config[configuration_doc.CORE_FACADE_PORT] self.core_server = None if config.get_value('flask_debug', False): if not is_testing(): print("Using a different server (relying on Flask rather than on Python's WsgiHttpServer)", file=sys.stderr) self.core_server_thread = threading.Thread(target = application.run, kwargs = { 'port' : port, 'debug' : True, 'use_reloader' : False }) else: server_creator = lambda : WsgiHttpServer(script_name, (listen, port), NewWsgiHttpHandler, application, timeout) self.core_server_thread = ServerThread(server_creator, timeout, self)
def __init__(self, config, db): threading.Thread.__init__(self) self.config = config self.db = db self.setDaemon(True) self.stopping = False self.local_country = config[configuration_doc.CORE_LOCAL_COUNTRY] self.local_city = config[configuration_doc.CORE_LOCAL_CITY] geoip2_city_filepath = self.config[ configuration_doc.CORE_GEOIP2_CITY_FILEPATH] if not os.path.exists(geoip2_city_filepath or 'not_found_file'): if not is_testing() and not config[ configuration_doc.CORE_IGNORE_LOCATIONS]: local_directory = os.path.abspath(".") if " " in local_directory: local_directory = '"{0}"'.format(local_directory) print( "{filepath} not found. Run: weblab-admin.py locations {directory} --reset-database --reset-cache" .format(filepath=geoip2_city_filepath, directory=local_directory)) else: if self.local_country is None or self.local_city is None: try: local_public_ip_address = requests.get( "http://ipinfo.io/json").json()['ip'] except Exception as e: local_public_ip_address = None if local_public_ip_address is None: try: local_public_ip_address = requests.get( "https://api.ipify.org/?format=json").json()['ip'] except Exception as e: local_public_ip_address = None if local_public_ip_address is not None: try: reader = GeoIP2Reader(geoip2_city_filepath) if self.local_country is None: self.local_country = reader.city( local_public_ip_address).country.iso_code if self.local_city is None: self.local_city = reader.city( local_public_ip_address).city.name except Exception: print("Error trying to obtain city for IP: {0}".format( local_public_ip_address)) traceback.print_exc() self.locator = AddressLocator(config, local_country=self.local_country, local_city=self.local_city)
def run(self): timeout = 0.2 if is_testing(): timeout = 0.01 while not self.stopped: try: element = self.queue.get(timeout=timeout) except Queue.Empty: continue if element is not None: self._iterate(element)
def __init__(self, coord_address, locator, cfg_manager, *args, **kwargs): super(LogicExperiment, self).__init__(*args, **kwargs) self.circuit_generator = CircuitGenerator() self._cfg_manager = cfg_manager try: self.webcam_url = self._cfg_manager.get_value(CFG_WEBCAM_URL, "") except: self.webcam_url = '' interfaces = [] if not is_testing(): interfaces.append(ConsoleInterface()) if self._cfg_manager.get_value(XILINX_ENABLED, False): interfaces.append(XilinxInterface(cfg_manager)) self.interfaces = HardwareInterfaceCollector(interfaces)
def __init__(self, coord_address, locator, cfg_manager, *args, **kwargs): super(LogicExperiment,self).__init__(*args, **kwargs) self.circuit_generator = CircuitGenerator() self._cfg_manager = cfg_manager try: self.webcam_url = self._cfg_manager.get_value(CFG_WEBCAM_URL, "") except: self.webcam_url = '' interfaces = [] if not is_testing(): interfaces.append(ConsoleInterface()) if self._cfg_manager.get_value(XILINX_ENABLED, False): interfaces.append(XilinxInterface(cfg_manager)) self.interfaces = HardwareInterfaceCollector(interfaces)
def __init__(self, application, port, instance): super(InternalFlaskServer, self).__init__(instance) self.application = application self.port = port self.instance = instance if is_testing(): @application.route('/_shutdown') def shutdown_func(): func = request.environ.get('werkzeug.server.shutdown') if func: func() return "Shutting down" else: return "Shutdown not available" self._thread = threading.Thread(target = self.application.run, kwargs = {'port' : self.port, 'debug' : False, 'host' : '', 'threaded' : True}) self._thread.setDaemon(True) self._thread.setName(next_counter('InternalFlaskServer'))
def __init__(self, config, db): threading.Thread.__init__(self) self.config = config self.db = db self.setDaemon(True) self.stopping = False self.local_country = config[configuration_doc.CORE_LOCAL_COUNTRY] self.local_city = config[configuration_doc.CORE_LOCAL_CITY] geoip2_city_filepath = self.config[configuration_doc.CORE_GEOIP2_CITY_FILEPATH] if not os.path.exists(geoip2_city_filepath or 'not_found_file'): if not is_testing() and not config[configuration_doc.CORE_IGNORE_LOCATIONS]: local_directory = os.path.abspath(".") if " " in local_directory: local_directory = '"{0}"'.format(local_directory) print("{filepath} not found. Run: weblab-admin locations {directory} --reset-database --reset-cache".format(filepath=geoip2_city_filepath, directory=local_directory)) else: if self.local_country is None or self.local_city is None: try: local_public_ip_address = requests.get("http://ipinfo.io/json").json()['ip'] except Exception as e: local_public_ip_address = None if local_public_ip_address is None: try: local_public_ip_address = requests.get("https://api.ipify.org/?format=json").json()['ip'] except Exception as e: local_public_ip_address = None if local_public_ip_address is not None: try: reader = GeoIP2Reader(geoip2_city_filepath) if self.local_country is None: self.local_country = reader.city(local_public_ip_address).country.iso_code if self.local_city is None: self.local_city = reader.city(local_public_ip_address).city.name except Exception: print("Error trying to obtain city for IP: {0}".format(local_public_ip_address)) traceback.print_exc() self.locator = AddressLocator(config, local_country = self.local_country, local_city = self.local_city)
def __init__(self, config, application): the_server_route = config[configuration_doc.CORE_FACADE_SERVER_ROUTE] core_server_url = config[configuration_doc.CORE_SERVER_URL] core_server_url_parsed = urlparse.urlparse(core_server_url) if core_server_url.startswith('http://') or core_server_url.startswith( 'https://'): the_location = core_server_url_parsed.path else: the_location = '/weblab' class NewWsgiHttpHandler(WrappedWSGIRequestHandler): server_route = the_server_route location = the_location script_name = core_server_url_parsed.path.split('/weblab')[0] timeout = config[configuration_doc.FACADE_TIMEOUT] listen = config[configuration_doc.CORE_FACADE_BIND] port = config[configuration_doc.CORE_FACADE_PORT] self.core_server = None if config.get_value('flask_debug', False): if not is_testing(): print( "Using a different server (relying on Flask rather than on Python's WsgiHttpServer)", file=sys.stderr) self.core_server_thread = threading.Thread(target=application.run, kwargs={ 'port': port, 'debug': True, 'use_reloader': False }) else: server_creator = lambda: WsgiHttpServer(script_name, ( listen, port), NewWsgiHttpHandler, application, timeout) self.core_server_thread = ServerThread(server_creator, timeout, self)
def list_expired_reservations(self, expiration_time): expiration_timestamp = time.mktime( expiration_time.timetuple()) + expiration_time.microsecond / 10e6 client = self._redis_maker() # This is not a problem in SQL, since we say "retrieve only those that have expired" # However, I simply don't know how to say that in redis, even using expire or expireat. # The only way I can think of is to check the whole table of reservations. So we have # established a mechanism based on expiration to avoid performing this more than once per # second acquired = client.hset(WEBLAB_RESERVATIONS_LOCK, "locked", 1) if not acquired and not is_testing(): # When testing, we want to avoid that two calls return different results, so # we ignore the mechanism return [] client.expire(WEBLAB_RESERVATIONS_LOCK, 1) # Every second reservation_ids = client.smembers(WEBLAB_RESERVATIONS) pipeline = client.pipeline() for reservation_id in reservation_ids: weblab_reservation_status = WEBLAB_RESERVATION_STATUS % reservation_id pipeline.hget(weblab_reservation_status, LATEST_ACCESS) expired_reservation_ids = [] for reservation_id, latest_access_str in zip(reservation_ids, pipeline.execute()): if latest_access_str is None: continue latest_access = float(latest_access_str) if latest_access is not None and latest_access < expiration_timestamp: expired_reservation_ids.append(reservation_id) return expired_reservation_ids
def stop(self): super(InternalFlaskServer, self).stop() if is_testing(): requests.get('http://127.0.0.1:%s/_shutdown' % self.port) self._thread.join(5)
from __future__ import print_function, unicode_literals import weakref from voodoo.resources_manager import is_testing ########################################### # # By default, it only checks the data # types whenever we are unit testing. # This way, we keep the system documented # and catch the failures while testing, # but it has no performance impact in # production. # CHECKING = __debug__ and is_testing() ANY = object() NONE = type(None) ITERATION_TYPE = object() LIST_TYPE = object() TUPLE_TYPE = object() def LIST(list_type): """Check that it is a list of elements of type list_type""" return (LIST_TYPE, list_type) def TUPLE(tuple_type): """Check that it is a tuple of elements of type tuple_type""" return (TUPLE_TYPE, tuple_type)
def __init__(self, server, cfg_manager): core_server_url = cfg_manager.get_value( 'core_server_url', '' ) self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or '' self.app = Flask('weblab.core.wl') self.app.config['SECRET_KEY'] = os.urandom(32) self.app.config['APPLICATION_ROOT'] = self.script_name self.app.config['SESSION_COOKIE_PATH'] = self.script_name + '/weblab/' self.app.config['SESSION_COOKIE_NAME'] = 'weblabsession' # Initialize internationalization code. initialize_i18n(self.app) # Mostly for debugging purposes, this snippet will print the site-map so that we can check # which methods we are routing. @self.app.route("/site-map") def site_map(): lines = [] for rule in self.app.url_map.iter_rules(): line = str(escape(repr(rule))) lines.append(line) ret = "<br>".join(lines) return ret flask_debug = cfg_manager.get_value('flask_debug', False) core_facade_port = cfg_manager.get_value(configuration_doc.CORE_FACADE_PORT, 'unknown') if flask_debug and not is_testing(): print("*" * 50, file=sys.stderr) print("WARNING " * 5, file=sys.stderr) print("flask_debug is set to True. This is an important security leak. Do not use it in production, only for bugfixing!!!", file=sys.stderr) print("If you want to see the debug toolbar in Flask pages, also use http://localhost:{0}/weblab/".format(core_facade_port), file=sys.stderr) print("WARNING " * 5, file=sys.stderr) print("*" * 50, file=sys.stderr) self.app.config['DEBUG'] = flask_debug if os.path.exists('logs'): f = os.path.join('logs','admin_app.log') else: f = 'admin_app.log' file_handler = RotatingFileHandler(f, maxBytes = 50 * 1024 * 1024) file_handler.setLevel(logging.WARNING) self.app.logger.addHandler(file_handler) super(WebLabFlaskServer, self).__init__(cfg_manager, self.app) json_api = Blueprint('json', __name__) weblab_api.apply_routes_api(json_api, server) self.app.register_blueprint(json_api, url_prefix = '/weblab/json') self.app.register_blueprint(json_api, url_prefix = '/weblab/login/json') authn_web = Blueprint('login_web', __name__) weblab_api.apply_routes_login_web(authn_web, server) self.app.register_blueprint(authn_web, url_prefix = '/weblab/login/web') static_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static')) core_web = Blueprint('core_web', __name__, static_folder=static_folder) weblab_api.apply_routes_web(core_web, server) self.app.register_blueprint(core_web, url_prefix = '/weblab/web') # Register the blueprint for the new (year 2015) flask-based web client. # The .apply_routes_webclient method is dynamically generated, the name matches # that in the wl.py module. # Attempt at setting the right static folder. core_webclient = Blueprint('core_webclient', __name__, static_folder=static_folder) weblab_api.apply_routes_webclient(core_webclient, server) self.app.register_blueprint(core_webclient, url_prefix = '/weblab/web/webclient') @self.app.context_processor def inject_weblab_api(): return dict(weblab_api=weblab_api) self.admin_app = AdministrationApplication(self.app, cfg_manager, server) if flask_debug: from flask_debugtoolbar import DebugToolbarExtension toolbar = DebugToolbarExtension() toolbar.init_app(self.app) self.app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False self.app.config['DEBUG_TB_PROFILER_ENABLED'] = True
def __init__(self, coord_address, locator, cfg_manager, dont_start = False, *args, **kwargs): super(UserProcessingServer,self).__init__(*args, **kwargs) log.log( UserProcessingServer, log.level.Info, "Starting Core Server...") self._stopping = False self._cfg_manager = cfg_manager self.config = cfg_manager self._locator = locator self.core_server_url = cfg_manager.get_doc_value(configuration_doc.CORE_SERVER_URL) if cfg_manager.get_value(configuration_doc.CORE_UNIVERSAL_IDENTIFIER, 'default') == 'default' or cfg_manager.get_value(configuration_doc.CORE_UNIVERSAL_IDENTIFIER_HUMAN, 'default') == 'default': generated = uuid.uuid1() msg = "Property %(property)s or %(property_human)s not configured. Please establish: %(property)s = '%(uuid)s' and %(property_human)s = 'server at university X'. Otherwise, when federating the experiment it could enter in an endless loop." % { 'property' : configuration_doc.CORE_UNIVERSAL_IDENTIFIER, 'property_human' : configuration_doc.CORE_UNIVERSAL_IDENTIFIER_HUMAN, 'uuid' : generated } print(msg) print(msg, file = sys.stderr) log.log( UserProcessingServer, log.level.Error, msg) self.core_server_universal_id = cfg_manager.get_doc_value(configuration_doc.CORE_UNIVERSAL_IDENTIFIER) self.core_server_universal_id_human = cfg_manager.get_doc_value(configuration_doc.CORE_UNIVERSAL_IDENTIFIER_HUMAN) # # Create session managers # session_type_str = cfg_manager.get_doc_value(configuration_doc.WEBLAB_CORE_SERVER_SESSION_TYPE) if not hasattr(SessionType, session_type_str): raise coreExc.NotASessionTypeError( 'Not a session type: %s' % session_type_str ) session_type = getattr(SessionType, session_type_str) session_pool_id = cfg_manager.get_doc_value(configuration_doc.WEBLAB_CORE_SERVER_SESSION_POOL_ID) self._session_manager = SessionManager.SessionManager( cfg_manager, session_type, session_pool_id ) reservations_session_pool_id = cfg_manager.get_value(WEBLAB_CORE_SERVER_RESERVATIONS_SESSION_POOL_ID, "CoreServerReservations") self._reservations_session_manager = SessionManager.SessionManager( cfg_manager, session_type, reservations_session_pool_id ) # # Coordination # coordinator_implementation = cfg_manager.get_doc_value(configuration_doc.COORDINATOR_IMPL) self._coordinator = coordinator_create(coordinator_implementation, self._locator, cfg_manager) # # Database and information storage managers # self._db_manager = DatabaseGateway(cfg_manager) self.db = self._db_manager cfg_manager.client = DbConfig(self.db.client_configuration) cfg_manager.server = DbConfig(self.db.server_configuration) self._commands_store = TemporalInformationStore.CommandsTemporalInformationStore() self._temporal_information_retriever = TemporalInformationRetriever.TemporalInformationRetriever(cfg_manager, self._coordinator.initial_store, self._coordinator.finished_store, self._commands_store, self._coordinator.completed_store, self._db_manager) self._temporal_information_retriever.start() clean = cfg_manager.get('core_number') == 0 if clean: if not is_testing(): print("Starting core server... %s" % time.asctime()) sys.stdout.flush() print("Starting core server... %s" % time.asctime(), file=sys.stderr) sys.stderr.flush() self._location_retriever = LocationRetriever(cfg_manager, self._db_manager) self._location_retriever.start() else: self._location_retriever = None # # Alive users # self._alive_users_collection = AliveUsersCollection.AliveUsersCollection( self._locator, self._cfg_manager, session_type, self._reservations_session_manager, self._coordinator, self._commands_store, self._coordinator.finished_reservations_store) # Login Manager self._login_manager = LoginManager(self._db_manager, self) # # Initialize facade (comm) servers # self._server_route = cfg_manager.get_doc_value(configuration_doc.CORE_FACADE_SERVER_ROUTE) self.flask_server = WebLabFlaskServer(self, cfg_manager) self.babel = self.flask_server.babel self.dont_start = cfg_manager.get_value('dont_start', dont_start) if not self.dont_start: self.flask_server.start() self.app = self.flask_server.app # # Start checking times # checking_time = self._cfg_manager.get_value(CHECKING_TIME_NAME, DEFAULT_CHECKING_TIME) timer = threading.Timer(checking_time, self._renew_checker_timer) timer.setName(counter.next_name("ups-checker-timer")) timer.setDaemon(True) timer.start() _resource_manager.add_resource(timer)
def wait_and_turn_off(self): if is_testing(): pass else: time.sleep(7) self.interfaces.turn_off()
log.log(ResourcesCheckerThread, log.level.Critical, "Exception checking resources: %s" % e) log.log_exc(ResourcesCheckerThread, log.level.Error) checker_thread = None def reset(): global checker_thread checker_thread = ResourcesCheckerThread() checker_thread.setDaemon(True) checker_thread.start() def clean(): global checker_thread if checker_thread is not None: checker_thread.stopping = True checker_thread = None if not is_testing(): reset() def set_coordinator(coordinator, new_frequency): if checker_thread is not None: checker_thread.frequency = new_frequency checker_thread.coordinator = weakref.ref(coordinator)
def test_is_testing(self): # We are testing self.assertTrue(RM.is_testing())
from __future__ import print_function, unicode_literals import weakref from voodoo.resources_manager import is_testing ########################################### # # By default, it only checks the data # types whenever we are unit testing. # This way, we keep the system documented # and catch the failures while testing, # but it has no performance impact in # production. # CHECKING = __debug__ and is_testing() ANY = object() NONE = type(None) ITERATION_TYPE = object() LIST_TYPE = object() TUPLE_TYPE = object() def LIST(list_type): """Check that it is a list of elements of type list_type""" return (LIST_TYPE, list_type) def TUPLE(tuple_type):
def __init__(self, server, cfg_manager): core_server_url = cfg_manager.get_value( 'core_server_url', '' ) self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or '' self.app = Flask('weblab.core.wl') self.app.wsgi_app = ProxyFix(self.app.wsgi_app) self.app.config['SECRET_KEY'] = os.urandom(32) self.app.config['APPLICATION_ROOT'] = self.script_name self.app.config['SESSION_COOKIE_PATH'] = self.script_name + '/weblab/' self.app.config['SESSION_COOKIE_NAME'] = 'weblabsession' # Initialize internationalization code. self.babel = initialize_i18n(self.app) # Mostly for debugging purposes, this snippet will print the site-map so that we can check # which methods we are routing. @self.app.route("/site-map") def site_map(): lines = [] for rule in self.app.url_map.iter_rules(): line = str(escape(repr(rule))) lines.append(line) ret = "<br>".join(lines) return ret flask_debug = cfg_manager.get_value('flask_debug', False) core_facade_port = cfg_manager.get_value(configuration_doc.CORE_FACADE_PORT, 'unknown') if flask_debug and not is_testing(): print("*" * 50, file=sys.stderr) print("WARNING " * 5, file=sys.stderr) print("flask_debug is set to True. This is an important security leak. Do not use it in production, only for bugfixing!!!", file=sys.stderr) print("If you want to see the debug toolbar in Flask pages, also use http://localhost:{0}/weblab/".format(core_facade_port), file=sys.stderr) print("WARNING " * 5, file=sys.stderr) print("*" * 50, file=sys.stderr) self.app.config['DEBUG'] = flask_debug if os.path.exists('logs'): f = os.path.join('logs','admin_app.log') else: f = 'admin_app.log' file_handler = RotatingFileHandler(f, maxBytes = 50 * 1024 * 1024) file_handler.setLevel(logging.WARNING) self.app.logger.addHandler(file_handler) super(WebLabFlaskServer, self).__init__(cfg_manager, self.app) json_api = Blueprint('json', __name__) weblab_api.apply_routes_api(json_api, server) self.app.register_blueprint(json_api, url_prefix = '/weblab/json') self.app.register_blueprint(json_api, url_prefix = '/weblab/login/json') authn_web = Blueprint('login_web', __name__) weblab_api.apply_routes_login_web(authn_web, server) self.app.register_blueprint(authn_web, url_prefix = '/weblab/login/web') static_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static')) core_web = Blueprint('core_web', __name__, static_folder=static_folder) weblab_api.apply_routes_web(core_web, server) self.app.register_blueprint(core_web, url_prefix = '/weblab/web') # Register the blueprint for the new (year 2015) flask-based web client. # The .apply_routes_webclient method is dynamically generated, the name matches # that in the wl.py module. # Attempt at setting the right static folder. core_webclient = Blueprint('core_webclient', __name__, static_folder=static_folder) weblab_api.apply_routes_webclient(core_webclient, server) self.app.register_blueprint(core_webclient, url_prefix = '/weblab') @self.app.context_processor def inject_weblab_api(): return dict(weblab_api=weblab_api, display_date=display_date, get_locale=get_locale, wl_config=cfg_manager) self.admin_app = AdministrationApplication(self.app, cfg_manager, server) if flask_debug: from flask_debugtoolbar import DebugToolbarExtension toolbar = DebugToolbarExtension() toolbar.init_app(self.app) self.app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
def __init__(self, coord_address, locator, cfg_manager, dont_start=False, *args, **kwargs): super(UserProcessingServer, self).__init__(*args, **kwargs) log.log(UserProcessingServer, log.level.Info, "Starting Core Server...") self._stopping = False self._cfg_manager = cfg_manager self.config = cfg_manager self._locator = locator self.core_server_url = cfg_manager.get_doc_value( configuration_doc.CORE_SERVER_URL) if cfg_manager.get_value( configuration_doc.CORE_UNIVERSAL_IDENTIFIER, 'default') == 'default' or cfg_manager.get_value( configuration_doc.CORE_UNIVERSAL_IDENTIFIER_HUMAN, 'default') == 'default': generated = uuid.uuid1() msg = "Property %(property)s or %(property_human)s not configured. Please establish: %(property)s = '%(uuid)s' and %(property_human)s = 'server at university X'. Otherwise, when federating the experiment it could enter in an endless loop." % { 'property': configuration_doc.CORE_UNIVERSAL_IDENTIFIER, 'property_human': configuration_doc.CORE_UNIVERSAL_IDENTIFIER_HUMAN, 'uuid': generated } print(msg) print(msg, file=sys.stderr) log.log(UserProcessingServer, log.level.Error, msg) self.core_server_universal_id = cfg_manager.get_doc_value( configuration_doc.CORE_UNIVERSAL_IDENTIFIER) self.core_server_universal_id_human = cfg_manager.get_doc_value( configuration_doc.CORE_UNIVERSAL_IDENTIFIER_HUMAN) # # Create session managers # session_type_str = cfg_manager.get_doc_value( configuration_doc.WEBLAB_CORE_SERVER_SESSION_TYPE) if not hasattr(SessionType, session_type_str): raise coreExc.NotASessionTypeError('Not a session type: %s' % session_type_str) session_type = getattr(SessionType, session_type_str) session_pool_id = cfg_manager.get_doc_value( configuration_doc.WEBLAB_CORE_SERVER_SESSION_POOL_ID) self._session_manager = SessionManager.SessionManager( cfg_manager, session_type, session_pool_id) reservations_session_pool_id = cfg_manager.get_value( WEBLAB_CORE_SERVER_RESERVATIONS_SESSION_POOL_ID, "CoreServerReservations") self._reservations_session_manager = SessionManager.SessionManager( cfg_manager, session_type, reservations_session_pool_id) # # Coordination # coordinator_implementation = cfg_manager.get_doc_value( configuration_doc.COORDINATOR_IMPL) self._coordinator = coordinator_create(coordinator_implementation, self._locator, cfg_manager) # # Database and information storage managers # self._db_manager = DatabaseGateway(cfg_manager) self.db = self._db_manager cfg_manager.client = DbConfig(self.db.client_configuration) cfg_manager.server = DbConfig(self.db.server_configuration) self._commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) self._temporal_information_retriever = TemporalInformationRetriever.TemporalInformationRetriever( cfg_manager, self._coordinator.initial_store, self._coordinator.finished_store, self._commands_store, self._coordinator.completed_store, self._db_manager) self._temporal_information_retriever.start() clean = cfg_manager.get('core_number') == 0 if clean: if not is_testing(): print("Starting core server... %s" % time.asctime()) sys.stdout.flush() print("Starting core server... %s" % time.asctime(), file=sys.stderr) sys.stderr.flush() # self._location_retriever = LocationRetriever(cfg_manager, self._db_manager) # self._location_retriever.start() self._location_retriever = None else: self._location_retriever = None # # Alive users # self._alive_users_collection = AliveUsersCollection.AliveUsersCollection( self._locator, self._cfg_manager, session_type, self._reservations_session_manager, self._coordinator, self._commands_store, self._coordinator.finished_reservations_store) # Login Manager self._login_manager = LoginManager(self._db_manager, self) # # Initialize facade (comm) servers # self._server_route = cfg_manager.get_doc_value( configuration_doc.CORE_FACADE_SERVER_ROUTE) self.flask_server = WebLabFlaskServer(self, cfg_manager) self.babel = self.flask_server.babel self.dont_start = cfg_manager.get_value('dont_start', dont_start) if not self.dont_start: self.flask_server.start() self.app = self.flask_server.app # # Start checking times # checking_time = self._cfg_manager.get_value(CHECKING_TIME_NAME, DEFAULT_CHECKING_TIME) timer = threading.Timer(checking_time, self._renew_checker_timer) timer.setName(counter.next_name("ups-checker-timer")) timer.setDaemon(True) timer.start() _resource_manager.add_resource(timer)
continue # coordinator not configured yet checker = self.Checker(coordinator) checker.check() except Exception as e: log.log(ResourcesCheckerThread, log.level.Critical, "Exception checking resources: %s" % e ) log.log_exc(ResourcesCheckerThread, log.level.Error) checker_thread = None def reset(): global checker_thread checker_thread = ResourcesCheckerThread() checker_thread.setDaemon(True) checker_thread.start() def clean(): global checker_thread if checker_thread is not None: checker_thread.stopping = True checker_thread = None if not is_testing(): reset() def set_coordinator(coordinator, new_frequency): if checker_thread is not None: checker_thread.frequency = new_frequency checker_thread.coordinator = weakref.ref(coordinator)