{"action":"created","comment":{"url":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/comments/48972335","id":48972335,"diff_hunk":"@@ -0,0 +1,316 @@\n+/**\n+ * Copyright (c) 2012 YCSB contributors. All rights reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you\n+ * may not use this file except in compliance with the License. You\n+ * may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n+ * implied. See the License for the specific language governing\n+ * permissions and limitations under the License. See accompanying\n+ * LICENSE file.\n+ */\n+\n+package com.yahoo.ycsb.db;\n+\n+import com.yahoo.ycsb.ByteIterator;\n+import com.yahoo.ycsb.DB;\n+import com.yahoo.ycsb.DBException;\n+import com.yahoo.ycsb.Status;\n+import com.yahoo.ycsb.StringByteIterator;\n+\n+import org.apache.solr.client.solrj.SolrQuery;\n+import org.apache.solr.client.solrj.impl.CloudSolrClient;\n+import org.apache.solr.client.solrj.impl.HttpSolrClient;\n+import org.apache.solr.client.solrj.response.QueryResponse;\n+import org.apache.solr.client.solrj.response.UpdateResponse;\n+import org.apache.solr.client.solrj.util.ClientUtils;\n+import org.apache.solr.common.SolrDocument;\n+import org.apache.solr.common.SolrInputDocument;\n+\n+import java.io.IOException;\n+import java.util.HashMap;\n+import java.util.Map.Entry;\n+import java.util.Properties;\n+import java.util.Set;\n+import java.util.Vector;\n+\n+/**\n+ * Solr client for YCSB framework.\n+ *\n+ * <p>\n+ * Default properties to set:\n+ * </p>\n+ * <ul>\n+ * <li>table = ycsb\n+ * <li>solr.cloud = false\n+ * <li>zookeeper.host.list\n+ * <li>solr.host.list\n+ * </ul>\n+ *\n+ * @author Gerard Haughian\n+ *\n+ */\n+public class SolrClient extends DB {\n+\n+  public static final String DEFAULT_COLLECTION_NAME = \"ycsb\";\n+  public static final String DEFAULT_CLOUD_MODE = \"false\";\n+  public static final String DEFAULT_REMOTE_ZOOKEEPER_HOST = \"localhost:2181\";\n+  public static final String DEFAULT_REMOTE_SOLR_HOST = \"localhost:8983\";\n+  private CloudSolrClient cloudClient;\n+  private HttpSolrClient httpClient;\n+\n+  private Boolean cloudMode;\n+\n+  /**\n+   * Initialize any state for this DB. Called once per DB instance; there is one DB instance per\n+   * client thread.\n+   */\n+  @Override\n+  public void init() throws DBException {\n+    // initialize Solr driver\n+    Properties props = getProperties();\n+    String collectionName = props.getProperty(\"table\", DEFAULT_COLLECTION_NAME);\n+    // TO-DO: Add a check that the collection exists\n+    // Check if Solr cluster is running in SolrCloud mode\n+    cloudMode = Boolean.parseBoolean(props.getProperty(\"solr.cloud\", DEFAULT_CLOUD_MODE));\n+    System.out.println(\"Solr Cloud Mode = \" + cloudMode);\n+    if (cloudMode) {\n+      System.out.println(\"Solr Zookeeper Remote Hosts = \"\n+          + props.getProperty(\"zookeeper.host.list\", DEFAULT_REMOTE_ZOOKEEPER_HOST));\n+\n+      CloudSolrClient server = new CloudSolrClient(\n+          props.getProperty(\"zookeeper.host.list\", DEFAULT_REMOTE_ZOOKEEPER_HOST));\n+      server.setDefaultCollection(collectionName);\n+      cloudClient = server;\n+    } else { // Start node only if cluster mode is disabled\n+      HttpSolrClient server = new HttpSolrClient(\n+          \"http://\" + props.getProperty(\"solr.host.list\", DEFAULT_REMOTE_SOLR_HOST) + \"/solr\");\n+      httpClient = server;\n+    }\n+  }\n+\n+  @Override\n+  public void cleanup() throws DBException {\n+    try {\n+      if (cloudMode) {\n+        cloudClient.close();\n+      } else {\n+        httpClient.close();\n+      }\n+    } catch (IOException e) {\n+      e.printStackTrace();\n+    }\n+  }\n+\n+  /**\n+   * Insert a record in the database. Any field/value pairs in the specified values HashMap will be\n+   * written into the record with the specified record key.\n+   *\n+   * @param table\n+   *          The name of the table\n+   * @param key\n+   *          The record key of the record to insert.\n+   * @param values\n+   *          A HashMap of field/value pairs to insert in the record\n+   * @return Zero on success, a non-zero error code on error. See this class's description for a\n+   *         discussion of error codes.\n+   */\n+  @Override\n+  public Status insert(String table, String key, HashMap<String, ByteIterator> values) {\n+    try {\n+      SolrInputDocument doc = new SolrInputDocument();\n+\n+      doc.addField(\"id\", key);\n+      for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {\n+        doc.addField(entry.getKey(), entry.getValue());\n+      }\n+\n+      if (cloudMode) {\n+        cloudClient.add(table, doc);\n+        cloudClient.commit(table);\n+      } else {\n+        httpClient.add(table, doc);\n+        httpClient.commit(table);\n+      }\n+\n+      return Status.OK;\n+    } catch (Exception e) {","path":"solr/src/main/java/com/yahoo/ycsb/db/SolrClient.java","position":142,"original_position":142,"commit_id":"b07fbf0e182c74639d16e587192883a1e08654f6","original_commit_id":"b07fbf0e182c74639d16e587192883a1e08654f6","user":{"login":"risdenk","id":3384157,"avatar_url":"https://avatars.githubusercontent.com/u/3384157?v=3","gravatar_id":"","url":"https://api.github.com/users/risdenk","html_url":"https://github.com/risdenk","followers_url":"https://api.github.com/users/risdenk/followers","following_url":"https://api.github.com/users/risdenk/following{/other_user}","gists_url":"https://api.github.com/users/risdenk/gists{/gist_id}","starred_url":"https://api.github.com/users/risdenk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/risdenk/subscriptions","organizations_url":"https://api.github.com/users/risdenk/orgs","repos_url":"https://api.github.com/users/risdenk/repos","events_url":"https://api.github.com/users/risdenk/events{/privacy}","received_events_url":"https://api.github.com/users/risdenk/received_events","type":"User","site_admin":false},"body":"should be more explicit about what exceptions are being caught","created_at":"2016-01-06T15:59:45Z","updated_at":"2016-01-06T15:59:45Z","html_url":"https://github.com/brianfrankcooper/YCSB/pull/574#discussion_r48972335","pull_request_url":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574","_links":{"self":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/comments/48972335"},"html":{"href":"https://github.com/brianfrankcooper/YCSB/pull/574#discussion_r48972335"},"pull_request":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574"}}},"pull_request":{"url":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574","id":55199928,"html_url":"https://github.com/brianfrankcooper/YCSB/pull/574","diff_url":"https://github.com/brianfrankcooper/YCSB/pull/574.diff","patch_url":"https://github.com/brianfrankcooper/YCSB/pull/574.patch","issue_url":"https://api.github.com/repos/brianfrankcooper/YCSB/issues/574","number":574,"state":"open","locked":false,"title":"Adding Apache Solr Support","user":{"login":"ghaughian","id":7100105,"avatar_url":"https://avatars.githubusercontent.com/u/7100105?v=3","gravatar_id":"","url":"https://api.github.com/users/ghaughian","html_url":"https://github.com/ghaughian","followers_url":"https://api.github.com/users/ghaughian/followers","following_url":"https://api.github.com/users/ghaughian/following{/other_user}","gists_url":"https://api.github.com/users/ghaughian/gists{/gist_id}","starred_url":"https://api.github.com/users/ghaughian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghaughian/subscriptions","organizations_url":"https://api.github.com/users/ghaughian/orgs","repos_url":"https://api.github.com/users/ghaughian/repos","events_url":"https://api.github.com/users/ghaughian/events{/privacy}","received_events_url":"https://api.github.com/users/ghaughian/received_events","type":"User","site_admin":false},"body":"Since ElasticSearch is supported I thought it would be beneficial to have Solr supported also. I'm sure there are people out there who would love to compare head-to-head these 2 search engine technologies. ","created_at":"2016-01-06T10:50:34Z","updated_at":"2016-01-06T15:59:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe94a92246a1970f17a626bd2d3ce6cdad507337","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574/commits","review_comments_url":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574/comments","review_comment_url":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/comments{/number}","comments_url":"https://api.github.com/repos/brianfrankcooper/YCSB/issues/574/comments","statuses_url":"https://api.github.com/repos/brianfrankcooper/YCSB/statuses/b07fbf0e182c74639d16e587192883a1e08654f6","head":{"label":"ghaughian:master","ref":"master","sha":"b07fbf0e182c74639d16e587192883a1e08654f6","user":{"login":"ghaughian","id":7100105,"avatar_url":"https://avatars.githubusercontent.com/u/7100105?v=3","gravatar_id":"","url":"https://api.github.com/users/ghaughian","html_url":"https://github.com/ghaughian","followers_url":"https://api.github.com/users/ghaughian/followers","following_url":"https://api.github.com/users/ghaughian/following{/other_user}","gists_url":"https://api.github.com/users/ghaughian/gists{/gist_id}","starred_url":"https://api.github.com/users/ghaughian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghaughian/subscriptions","organizations_url":"https://api.github.com/users/ghaughian/orgs","repos_url":"https://api.github.com/users/ghaughian/repos","events_url":"https://api.github.com/users/ghaughian/events{/privacy}","received_events_url":"https://api.github.com/users/ghaughian/received_events","type":"User","site_admin":false},"repo":{"id":48797571,"name":"YCSB-1","full_name":"ghaughian/YCSB-1","owner":{"login":"ghaughian","id":7100105,"avatar_url":"https://avatars.githubusercontent.com/u/7100105?v=3","gravatar_id":"","url":"https://api.github.com/users/ghaughian","html_url":"https://github.com/ghaughian","followers_url":"https://api.github.com/users/ghaughian/followers","following_url":"https://api.github.com/users/ghaughian/following{/other_user}","gists_url":"https://api.github.com/users/ghaughian/gists{/gist_id}","starred_url":"https://api.github.com/users/ghaughian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghaughian/subscriptions","organizations_url":"https://api.github.com/users/ghaughian/orgs","repos_url":"https://api.github.com/users/ghaughian/repos","events_url":"https://api.github.com/users/ghaughian/events{/privacy}","received_events_url":"https://api.github.com/users/ghaughian/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ghaughian/YCSB-1","description":"Yahoo! Cloud Serving Benchmark","fork":true,"url":"https://api.github.com/repos/ghaughian/YCSB-1","forks_url":"https://api.github.com/repos/ghaughian/YCSB-1/forks","keys_url":"https://api.github.com/repos/ghaughian/YCSB-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ghaughian/YCSB-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ghaughian/YCSB-1/teams","hooks_url":"https://api.github.com/repos/ghaughian/YCSB-1/hooks","issue_events_url":"https://api.github.com/repos/ghaughian/YCSB-1/issues/events{/number}","events_url":"https://api.github.com/repos/ghaughian/YCSB-1/events","assignees_url":"https://api.github.com/repos/ghaughian/YCSB-1/assignees{/user}","branches_url":"https://api.github.com/repos/ghaughian/YCSB-1/branches{/branch}","tags_url":"https://api.github.com/repos/ghaughian/YCSB-1/tags","blobs_url":"https://api.github.com/repos/ghaughian/YCSB-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ghaughian/YCSB-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ghaughian/YCSB-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/ghaughian/YCSB-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ghaughian/YCSB-1/statuses/{sha}","languages_url":"https://api.github.com/repos/ghaughian/YCSB-1/languages","stargazers_url":"https://api.github.com/repos/ghaughian/YCSB-1/stargazers","contributors_url":"https://api.github.com/repos/ghaughian/YCSB-1/contributors","subscribers_url":"https://api.github.com/repos/ghaughian/YCSB-1/subscribers","subscription_url":"https://api.github.com/repos/ghaughian/YCSB-1/subscription","commits_url":"https://api.github.com/repos/ghaughian/YCSB-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/ghaughian/YCSB-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/ghaughian/YCSB-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/ghaughian/YCSB-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/ghaughian/YCSB-1/contents/{+path}","compare_url":"https://api.github.com/repos/ghaughian/YCSB-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ghaughian/YCSB-1/merges","archive_url":"https://api.github.com/repos/ghaughian/YCSB-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ghaughian/YCSB-1/downloads","issues_url":"https://api.github.com/repos/ghaughian/YCSB-1/issues{/number}","pulls_url":"https://api.github.com/repos/ghaughian/YCSB-1/pulls{/number}","milestones_url":"https://api.github.com/repos/ghaughian/YCSB-1/milestones{/number}","notifications_url":"https://api.github.com/repos/ghaughian/YCSB-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ghaughian/YCSB-1/labels{/name}","releases_url":"https://api.github.com/repos/ghaughian/YCSB-1/releases{/id}","created_at":"2015-12-30T11:25:24Z","updated_at":"2015-12-30T11:25:26Z","pushed_at":"2016-01-06T13:17:05Z","git_url":"git://github.com/ghaughian/YCSB-1.git","ssh_url":"git@github.com:ghaughian/YCSB-1.git","clone_url":"https://github.com/ghaughian/YCSB-1.git","svn_url":"https://github.com/ghaughian/YCSB-1","homepage":"http://research.yahoo.com/Web_Information_Management/YCSB","size":29977,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"brianfrankcooper:master","ref":"master","sha":"c4d38feba2623a9878953c8d81d2656fe26b6cc8","user":{"login":"brianfrankcooper","id":247619,"avatar_url":"https://avatars.githubusercontent.com/u/247619?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfrankcooper","html_url":"https://github.com/brianfrankcooper","followers_url":"https://api.github.com/users/brianfrankcooper/followers","following_url":"https://api.github.com/users/brianfrankcooper/following{/other_user}","gists_url":"https://api.github.com/users/brianfrankcooper/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfrankcooper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfrankcooper/subscriptions","organizations_url":"https://api.github.com/users/brianfrankcooper/orgs","repos_url":"https://api.github.com/users/brianfrankcooper/repos","events_url":"https://api.github.com/users/brianfrankcooper/events{/privacy}","received_events_url":"https://api.github.com/users/brianfrankcooper/received_events","type":"User","site_admin":false},"repo":{"id":618492,"name":"YCSB","full_name":"brianfrankcooper/YCSB","owner":{"login":"brianfrankcooper","id":247619,"avatar_url":"https://avatars.githubusercontent.com/u/247619?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfrankcooper","html_url":"https://github.com/brianfrankcooper","followers_url":"https://api.github.com/users/brianfrankcooper/followers","following_url":"https://api.github.com/users/brianfrankcooper/following{/other_user}","gists_url":"https://api.github.com/users/brianfrankcooper/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfrankcooper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfrankcooper/subscriptions","organizations_url":"https://api.github.com/users/brianfrankcooper/orgs","repos_url":"https://api.github.com/users/brianfrankcooper/repos","events_url":"https://api.github.com/users/brianfrankcooper/events{/privacy}","received_events_url":"https://api.github.com/users/brianfrankcooper/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brianfrankcooper/YCSB","description":"Yahoo! Cloud Serving Benchmark","fork":false,"url":"https://api.github.com/repos/brianfrankcooper/YCSB","forks_url":"https://api.github.com/repos/brianfrankcooper/YCSB/forks","keys_url":"https://api.github.com/repos/brianfrankcooper/YCSB/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brianfrankcooper/YCSB/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brianfrankcooper/YCSB/teams","hooks_url":"https://api.github.com/repos/brianfrankcooper/YCSB/hooks","issue_events_url":"https://api.github.com/repos/brianfrankcooper/YCSB/issues/events{/number}","events_url":"https://api.github.com/repos/brianfrankcooper/YCSB/events","assignees_url":"https://api.github.com/repos/brianfrankcooper/YCSB/assignees{/user}","branches_url":"https://api.github.com/repos/brianfrankcooper/YCSB/branches{/branch}","tags_url":"https://api.github.com/repos/brianfrankcooper/YCSB/tags","blobs_url":"https://api.github.com/repos/brianfrankcooper/YCSB/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brianfrankcooper/YCSB/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brianfrankcooper/YCSB/git/refs{/sha}","trees_url":"https://api.github.com/repos/brianfrankcooper/YCSB/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brianfrankcooper/YCSB/statuses/{sha}","languages_url":"https://api.github.com/repos/brianfrankcooper/YCSB/languages","stargazers_url":"https://api.github.com/repos/brianfrankcooper/YCSB/stargazers","contributors_url":"https://api.github.com/repos/brianfrankcooper/YCSB/contributors","subscribers_url":"https://api.github.com/repos/brianfrankcooper/YCSB/subscribers","subscription_url":"https://api.github.com/repos/brianfrankcooper/YCSB/subscription","commits_url":"https://api.github.com/repos/brianfrankcooper/YCSB/commits{/sha}","git_commits_url":"https://api.github.com/repos/brianfrankcooper/YCSB/git/commits{/sha}","comments_url":"https://api.github.com/repos/brianfrankcooper/YCSB/comments{/number}","issue_comment_url":"https://api.github.com/repos/brianfrankcooper/YCSB/issues/comments{/number}","contents_url":"https://api.github.com/repos/brianfrankcooper/YCSB/contents/{+path}","compare_url":"https://api.github.com/repos/brianfrankcooper/YCSB/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brianfrankcooper/YCSB/merges","archive_url":"https://api.github.com/repos/brianfrankcooper/YCSB/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brianfrankcooper/YCSB/downloads","issues_url":"https://api.github.com/repos/brianfrankcooper/YCSB/issues{/number}","pulls_url":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls{/number}","milestones_url":"https://api.github.com/repos/brianfrankcooper/YCSB/milestones{/number}","notifications_url":"https://api.github.com/repos/brianfrankcooper/YCSB/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brianfrankcooper/YCSB/labels{/name}","releases_url":"https://api.github.com/repos/brianfrankcooper/YCSB/releases{/id}","created_at":"2010-04-19T20:52:11Z","updated_at":"2016-01-06T13:26:07Z","pushed_at":"2016-01-06T14:45:27Z","git_url":"git://github.com/brianfrankcooper/YCSB.git","ssh_url":"git@github.com:brianfrankcooper/YCSB.git","clone_url":"https://github.com/brianfrankcooper/YCSB.git","svn_url":"https://github.com/brianfrankcooper/YCSB","homepage":"http://research.yahoo.com/Web_Information_Management/YCSB","size":176160,"stargazers_count":1046,"watchers_count":1046,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":710,"mirror_url":null,"open_issues_count":140,"forks":710,"open_issues":140,"watchers":1046,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574"},"html":{"href":"https://github.com/brianfrankcooper/YCSB/pull/574"},"issue":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/issues/574"},"comments":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/issues/574/comments"},"review_comments":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574/comments"},"review_comment":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/pulls/574/commits"},"statuses":{"href":"https://api.github.com/repos/brianfrankcooper/YCSB/statuses/b07fbf0e182c74639d16e587192883a1e08654f6"}}}}