{"action":"created","comment":{"url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/comments/73583411","id":73583411,"diff_hunk":"@@ -118,5 +150,143 @@ def take_lock(self, *args, **kwargs):\n                 _LOG.error('Failed to obtain lock for exhibitor, retrying', exc_info=e)\n \n \n-def load_exhibitor(initial_hosts: list, zookeeper_prefix):\n-    return Exhibitor(initial_hosts, 8181, zookeeper_prefix)\n+class BukuExhibitor(object):\n+    def __init__(self, exhibitor: _Exhibitor, async=True):\n+        self.exhibitor = exhibitor\n+        self.async = async\n+        try:\n+            self.exhibitor.create('/bubuku/changes', makepath=True)\n+        except NodeExistsError:\n+            pass\n+\n+    def is_broker_registered(self, broker_id):\n+        try:\n+            _, stat = self.exhibitor.get('/brokers/ids/{}'.format(broker_id))\n+            return stat is not None\n+        except NoNodeError:\n+            return False\n+\n+    def get_broker_ids(self) -> list:\n+        \"\"\"\n+        Gets list of available broker ids\n+        :return: Sorted list of strings - active broker ids.\n+        \"\"\"\n+        return sorted(self.exhibitor.get_children('/brokers/ids'))\n+\n+    def load_partition_assignment(self) -> list:\n+        \"\"\"\n+        Lists all the assignments of partitions to particular broker ids.\n+        :returns generator of tuples (topic_name:str, partition:int, replica_list:list(int)), for ex. \"test\", 0, [1,2,3]\n+        \"\"\"\n+        if self.async:\n+            results = [(topic, self.exhibitor.get_async('/brokers/topics/{}'.format(topic))) for topic in\n+                       self.exhibitor.get_children('/brokers/topics')]\n+            for topic, cb in results:\n+                try:\n+                    value, stat = cb.get(block=True)\n+                except ConnectionLossException:\n+                    value, stat = self.exhibitor.get('/brokers/topics/{}'.format(topic))\n+                data = json.loads(value.decode('utf-8'))\n+                for k, v in data['partitions'].items():\n+                    yield (topic, int(k), v)\n+\n+        else:\n+            for topic in self.exhibitor.get_children('/brokers/topics'):\n+                data = json.loads(self.exhibitor.get('/brokers/topics/{}'.format(topic))[0].decode('utf-8'))\n+                for k, v in data['partitions'].items():\n+                    yield (topic, int(k), v)\n+\n+    def load_partition_states(self) -> list:\n+        \"\"\"\n+        Lists all the current partition states (leaders and isr list)\n+        :return: generator of tuples\n+        (topic_name: str, partition: int, state: json from /brokers/topics/{}/partitions/{}/state)\n+        \"\"\"\n+        if self.async:\n+            asyncs = []\n+            for topic, partition, _ in self.load_partition_assignment():\n+                asyncs.append((topic, partition, self.exhibitor.get_async(\n+                    '/brokers/topics/{}/partitions/{}/state'.format(topic, partition))))\n+            for topic, partition, async in asyncs:\n+                try:\n+                    value, stat = async.get(block=True)\n+                except ConnectionLossException:\n+                    value, stat = self.exhibitor.get('/brokers/topics/{}/partitions/{}/state'.format(topic, partition))\n+                yield (topic, int(partition), json.loads(value.decode('utf-8')))\n+        else:\n+            for topic in self.exhibitor.get_children('/brokers/topics'):\n+                for partition in self.exhibitor.get_children('/brokers/topics/{}/partitions'.format(topic)):\n+                    state = json.loads(self.exhibitor.get('/brokers/topics/{}/partitions/{}/state'.format(\n+                        topic, partition))[0].decode('utf-8'))\n+                    yield (topic, int(partition), state)\n+\n+    def reallocate_partition(self, topic: str, partition: object, replicas: list) -> bool:\n+        \"\"\"\n+        Reallocates partition to replica list\n+        :param topic: topic to move\n+        :param partition: partition to move (can be str or int)\n+        :param replicas: list of replicas to move to\n+        :return: If reallocation was successful (node for reallocation was created)\n+        \"\"\"\n+        j = {\n+            \"version\": \"1\",\n+            \"partitions\": [\n+                {\n+                    \"topic\": topic,\n+                    \"partition\": int(partition),\n+                    \"replicas\": [int(p) for p in replicas],\n+                }\n+            ]\n+        }\n+        try:\n+            data = json.dumps(j)\n+            self.exhibitor.create(\"/admin/reassign_partitions\", data.encode('utf-8'))\n+            _LOG.info(\"Reallocating {}\".format(data))\n+            return True\n+        except NodeExistsError:\n+            _LOG.info(\"Waiting for free reallocation slot, still in progress...\")\n+        return False\n+\n+    def update_disk_stats(self, broker_id: str, data: dict):\n+        data_bytes = json.dumps(data, sort_keys=True).encode('utf-8')","path":"bubuku/zookeeper.py","position":190,"original_position":190,"commit_id":"9aa2b0ad28f6fff091124e15b7e73c63296883fd","original_commit_id":"9aa2b0ad28f6fff091124e15b7e73c63296883fd","user":{"login":"v-stepanov","id":13309177,"avatar_url":"https://avatars.githubusercontent.com/u/13309177?v=3","gravatar_id":"","url":"https://api.github.com/users/v-stepanov","html_url":"https://github.com/v-stepanov","followers_url":"https://api.github.com/users/v-stepanov/followers","following_url":"https://api.github.com/users/v-stepanov/following{/other_user}","gists_url":"https://api.github.com/users/v-stepanov/gists{/gist_id}","starred_url":"https://api.github.com/users/v-stepanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/v-stepanov/subscriptions","organizations_url":"https://api.github.com/users/v-stepanov/orgs","repos_url":"https://api.github.com/users/v-stepanov/repos","events_url":"https://api.github.com/users/v-stepanov/events{/privacy}","received_events_url":"https://api.github.com/users/v-stepanov/received_events","type":"User","site_admin":false},"body":"I think you lost `separators=(',', ':')`. It actually saves some space.","created_at":"2016-08-04T19:03:52Z","updated_at":"2016-08-04T19:03:52Z","html_url":"https://github.com/zalando-incubator/bubuku/pull/28#discussion_r73583411","pull_request_url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28","_links":{"self":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/comments/73583411"},"html":{"href":"https://github.com/zalando-incubator/bubuku/pull/28#discussion_r73583411"},"pull_request":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28"}}},"pull_request":{"url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28","id":80105046,"html_url":"https://github.com/zalando-incubator/bubuku/pull/28","diff_url":"https://github.com/zalando-incubator/bubuku/pull/28.diff","patch_url":"https://github.com/zalando-incubator/bubuku/pull/28.patch","issue_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues/28","number":28,"state":"open","locked":false,"title":"Use get_async for bulk operations on zookeeper","user":{"login":"antban","id":2656223,"avatar_url":"https://avatars.githubusercontent.com/u/2656223?v=3","gravatar_id":"","url":"https://api.github.com/users/antban","html_url":"https://github.com/antban","followers_url":"https://api.github.com/users/antban/followers","following_url":"https://api.github.com/users/antban/following{/other_user}","gists_url":"https://api.github.com/users/antban/gists{/gist_id}","starred_url":"https://api.github.com/users/antban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antban/subscriptions","organizations_url":"https://api.github.com/users/antban/orgs","repos_url":"https://api.github.com/users/antban/repos","events_url":"https://api.github.com/users/antban/events{/privacy}","received_events_url":"https://api.github.com/users/antban/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-04T16:02:47Z","updated_at":"2016-08-04T19:03:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c7dbd57a916972b28f529c813d919589d46959db","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28/commits","review_comments_url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28/comments","review_comment_url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues/28/comments","statuses_url":"https://api.github.com/repos/zalando-incubator/bubuku/statuses/9aa2b0ad28f6fff091124e15b7e73c63296883fd","head":{"label":"zalando-incubator:I25","ref":"I25","sha":"9aa2b0ad28f6fff091124e15b7e73c63296883fd","user":{"login":"zalando-incubator","id":18533786,"avatar_url":"https://avatars.githubusercontent.com/u/18533786?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-incubator","html_url":"https://github.com/zalando-incubator","followers_url":"https://api.github.com/users/zalando-incubator/followers","following_url":"https://api.github.com/users/zalando-incubator/following{/other_user}","gists_url":"https://api.github.com/users/zalando-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-incubator/subscriptions","organizations_url":"https://api.github.com/users/zalando-incubator/orgs","repos_url":"https://api.github.com/users/zalando-incubator/repos","events_url":"https://api.github.com/users/zalando-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-incubator/received_events","type":"Organization","site_admin":false},"repo":{"id":64120851,"name":"bubuku","full_name":"zalando-incubator/bubuku","owner":{"login":"zalando-incubator","id":18533786,"avatar_url":"https://avatars.githubusercontent.com/u/18533786?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-incubator","html_url":"https://github.com/zalando-incubator","followers_url":"https://api.github.com/users/zalando-incubator/followers","following_url":"https://api.github.com/users/zalando-incubator/following{/other_user}","gists_url":"https://api.github.com/users/zalando-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-incubator/subscriptions","organizations_url":"https://api.github.com/users/zalando-incubator/orgs","repos_url":"https://api.github.com/users/zalando-incubator/repos","events_url":"https://api.github.com/users/zalando-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-incubator/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando-incubator/bubuku","description":null,"fork":false,"url":"https://api.github.com/repos/zalando-incubator/bubuku","forks_url":"https://api.github.com/repos/zalando-incubator/bubuku/forks","keys_url":"https://api.github.com/repos/zalando-incubator/bubuku/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando-incubator/bubuku/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando-incubator/bubuku/teams","hooks_url":"https://api.github.com/repos/zalando-incubator/bubuku/hooks","issue_events_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues/events{/number}","events_url":"https://api.github.com/repos/zalando-incubator/bubuku/events","assignees_url":"https://api.github.com/repos/zalando-incubator/bubuku/assignees{/user}","branches_url":"https://api.github.com/repos/zalando-incubator/bubuku/branches{/branch}","tags_url":"https://api.github.com/repos/zalando-incubator/bubuku/tags","blobs_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando-incubator/bubuku/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando-incubator/bubuku/languages","stargazers_url":"https://api.github.com/repos/zalando-incubator/bubuku/stargazers","contributors_url":"https://api.github.com/repos/zalando-incubator/bubuku/contributors","subscribers_url":"https://api.github.com/repos/zalando-incubator/bubuku/subscribers","subscription_url":"https://api.github.com/repos/zalando-incubator/bubuku/subscription","commits_url":"https://api.github.com/repos/zalando-incubator/bubuku/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando-incubator/bubuku/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando-incubator/bubuku/contents/{+path}","compare_url":"https://api.github.com/repos/zalando-incubator/bubuku/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando-incubator/bubuku/merges","archive_url":"https://api.github.com/repos/zalando-incubator/bubuku/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando-incubator/bubuku/downloads","issues_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues{/number}","pulls_url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando-incubator/bubuku/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando-incubator/bubuku/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando-incubator/bubuku/labels{/name}","releases_url":"https://api.github.com/repos/zalando-incubator/bubuku/releases{/id}","deployments_url":"https://api.github.com/repos/zalando-incubator/bubuku/deployments","created_at":"2016-07-25T09:18:17Z","updated_at":"2016-08-04T08:54:19Z","pushed_at":"2016-08-04T16:02:47Z","git_url":"git://github.com/zalando-incubator/bubuku.git","ssh_url":"git@github.com:zalando-incubator/bubuku.git","clone_url":"https://github.com/zalando-incubator/bubuku.git","svn_url":"https://github.com/zalando-incubator/bubuku","homepage":null,"size":131,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":1,"default_branch":"master"}},"base":{"label":"zalando-incubator:master","ref":"master","sha":"643f69eba03427983ef092eb9ad7f44e45204fc7","user":{"login":"zalando-incubator","id":18533786,"avatar_url":"https://avatars.githubusercontent.com/u/18533786?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-incubator","html_url":"https://github.com/zalando-incubator","followers_url":"https://api.github.com/users/zalando-incubator/followers","following_url":"https://api.github.com/users/zalando-incubator/following{/other_user}","gists_url":"https://api.github.com/users/zalando-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-incubator/subscriptions","organizations_url":"https://api.github.com/users/zalando-incubator/orgs","repos_url":"https://api.github.com/users/zalando-incubator/repos","events_url":"https://api.github.com/users/zalando-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-incubator/received_events","type":"Organization","site_admin":false},"repo":{"id":64120851,"name":"bubuku","full_name":"zalando-incubator/bubuku","owner":{"login":"zalando-incubator","id":18533786,"avatar_url":"https://avatars.githubusercontent.com/u/18533786?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando-incubator","html_url":"https://github.com/zalando-incubator","followers_url":"https://api.github.com/users/zalando-incubator/followers","following_url":"https://api.github.com/users/zalando-incubator/following{/other_user}","gists_url":"https://api.github.com/users/zalando-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando-incubator/subscriptions","organizations_url":"https://api.github.com/users/zalando-incubator/orgs","repos_url":"https://api.github.com/users/zalando-incubator/repos","events_url":"https://api.github.com/users/zalando-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/zalando-incubator/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando-incubator/bubuku","description":null,"fork":false,"url":"https://api.github.com/repos/zalando-incubator/bubuku","forks_url":"https://api.github.com/repos/zalando-incubator/bubuku/forks","keys_url":"https://api.github.com/repos/zalando-incubator/bubuku/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando-incubator/bubuku/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando-incubator/bubuku/teams","hooks_url":"https://api.github.com/repos/zalando-incubator/bubuku/hooks","issue_events_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues/events{/number}","events_url":"https://api.github.com/repos/zalando-incubator/bubuku/events","assignees_url":"https://api.github.com/repos/zalando-incubator/bubuku/assignees{/user}","branches_url":"https://api.github.com/repos/zalando-incubator/bubuku/branches{/branch}","tags_url":"https://api.github.com/repos/zalando-incubator/bubuku/tags","blobs_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando-incubator/bubuku/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando-incubator/bubuku/languages","stargazers_url":"https://api.github.com/repos/zalando-incubator/bubuku/stargazers","contributors_url":"https://api.github.com/repos/zalando-incubator/bubuku/contributors","subscribers_url":"https://api.github.com/repos/zalando-incubator/bubuku/subscribers","subscription_url":"https://api.github.com/repos/zalando-incubator/bubuku/subscription","commits_url":"https://api.github.com/repos/zalando-incubator/bubuku/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando-incubator/bubuku/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando-incubator/bubuku/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando-incubator/bubuku/contents/{+path}","compare_url":"https://api.github.com/repos/zalando-incubator/bubuku/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando-incubator/bubuku/merges","archive_url":"https://api.github.com/repos/zalando-incubator/bubuku/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando-incubator/bubuku/downloads","issues_url":"https://api.github.com/repos/zalando-incubator/bubuku/issues{/number}","pulls_url":"https://api.github.com/repos/zalando-incubator/bubuku/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando-incubator/bubuku/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando-incubator/bubuku/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando-incubator/bubuku/labels{/name}","releases_url":"https://api.github.com/repos/zalando-incubator/bubuku/releases{/id}","deployments_url":"https://api.github.com/repos/zalando-incubator/bubuku/deployments","created_at":"2016-07-25T09:18:17Z","updated_at":"2016-08-04T08:54:19Z","pushed_at":"2016-08-04T16:02:47Z","git_url":"git://github.com/zalando-incubator/bubuku.git","ssh_url":"git@github.com:zalando-incubator/bubuku.git","clone_url":"https://github.com/zalando-incubator/bubuku.git","svn_url":"https://github.com/zalando-incubator/bubuku","homepage":null,"size":131,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28"},"html":{"href":"https://github.com/zalando-incubator/bubuku/pull/28"},"issue":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/issues/28"},"comments":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/issues/28/comments"},"review_comments":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28/comments"},"review_comment":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/pulls/28/commits"},"statuses":{"href":"https://api.github.com/repos/zalando-incubator/bubuku/statuses/9aa2b0ad28f6fff091124e15b7e73c63296883fd"}}}}
{"actor":{"display_login":"v-stepanov"}}