{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/25296955","id":25296955,"diff_hunk":"@@ -0,0 +1,195 @@\n+/*\n+ * Copyright © 2015 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.data.tools;\n+\n+import co.cask.cdap.api.common.Bytes;\n+import co.cask.cdap.api.dataset.DatasetDefinition;\n+import co.cask.cdap.api.dataset.DatasetProperties;\n+import co.cask.cdap.api.dataset.table.Row;\n+import co.cask.cdap.api.dataset.table.Scanner;\n+import co.cask.cdap.api.dataset.table.Table;\n+import co.cask.cdap.app.runtime.ProgramController;\n+import co.cask.cdap.common.conf.Constants;\n+import co.cask.cdap.data2.datafabric.dataset.DatasetsUtil;\n+import co.cask.cdap.data2.dataset2.lib.table.MDSKey;\n+import co.cask.cdap.data2.dataset2.tx.Transactional;\n+import co.cask.cdap.internal.app.store.AppMetadataStore;\n+import co.cask.cdap.internal.app.store.ApplicationMeta;\n+import co.cask.cdap.internal.app.store.DefaultStore;\n+import co.cask.cdap.notifications.feeds.service.MDSNotificationFeedStore;\n+import co.cask.cdap.proto.Id;\n+import co.cask.cdap.proto.RunRecord;\n+import co.cask.tephra.TransactionExecutor;\n+import com.google.common.base.Supplier;\n+import com.google.common.base.Throwables;\n+import com.google.common.collect.Iterators;\n+import com.google.inject.Injector;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.net.URI;\n+import java.net.URISyntaxException;\n+import java.util.Iterator;\n+\n+/**\n+ * Upgraded the Meta Data for applications\n+ */\n+public class MDSUpgrade extends AbstractUpgrade implements Upgrade {\n+\n+  private static final Logger LOG = LoggerFactory.getLogger(MDSUpgrade.class);\n+  private static final String[] OTHERS = {AppMetadataStore.TYPE_STREAM, AppMetadataStore.TYPE_NAMESPACE,\n+    MDSNotificationFeedStore.TYPE_NOTIFICATION_FEED};\n+\n+  private final Transactional<UpgradeTable, Table> appMDS;\n+\n+  public MDSUpgrade() {\n+    this.appMDS = Transactional.of(executorFactory, new Supplier<UpgradeTable>() {\n+      @Override\n+      public UpgradeTable get() {\n+        try {\n+          Table table = DatasetsUtil.getOrCreateDataset(namespacedFramework, Id.DatasetInstance.from\n+                                                          (Constants.SYSTEM_NAMESPACE_ID, DefaultStore.APP_META_TABLE),\n+                                                        \"table\", DatasetProperties.EMPTY,\n+                                                        DatasetDefinition.NO_ARGUMENTS, null);\n+          return new UpgradeTable(table);\n+        } catch (Exception e) {\n+          LOG.error(\"Failed to access {} table\", DefaultStore.APP_META_TABLE, e);\n+          throw Throwables.propagate(e);\n+        }\n+      }\n+    });\n+  }\n+\n+  @Override\n+  public void upgrade(Injector injector) throws Exception {\n+    appMDS.executeUnchecked(new TransactionExecutor.\n+      Function<UpgradeTable, Void>() {\n+      @Override\n+      public Void apply(UpgradeTable configTable) throws Exception {\n+        Scanner rows = configTable.table.scan(null, null);\n+        Row row;\n+        while ((row = rows.next()) != null) {\n+          String key = Bytes.toString(row.getRow()).trim();\n+          if (key.contains(AppMetadataStore.TYPE_APP_META)) {","path":"cdap-master/src/main/java/co/cask/cdap/data/tools/MDSUpgrade.java","position":87,"original_position":87,"commit_id":"31c2d53416eb106d4501072c72a825aee97e48ac","original_commit_id":"31c2d53416eb106d4501072c72a825aee97e48ac","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":"Should use ``MDSKey`` for deserialization, get the string and then compare with equals, I think. Much cleaner and safer. Perhaps create the ``MDSKey`` here and pass it to the handler methods below, instead of creating it in each method. The String contains operations you have here may not be as safe.","created_at":"2015-02-24T21:56:30Z","updated_at":"2015-02-24T21:56:30Z","html_url":"https://github.com/caskdata/cdap/pull/1388#discussion_r25296955","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/1388","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/25296955"},"html":{"href":"https://github.com/caskdata/cdap/pull/1388#discussion_r25296955"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1388"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/1388","id":29793553,"html_url":"https://github.com/caskdata/cdap/pull/1388","diff_url":"https://github.com/caskdata/cdap/pull/1388.diff","patch_url":"https://github.com/caskdata/cdap/pull/1388.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/1388","number":1388,"state":"open","locked":false,"title":"Upgrade tool for 2.8","user":{"login":"rohitsinha54","id":1472867,"avatar_url":"https://avatars.githubusercontent.com/u/1472867?v=3","gravatar_id":"","url":"https://api.github.com/users/rohitsinha54","html_url":"https://github.com/rohitsinha54","followers_url":"https://api.github.com/users/rohitsinha54/followers","following_url":"https://api.github.com/users/rohitsinha54/following{/other_user}","gists_url":"https://api.github.com/users/rohitsinha54/gists{/gist_id}","starred_url":"https://api.github.com/users/rohitsinha54/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohitsinha54/subscriptions","organizations_url":"https://api.github.com/users/rohitsinha54/orgs","repos_url":"https://api.github.com/users/rohitsinha54/repos","events_url":"https://api.github.com/users/rohitsinha54/events{/privacy}","received_events_url":"https://api.github.com/users/rohitsinha54/received_events","type":"User","site_admin":false},"body":"An initial PR for Upgrade tool for review.\r\nThe Upgrade tool currently does:\r\n- Creates the default namespace\r\n- Does application meta upgrade\r\n- Does log.meta upgrade\r\n- Does Archive upgrades\r\n","created_at":"2015-02-23T09:02:47Z","updated_at":"2015-02-24T21:56:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc80d79ec683e7cc145aeb0bd79c67a7a9870e5a","assignee":{"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},"milestone":{"url":"https://api.github.com/repos/caskdata/cdap/milestones/3","labels_url":"https://api.github.com/repos/caskdata/cdap/milestones/3/labels","id":944584,"number":3,"title":"2.8.0","description":null,"creator":{"login":"jwang47","id":1084704,"avatar_url":"https://avatars.githubusercontent.com/u/1084704?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang47","html_url":"https://github.com/jwang47","followers_url":"https://api.github.com/users/jwang47/followers","following_url":"https://api.github.com/users/jwang47/following{/other_user}","gists_url":"https://api.github.com/users/jwang47/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang47/subscriptions","organizations_url":"https://api.github.com/users/jwang47/orgs","repos_url":"https://api.github.com/users/jwang47/repos","events_url":"https://api.github.com/users/jwang47/events{/privacy}","received_events_url":"https://api.github.com/users/jwang47/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":83,"state":"open","created_at":"2015-01-21T01:15:14Z","updated_at":"2015-02-24T19:25:15Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/1388/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/1388/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/1388/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/31c2d53416eb106d4501072c72a825aee97e48ac","head":{"label":"caskdata:feature/upgrade-tool","ref":"feature/upgrade-tool","sha":"31c2d53416eb106d4501072c72a825aee97e48ac","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}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-02-24T19:25:16Z","pushed_at":"2015-02-24T21:56:20Z","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":784314,"stargazers_count":27,"watchers_count":27,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":9,"mirror_url":null,"open_issues_count":22,"forks":9,"open_issues":22,"watchers":27,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"8da3370a3073d552f544162d283e3997e623e0ce","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}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-02-24T19:25:16Z","pushed_at":"2015-02-24T21:56:20Z","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":784314,"stargazers_count":27,"watchers_count":27,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":9,"mirror_url":null,"open_issues_count":22,"forks":9,"open_issues":22,"watchers":27,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1388"},"html":{"href":"https://github.com/caskdata/cdap/pull/1388"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/1388"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/1388/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1388/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1388/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/31c2d53416eb106d4501072c72a825aee97e48ac"}}}}