Esempio n. 1
0
    def on_dir(directory, configuration_files, configuration_values):
        parser = argparse.ArgumentParser(usage='%(prog)s locations DIR [options]')
        parser.add_argument('--redownload', action='store_true', help='Force redownload of databases')
        parser.add_argument('--reset-database', action='store_true', help='Reset the database, forcing the server to download all the data again')
        parser.add_argument('--reset-cache', action='store_true', help='Reset the database, forcing the server to download all the data again')
        args = parser.parse_args(sys.argv[3:])

        config = ConfigurationManager.create(directory, configuration_files, configuration_values)

        for filename in 'GeoLite2-Country.mmdb', 'GeoLite2-City.mmdb':
            if os.path.exists(filename):
                print("Found %s" % filename)
                if args.redownload:
                    print("Redownloading...")
            else:
                print("%s not found. Downloading..." % filename)

            if args.redownload or not os.path.exists(filename):
                r = requests.get("http://geolite.maxmind.com/download/geoip/database/%s.gz" % filename)
                open('%s.gz' % filename,'wb').write(r.content)
                uncompressed = gzip.open('%s.gz' % filename).read()
                open(filename, 'wb').write(uncompressed)
                print("Downloaded")

        db = DatabaseGateway(config)

        if args.reset_database:
            print("Resetting database")
            db.reset_locations_database()

        if args.reset_cache:
            print("Resetting cache")
            db.reset_locations_cache()
    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)
Esempio n. 3
0
    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)