{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments/70643313","id":70643313,"diff_hunk":"@@ -0,0 +1,113 @@\n+/*\n+ * Copyright © 2016 Cask Data, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n+ * use this file except in compliance with the License. You may obtain a copy of\n+ * 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, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+ * License for the specific language governing permissions and limitations under\n+ * the License.\n+ */\n+package co.cask.hydrator.plugin.batch;\n+\n+import co.cask.cdap.api.annotation.Description;\n+import co.cask.cdap.api.annotation.Name;\n+import co.cask.cdap.api.annotation.Plugin;\n+import co.cask.cdap.api.data.format.StructuredRecord;\n+import co.cask.cdap.api.data.schema.Schema;\n+import co.cask.cdap.api.dataset.lib.KeyValue;\n+import co.cask.cdap.etl.api.Emitter;\n+import co.cask.cdap.etl.api.PipelineConfigurer;\n+import co.cask.cdap.etl.api.batch.BatchRuntimeContext;\n+import co.cask.cdap.etl.api.batch.BatchSink;\n+import co.cask.cdap.etl.api.batch.BatchSinkContext;\n+import co.cask.hydrator.plugin.common.SolrSearchSinkConfig;\n+import co.cask.hydrator.plugin.common.SolrSearchSinkUtility;\n+import org.apache.hadoop.mapreduce.Job;\n+import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat;\n+import org.apache.solr.client.solrj.SolrClient;\n+import org.apache.solr.common.SolrInputDocument;\n+import org.apache.solr.common.SolrInputField;\n+\n+import java.util.Map;\n+\n+/**\n+ * Batch SolrSearch Sink Plugin - Writes data to a Sinlge Node Solr or to SolrCloud.\n+ */\n+@Plugin(type = BatchSink.PLUGIN_TYPE)\n+@Name(\"SolrSearch\")\n+@Description(\"This plugin allows users to build the pipelines to write data to Solr. \" +\n+  \"The input fields coming from the previous stage of the pipeline are mapped to Solr fields. User can also specify \" +\n+  \"the mode of the Solr to connect to. For example, Single Node Solr or SolrCloud.\")\n+public class SolrSearchSink extends BatchSink<StructuredRecord, SolrInputField, SolrInputDocument> {\n+\n+  private final SolrSearchSinkConfig config;\n+  private String uniqueKey;\n+  private Map<String, String> outputFieldMap;\n+  private SolrClient solrClient;\n+\n+  public SolrSearchSink(SolrSearchSinkConfig config) {\n+    this.config = config;\n+  }\n+\n+  @Override\n+  public void prepareRun(BatchSinkContext batchSinkContext) throws Exception {\n+    // Setting outputformat class in order to resolve the 'Output directory not set' error.\n+    Job job = batchSinkContext.getHadoopJob();\n+    job.setOutputFormatClass(NullOutputFormat.class);\n+  }\n+\n+  @Override\n+  public void configurePipeline(PipelineConfigurer pipelineConfigurer) {\n+    Schema inputSchema = pipelineConfigurer.getStageConfigurer().getInputSchema();\n+    SolrSearchSinkUtility.validateSolrConnectionString(config);\n+    SolrSearchSinkUtility.verifySolrConfiguration(config);\n+    if (inputSchema != null) {\n+      SolrSearchSinkUtility.validateIdField(inputSchema, config);\n+      SolrSearchSinkUtility.validateInputFieldsDataType(inputSchema);\n+    }\n+  }\n+\n+  @Override\n+  public void initialize(BatchRuntimeContext context) throws Exception {\n+    uniqueKey = config.getIdField();\n+    outputFieldMap = config.getOutputFieldMap();\n+    solrClient = SolrSearchSinkUtility.getSolrConnection(config);\n+  }\n+\n+  @Override\n+  public void transform(StructuredRecord structuredRecord, Emitter<KeyValue<SolrInputField, SolrInputDocument>> emitter)\n+    throws Exception {\n+    String solrFieldName;\n+    SolrInputDocument document;\n+\n+    SolrSearchSinkUtility.validateIdField(structuredRecord.getSchema(), config);\n+    SolrSearchSinkUtility.validateInputFieldsDataType(structuredRecord.getSchema());\n+\n+    if (structuredRecord.get(uniqueKey) == null) {\n+      return;\n+    }\n+    document = new SolrInputDocument();\n+    for (Schema.Field field : structuredRecord.getSchema().getFields()) {\n+      solrFieldName = field.getName();\n+      if (outputFieldMap.containsKey(solrFieldName)) {\n+        document.addField(outputFieldMap.get(solrFieldName), structuredRecord.get(solrFieldName));\n+      } else {\n+        document.addField(solrFieldName, structuredRecord.get(solrFieldName));\n+      }\n+    }\n+    solrClient.add(document);\n+    solrClient.commit();","path":"solrsearch-plugins/src/main/java/co.cask.hydrator.plugin/batch/SolrSearchSink.java","position":104,"original_position":105,"commit_id":"656f6da70d375a0342b0e19c885a974693a6a165","original_commit_id":"d9ea06c15a570d2e3ca7a2d2742a392084e274fd","user":{"login":"rashig","id":13198718,"avatar_url":"https://avatars.githubusercontent.com/u/13198718?v=3","gravatar_id":"","url":"https://api.github.com/users/rashig","html_url":"https://github.com/rashig","followers_url":"https://api.github.com/users/rashig/followers","following_url":"https://api.github.com/users/rashig/following{/other_user}","gists_url":"https://api.github.com/users/rashig/gists{/gist_id}","starred_url":"https://api.github.com/users/rashig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rashig/subscriptions","organizations_url":"https://api.github.com/users/rashig/orgs","repos_url":"https://api.github.com/users/rashig/repos","events_url":"https://api.github.com/users/rashig/events{/privacy}","received_events_url":"https://api.github.com/users/rashig/received_events","type":"User","site_admin":false},"body":"Started working on SolrSearch batch sink using SolrOutputFormat class, and I will update the PR once done.","created_at":"2016-07-13T15:04:26Z","updated_at":"2016-07-13T15:04:27Z","html_url":"https://github.com/caskdata/hydrator-plugins/pull/305#discussion_r70643313","pull_request_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305","_links":{"self":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments/70643313"},"html":{"href":"https://github.com/caskdata/hydrator-plugins/pull/305#discussion_r70643313"},"pull_request":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305","id":76761206,"html_url":"https://github.com/caskdata/hydrator-plugins/pull/305","diff_url":"https://github.com/caskdata/hydrator-plugins/pull/305.diff","patch_url":"https://github.com/caskdata/hydrator-plugins/pull/305.patch","issue_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/305","number":305,"state":"open","locked":false,"title":"Initial Draft for SolrSearch sink plugin.[CDAP 6178]","user":{"login":"rashig","id":13198718,"avatar_url":"https://avatars.githubusercontent.com/u/13198718?v=3","gravatar_id":"","url":"https://api.github.com/users/rashig","html_url":"https://github.com/rashig","followers_url":"https://api.github.com/users/rashig/followers","following_url":"https://api.github.com/users/rashig/following{/other_user}","gists_url":"https://api.github.com/users/rashig/gists{/gist_id}","starred_url":"https://api.github.com/users/rashig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rashig/subscriptions","organizations_url":"https://api.github.com/users/rashig/orgs","repos_url":"https://api.github.com/users/rashig/repos","events_url":"https://api.github.com/users/rashig/events{/privacy}","received_events_url":"https://api.github.com/users/rashig/received_events","type":"User","site_admin":false},"body":"SolrSearch Sink Plugin to write data to a Sinlge Node Solr or to SolrCloud. For design and implementation, please refer:\r\nhttps://wiki.cask.co/display/CE/Solr+Search+or+Cloudera+Search \r\n\r\n","created_at":"2016-07-08T14:27:30Z","updated_at":"2016-07-13T15:04:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2c7e2fb3fa08fdebb2d3ff4cddea70d0d53906a0","assignee":{"login":"albertshau","id":5215004,"avatar_url":"https://avatars.githubusercontent.com/u/5215004?v=3","gravatar_id":"","url":"https://api.github.com/users/albertshau","html_url":"https://github.com/albertshau","followers_url":"https://api.github.com/users/albertshau/followers","following_url":"https://api.github.com/users/albertshau/following{/other_user}","gists_url":"https://api.github.com/users/albertshau/gists{/gist_id}","starred_url":"https://api.github.com/users/albertshau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertshau/subscriptions","organizations_url":"https://api.github.com/users/albertshau/orgs","repos_url":"https://api.github.com/users/albertshau/repos","events_url":"https://api.github.com/users/albertshau/events{/privacy}","received_events_url":"https://api.github.com/users/albertshau/received_events","type":"User","site_admin":false},"assignees":[{"login":"albertshau","id":5215004,"avatar_url":"https://avatars.githubusercontent.com/u/5215004?v=3","gravatar_id":"","url":"https://api.github.com/users/albertshau","html_url":"https://github.com/albertshau","followers_url":"https://api.github.com/users/albertshau/followers","following_url":"https://api.github.com/users/albertshau/following{/other_user}","gists_url":"https://api.github.com/users/albertshau/gists{/gist_id}","starred_url":"https://api.github.com/users/albertshau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertshau/subscriptions","organizations_url":"https://api.github.com/users/albertshau/orgs","repos_url":"https://api.github.com/users/albertshau/repos","events_url":"https://api.github.com/users/albertshau/events{/privacy}","received_events_url":"https://api.github.com/users/albertshau/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305/commits","review_comments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305/comments","review_comment_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/305/comments","statuses_url":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/656f6da70d375a0342b0e19c885a974693a6a165","head":{"label":"rashig:develop","ref":"develop","sha":"656f6da70d375a0342b0e19c885a974693a6a165","user":{"login":"rashig","id":13198718,"avatar_url":"https://avatars.githubusercontent.com/u/13198718?v=3","gravatar_id":"","url":"https://api.github.com/users/rashig","html_url":"https://github.com/rashig","followers_url":"https://api.github.com/users/rashig/followers","following_url":"https://api.github.com/users/rashig/following{/other_user}","gists_url":"https://api.github.com/users/rashig/gists{/gist_id}","starred_url":"https://api.github.com/users/rashig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rashig/subscriptions","organizations_url":"https://api.github.com/users/rashig/orgs","repos_url":"https://api.github.com/users/rashig/repos","events_url":"https://api.github.com/users/rashig/events{/privacy}","received_events_url":"https://api.github.com/users/rashig/received_events","type":"User","site_admin":false},"repo":{"id":58214089,"name":"hydrator-plugins","full_name":"rashig/hydrator-plugins","owner":{"login":"rashig","id":13198718,"avatar_url":"https://avatars.githubusercontent.com/u/13198718?v=3","gravatar_id":"","url":"https://api.github.com/users/rashig","html_url":"https://github.com/rashig","followers_url":"https://api.github.com/users/rashig/followers","following_url":"https://api.github.com/users/rashig/following{/other_user}","gists_url":"https://api.github.com/users/rashig/gists{/gist_id}","starred_url":"https://api.github.com/users/rashig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rashig/subscriptions","organizations_url":"https://api.github.com/users/rashig/orgs","repos_url":"https://api.github.com/users/rashig/repos","events_url":"https://api.github.com/users/rashig/events{/privacy}","received_events_url":"https://api.github.com/users/rashig/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rashig/hydrator-plugins","description":"Cask Hydrator Plugins Repository","fork":true,"url":"https://api.github.com/repos/rashig/hydrator-plugins","forks_url":"https://api.github.com/repos/rashig/hydrator-plugins/forks","keys_url":"https://api.github.com/repos/rashig/hydrator-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rashig/hydrator-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rashig/hydrator-plugins/teams","hooks_url":"https://api.github.com/repos/rashig/hydrator-plugins/hooks","issue_events_url":"https://api.github.com/repos/rashig/hydrator-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/rashig/hydrator-plugins/events","assignees_url":"https://api.github.com/repos/rashig/hydrator-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/rashig/hydrator-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/rashig/hydrator-plugins/tags","blobs_url":"https://api.github.com/repos/rashig/hydrator-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rashig/hydrator-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rashig/hydrator-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/rashig/hydrator-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rashig/hydrator-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/rashig/hydrator-plugins/languages","stargazers_url":"https://api.github.com/repos/rashig/hydrator-plugins/stargazers","contributors_url":"https://api.github.com/repos/rashig/hydrator-plugins/contributors","subscribers_url":"https://api.github.com/repos/rashig/hydrator-plugins/subscribers","subscription_url":"https://api.github.com/repos/rashig/hydrator-plugins/subscription","commits_url":"https://api.github.com/repos/rashig/hydrator-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/rashig/hydrator-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/rashig/hydrator-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/rashig/hydrator-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/rashig/hydrator-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/rashig/hydrator-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rashig/hydrator-plugins/merges","archive_url":"https://api.github.com/repos/rashig/hydrator-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rashig/hydrator-plugins/downloads","issues_url":"https://api.github.com/repos/rashig/hydrator-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/rashig/hydrator-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/rashig/hydrator-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/rashig/hydrator-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rashig/hydrator-plugins/labels{/name}","releases_url":"https://api.github.com/repos/rashig/hydrator-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/rashig/hydrator-plugins/deployments","created_at":"2016-05-06T14:47:04Z","updated_at":"2016-05-06T14:47:07Z","pushed_at":"2016-07-13T14:56:31Z","git_url":"git://github.com/rashig/hydrator-plugins.git","ssh_url":"git@github.com:rashig/hydrator-plugins.git","clone_url":"https://github.com/rashig/hydrator-plugins.git","svn_url":"https://github.com/rashig/hydrator-plugins","homepage":"","size":2819,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"cd7dce446671015aa1e0115cc4a7a04a35d969bb","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":39922362,"name":"hydrator-plugins","full_name":"caskdata/hydrator-plugins","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/hydrator-plugins","description":"Cask Hydrator Plugins Repository","fork":false,"url":"https://api.github.com/repos/caskdata/hydrator-plugins","forks_url":"https://api.github.com/repos/caskdata/hydrator-plugins/forks","keys_url":"https://api.github.com/repos/caskdata/hydrator-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/hydrator-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/hydrator-plugins/teams","hooks_url":"https://api.github.com/repos/caskdata/hydrator-plugins/hooks","issue_events_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/hydrator-plugins/events","assignees_url":"https://api.github.com/repos/caskdata/hydrator-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/hydrator-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/hydrator-plugins/tags","blobs_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/hydrator-plugins/languages","stargazers_url":"https://api.github.com/repos/caskdata/hydrator-plugins/stargazers","contributors_url":"https://api.github.com/repos/caskdata/hydrator-plugins/contributors","subscribers_url":"https://api.github.com/repos/caskdata/hydrator-plugins/subscribers","subscription_url":"https://api.github.com/repos/caskdata/hydrator-plugins/subscription","commits_url":"https://api.github.com/repos/caskdata/hydrator-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/hydrator-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/hydrator-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/hydrator-plugins/merges","archive_url":"https://api.github.com/repos/caskdata/hydrator-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/hydrator-plugins/downloads","issues_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/hydrator-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/hydrator-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/hydrator-plugins/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/hydrator-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/deployments","created_at":"2015-07-30T00:14:48Z","updated_at":"2016-07-04T15:58:46Z","pushed_at":"2016-07-13T14:56:32Z","git_url":"git://github.com/caskdata/hydrator-plugins.git","ssh_url":"git@github.com:caskdata/hydrator-plugins.git","clone_url":"https://github.com/caskdata/hydrator-plugins.git","svn_url":"https://github.com/caskdata/hydrator-plugins","homepage":"","size":3176,"stargazers_count":18,"watchers_count":18,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":8,"forks":13,"open_issues":8,"watchers":18,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305"},"html":{"href":"https://github.com/caskdata/hydrator-plugins/pull/305"},"issue":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/305"},"comments":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/305/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/305/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/656f6da70d375a0342b0e19c885a974693a6a165"}}}}
{"actor":{"display_login":"rashig"}}