{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/55928135","id":55928135,"diff_hunk":"@@ -0,0 +1,423 @@\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+\n+package co.cask.cdap.admin;\n+\n+import co.cask.cdap.api.Admin;\n+import co.cask.cdap.api.RuntimeContext;\n+import co.cask.cdap.api.annotation.ProcessInput;\n+import co.cask.cdap.api.app.AbstractApplication;\n+import co.cask.cdap.api.common.Bytes;\n+import co.cask.cdap.api.dataset.DatasetManagementException;\n+import co.cask.cdap.api.dataset.DatasetProperties;\n+import co.cask.cdap.api.dataset.InstanceConflictException;\n+import co.cask.cdap.api.dataset.InstanceNotFoundException;\n+import co.cask.cdap.api.dataset.lib.FileSet;\n+import co.cask.cdap.api.dataset.lib.KeyValueTable;\n+import co.cask.cdap.api.dataset.table.Table;\n+import co.cask.cdap.api.flow.AbstractFlow;\n+import co.cask.cdap.api.flow.flowlet.AbstractFlowlet;\n+import co.cask.cdap.api.flow.flowlet.OutputEmitter;\n+import co.cask.cdap.api.flow.flowlet.StreamEvent;\n+import co.cask.cdap.api.mapreduce.AbstractMapReduce;\n+import co.cask.cdap.api.mapreduce.MapReduceContext;\n+import co.cask.cdap.api.service.AbstractService;\n+import co.cask.cdap.api.service.http.AbstractHttpServiceHandler;\n+import co.cask.cdap.api.service.http.HttpServiceRequest;\n+import co.cask.cdap.api.service.http.HttpServiceResponder;\n+import co.cask.cdap.api.spark.AbstractSpark;\n+import co.cask.cdap.api.spark.JavaSparkProgram;\n+import co.cask.cdap.api.spark.SparkContext;\n+import co.cask.cdap.api.worker.AbstractWorker;\n+import co.cask.cdap.api.workflow.AbstractWorkflow;\n+import co.cask.cdap.api.workflow.AbstractWorkflowAction;\n+import co.cask.cdap.internal.guava.reflect.TypeToken;\n+import com.google.common.base.Throwables;\n+import com.google.common.collect.Iterables;\n+import com.google.gson.Gson;\n+import org.apache.hadoop.io.LongWritable;\n+import org.apache.hadoop.io.Text;\n+import org.apache.hadoop.mapreduce.Job;\n+import org.apache.hadoop.mapreduce.Mapper;\n+import org.apache.hadoop.mapreduce.Reducer;\n+import org.apache.spark.api.java.JavaPairRDD;\n+import org.apache.spark.api.java.JavaRDD;\n+import org.apache.spark.api.java.function.FlatMapFunction;\n+import org.apache.spark.api.java.function.Function2;\n+import org.apache.spark.api.java.function.PairFunction;\n+import org.junit.Assert;\n+import scala.Tuple2;\n+\n+import java.io.IOException;\n+import java.util.Arrays;\n+import java.util.HashMap;\n+import java.util.Map;\n+import javax.ws.rs.DELETE;\n+import javax.ws.rs.GET;\n+import javax.ws.rs.POST;\n+import javax.ws.rs.PUT;\n+import javax.ws.rs.Path;\n+import javax.ws.rs.PathParam;\n+\n+public class AdminApp extends AbstractApplication {\n+\n+  public static final String FLOW_NAME = \"AdminFlow\";\n+  public static final String MAPREDUCE_NAME = \"AdminMapReduce\";\n+  public static final String SPARK_NAME = \"AdminSpark\";\n+  public static final String SPARK_SCALA_NAME = \"AdminScalaSpark\";\n+  public static final String SERVICE_NAME = \"AdminService\";\n+  public static final String WORKER_NAME = \"AdminWorker\";\n+  public static final String WORKFLOW_NAME = \"AdminWorkflow\";\n+\n+  @Override\n+  public void configure() {\n+    addStream(\"events\");\n+    addFlow(new AdminFlow());\n+    addMapReduce(new AdminMapReduce());\n+    addSpark(new AdminSpark());\n+    addSpark(new AdminScalaSpark());\n+    addWorker(new AdminWorker());\n+    addWorkflow(new AdminWorkflow());\n+    addService(new AbstractService() {\n+      @Override\n+      protected void configure() {\n+        setName(SERVICE_NAME);\n+        addHandler(new DatasetAdminHandler());\n+      }\n+    });\n+  }\n+\n+  public static class DatasetAdminHandler extends AbstractHttpServiceHandler {\n+\n+    private static final Gson GSON = new Gson();\n+\n+    @GET\n+    @Path(\"exists/{dataset}\")\n+    public void exists(HttpServiceRequest request, HttpServiceResponder responder,\n+                       @PathParam(\"dataset\") String dataset) throws DatasetManagementException {\n+      Admin admin = getContext().getAdmin();\n+      responder.sendString(Boolean.toString(admin.datasetExists(dataset)));\n+    }\n+\n+    @GET\n+    @Path(\"type/{dataset}\")\n+    public void type(HttpServiceRequest request, HttpServiceResponder responder,\n+                     @PathParam(\"dataset\") String dataset) throws DatasetManagementException {\n+      Admin admin = getContext().getAdmin();\n+      String type = admin.getDatasetType(dataset);\n+      if (type == null) {\n+        responder.sendStatus(404);","path":"cdap-unit-test/src/test/java/co/cask/cdap/admin/AdminApp.java","position":122,"original_position":122,"commit_id":"6f32e3ba9a797eeab0711491aebd653ef2eaca97","original_commit_id":"5ae6f9320628036bd7ce16c753097b54454aedae","user":{"login":"anew","id":483004,"avatar_url":"https://avatars.githubusercontent.com/u/483004?v=3","gravatar_id":"","url":"https://api.github.com/users/anew","html_url":"https://github.com/anew","followers_url":"https://api.github.com/users/anew/followers","following_url":"https://api.github.com/users/anew/following{/other_user}","gists_url":"https://api.github.com/users/anew/gists{/gist_id}","starred_url":"https://api.github.com/users/anew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anew/subscriptions","organizations_url":"https://api.github.com/users/anew/orgs","repos_url":"https://api.github.com/users/anew/repos","events_url":"https://api.github.com/users/anew/events{/privacy}","received_events_url":"https://api.github.com/users/anew/received_events","type":"User","site_admin":false},"body":"Although, that makes the app depend on netty. Since CDAP does not expose constants for HTTP codes, I'd rather not use that. ","created_at":"2016-03-12T21:42:23Z","updated_at":"2016-03-12T21:42:23Z","html_url":"https://github.com/caskdata/cdap/pull/5290#discussion_r55928135","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/5290","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/55928135"},"html":{"href":"https://github.com/caskdata/cdap/pull/5290#discussion_r55928135"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5290"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/5290","id":62627308,"html_url":"https://github.com/caskdata/cdap/pull/5290","diff_url":"https://github.com/caskdata/cdap/pull/5290.diff","patch_url":"https://github.com/caskdata/cdap/pull/5290.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/5290","number":5290,"state":"open","locked":false,"title":"[cdap 3051] dataset admin in programs","user":{"login":"anew","id":483004,"avatar_url":"https://avatars.githubusercontent.com/u/483004?v=3","gravatar_id":"","url":"https://api.github.com/users/anew","html_url":"https://github.com/anew","followers_url":"https://api.github.com/users/anew/followers","following_url":"https://api.github.com/users/anew/following{/other_user}","gists_url":"https://api.github.com/users/anew/gists{/gist_id}","starred_url":"https://api.github.com/users/anew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anew/subscriptions","organizations_url":"https://api.github.com/users/anew/orgs","repos_url":"https://api.github.com/users/anew/repos","events_url":"https://api.github.com/users/anew/events{/privacy}","received_events_url":"https://api.github.com/users/anew/received_events","type":"User","site_admin":false},"body":"Adds the ability to perform dataset admin operations in programs. \r\n- Design: https://wiki.cask.co/display/CE/Operations+in+Apps\r\n- Jira: https://issues.cask.co/browse/CDAP-3051\r\n- Build: http://builds.cask.co/browse/CDAP-DUT3657\r\n\r\nDetails: \r\n- adds a new interface Admin and a way to getAdmin() from every program context (through RuntimeContext). The Admin interface will be extended in the future to support more operations.\r\n- implementation of Admin using RemoteDatasetFramework. This is necessary (instead of instantiating a DatasetAdmin and calling it directly in the program context) because we need to make sure meta data and lineage are recorded correctly (which DatasetAdmin would not do).\r\n- Therefore added a truncateInstance() method to DatasetFramework and its implementations.\r\n- Also, moved the DatasetManagementException and its subclasses to API. That causes lots of changes in other classes' imports\r\n- A few minor fixes to DatasetFramework to throw a not-found exception when a dataset is not found (it used to throw a conflict exception).\r\n- Added test cases to test admin operations in flows, services, workers, workflow actions, mapreduce, and spark. \r\n","created_at":"2016-03-12T02:02:59Z","updated_at":"2016-03-12T21:42:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a74c905685557d45cfb1c172377c149dcd8eeba7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/5290/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/5290/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/5290/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/6f32e3ba9a797eeab0711491aebd653ef2eaca97","head":{"label":"caskdata:feature/cdap-3051-admin-in-programs","ref":"feature/cdap-3051-admin-in-programs","sha":"6f32e3ba9a797eeab0711491aebd653ef2eaca97","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":22542759,"name":"cdap","full_name":"caskdata/cdap","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/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/cdap/deployments","created_at":"2014-08-02T09:00:10Z","updated_at":"2016-03-07T20:33:21Z","pushed_at":"2016-03-12T21:27:38Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":534673,"stargazers_count":105,"watchers_count":105,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":36,"mirror_url":null,"open_issues_count":20,"forks":36,"open_issues":20,"watchers":105,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"045c85917c8f3ac1633fb7361e0d949dd93978e0","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":22542759,"name":"cdap","full_name":"caskdata/cdap","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/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/cdap/deployments","created_at":"2014-08-02T09:00:10Z","updated_at":"2016-03-07T20:33:21Z","pushed_at":"2016-03-12T21:27:38Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":534673,"stargazers_count":105,"watchers_count":105,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":36,"mirror_url":null,"open_issues_count":20,"forks":36,"open_issues":20,"watchers":105,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5290"},"html":{"href":"https://github.com/caskdata/cdap/pull/5290"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/5290"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/5290/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5290/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/5290/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/6f32e3ba9a797eeab0711491aebd653ef2eaca97"}}}}