コード例 #1
0
        def _call():
            result = self._route_call(
                None, self._link, async.get_retid(), Auth.get_current_idendesc(), dst, func_name, timeout, list(args)
            )

            if callback != None:
                callback(result)
コード例 #2
0
    def write_lock(self,lockname):
        def _send(link):
            def __cb(result):
                nonlocal count

                stat,ret = result
                if stat == False and ret == 'Enoexist':
                    self.client_linkmap.pop(link,None)

                count -= 1
                if count == 0:
                    async.ret(retid)

            self._proxy.call_async(link + 'lockclient/',
                                   'sync_write_lock',
                                   3600000,
                                   __cb,
                                   lockname)
        
        with Auth.change_current_iden(self._idendesc):
            links = list(self.client_linkmap)
            count = len(links)
            retid = async.get_retid()
            for link in links:
                _send(link)

        async.switch_top()
コード例 #3
0
        def _call():
            result = self._route_call(None, self._link, async .get_retid(),
                                      Auth.get_current_idendesc(), dst,
                                      func_name, timeout, list(args))

            if callback != None:
                callback(result)
コード例 #4
0
    def sendfile(self, dst_link, filepath):
        def _callback(err):
            if self._ret_sendfile(filekey, err) and err != None:
                with Auth.change_current_iden(self._idendesc, self._auth):
                    self.call(dst_link + "imc/", "abort_sendfile", 65536, filekey, err)

        filekey = SHA512.new(uuid.uuid1().bytes + ssl.RAND_bytes(64)).hexdigest()
        filesize = os.stat(filepath).st_size

        fileresult = FileResult(filekey)

        self._info_filekeymap[filekey] = {
            "filesize": filesize,
            "filepath": filepath,
            "fileresult": fileresult,
            "timer": self._ioloop.add_timeout(
                datetime.timedelta(days=1), lambda: self._ret_sendfile(filekey, "Etimeout")
            ),
            "callback": tornado.stack_context.wrap(_callback),
        }

        with Auth.change_current_iden(self._idendesc, self._auth):
            stat, ret = self.call(dst_link + "imc/", "pend_recvfile", 65536, self._link, filekey, filesize)

        if stat == False:
            self._ret_sendfile(filekey, "Enoexist")

        return fileresult
コード例 #5
0
 def _client_call(self, client, func, *args, timeout=10000):
     client += 'blobclient/'
     with Auth.change_current_iden(self._idendesc):
         sta, ret = self._proxy.call(client, func, timeout, *args)
     if not sta:
         self.disconnect_client(client)
     return (sta, ret)
コード例 #6
0
 def _client_call(self, client, func, *args, timeout=10000):
     client += 'blobclient/'
     with Auth.change_current_iden(self._idendesc):
         sta, ret = self._proxy.call(client, func, timeout, *args)
     if not sta:
         self.disconnect_client(client)
     return (sta, ret)
コード例 #7
0
 def connect_server(self, serverlink=None):
     if serverlink:
         self._server = serverlink
     server = self._server + 'blobserver/'
     with Auth.change_current_iden(self._idendesc):
         sta, ret = self._proxy.call(server, 'connect_client', 10000,
                                     self._link)
     self._is_connected = sta
     if self._is_connected:
         # TODO:
         pass
コード例 #8
0
 def connect_server(self, serverlink=None):
     if serverlink:
         self._server = serverlink
     server = self._server + 'blobserver/'
     with Auth.change_current_iden(self._idendesc):
         sta, ret = self._proxy.call(server, 'connect_client', 10000,
                                     self._link)
     self._is_connected = sta
     if self._is_connected:
         # TODO:
         pass
コード例 #9
0
    def _server_call(self, func, *args):
        if not self._is_connected:
            if not self.connect_server():
                pass

        server = self._server + 'blobserver/'
        with Auth.change_current_iden(self._idendesc):
            sta, ret = self._proxy.call(server, func, 10000, self._link, *args)
        if not sta:
            self._is_connected = False
        return (sta, ret)
コード例 #10
0
 def _server_call(self, func, *args):
     if not self._is_connected:
         if not self.connect_server():
             pass
         
     server = self._server + 'blobserver/'
     with Auth.change_current_iden(self._idendesc):
         sta, ret = self._proxy.call(server, func, 10000,
                                     self._link, *args)
     if not sta:
         self._is_connected = False
     return (sta, ret)
コード例 #11
0
    def write_unlock(self, lockname):
        def _cb(result):
            stat, ret = result
            if stat == False and ret == 'Enoexist':
                self.client_linkmap.pop(link, None)

        with Auth.change_current_iden(self._idendesc):
            links = list(self.client_linkmap)
            for link in links:
                self._proxy.call_async(link + 'lockclient/',
                                       'sync_write_unlock', 10000, _cb,
                                       lockname)
コード例 #12
0
    def write_unlock(self,lockname):
        def _cb(result):
            stat,ret = result
            if stat == False and ret == 'Enoexist':
                self.client_linkmap.pop(link,None)

        with Auth.change_current_iden(self._idendesc):
            links = list(self.client_linkmap)
            for link in links:
                self._proxy.call_async(link + 'lockclient/',
                                       'sync_write_unlock',
                                       10000,
                                       _cb,
                                       lockname)
コード例 #13
0
    def __init__(self, proxy, idendesc, serverlink):
        self.RWLOCK_READ = 1
        self.RWLOCK_WRITE = 2

        self._proxy = proxy
        self._idendesc = idendesc
        self._callpath = serverlink + 'lockserver/'

        self.rwlock_namemap = {}

        self._proxy.register_call('lockclient/', 'sync_write_lock',
                                  self.sync_write_lock)
        self._proxy.register_call('lockclient/', 'sync_write_unlock',
                                  self.sync_write_unlock)

        with Auth.change_current_iden(self._idendesc):
            self._proxy.instance.call(self._callpath, 'connect_client', 10000)

        LockClient.instance = self
コード例 #14
0
    def __init__(self,proxy,idendesc,serverlink):
        self.RWLOCK_READ = 1
        self.RWLOCK_WRITE = 2

        self._proxy = proxy
        self._idendesc = idendesc
        self._callpath = serverlink + 'lockserver/'

        self.rwlock_namemap = {}

        self._proxy.register_call('lockclient/','sync_write_lock',
                                  self.sync_write_lock)
        self._proxy.register_call('lockclient/','sync_write_unlock',
                                  self.sync_write_unlock)

        with Auth.change_current_iden(self._idendesc):
            self._proxy.instance.call(self._callpath,'connect_client',10000)

        LockClient.instance = self
コード例 #15
0
    def sendfile(self, dst_link, filepath):
        def _callback(err):
            if self._ret_sendfile(filekey, err) and err != None:
                with Auth.change_current_iden(self._idendesc, self._auth):
                    self.call(dst_link + 'imc/', 'abort_sendfile', 65536,
                              filekey, err)

        filekey = SHA512.new(uuid.uuid1().bytes +
                             ssl.RAND_bytes(64)).hexdigest()
        filesize = os.stat(filepath).st_size

        fileresult = FileResult(filekey)

        self._info_filekeymap[filekey] = {
            'filesize':
            filesize,
            'filepath':
            filepath,
            'fileresult':
            fileresult,
            'timer':
            self._ioloop.add_timeout(
                datetime.timedelta(days=1),
                lambda: self._ret_sendfile(filekey, 'Etimeout')),
            'callback':
            tornado.stack_context.wrap(_callback)
        }

        with Auth.change_current_iden(self._idendesc, self._auth):
            stat, ret = self.call(dst_link + 'imc/', 'pend_recvfile', 65536,
                                  self._link, filekey, filesize)

        if stat == False:
            self._ret_sendfile(filekey, 'Enoexist')

        return fileresult
コード例 #16
0
    def write_lock(self, lockname):
        def _send(link):
            def __cb(result):
                nonlocal count

                stat, ret = result
                if stat == False and ret == 'Enoexist':
                    self.client_linkmap.pop(link, None)

                count -= 1
                if count == 0:
                    async .ret(retid)

            self._proxy.call_async(link + 'lockclient/', 'sync_write_lock',
                                   3600000, __cb, lockname)

        with Auth.change_current_iden(self._idendesc):
            links = list(self.client_linkmap)
            count = len(links)
            retid = async .get_retid()
            for link in links:
                _send(link)

        async .switch_top()
コード例 #17
0
 def _client_call_async(self, client, func, callback, *args, timeout=10000):
     client += 'blobclient/'
     with Auth.change_current_iden(self._idendesc):
         self._proxy.call_async(client, func, timeout, callback, *args)
コード例 #18
0
 def write_unlock(self,lockname):
     with Auth.change_current_iden(self._idendesc):
         self._proxy.instance.call(self._callpath,'write_unlock',10000,
                                   lockname)
コード例 #19
0
 def call(self, dst, func_name, timeout, *args):
     return self._route_call(None, self._link, async .get_retid(),
                             Auth.get_current_idendesc(), dst, func_name,
                             timeout, list(args))
コード例 #20
0
 def __abort_cb(err):
     if self._ret_sendfile(filekey, err):
         with Auth.change_current_iden(self._idendesc, self._auth):
             self.call(src_link + "imc/", "abort_sendfile", 65536, filekey, err)
コード例 #21
0
 def _callback(err):
     if self._ret_sendfile(filekey, err) and err != None:
         with Auth.change_current_iden(self._idendesc, self._auth):
             self.call(dst_link + 'imc/', 'abort_sendfile', 65536,
                       filekey, err)
コード例 #22
0
 def _callback(err):
     if self._ret_sendfile(filekey, err) and err != None:
         with Auth.change_current_iden(self._idendesc, self._auth):
             self.call(dst_link + "imc/", "abort_sendfile", 65536, filekey, err)
コード例 #23
0
    def _route_call(self, in_conn, caller_link, caller_retid, idendesc, dst, func_name, timeout, param):
        def __add_wait_caller(conn_link):
            self._conn_retidmap[conn_link][caller_retid] = {
                "timer": self._ioloop.add_timeout(
                    datetime.timedelta(milliseconds=timeout),
                    lambda: self._ret_call(caller_link, caller_retid, (False, "Etimeout")),
                ),
                "caller_link": caller_link,
                "caller_retid": caller_retid,
            }

        def __del_wait_caller(conn_link):
            wait = self._conn_retidmap[conn_link].pop(caller_retid)
            self._ioloop.remove_timeout(wait["timer"])

        def __ret(result):
            if caller_link == self._link:
                return result

            else:
                conn = self._request_conn(caller_link)
                if conn != None:
                    self._send_msg_ret(conn, caller_link, caller_retid, result)

        if in_conn != None:
            in_link = in_conn.link

        else:
            in_link = self._link

        iden = self._auth.verify_iden(in_link, idendesc)
        if iden == None:
            return __ret((False, "Eilliden"))

        try:
            dst_part = dst.split("/")
            dst_link = "".join(["/", dst_part[1], "/", dst_part[2], "/"])
            dst_path = dst_part[3:-1]

        except Exception:
            return __ret((False, "Enoexist"))

        if dst_link == self._link:
            __add_wait_caller(self._link)

            try:
                with Auth.change_current_iden(None, self._auth):
                    dpart = deque(dst_path)
                    child, name, filt = self._callpath_root
                    for func in filt:
                        func(dpart, func_name)

                    for part in dst_path:
                        child, name, filt = child[part]

                        dpart.popleft()
                        for func in filt:
                            func(dpart, func_name)

                    func = name[func_name]

            except KeyError:
                return __ret((False, "Enoexist"))

            except Exception:
                return __ret((False, "Einternal"))

            if Auth.get_current_idendesc() == idendesc:
                result = func(*param)

            else:
                with Auth.change_current_iden(idendesc, self._auth):
                    result = func(*param)

            __del_wait_caller(self._link)

            return __ret(result)

        else:
            conn = self._request_conn(dst_link)
            if conn == None:
                return __ret((False, "Enoexist"))

            else:
                if caller_link == self._link:
                    __add_wait_caller(conn.link)

                    self._send_msg_call(conn, caller_link, caller_retid, idendesc, dst, func_name, timeout, param)

                    result = async.switch_top()

                    __del_wait_caller(conn.link)

                    return __ret(result)

                else:
                    self._send_msg_call(conn, caller_link, caller_retid, idendesc, dst, func_name, timeout, param)

                    return
コード例 #24
0
 def __abort_cb(err):
     if self._ret_sendfile(filekey, err):
         with Auth.change_current_iden(self._idendesc, self._auth):
             self.call(src_link + 'imc/', 'abort_sendfile', 65536,
                       filekey, err)
コード例 #25
0
    def _route_call(self, in_conn, caller_link, caller_retid, idendesc, dst,
                    func_name, timeout, param):
        def __add_wait_caller(conn_link):
            self._conn_retidmap[conn_link][caller_retid] = {
                'timer':
                self._ioloop.add_timeout(
                    datetime.timedelta(milliseconds=timeout),
                    lambda: self._ret_call(caller_link, caller_retid,
                                           (False, 'Etimeout'))),
                'caller_link':
                caller_link,
                'caller_retid':
                caller_retid
            }

        def __del_wait_caller(conn_link):
            wait = self._conn_retidmap[conn_link].pop(caller_retid)
            self._ioloop.remove_timeout(wait['timer'])

        def __ret(result):
            if caller_link == self._link:
                return result

            else:
                conn = self._request_conn(caller_link)
                if conn != None:
                    self._send_msg_ret(conn, caller_link, caller_retid, result)

        if in_conn != None:
            in_link = in_conn.link

        else:
            in_link = self._link

        iden = self._auth.verify_iden(in_link, idendesc)
        if iden == None:
            return __ret((False, 'Eilliden'))

        try:
            dst_part = dst.split('/')
            dst_link = ''.join(['/', dst_part[1], '/', dst_part[2], '/'])
            dst_path = dst_part[3:-1]

        except Exception:
            return __ret((False, 'Enoexist'))

        if dst_link == self._link:
            __add_wait_caller(self._link)

            try:
                with Auth.change_current_iden(None, self._auth):
                    dpart = deque(dst_path)
                    child, name, filt = self._callpath_root
                    for func in filt:
                        func(dpart, func_name)

                    for part in dst_path:
                        child, name, filt = child[part]

                        dpart.popleft()
                        for func in filt:
                            func(dpart, func_name)

                    func = name[func_name]

            except KeyError:
                return __ret((False, 'Enoexist'))

            except Exception:
                return __ret((False, 'Einternal'))

            if Auth.get_current_idendesc() == idendesc:
                result = func(*param)

            else:
                with Auth.change_current_iden(idendesc, self._auth):
                    result = func(*param)

            __del_wait_caller(self._link)

            return __ret(result)

        else:
            conn = self._request_conn(dst_link)
            if conn == None:
                return __ret((False, 'Enoexist'))

            else:
                if caller_link == self._link:
                    __add_wait_caller(conn.link)

                    self._send_msg_call(conn, caller_link, caller_retid,
                                        idendesc, dst, func_name, timeout,
                                        param)

                    result = async .switch_top()

                    __del_wait_caller(conn.link)

                    return __ret(result)

                else:
                    self._send_msg_call(conn, caller_link, caller_retid,
                                        idendesc, dst, func_name, timeout,
                                        param)

                    return
コード例 #26
0
 def call(self, dst, func_name, timeout, *args):
     return self._route_call(
         None, self._link, async.get_retid(), Auth.get_current_idendesc(), dst, func_name, timeout, list(args)
     )
コード例 #27
0
 def write_unlock(self, lockname):
     with Auth.change_current_iden(self._idendesc):
         self._proxy.instance.call(self._callpath, 'write_unlock', 10000,
                                   lockname)
コード例 #28
0
 def connect_client(self):
     link = Auth.get_current_iden()['link']
     self.client_linkmap.add(link)
コード例 #29
0
 def connect_client(self):
     link = Auth.get_current_iden()['link']
     self.client_linkmap.add(link) 
コード例 #30
0
 def _client_call_async(self, client, func, callback, 
                        *args, timeout=10000):
     client += 'blobclient/'
     with Auth.change_current_iden(self._idendesc):
         self._proxy.call_async(client, func, timeout, callback, *args)