{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/88970621","pull_request_review_id":9521711,"id":88970621,"diff_hunk":"@@ -16,46 +16,145 @@\n \n package co.cask.cdap.internal.app.preview;\n \n+import co.cask.cdap.api.artifact.ArtifactScope;\n import co.cask.cdap.api.metrics.MetricTimeSeries;\n import co.cask.cdap.app.preview.PreviewManager;\n import co.cask.cdap.app.preview.PreviewStatus;\n+import co.cask.cdap.app.runtime.ProgramController;\n+import co.cask.cdap.app.runtime.ProgramRuntimeService;\n+import co.cask.cdap.app.store.preview.PreviewStore;\n import co.cask.cdap.common.NotFoundException;\n+import co.cask.cdap.internal.app.deploy.ProgramTerminator;\n+import co.cask.cdap.internal.app.runtime.AbstractListener;\n+import co.cask.cdap.internal.app.services.ApplicationLifecycleService;\n+import co.cask.cdap.internal.app.services.ProgramLifecycleService;\n+import co.cask.cdap.proto.BasicThrowable;\n+import co.cask.cdap.proto.Id;\n+import co.cask.cdap.proto.ProgramType;\n import co.cask.cdap.proto.artifact.AppRequest;\n+import co.cask.cdap.proto.artifact.ArtifactSummary;\n import co.cask.cdap.proto.id.ApplicationId;\n import co.cask.cdap.proto.id.NamespaceId;\n+import co.cask.cdap.proto.id.ProgramId;\n+import com.google.gson.Gson;\n+import com.google.gson.JsonElement;\n+import com.google.inject.Inject;\n import org.apache.twill.api.logging.LogEntry;\n+import org.apache.twill.common.Threads;\n \n+import java.util.ArrayList;\n import java.util.Collection;\n+import java.util.HashMap;\n import java.util.List;\n import java.util.Map;\n+import javax.annotation.Nullable;\n \n /**\n  * Default implementation of the {@link PreviewManager}.\n  */\n public class DefaultPreviewManager implements PreviewManager {\n+  private static final Gson GSON = new Gson();\n+  private final ApplicationLifecycleService applicationLifecycleService;\n+  private final ProgramLifecycleService programLifecycleService;\n+  private final PreviewStore previewStore;\n+  private PreviewStatus status;\n+  private AppRequest request;\n+\n+  @Inject\n+  DefaultPreviewManager(ApplicationLifecycleService applicationLifecycleService,\n+                        ProgramLifecycleService programLifecycleService, PreviewStore previewStore) {\n+    this.applicationLifecycleService = applicationLifecycleService;\n+    this.programLifecycleService = programLifecycleService;\n+    this.previewStore = previewStore;\n+    this.status = null;\n+  }\n+\n   @Override\n-  public ApplicationId start(NamespaceId namespaceId, AppRequest<?> request) throws Exception {\n-    return null;\n+  public void start(ApplicationId preview, AppRequest<?> request) throws Exception {\n+    this.request = request;\n+    ArtifactSummary artifactSummary = request.getArtifact();\n+    NamespaceId artifactNamespace = ArtifactScope.SYSTEM.equals((artifactSummary.getScope())) ? NamespaceId.SYSTEM\n+      : preview.getParent();\n+\n+    Id.Artifact artifactId =\n+      Id.Artifact.from(artifactNamespace.toId(), artifactSummary.getName(), artifactSummary.getVersion());\n+\n+    String config = request.getConfig() == null ? null : GSON.toJson(request.getConfig());\n+\n+    try {\n+      applicationLifecycleService.deployApp(preview.getParent(), preview.getApplication(), preview.getVersion(),\n+                                            artifactId, config, new ProgramTerminator() {\n+        @Override\n+        public void stop(ProgramId programId) throws Exception {\n+\n+        }\n+      });\n+    } catch (Exception e) {\n+      this.status = new PreviewStatus(PreviewStatus.Status.DEPLOY_FAILED, new BasicThrowable(e));\n+      return;\n+    }\n+\n+    ProgramId programId = getProgramIdFromRequest(preview, request);\n+    ProgramRuntimeService.RuntimeInfo runtimeInfo = programLifecycleService.start(programId,\n+                                                                                  new HashMap<String, String>(),\n+                                                                                  new HashMap<String, String>(), false);\n+\n+    runtimeInfo.getController().addListener(new AbstractListener() {\n+      @Override\n+      public void init(ProgramController.State currentState, @Nullable Throwable cause) {\n+        status = new PreviewStatus(PreviewStatus.Status.RUNNING, null);\n+      }\n+\n+      @Override\n+      public void completed() {\n+        status = new PreviewStatus(PreviewStatus.Status.COMPLETED, null);\n+      }\n+\n+      @Override\n+      public void killed() {\n+        status = new PreviewStatus(PreviewStatus.Status.KILLED, null);\n+      }\n+\n+      @Override\n+      public void error(Throwable cause) {\n+        status = new PreviewStatus(PreviewStatus.Status.RUN_FAILED, new BasicThrowable(cause));\n+      }\n+    }, Threads.SAME_THREAD_EXECUTOR);\n+  }\n+\n+  private ProgramId getProgramIdFromRequest(ApplicationId preview, AppRequest request) {\n+    if (request.getPreview() == null) {","path":"cdap-app-fabric/src/main/java/co/cask/cdap/internal/app/preview/DefaultPreviewManager.java","position":113,"original_position":113,"commit_id":"d755096aa75dad8926294af35b0f8ecf7aa8bfcf","original_commit_id":"d755096aa75dad8926294af35b0f8ecf7aa8bfcf","user":{"login":"bdmogal","id":3895099,"avatar_url":"https://avatars.githubusercontent.com/u/3895099?v=3","gravatar_id":"","url":"https://api.github.com/users/bdmogal","html_url":"https://github.com/bdmogal","followers_url":"https://api.github.com/users/bdmogal/followers","following_url":"https://api.github.com/users/bdmogal/following{/other_user}","gists_url":"https://api.github.com/users/bdmogal/gists{/gist_id}","starred_url":"https://api.github.com/users/bdmogal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdmogal/subscriptions","organizations_url":"https://api.github.com/users/bdmogal/orgs","repos_url":"https://api.github.com/users/bdmogal/repos","events_url":"https://api.github.com/users/bdmogal/events{/privacy}","received_events_url":"https://api.github.com/users/bdmogal/received_events","type":"User","site_admin":false},"body":"add a todo to remove this?","created_at":"2016-11-21T19:33:57Z","updated_at":"2016-11-21T19:33:57Z","html_url":"https://github.com/caskdata/cdap/pull/7153#discussion_r88970621","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/7153","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/88970621"},"html":{"href":"https://github.com/caskdata/cdap/pull/7153#discussion_r88970621"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/7153"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/7153","id":94657822,"html_url":"https://github.com/caskdata/cdap/pull/7153","diff_url":"https://github.com/caskdata/cdap/pull/7153.diff","patch_url":"https://github.com/caskdata/cdap/pull/7153.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/7153","number":7153,"state":"open","locked":false,"title":"Implementation of PreviewManager.","user":{"login":"sagarkapare","id":5713570,"avatar_url":"https://avatars.githubusercontent.com/u/5713570?v=3","gravatar_id":"","url":"https://api.github.com/users/sagarkapare","html_url":"https://github.com/sagarkapare","followers_url":"https://api.github.com/users/sagarkapare/followers","following_url":"https://api.github.com/users/sagarkapare/following{/other_user}","gists_url":"https://api.github.com/users/sagarkapare/gists{/gist_id}","starred_url":"https://api.github.com/users/sagarkapare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sagarkapare/subscriptions","organizations_url":"https://api.github.com/users/sagarkapare/orgs","repos_url":"https://api.github.com/users/sagarkapare/repos","events_url":"https://api.github.com/users/sagarkapare/events{/privacy}","received_events_url":"https://api.github.com/users/sagarkapare/received_events","type":"User","site_admin":false},"body":"This PR contains changes to launch the preview and fetch the data generated for the preview. It also contains the DatasetFramework changes cherry-picked from #7120 added for end-to-end testing purpose. ","created_at":"2016-11-21T17:14:38Z","updated_at":"2016-11-21T19:51:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b5c811b7056696743254b9fe4c481058a082818c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/7153/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/7153/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/7153/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/d755096aa75dad8926294af35b0f8ecf7aa8bfcf","head":{"label":"caskdata:fix/preview-manager-impl","ref":"fix/preview-manager-impl","sha":"d755096aa75dad8926294af35b0f8ecf7aa8bfcf","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-11-20T06:59:34Z","pushed_at":"2016-11-21T19:39:08Z","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":668151,"stargazers_count":145,"watchers_count":145,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":65,"mirror_url":null,"open_issues_count":19,"forks":65,"open_issues":19,"watchers":145,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"f900af961da8e4bffdbcd23944f4468dd274de97","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-11-20T06:59:34Z","pushed_at":"2016-11-21T19:39:08Z","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":668151,"stargazers_count":145,"watchers_count":145,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":65,"mirror_url":null,"open_issues_count":19,"forks":65,"open_issues":19,"watchers":145,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/7153"},"html":{"href":"https://github.com/caskdata/cdap/pull/7153"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/7153"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/7153/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/7153/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/7153/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/d755096aa75dad8926294af35b0f8ecf7aa8bfcf"}}}}
{"actor":{"display_login":"bdmogal"}}