{"action":"created","comment":{"url":"https://api.github.com/repos/ground-context/ground/pulls/comments/103110596","pull_request_review_id":23888052,"id":103110596,"diff_hunk":"@@ -27,327 +27,289 @@\n import edu.berkeley.ground.exceptions.GroundException;\n import edu.berkeley.ground.plugins.hive.util.JsonUtil;\n \n+import org.apache.commons.httpclient.HttpException;\n import org.apache.hadoop.hive.metastore.api.Database;\n import org.apache.hadoop.hive.metastore.api.InvalidInputException;\n import org.apache.hadoop.hive.metastore.api.InvalidObjectException;\n import org.apache.hadoop.hive.metastore.api.MetaException;\n import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;\n import org.apache.hadoop.hive.metastore.api.Partition;\n import org.apache.hadoop.hive.metastore.api.Table;\n+import org.codehaus.jackson.JsonParseException;\n+import org.codehaus.jackson.map.JsonMappingException;\n import org.slf4j.Logger;\n import org.slf4j.LoggerFactory;\n \n+import java.io.IOException;\n import java.util.ArrayList;\n import java.util.HashMap;\n import java.util.List;\n import java.util.Map;\n \n public class GroundDatabase {\n-  static final private Logger LOG = LoggerFactory.getLogger(GroundDatabase.class.getName());\n+    static final private Logger LOG = LoggerFactory.getLogger(GroundDatabase.class.getName());\n \n-  static final String DATABASE_NODE = \"_DATABASE\";\n+    static final String DATABASE_NODE = \"_DATABASE\";\n \n-  static final String DATABASE_TABLE_EDGE = \"_DATABASE_TABLE\";\n+    static final String DATABASE_TABLE_EDGE = \"_DATABASE_TABLE\";\n \n-  private static final List<String> EMPTY_PARENT_LIST = new ArrayList<String>();\n+    private static final List<String> EMPTY_PARENT_LIST = new ArrayList<String>();\n \n-  private GroundReadWrite groundReadWrite = null;\n-  private GroundTable groundTable = null;\n+    private GroundReadWrite groundReadWrite = null;\n+    private GroundTable groundTable = null;\n \n-  GroundDatabase(GroundReadWrite ground) {\n-    groundReadWrite = ground;\n-    groundTable = new GroundTable(ground);\n-  }\n+    GroundDatabase(GroundReadWrite ground) {\n+        groundReadWrite = ground;\n+        groundTable = new GroundTable(ground);\n+    }\n+\n+    Node getNode(String dbName) throws GroundException {\n+        LOG.debug(\"Fetching database node: \" + dbName);\n+        return groundReadWrite.getNode(dbName);\n+    }\n \n-  Node getNode(String dbName) throws GroundException {\n-    try {\n-      LOG.debug(\"Fetching database node: \" + dbName);\n-      return groundReadWrite.getNodeFactory().retrieveFromDatabase(dbName);\n-    } catch (GroundException ge1) {\n-      LOG.debug(\"Not found - Creating databsae node: {}\", dbName);\n+    Structure getNodeStructure(String dbName) throws GroundException {\n+        return groundReadWrite.getStructure(dbName);\n+    }\n \n-      Node node = groundReadWrite.getNodeFactory().create(dbName);\n-      Structure nodeStruct = groundReadWrite.getStructureFactory().create(node.getName());\n-      LOG.debug(\"node structure created {}\", nodeStruct);\n-      return node;\n+    Edge getEdge(NodeVersion nodeVersion) throws GroundException {\n+        String edgeId = nodeVersion.getNodeId();\n+        LOG.debug(\"Fetching database table edge: \" + edgeId);\n+        return groundReadWrite.getEdge(edgeId);\n     }\n-  }\n-\n-  Structure getNodeStructure(String dbName) throws GroundException {\n-    try {\n-      Node node = this.getNode(dbName);\n-      return groundReadWrite.getStructureFactory().retrieveFromDatabase(dbName);\n-    } catch (GroundException e) {\n-      LOG.error(\"Unable to fetch database node structure\");\n-      throw e;\n+\n+    Structure getEdgeStructure(NodeVersion nodeVersion) throws GroundException {\n+        try {\n+            LOG.debug(\"Fetching database table edge structure: \" + nodeVersion.getNodeId());\n+            Edge edge = this.getEdge(nodeVersion);\n+            return groundReadWrite.getStructure(edge.getName());\n+        } catch (GroundException e) {\n+            LOG.debug(\"Not found - database table edge structure: \" + nodeVersion.getNodeId());\n+            throw new GroundException(e);\n+        }\n     }\n-  }\n-\n-  Edge getEdge(NodeVersion nodeVersion) throws GroundException {\n-    String edgeId = \"\" + nodeVersion.getNodeId();\n-    try {\n-      LOG.debug(\"Fetching database table edge: \" + edgeId);\n-      return groundReadWrite.getEdgeFactory().retrieveFromDatabase(edgeId);\n-    } catch (GroundException e) {\n-      LOG.debug(\"Not found - Creating database table edge: \" + edgeId);\n-      Edge edge = groundReadWrite.getEdgeFactory().create(edgeId);\n-      Structure edgeStruct = groundReadWrite.getStructureFactory().create(edge.getName());\n-      return edge;\n+\n+    Database getDatabase(String dbName) throws GroundException {\n+        List<String> versions = groundReadWrite.getLatestVersions(dbName);\n+        if (versions.isEmpty()) {\n+            throw new GroundException(\"Database node not found: \" + dbName);\n+        }\n+        NodeVersion latestVersion = groundReadWrite.getNodeVersion(versions.get(0));\n+        Map<String, Tag> dbTag = latestVersion.getTags();\n+        return JsonUtil.fromJSON((String) dbTag.get(dbName).getValue(), Database.class);\n     }\n-  }\n-\n-  Structure getEdgeStructure(NodeVersion nodeVersion) throws GroundException {\n-    try {\n-      LOG.debug(\"Fetching database table edge structure: \" + nodeVersion.getNodeId());\n-      Edge edge = this.getEdge(nodeVersion);\n-      return groundReadWrite.getStructureFactory().retrieveFromDatabase(edge.getName());\n-    } catch (GroundException e) {\n-      LOG.debug(\"Not found - database table edge structure: \" + nodeVersion.getNodeId());\n-      throw e;\n+\n+    NodeVersion createDatabase(Database db) throws InvalidObjectException, MetaException {\n+        if (db == null) {\n+            throw new InvalidObjectException(\"Database object passed is null\");\n+        }\n+        try {\n+            String dbName = db.getName();\n+            Node dbNode = this.getNode(dbName);\n+            Structure dbStruct = groundReadWrite.createStructure(dbName);\n+            LOG.debug(\"Node and Structure {}, {}\", dbNode.getId(), dbStruct.getId());\n+            Map<String, GroundType> structVersionAttribs = new HashMap<>();\n+            structVersionAttribs.put(dbName, GroundType.STRING);","path":"plugins/hive-plugin/src/main/java/edu/berkeley/ground/plugins/hive/GroundDatabase.java","position":137,"original_position":137,"commit_id":"e467ffdf6776194820da570b281a7eea60c39bbc","original_commit_id":"e467ffdf6776194820da570b281a7eea60c39bbc","user":{"login":"ramach","id":5705100,"avatar_url":"https://avatars.githubusercontent.com/u/5705100?v=3","gravatar_id":"","url":"https://api.github.com/users/ramach","html_url":"https://github.com/ramach","followers_url":"https://api.github.com/users/ramach/followers","following_url":"https://api.github.com/users/ramach/following{/other_user}","gists_url":"https://api.github.com/users/ramach/gists{/gist_id}","starred_url":"https://api.github.com/users/ramach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramach/subscriptions","organizations_url":"https://api.github.com/users/ramach/orgs","repos_url":"https://api.github.com/users/ramach/repos","events_url":"https://api.github.com/users/ramach/events{/privacy}","received_events_url":"https://api.github.com/users/ramach/received_events","type":"User","site_admin":false},"body":"got it thanks! Essentially have a generic key (like datebaseName, tableName, partitionName) and values will be a list - of a particular key type - correct?","created_at":"2017-02-26T17:22:08Z","updated_at":"2017-02-26T17:22:08Z","html_url":"https://github.com/ground-context/ground/pull/41#discussion_r103110596","pull_request_url":"https://api.github.com/repos/ground-context/ground/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/ground-context/ground/pulls/comments/103110596"},"html":{"href":"https://github.com/ground-context/ground/pull/41#discussion_r103110596"},"pull_request":{"href":"https://api.github.com/repos/ground-context/ground/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/ground-context/ground/pulls/41","id":107098930,"html_url":"https://github.com/ground-context/ground/pull/41","diff_url":"https://github.com/ground-context/ground/pull/41.diff","patch_url":"https://github.com/ground-context/ground/pull/41.patch","issue_url":"https://api.github.com/repos/ground-context/ground/issues/41","number":41,"state":"open","locked":false,"title":"[GROUND-24] Refactor Hive Plugin and migrate to the Ground REST API","user":{"login":"ramach","id":5705100,"avatar_url":"https://avatars.githubusercontent.com/u/5705100?v=3","gravatar_id":"","url":"https://api.github.com/users/ramach","html_url":"https://github.com/ramach","followers_url":"https://api.github.com/users/ramach/followers","following_url":"https://api.github.com/users/ramach/following{/other_user}","gists_url":"https://api.github.com/users/ramach/gists{/gist_id}","starred_url":"https://api.github.com/users/ramach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramach/subscriptions","organizations_url":"https://api.github.com/users/ramach/orgs","repos_url":"https://api.github.com/users/ramach/repos","events_url":"https://api.github.com/users/ramach/events{/privacy}","received_events_url":"https://api.github.com/users/ramach/received_events","type":"User","site_admin":false},"body":"Ground Hive Plugin version using Ground REST APIs. Test cases are not working (see below) - am still debugging. It is NOT ready for merge yet - since there are major changes am submitting  to get the process started\r\n\r\nError during node creation:\r\n\r\n127.0.0.1 - - [21/Feb/2017:00:28:40 +0000] \"POST /nodes/_METASTORE HTTP/1.1\" 500 110 \"-\" \"Jakarta Commons-HttpClient/3.1\" 36\r\nINFO  [2017-02-21 00:28:40,986] edu.berkeley.ground.resources.NodesResource: Retrieving the latest version of node _METASTORE.\r\nERROR [2017-02-21 00:28:41,008] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: b3b8195962d955a9\r\n! org.neo4j.driver.v1.exceptions.ClientException: The client has provided incorrect authentication details too many times in a row.","created_at":"2017-02-21T01:08:02Z","updated_at":"2017-02-26T17:22:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"38899dbc2761f7ef2799c96826fdd324415eb760","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ground-context/ground/pulls/41/commits","review_comments_url":"https://api.github.com/repos/ground-context/ground/pulls/41/comments","review_comment_url":"https://api.github.com/repos/ground-context/ground/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ground-context/ground/issues/41/comments","statuses_url":"https://api.github.com/repos/ground-context/ground/statuses/e467ffdf6776194820da570b281a7eea60c39bbc","head":{"label":"ramach:master","ref":"master","sha":"e467ffdf6776194820da570b281a7eea60c39bbc","user":{"login":"ramach","id":5705100,"avatar_url":"https://avatars.githubusercontent.com/u/5705100?v=3","gravatar_id":"","url":"https://api.github.com/users/ramach","html_url":"https://github.com/ramach","followers_url":"https://api.github.com/users/ramach/followers","following_url":"https://api.github.com/users/ramach/following{/other_user}","gists_url":"https://api.github.com/users/ramach/gists{/gist_id}","starred_url":"https://api.github.com/users/ramach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramach/subscriptions","organizations_url":"https://api.github.com/users/ramach/orgs","repos_url":"https://api.github.com/users/ramach/repos","events_url":"https://api.github.com/users/ramach/events{/privacy}","received_events_url":"https://api.github.com/users/ramach/received_events","type":"User","site_admin":false},"repo":{"id":60533298,"name":"ground","full_name":"ramach/ground","owner":{"login":"ramach","id":5705100,"avatar_url":"https://avatars.githubusercontent.com/u/5705100?v=3","gravatar_id":"","url":"https://api.github.com/users/ramach","html_url":"https://github.com/ramach","followers_url":"https://api.github.com/users/ramach/followers","following_url":"https://api.github.com/users/ramach/following{/other_user}","gists_url":"https://api.github.com/users/ramach/gists{/gist_id}","starred_url":"https://api.github.com/users/ramach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramach/subscriptions","organizations_url":"https://api.github.com/users/ramach/orgs","repos_url":"https://api.github.com/users/ramach/repos","events_url":"https://api.github.com/users/ramach/events{/privacy}","received_events_url":"https://api.github.com/users/ramach/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ramach/ground","description":"An open-source, vendor-neutral data context service.","fork":true,"url":"https://api.github.com/repos/ramach/ground","forks_url":"https://api.github.com/repos/ramach/ground/forks","keys_url":"https://api.github.com/repos/ramach/ground/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ramach/ground/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ramach/ground/teams","hooks_url":"https://api.github.com/repos/ramach/ground/hooks","issue_events_url":"https://api.github.com/repos/ramach/ground/issues/events{/number}","events_url":"https://api.github.com/repos/ramach/ground/events","assignees_url":"https://api.github.com/repos/ramach/ground/assignees{/user}","branches_url":"https://api.github.com/repos/ramach/ground/branches{/branch}","tags_url":"https://api.github.com/repos/ramach/ground/tags","blobs_url":"https://api.github.com/repos/ramach/ground/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ramach/ground/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ramach/ground/git/refs{/sha}","trees_url":"https://api.github.com/repos/ramach/ground/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ramach/ground/statuses/{sha}","languages_url":"https://api.github.com/repos/ramach/ground/languages","stargazers_url":"https://api.github.com/repos/ramach/ground/stargazers","contributors_url":"https://api.github.com/repos/ramach/ground/contributors","subscribers_url":"https://api.github.com/repos/ramach/ground/subscribers","subscription_url":"https://api.github.com/repos/ramach/ground/subscription","commits_url":"https://api.github.com/repos/ramach/ground/commits{/sha}","git_commits_url":"https://api.github.com/repos/ramach/ground/git/commits{/sha}","comments_url":"https://api.github.com/repos/ramach/ground/comments{/number}","issue_comment_url":"https://api.github.com/repos/ramach/ground/issues/comments{/number}","contents_url":"https://api.github.com/repos/ramach/ground/contents/{+path}","compare_url":"https://api.github.com/repos/ramach/ground/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ramach/ground/merges","archive_url":"https://api.github.com/repos/ramach/ground/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ramach/ground/downloads","issues_url":"https://api.github.com/repos/ramach/ground/issues{/number}","pulls_url":"https://api.github.com/repos/ramach/ground/pulls{/number}","milestones_url":"https://api.github.com/repos/ramach/ground/milestones{/number}","notifications_url":"https://api.github.com/repos/ramach/ground/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ramach/ground/labels{/name}","releases_url":"https://api.github.com/repos/ramach/ground/releases{/id}","deployments_url":"https://api.github.com/repos/ramach/ground/deployments","created_at":"2016-06-06T14:11:17Z","updated_at":"2016-06-06T14:11:18Z","pushed_at":"2017-02-21T00:53:28Z","git_url":"git://github.com/ramach/ground.git","ssh_url":"git@github.com:ramach/ground.git","clone_url":"https://github.com/ramach/ground.git","svn_url":"https://github.com/ramach/ground","homepage":"http://www.ground-metadata.org","size":3096,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ground-context:master","ref":"master","sha":"37021e74781e404ae6886571d8c756db66797033","user":{"login":"ground-context","id":17051871,"avatar_url":"https://avatars.githubusercontent.com/u/17051871?v=3","gravatar_id":"","url":"https://api.github.com/users/ground-context","html_url":"https://github.com/ground-context","followers_url":"https://api.github.com/users/ground-context/followers","following_url":"https://api.github.com/users/ground-context/following{/other_user}","gists_url":"https://api.github.com/users/ground-context/gists{/gist_id}","starred_url":"https://api.github.com/users/ground-context/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ground-context/subscriptions","organizations_url":"https://api.github.com/users/ground-context/orgs","repos_url":"https://api.github.com/users/ground-context/repos","events_url":"https://api.github.com/users/ground-context/events{/privacy}","received_events_url":"https://api.github.com/users/ground-context/received_events","type":"Organization","site_admin":false},"repo":{"id":57158287,"name":"ground","full_name":"ground-context/ground","owner":{"login":"ground-context","id":17051871,"avatar_url":"https://avatars.githubusercontent.com/u/17051871?v=3","gravatar_id":"","url":"https://api.github.com/users/ground-context","html_url":"https://github.com/ground-context","followers_url":"https://api.github.com/users/ground-context/followers","following_url":"https://api.github.com/users/ground-context/following{/other_user}","gists_url":"https://api.github.com/users/ground-context/gists{/gist_id}","starred_url":"https://api.github.com/users/ground-context/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ground-context/subscriptions","organizations_url":"https://api.github.com/users/ground-context/orgs","repos_url":"https://api.github.com/users/ground-context/repos","events_url":"https://api.github.com/users/ground-context/events{/privacy}","received_events_url":"https://api.github.com/users/ground-context/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ground-context/ground","description":"An open-source, vendor-neutral data context service.","fork":false,"url":"https://api.github.com/repos/ground-context/ground","forks_url":"https://api.github.com/repos/ground-context/ground/forks","keys_url":"https://api.github.com/repos/ground-context/ground/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ground-context/ground/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ground-context/ground/teams","hooks_url":"https://api.github.com/repos/ground-context/ground/hooks","issue_events_url":"https://api.github.com/repos/ground-context/ground/issues/events{/number}","events_url":"https://api.github.com/repos/ground-context/ground/events","assignees_url":"https://api.github.com/repos/ground-context/ground/assignees{/user}","branches_url":"https://api.github.com/repos/ground-context/ground/branches{/branch}","tags_url":"https://api.github.com/repos/ground-context/ground/tags","blobs_url":"https://api.github.com/repos/ground-context/ground/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ground-context/ground/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ground-context/ground/git/refs{/sha}","trees_url":"https://api.github.com/repos/ground-context/ground/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ground-context/ground/statuses/{sha}","languages_url":"https://api.github.com/repos/ground-context/ground/languages","stargazers_url":"https://api.github.com/repos/ground-context/ground/stargazers","contributors_url":"https://api.github.com/repos/ground-context/ground/contributors","subscribers_url":"https://api.github.com/repos/ground-context/ground/subscribers","subscription_url":"https://api.github.com/repos/ground-context/ground/subscription","commits_url":"https://api.github.com/repos/ground-context/ground/commits{/sha}","git_commits_url":"https://api.github.com/repos/ground-context/ground/git/commits{/sha}","comments_url":"https://api.github.com/repos/ground-context/ground/comments{/number}","issue_comment_url":"https://api.github.com/repos/ground-context/ground/issues/comments{/number}","contents_url":"https://api.github.com/repos/ground-context/ground/contents/{+path}","compare_url":"https://api.github.com/repos/ground-context/ground/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ground-context/ground/merges","archive_url":"https://api.github.com/repos/ground-context/ground/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ground-context/ground/downloads","issues_url":"https://api.github.com/repos/ground-context/ground/issues{/number}","pulls_url":"https://api.github.com/repos/ground-context/ground/pulls{/number}","milestones_url":"https://api.github.com/repos/ground-context/ground/milestones{/number}","notifications_url":"https://api.github.com/repos/ground-context/ground/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ground-context/ground/labels{/name}","releases_url":"https://api.github.com/repos/ground-context/ground/releases{/id}","deployments_url":"https://api.github.com/repos/ground-context/ground/deployments","created_at":"2016-04-26T20:04:23Z","updated_at":"2017-02-22T05:18:39Z","pushed_at":"2017-02-24T19:48:42Z","git_url":"git://github.com/ground-context/ground.git","ssh_url":"git@github.com:ground-context/ground.git","clone_url":"https://github.com/ground-context/ground.git","svn_url":"https://github.com/ground-context/ground","homepage":"http://www.ground-context.org","size":3106,"stargazers_count":46,"watchers_count":46,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":5,"forks":18,"open_issues":5,"watchers":46,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ground-context/ground/pulls/41"},"html":{"href":"https://github.com/ground-context/ground/pull/41"},"issue":{"href":"https://api.github.com/repos/ground-context/ground/issues/41"},"comments":{"href":"https://api.github.com/repos/ground-context/ground/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/ground-context/ground/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/ground-context/ground/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ground-context/ground/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/ground-context/ground/statuses/e467ffdf6776194820da570b281a7eea60c39bbc"}}}}
{"actor":{"display_login":"ramach"}}