{"action":"created","comment":{"url":"https://api.github.com/repos/VoltDB/deployment/pulls/comments/45224411","id":45224411,"diff_hunk":"@@ -0,0 +1,671 @@\n+# This file is part of VoltDB.\n+\n+# Copyright (C) 2008-2015 VoltDB Inc.\n+#\n+# This file contains original code and/or modifications of original code.\n+# Any modifications made by VoltDB Inc. are licensed under the following\n+# terms and conditions:\n+#\n+# Permission is hereby granted, free of charge, to any person obtaining\n+# a copy of this software and associated documentation files (the\n+# \"Software\"), to deal in the Software without restriction, including\n+# without limitation the rights to use, copy, modify, merge, publish,\n+# distribute, sublicense, and/or sell copies of the Software, and to\n+# permit persons to whom the Software is furnished to do so, subject to\n+# the following conditions:\n+#\n+# The above copyright notice and this permission notice shall be\n+# included in all copies or substantial portions of the Software.\n+\n+# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n+# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n+# OTHER DEALINGS IN THE SOFTWARE.\n+\n+\n+from flask import Flask, render_template, jsonify, abort, make_response, request\n+from flask.views import MethodView\n+\n+import socket\n+\n+app = Flask(__name__, template_folder =\"../templates\", static_folder=\"../static\")\n+\n+\n+servers = []\n+\n+\n+\n+@app.errorhandler(400)\n+def not_found(error):\n+    return make_response(jsonify( { 'error': 'Bad request' } ), 400)\n+\n+@app.errorhandler(404)\n+def not_found(error):\n+    return make_response(jsonify({'error': 'Not found'}), 404)\n+\n+@app.route(\"/\")\n+def index():\n+    return render_template(\"index.html\")\n+\n+def make_public_server(servers):\n+    new_server = {}\n+    for field in servers:\n+        new_server[field] = servers[field]\n+    return new_server\n+\n+isCurrentNodeAdded = False\n+\n+class ServerAPI(MethodView):\n+\n+    def get(self, server_id):\n+        global isCurrentNodeAdded\n+        myhostname = socket.gethostname()\n+        myhostorip = socket.gethostbyname(myhostname)\n+\n+        if server_id is None:\n+\n+            if not servers and isCurrentNodeAdded==False:\n+                #add default server\n+                isCurrentNodeAdded = True\n+                servers.append(\n+                    {\n+                        'id': 1,\n+                        'name': myhostname,\n+                        'hostname': myhostorip,\n+                        'description': \"\",\n+                        'enabled': True,\n+                        'external-interface': \"\",\n+                        'internal-interface': \"\",\n+                        'public-interface':\"\",\n+                        \"client-listener\":\"\",\n+                        \"internal-listener\":\"\",\n+                        \"admin-listener\":\"\",\n+                        \"http-listener\":\"\",\n+                        \"replication-listener\":\"\",\n+                        \"zookeeper-listener\":\"\",\n+                        \"placement-group\":\"\"\n+                    }\n+                    )\n+\n+            # return a list of users\n+            return jsonify( { 'servers': map(make_public_server, servers) } )\n+        else:\n+            # expose a single user\n+            server = filter(lambda t: t['id'] == server_id, servers)\n+            if len(server) == 0:\n+                abort(404)\n+            return jsonify( { 'server': make_public_server(server[0]) } )\n+\n+    def post(self):\n+        if not request.json or not 'name' in request.json or not 'hostname' in request.json:\n+            abort(400)\n+\n+        if request.json['name']==\"\":\n+            return make_response(jsonify({'error':'Server name is required'}),404)\n+\n+        if request.json['hostname']==\"\":\n+            return make_response(jsonify({'error':'Host name is required'}),404)\n+\n+        server = filter(lambda t: t['name'] == request.json['name'], servers)\n+        if len(server)!=0:\n+            return make_response(jsonify({'error': 'Server name already exists'}), 404)\n+\n+        server = filter(lambda t: t['hostname'] == request.json['hostname'], servers)\n+        if len(server)!=0:\n+            return make_response(jsonify({'error': 'Host name already exists'}), 404)\n+\n+        if 'admin-listener' in request.json:\n+            if(request.json['admin-listener']!=\"\"):\n+                if(\":\" in request.json['admin-listener']):\n+                    count =  request.json['admin-listener'].count(\":\")\n+                    if(count>1):\n+                       return make_response(jsonify({'error': 'Invalid admin listener'}), 404)\n+                    #validate both ip as well as port\n+                    array =  request.json['admin-listener'].split(\":\")\n+                    try:\n+                        socket.inet_aton(array[0])\n+                    # legal\n+                    except socket.error:\n+                        return make_response(jsonify({'error': 'Invalid IP address'}), 404)\n+\n+                    #validate port only\n+                    try:\n+                        val = int(array[1])\n+                        if val<0:\n+                            return make_response(jsonify({'error': 'Admin Listener must be a positive number'}), 404)\n+                        elif val<1 or val>=65535:\n+                            return make_response(jsonify({'error': 'Admin Listener must be greater than 1 and less than 65535'}), 404)\n+                    except ValueError:\n+                        return make_response(jsonify({'error': 'Admin Listener must be a positive number'}), 404)\n+\n+                else:\n+                    try:\n+                        val = int(request.json['admin-listener'])\n+                        if val<0:\n+                            return make_response(jsonify({'error': 'Admin Listener must be a positive number'}), 404)\n+                        elif val<1 or val>65536:\n+                            return make_response(jsonify({'error': 'Admin Listener must be greater than 1 and less than 65535'}), 404)\n+                    except ValueError:\n+                        return make_response(jsonify({'error': 'Admin Listener must be a positive number'}), 404)\n+\n+        if 'internal-listener' in request.json:\n+            if(request.json['internal-listener']!=\"\"):\n+                if(\":\" in request.json['internal-listener']):\n+                    count =  request.json['internal-listener'].count(\":\")\n+                    if(count>1):\n+                       return make_response(jsonify({'error': 'Invalid internal listener'}), 404)","path":"vdm/server/HTTPListener.py","position":159,"original_position":159,"commit_id":"4536bed23ee5d5adbde4387619273bfe187d845d","original_commit_id":"4536bed23ee5d5adbde4387619273bfe187d845d","user":{"login":"vtkstef","id":662716,"avatar_url":"https://avatars.githubusercontent.com/u/662716?v=3","gravatar_id":"","url":"https://api.github.com/users/vtkstef","html_url":"https://github.com/vtkstef","followers_url":"https://api.github.com/users/vtkstef/followers","following_url":"https://api.github.com/users/vtkstef/following{/other_user}","gists_url":"https://api.github.com/users/vtkstef/gists{/gist_id}","starred_url":"https://api.github.com/users/vtkstef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtkstef/subscriptions","organizations_url":"https://api.github.com/users/vtkstef/orgs","repos_url":"https://api.github.com/users/vtkstef/repos","events_url":"https://api.github.com/users/vtkstef/events{/privacy}","received_events_url":"https://api.github.com/users/vtkstef/received_events","type":"User","site_admin":false},"body":"generally I see a lot of repeated code that could be made cleaner by implementing simple validating and checking methods: string checking , numeric value checking, and so on","created_at":"2015-11-18T16:43:57Z","updated_at":"2015-11-18T16:43:57Z","html_url":"https://github.com/VoltDB/deployment/pull/2#discussion_r45224411","pull_request_url":"https://api.github.com/repos/VoltDB/deployment/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/VoltDB/deployment/pulls/comments/45224411"},"html":{"href":"https://github.com/VoltDB/deployment/pull/2#discussion_r45224411"},"pull_request":{"href":"https://api.github.com/repos/VoltDB/deployment/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/VoltDB/deployment/pulls/2","id":50801360,"html_url":"https://github.com/VoltDB/deployment/pull/2","diff_url":"https://github.com/VoltDB/deployment/pull/2.diff","patch_url":"https://github.com/VoltDB/deployment/pull/2.patch","issue_url":"https://api.github.com/repos/VoltDB/deployment/issues/2","number":2,"state":"open","locked":false,"title":"Vdm 2","user":{"login":"deerwalk","id":2248797,"avatar_url":"https://avatars.githubusercontent.com/u/2248797?v=3","gravatar_id":"","url":"https://api.github.com/users/deerwalk","html_url":"https://github.com/deerwalk","followers_url":"https://api.github.com/users/deerwalk/followers","following_url":"https://api.github.com/users/deerwalk/following{/other_user}","gists_url":"https://api.github.com/users/deerwalk/gists{/gist_id}","starred_url":"https://api.github.com/users/deerwalk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deerwalk/subscriptions","organizations_url":"https://api.github.com/users/deerwalk/orgs","repos_url":"https://api.github.com/users/deerwalk/repos","events_url":"https://api.github.com/users/deerwalk/events{/privacy}","received_events_url":"https://api.github.com/users/deerwalk/received_events","type":"User","site_admin":false},"body":"VDM:2 - Implemented Server Interface","created_at":"2015-11-16T11:55:20Z","updated_at":"2015-11-18T16:43:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ced8da7fe3acb5017132476b49508f79340a10c8","assignee":{"login":"vtkstef","id":662716,"avatar_url":"https://avatars.githubusercontent.com/u/662716?v=3","gravatar_id":"","url":"https://api.github.com/users/vtkstef","html_url":"https://github.com/vtkstef","followers_url":"https://api.github.com/users/vtkstef/followers","following_url":"https://api.github.com/users/vtkstef/following{/other_user}","gists_url":"https://api.github.com/users/vtkstef/gists{/gist_id}","starred_url":"https://api.github.com/users/vtkstef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtkstef/subscriptions","organizations_url":"https://api.github.com/users/vtkstef/orgs","repos_url":"https://api.github.com/users/vtkstef/repos","events_url":"https://api.github.com/users/vtkstef/events{/privacy}","received_events_url":"https://api.github.com/users/vtkstef/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/VoltDB/deployment/pulls/2/commits","review_comments_url":"https://api.github.com/repos/VoltDB/deployment/pulls/2/comments","review_comment_url":"https://api.github.com/repos/VoltDB/deployment/pulls/comments{/number}","comments_url":"https://api.github.com/repos/VoltDB/deployment/issues/2/comments","statuses_url":"https://api.github.com/repos/VoltDB/deployment/statuses/4536bed23ee5d5adbde4387619273bfe187d845d","head":{"label":"VoltDB:VDM-2","ref":"VDM-2","sha":"4536bed23ee5d5adbde4387619273bfe187d845d","user":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"repo":{"id":43510853,"name":"deployment","full_name":"VoltDB/deployment","owner":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/VoltDB/deployment","description":"","fork":false,"url":"https://api.github.com/repos/VoltDB/deployment","forks_url":"https://api.github.com/repos/VoltDB/deployment/forks","keys_url":"https://api.github.com/repos/VoltDB/deployment/keys{/key_id}","collaborators_url":"https://api.github.com/repos/VoltDB/deployment/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/VoltDB/deployment/teams","hooks_url":"https://api.github.com/repos/VoltDB/deployment/hooks","issue_events_url":"https://api.github.com/repos/VoltDB/deployment/issues/events{/number}","events_url":"https://api.github.com/repos/VoltDB/deployment/events","assignees_url":"https://api.github.com/repos/VoltDB/deployment/assignees{/user}","branches_url":"https://api.github.com/repos/VoltDB/deployment/branches{/branch}","tags_url":"https://api.github.com/repos/VoltDB/deployment/tags","blobs_url":"https://api.github.com/repos/VoltDB/deployment/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/VoltDB/deployment/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/VoltDB/deployment/git/refs{/sha}","trees_url":"https://api.github.com/repos/VoltDB/deployment/git/trees{/sha}","statuses_url":"https://api.github.com/repos/VoltDB/deployment/statuses/{sha}","languages_url":"https://api.github.com/repos/VoltDB/deployment/languages","stargazers_url":"https://api.github.com/repos/VoltDB/deployment/stargazers","contributors_url":"https://api.github.com/repos/VoltDB/deployment/contributors","subscribers_url":"https://api.github.com/repos/VoltDB/deployment/subscribers","subscription_url":"https://api.github.com/repos/VoltDB/deployment/subscription","commits_url":"https://api.github.com/repos/VoltDB/deployment/commits{/sha}","git_commits_url":"https://api.github.com/repos/VoltDB/deployment/git/commits{/sha}","comments_url":"https://api.github.com/repos/VoltDB/deployment/comments{/number}","issue_comment_url":"https://api.github.com/repos/VoltDB/deployment/issues/comments{/number}","contents_url":"https://api.github.com/repos/VoltDB/deployment/contents/{+path}","compare_url":"https://api.github.com/repos/VoltDB/deployment/compare/{base}...{head}","merges_url":"https://api.github.com/repos/VoltDB/deployment/merges","archive_url":"https://api.github.com/repos/VoltDB/deployment/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/VoltDB/deployment/downloads","issues_url":"https://api.github.com/repos/VoltDB/deployment/issues{/number}","pulls_url":"https://api.github.com/repos/VoltDB/deployment/pulls{/number}","milestones_url":"https://api.github.com/repos/VoltDB/deployment/milestones{/number}","notifications_url":"https://api.github.com/repos/VoltDB/deployment/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/VoltDB/deployment/labels{/name}","releases_url":"https://api.github.com/repos/VoltDB/deployment/releases{/id}","created_at":"2015-10-01T17:38:06Z","updated_at":"2015-10-26T14:46:59Z","pushed_at":"2015-11-18T11:13:07Z","git_url":"git://github.com/VoltDB/deployment.git","ssh_url":"git@github.com:VoltDB/deployment.git","clone_url":"https://github.com/VoltDB/deployment.git","svn_url":"https://github.com/VoltDB/deployment","homepage":null,"size":550,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"VoltDB:master","ref":"master","sha":"657c76a60078b585c8fe0021d3ed34dec4b92b04","user":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"repo":{"id":43510853,"name":"deployment","full_name":"VoltDB/deployment","owner":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/VoltDB/deployment","description":"","fork":false,"url":"https://api.github.com/repos/VoltDB/deployment","forks_url":"https://api.github.com/repos/VoltDB/deployment/forks","keys_url":"https://api.github.com/repos/VoltDB/deployment/keys{/key_id}","collaborators_url":"https://api.github.com/repos/VoltDB/deployment/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/VoltDB/deployment/teams","hooks_url":"https://api.github.com/repos/VoltDB/deployment/hooks","issue_events_url":"https://api.github.com/repos/VoltDB/deployment/issues/events{/number}","events_url":"https://api.github.com/repos/VoltDB/deployment/events","assignees_url":"https://api.github.com/repos/VoltDB/deployment/assignees{/user}","branches_url":"https://api.github.com/repos/VoltDB/deployment/branches{/branch}","tags_url":"https://api.github.com/repos/VoltDB/deployment/tags","blobs_url":"https://api.github.com/repos/VoltDB/deployment/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/VoltDB/deployment/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/VoltDB/deployment/git/refs{/sha}","trees_url":"https://api.github.com/repos/VoltDB/deployment/git/trees{/sha}","statuses_url":"https://api.github.com/repos/VoltDB/deployment/statuses/{sha}","languages_url":"https://api.github.com/repos/VoltDB/deployment/languages","stargazers_url":"https://api.github.com/repos/VoltDB/deployment/stargazers","contributors_url":"https://api.github.com/repos/VoltDB/deployment/contributors","subscribers_url":"https://api.github.com/repos/VoltDB/deployment/subscribers","subscription_url":"https://api.github.com/repos/VoltDB/deployment/subscription","commits_url":"https://api.github.com/repos/VoltDB/deployment/commits{/sha}","git_commits_url":"https://api.github.com/repos/VoltDB/deployment/git/commits{/sha}","comments_url":"https://api.github.com/repos/VoltDB/deployment/comments{/number}","issue_comment_url":"https://api.github.com/repos/VoltDB/deployment/issues/comments{/number}","contents_url":"https://api.github.com/repos/VoltDB/deployment/contents/{+path}","compare_url":"https://api.github.com/repos/VoltDB/deployment/compare/{base}...{head}","merges_url":"https://api.github.com/repos/VoltDB/deployment/merges","archive_url":"https://api.github.com/repos/VoltDB/deployment/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/VoltDB/deployment/downloads","issues_url":"https://api.github.com/repos/VoltDB/deployment/issues{/number}","pulls_url":"https://api.github.com/repos/VoltDB/deployment/pulls{/number}","milestones_url":"https://api.github.com/repos/VoltDB/deployment/milestones{/number}","notifications_url":"https://api.github.com/repos/VoltDB/deployment/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/VoltDB/deployment/labels{/name}","releases_url":"https://api.github.com/repos/VoltDB/deployment/releases{/id}","created_at":"2015-10-01T17:38:06Z","updated_at":"2015-10-26T14:46:59Z","pushed_at":"2015-11-18T11:13:07Z","git_url":"git://github.com/VoltDB/deployment.git","ssh_url":"git@github.com:VoltDB/deployment.git","clone_url":"https://github.com/VoltDB/deployment.git","svn_url":"https://github.com/VoltDB/deployment","homepage":null,"size":550,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/VoltDB/deployment/pulls/2"},"html":{"href":"https://github.com/VoltDB/deployment/pull/2"},"issue":{"href":"https://api.github.com/repos/VoltDB/deployment/issues/2"},"comments":{"href":"https://api.github.com/repos/VoltDB/deployment/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/VoltDB/deployment/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/VoltDB/deployment/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/VoltDB/deployment/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/VoltDB/deployment/statuses/4536bed23ee5d5adbde4387619273bfe187d845d"}}}}