{"action":"created","comment":{"url":"https://api.github.com/repos/youtube/vitess/pulls/comments/22756443","id":22756443,"diff_hunk":"@@ -0,0 +1,72 @@\n+import os\n+import json\n+\n+from flask import Flask\n+app = Flask(__name__)\n+\n+from vtdb import keyrange\n+from vtdb import keyrange_constants\n+from vtdb import vtgatev2\n+from vtdb import vtgate_cursor\n+from vtdb import topology\n+from zk import zkocc\n+\n+# Constants and params\n+UNSHARDED = [keyrange.KeyRange(keyrange_constants.NON_PARTIAL_KEYRANGE)]\n+\n+# conn is the connection to vtgate.\n+conn = None\n+\n+@app.route(\"/\")\n+def index():\n+  return app.send_static_file('index.html')\n+\n+@app.route(\"/lrange/guestbook\")\n+def list_guestbook():\n+  # Read the list from a replica.\n+  cursor = conn.cursor('test_keyspace', 'replica', keyranges=UNSHARDED)\n+\n+  cursor.execute('SELECT * FROM test_table ORDER BY id', {})\n+  entries = [row[1] for row in cursor.fetchall()]\n+  cursor.close()\n+\n+  return json.dumps(entries)\n+\n+@app.route(\"/rpush/guestbook/<value>\")\n+def add_entry(value):\n+  # Insert a row on the master.\n+  cursor = conn.cursor('test_keyspace', 'master', keyranges=UNSHARDED, writable=True)\n+\n+  cursor.begin()\n+  cursor.execute('INSERT INTO test_table (msg) VALUES (%(msg)s)',\n+    {'msg': value})\n+  cursor.commit()\n+\n+  # Read the list back from master (critical read) because it's\n+  # important that the user sees his own addition immediately.\n+  cursor.execute('SELECT * FROM test_table ORDER BY id', {})\n+  entries = [row[1] for row in cursor.fetchall()]\n+  cursor.close()\n+\n+  return json.dumps(entries)\n+\n+@app.route(\"/env\")\n+def env():\n+  return json.dumps(dict(os.environ))\n+\n+if __name__ == \"__main__\":\n+  timeout = 10 # connect timeout in seconds\n+\n+  # Get vtgate service address from Kubernetes environment.\n+  addr = '%s:%s' % (os.environ['VTGATE_SERVICE_HOST'], os.environ['VTGATE_SERVICE_PORT'])\n+\n+  # Read topology from vtgate.\n+  # This is a temporary workaround until the VTGate V2 client is topology-free.","path":"examples/kubernetes/guestbook/main.py","position":64,"original_position":64,"commit_id":"64d0f56e2d0b8c7667b62dbde515766502dbf1d2","original_commit_id":"64d0f56e2d0b8c7667b62dbde515766502dbf1d2","user":{"login":"enisoc","id":6733629,"avatar_url":"https://avatars.githubusercontent.com/u/6733629?v=3","gravatar_id":"","url":"https://api.github.com/users/enisoc","html_url":"https://github.com/enisoc","followers_url":"https://api.github.com/users/enisoc/followers","following_url":"https://api.github.com/users/enisoc/following{/other_user}","gists_url":"https://api.github.com/users/enisoc/gists{/gist_id}","starred_url":"https://api.github.com/users/enisoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enisoc/subscriptions","organizations_url":"https://api.github.com/users/enisoc/orgs","repos_url":"https://api.github.com/users/enisoc/repos","events_url":"https://api.github.com/users/enisoc/events{/privacy}","received_events_url":"https://api.github.com/users/enisoc/received_events","type":"User","site_admin":false},"body":"That sounds nice. I'd love to get rid of the keyranges. I'd prefer putting the schema in through vtctld though if that's possible. I don't want the schema to be burned into the Kubernetes config file.\r\n\r\nThe problem is that I'd like to use the cursor, rather than calling execute on the connection directly. However, the vtgate_cursor is the place where that topology check happens, so I can't get around it even if I use vtgatev3. We'd need to modify VTGateCursor to know not to do the check if it's v3.","created_at":"2015-01-10T04:53:11Z","updated_at":"2015-01-10T04:53:11Z","html_url":"https://github.com/youtube/vitess/pull/306#discussion_r22756443","pull_request_url":"https://api.github.com/repos/youtube/vitess/pulls/306","_links":{"self":{"href":"https://api.github.com/repos/youtube/vitess/pulls/comments/22756443"},"html":{"href":"https://github.com/youtube/vitess/pull/306#discussion_r22756443"},"pull_request":{"href":"https://api.github.com/repos/youtube/vitess/pulls/306"}}},"pull_request":{"url":"https://api.github.com/repos/youtube/vitess/pulls/306","id":27141479,"html_url":"https://github.com/youtube/vitess/pull/306","diff_url":"https://github.com/youtube/vitess/pull/306.diff","patch_url":"https://github.com/youtube/vitess/pull/306.patch","issue_url":"https://api.github.com/repos/youtube/vitess/issues/306","number":306,"state":"open","locked":false,"title":"Port the Kubernetes guestbook example app to Vitess.","user":{"login":"enisoc","id":6733629,"avatar_url":"https://avatars.githubusercontent.com/u/6733629?v=3","gravatar_id":"","url":"https://api.github.com/users/enisoc","html_url":"https://github.com/enisoc","followers_url":"https://api.github.com/users/enisoc/followers","following_url":"https://api.github.com/users/enisoc/following{/other_user}","gists_url":"https://api.github.com/users/enisoc/gists{/gist_id}","starred_url":"https://api.github.com/users/enisoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enisoc/subscriptions","organizations_url":"https://api.github.com/users/enisoc/orgs","repos_url":"https://api.github.com/users/enisoc/repos","events_url":"https://api.github.com/users/enisoc/events{/privacy}","received_events_url":"https://api.github.com/users/enisoc/received_events","type":"User","site_admin":false},"body":"@alainjobart @sougou @shrutip \r\n\r\nFor those who are trying out the example, the end result is now more fun to play with. :)","created_at":"2015-01-10T01:18:45Z","updated_at":"2015-01-10T04:53:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d2a8d0be625ffa8daf07266d2e6660e7e4d9c806","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/youtube/vitess/pulls/306/commits","review_comments_url":"https://api.github.com/repos/youtube/vitess/pulls/306/comments","review_comment_url":"https://api.github.com/repos/youtube/vitess/pulls/comments/{number}","comments_url":"https://api.github.com/repos/youtube/vitess/issues/306/comments","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/64d0f56e2d0b8c7667b62dbde515766502dbf1d2","head":{"label":"youtube:guestbook","ref":"guestbook","sha":"64d0f56e2d0b8c7667b62dbde515766502dbf1d2","user":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"repo":{"id":11008207,"name":"vitess","full_name":"youtube/vitess","owner":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/youtube/vitess","description":"vitess provides servers and tools which facilitate scaling of MySQL databases for large scale web services.","fork":false,"url":"https://api.github.com/repos/youtube/vitess","forks_url":"https://api.github.com/repos/youtube/vitess/forks","keys_url":"https://api.github.com/repos/youtube/vitess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/youtube/vitess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/youtube/vitess/teams","hooks_url":"https://api.github.com/repos/youtube/vitess/hooks","issue_events_url":"https://api.github.com/repos/youtube/vitess/issues/events{/number}","events_url":"https://api.github.com/repos/youtube/vitess/events","assignees_url":"https://api.github.com/repos/youtube/vitess/assignees{/user}","branches_url":"https://api.github.com/repos/youtube/vitess/branches{/branch}","tags_url":"https://api.github.com/repos/youtube/vitess/tags","blobs_url":"https://api.github.com/repos/youtube/vitess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/youtube/vitess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/youtube/vitess/git/refs{/sha}","trees_url":"https://api.github.com/repos/youtube/vitess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/{sha}","languages_url":"https://api.github.com/repos/youtube/vitess/languages","stargazers_url":"https://api.github.com/repos/youtube/vitess/stargazers","contributors_url":"https://api.github.com/repos/youtube/vitess/contributors","subscribers_url":"https://api.github.com/repos/youtube/vitess/subscribers","subscription_url":"https://api.github.com/repos/youtube/vitess/subscription","commits_url":"https://api.github.com/repos/youtube/vitess/commits{/sha}","git_commits_url":"https://api.github.com/repos/youtube/vitess/git/commits{/sha}","comments_url":"https://api.github.com/repos/youtube/vitess/comments{/number}","issue_comment_url":"https://api.github.com/repos/youtube/vitess/issues/comments/{number}","contents_url":"https://api.github.com/repos/youtube/vitess/contents/{+path}","compare_url":"https://api.github.com/repos/youtube/vitess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/youtube/vitess/merges","archive_url":"https://api.github.com/repos/youtube/vitess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/youtube/vitess/downloads","issues_url":"https://api.github.com/repos/youtube/vitess/issues{/number}","pulls_url":"https://api.github.com/repos/youtube/vitess/pulls{/number}","milestones_url":"https://api.github.com/repos/youtube/vitess/milestones{/number}","notifications_url":"https://api.github.com/repos/youtube/vitess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/youtube/vitess/labels{/name}","releases_url":"https://api.github.com/repos/youtube/vitess/releases{/id}","created_at":"2013-06-27T21:20:28Z","updated_at":"2015-01-10T03:31:13Z","pushed_at":"2015-01-10T01:15:16Z","git_url":"git://github.com/youtube/vitess.git","ssh_url":"git@github.com:youtube/vitess.git","clone_url":"https://github.com/youtube/vitess.git","svn_url":"https://github.com/youtube/vitess","homepage":null,"size":56921,"stargazers_count":1973,"watchers_count":1973,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":231,"mirror_url":null,"open_issues_count":10,"forks":231,"open_issues":10,"watchers":1973,"default_branch":"master"}},"base":{"label":"youtube:master","ref":"master","sha":"2227ad5a135d4f11b6d99ab90e7f7ccd143b80e4","user":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"repo":{"id":11008207,"name":"vitess","full_name":"youtube/vitess","owner":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/youtube/vitess","description":"vitess provides servers and tools which facilitate scaling of MySQL databases for large scale web services.","fork":false,"url":"https://api.github.com/repos/youtube/vitess","forks_url":"https://api.github.com/repos/youtube/vitess/forks","keys_url":"https://api.github.com/repos/youtube/vitess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/youtube/vitess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/youtube/vitess/teams","hooks_url":"https://api.github.com/repos/youtube/vitess/hooks","issue_events_url":"https://api.github.com/repos/youtube/vitess/issues/events{/number}","events_url":"https://api.github.com/repos/youtube/vitess/events","assignees_url":"https://api.github.com/repos/youtube/vitess/assignees{/user}","branches_url":"https://api.github.com/repos/youtube/vitess/branches{/branch}","tags_url":"https://api.github.com/repos/youtube/vitess/tags","blobs_url":"https://api.github.com/repos/youtube/vitess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/youtube/vitess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/youtube/vitess/git/refs{/sha}","trees_url":"https://api.github.com/repos/youtube/vitess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/{sha}","languages_url":"https://api.github.com/repos/youtube/vitess/languages","stargazers_url":"https://api.github.com/repos/youtube/vitess/stargazers","contributors_url":"https://api.github.com/repos/youtube/vitess/contributors","subscribers_url":"https://api.github.com/repos/youtube/vitess/subscribers","subscription_url":"https://api.github.com/repos/youtube/vitess/subscription","commits_url":"https://api.github.com/repos/youtube/vitess/commits{/sha}","git_commits_url":"https://api.github.com/repos/youtube/vitess/git/commits{/sha}","comments_url":"https://api.github.com/repos/youtube/vitess/comments{/number}","issue_comment_url":"https://api.github.com/repos/youtube/vitess/issues/comments/{number}","contents_url":"https://api.github.com/repos/youtube/vitess/contents/{+path}","compare_url":"https://api.github.com/repos/youtube/vitess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/youtube/vitess/merges","archive_url":"https://api.github.com/repos/youtube/vitess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/youtube/vitess/downloads","issues_url":"https://api.github.com/repos/youtube/vitess/issues{/number}","pulls_url":"https://api.github.com/repos/youtube/vitess/pulls{/number}","milestones_url":"https://api.github.com/repos/youtube/vitess/milestones{/number}","notifications_url":"https://api.github.com/repos/youtube/vitess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/youtube/vitess/labels{/name}","releases_url":"https://api.github.com/repos/youtube/vitess/releases{/id}","created_at":"2013-06-27T21:20:28Z","updated_at":"2015-01-10T03:31:13Z","pushed_at":"2015-01-10T01:15:16Z","git_url":"git://github.com/youtube/vitess.git","ssh_url":"git@github.com:youtube/vitess.git","clone_url":"https://github.com/youtube/vitess.git","svn_url":"https://github.com/youtube/vitess","homepage":null,"size":56921,"stargazers_count":1973,"watchers_count":1973,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":231,"mirror_url":null,"open_issues_count":10,"forks":231,"open_issues":10,"watchers":1973,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/youtube/vitess/pulls/306"},"html":{"href":"https://github.com/youtube/vitess/pull/306"},"issue":{"href":"https://api.github.com/repos/youtube/vitess/issues/306"},"comments":{"href":"https://api.github.com/repos/youtube/vitess/issues/306/comments"},"review_comments":{"href":"https://api.github.com/repos/youtube/vitess/pulls/306/comments"},"review_comment":{"href":"https://api.github.com/repos/youtube/vitess/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/youtube/vitess/pulls/306/commits"},"statuses":{"href":"https://api.github.com/repos/youtube/vitess/statuses/64d0f56e2d0b8c7667b62dbde515766502dbf1d2"}}}}