Exemplo n.º 1
0
    def configure(self, config):
        def get_option(config, section, key):
            if not config.has_option(section, key):
                return None
            value = config.get(section, key)
            if value.isdigit():
                value = int(value)
            return value

        self.config = os.path.abspath(config)
        # now read the server config, we need some properties from it
        with open(self.config) as fp:
            dummy_section_name = "tarantool"
            config = ConfigParser.ConfigParser()
            config.readfp(TarantoolConfigFile(fp, dummy_section_name))

            self.pidfile = get_option(config, dummy_section_name, "pid_file")
            self.primary_port = get_option(config, dummy_section_name,
                                           "primary_port")
            self.admin_port = get_option(config, dummy_section_name,
                                         "admin_port")
            self.memcached_port = get_option(config, dummy_section_name,
                                             "memcached_port")

        self.port = self.admin_port
        self.admin = AdminConnection("localhost", self.admin_port)
        self.sql = BoxConnection("localhost", self.primary_port)
        if self.memcached_port != 0:
            # Run memcached client
            self.memcached = MemcachedConnection('localhost',
                                                 self.memcached_port)
Exemplo n.º 2
0
 def _sql(self, port):
     try:
         port = int(port)
     except ValueError as e:
         raise ValueError("Bad port number: '%s'" % port)
     if hasattr(self, 'sql'):
         del self.sql
     self.sql = BoxConnection('localhost', port)
Exemplo n.º 3
0
 def _iproto(self, port):
     try:
         port = int(port)
     except ValueError as e:
         raise ValueError("Bad port number: '%s'" % port)
     if hasattr(self, 'iproto'):
         del self.iproto
     self.iproto = BoxConnection('localhost', port)
Exemplo n.º 4
0
con1("active_connections")
con2 = AdminConnection('localhost', server.admin_port)
con2("active_connections")
con1.disconnect()
con2.disconnect()
admin("type(box.session.on_connect(nil))")
admin("type(box.session.on_disconnect(nil))")

# write audit trail of connect/disconnect into a space
admin("box.session.on_connect(function() box.insert(0, box.session.id()) end)")
admin("box.session.on_disconnect(function() box.delete(0, box.session.id()) end)")
con1("box.unpack('i', box.select(0, 0, box.session.id())[0]) == box.session.id()")
con1.disconnect()

# if on_connect() trigger raises an exception, the connection is dropped
admin("type(box.session.on_connect(function() nosuchfunction() end))")
con1 = BoxConnection('localhost', server.primary_port)
try:
    con1.execute("select * from t0 where k0=0")
    con1.execute("select * from t0 where k0=0")
except Exception as e:
    print "disconnected"

# cleanup

admin("type(box.session.on_connect(nil))")
admin("type(box.session.on_disconnect(nil))")
admin("active_connections")

# vim: syntax=python
Exemplo n.º 5
0
 def _iproto(self, port):
     if hasattr(self, 'iproto'):
         del self.iproto
     self.iproto = BoxConnection('localhost', port)