def test_fail(self): initial_store = TemporalInformationStore.InitialTemporalInformationStore( ) finished_store = TemporalInformationStore.FinishTemporalInformationStore( ) commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) completed_store = TemporalInformationStore.CompletedInformationStore() cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration) fake = FakeTemporalInformationRetriever(cfg_manager, initial_store, finished_store, commands_store, completed_store, None) fake.start() try: initial_time = time.time() while not hasattr(fake, 'failures') or fake.failures < 1: time.sleep(0.01) if time.time() - initial_time > 5: raise AssertionError( "Too long time passed waiting for failures to increase" ) finally: fake.stop() fake.join(1) self.assertFalse(fake.isAlive())
def setUp(self): self.mocker = mocker.Mocker() self.lab_mock = self.mocker.mock() self.locator = FakeLocator(lab=self.lab_mock) self.db = FakeDatabase() self.cfg_manager = ConfigurationManager.ConfigurationManager() self.cfg_manager.append_module(configuration_module) self.cfg_manager._set_value( COORDINATOR_LABORATORY_SERVERS, { 'server:laboratoryserver@labmachine': { 'inst1|ud-dummy|Dummy experiments': 'res_inst@res_type' } }) self.commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) self.coordinator = coordinator_create(SQLALCHEMY, self.locator, self.cfg_manager, ConfirmerClass=FakeConfirmer) self.coordinator._clean() self.coordinator.add_experiment_instance_id( "server:laboratoryserver@labmachine", ExperimentInstanceId('inst', 'ud-dummy', 'Dummy experiments'), Resource("res_type", "res_inst")) self.processor = UserProcessor.UserProcessor( self.locator, {'db_session_id': ValidDatabaseSessionId('my_db_session_id')}, self.cfg_manager, self.coordinator, self.db, self.commands_store)
def setUp(self): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration) self.dbmanager = DatabaseGateway(cfg_manager) self.dbmanager._delete_all_uses() session = self.dbmanager.Session() try: student1 = self.dbmanager._get_user(session, 'student1') finally: session.close() self.initial_store = TemporalInformationStore.InitialTemporalInformationStore( ) self.finished_store = TemporalInformationStore.FinishTemporalInformationStore( ) self.commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) self.completed_store = TemporalInformationStore.CompletedInformationStore( ) self.retriever = TemporalInformationRetriever.TemporalInformationRetriever( cfg_manager, self.initial_store, self.finished_store, self.commands_store, self.completed_store, self.dbmanager) self.retriever.timeout = 0.001 # Be quicker instead of waiting for half a second self.initial_time = self.end_time = datetime.datetime.now() self.initial_timestamp = self.end_timestamp = time.time() request_info = { 'username': '******', 'role': 'student', 'permission_scope': 'user', 'permission_id': student1.id } exp_id = ExperimentId('ud-dummy', 'Dummy Experiments') self.entry1 = TemporalInformationStore.InitialInformationEntry( RESERVATION1, exp_id, coord_addr('ser:inst@mach'), DATA1, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST1) self.entry2 = TemporalInformationStore.InitialInformationEntry( RESERVATION2, exp_id, coord_addr('ser:inst@mach'), DATA2, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST2) self.entry3 = TemporalInformationStore.InitialInformationEntry( RESERVATION3, exp_id, coord_addr('ser:inst@mach'), DATA3, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST3) self.entry4 = TemporalInformationStore.InitialInformationEntry( RESERVATION4, exp_id, coord_addr('ser:inst@mach'), DATA4, self.initial_time, self.end_time, request_info.copy(), DATA_REQUEST3)
def setUp(self): cfg_manager = ConfigurationManager.ConfigurationManager() cfg_manager.append_module(configuration_module) commands_store = TemporalInformationStore.CommandsTemporalInformationStore( ) locator = UserProcessorTest.FakeLocator(None) self.session_mgr = SessionManager.SessionManager( cfg_manager, SessionType.Memory, "foo") coordinator = DummyCoordinator() self.finished_reservations_store = Queue.Queue() self.auc = AliveUsersCollection.AliveUsersCollection( locator, cfg_manager, SessionType.Memory, self.session_mgr, coordinator, commands_store, self.finished_reservations_store) self.tm = TimeModule() self.auc._time_module = self.tm
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: 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 __init__(self, coord_address, locator, cfg_manager, *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._locator = locator if cfg_manager.get_value(WEBLAB_CORE_SERVER_UNIVERSAL_IDENTIFIER, 'default') == 'default' or cfg_manager.get_value(WEBLAB_CORE_SERVER_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' : WEBLAB_CORE_SERVER_UNIVERSAL_IDENTIFIER, 'property_human' : WEBLAB_CORE_SERVER_UNIVERSAL_IDENTIFIER_HUMAN, 'uuid' : generated } print msg print >> sys.stderr, msg log.log( UserProcessingServer, log.level.Error, msg) self.core_server_universal_id = cfg_manager.get_value(WEBLAB_CORE_SERVER_UNIVERSAL_IDENTIFIER, DEFAULT_WEBLAB_CORE_SERVER_UNIVERSAL_IDENTIFIER) self.core_server_universal_id_human = cfg_manager.get_value(WEBLAB_CORE_SERVER_UNIVERSAL_IDENTIFIER_HUMAN, DEFAULT_WEBLAB_CORE_SERVER_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_value(WEBLAB_CORE_SERVER_SESSION_POOL_ID, "UserProcessingServer") 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_value(WEBLAB_CORE_SERVER_COORDINATION_IMPLEMENTATION, SQLALCHEMY) self._coordinator = coordinator_create(coordinator_implementation, self._locator, cfg_manager) # # Database and information storage managers # self._db_manager = DatabaseManager.UserProcessingDatabaseManager(cfg_manager) 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() # # 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) # # Initialize facade (comm) servers # self._server_route = cfg_manager.get_value(UserProcessingFacadeServer.USER_PROCESSING_FACADE_SERVER_ROUTE, UserProcessingFacadeServer.DEFAULT_USER_PROCESSING_SERVER_ROUTE) self._facade_servers = [] for FacadeClass in self.FACADE_SERVERS: facade_server = FacadeClass(self, cfg_manager) self._facade_servers.append(facade_server) facade_server.start() # # Start checking times # self._initialize_checker_timer()