コード例 #1
0
ファイル: repository.py プロジェクト: tx626/dpm
 def __init__(self, addr, port):
     RPCServer.__init__(self, addr, port)
     len_up = len(UPLOAD_SERVERS)
     len_repo = len(REPOSITORY_SERVERS)
     if len_up < len_repo or len_up % len_repo != 0:
         show_error(self, 'failed to initialize')
         raise Exception('failed to initialize')
     addr = localhost()
     if addr not in REPOSITORY_SERVERS:
         show_error(self, 'failed to initialize')
         raise Exception('failed to initialize REPOSITORY_SERVERS')
     for i in range(len(REPOSITORY_SERVERS)):
         if addr == REPOSITORY_SERVERS[i]:
             break
     total = len_up / len_repo
     self._upload_servers = UPLOAD_SERVERS[i * total:(i + 1) * total]
     self._print('upload_servers=%s' % str(self._upload_servers))
     if HDFS:
         self._port = HDFS_PORT
         self._client = HDFSClient()
     else:
         self._port = FTP_PORT
         self._client = FTPClient()
         self._server = FTPServer()
     if REPO_DB:
         self._db = Database(addr=REPO_DB)
     else:
         self._db = Database(addr=addr)
     locks = []
     for _ in range(LOCK_MAX):
         locks.append(Lock())
     self._locks = HashRing(locks)
     if DEBUG:
         self._upload_cnt = 0
         self._download_cnt = 0