{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/25230811","id":25230811,"diff_hunk":"@@ -0,0 +1,122 @@\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.data2.transaction.queue;\n+\n+import co.cask.cdap.common.conf.CConfiguration;\n+import co.cask.cdap.common.conf.Constants;\n+import co.cask.cdap.common.queue.QueueName;\n+import co.cask.cdap.data2.datafabric.DefaultDatasetNamespace;\n+import co.cask.cdap.data2.util.hbase.HBaseTableUtil;\n+import co.cask.cdap.proto.Id;\n+\n+/**\n+ * Common implementation of table-based QueueAdmin\n+ */\n+public abstract class AbstractQueueAdmin implements QueueAdmin {\n+  private final String unqualifiedTableNamePrefix;\n+  private final String unqualifiedConfigTableNameSuffix;\n+  protected final DefaultDatasetNamespace namespace;\n+\n+  public AbstractQueueAdmin(CConfiguration conf, QueueConstants.QueueType type) {\n+    // system scoped\n+    // todo: we have to do that because queues do not follow dataset semantic fully (yet)\n+    this.unqualifiedTableNamePrefix = Constants.SYSTEM_NAMESPACE + \".\" + type.toString();\n+    this.unqualifiedConfigTableNameSuffix = Constants.SYSTEM_NAMESPACE + \".\" + QueueConstants.QUEUE_CONFIG_TABLE_NAME;\n+    this.namespace = new DefaultDatasetNamespace(conf);\n+  }\n+\n+  /**\n+   * @param queueTableName actual queue table name\n+   * @return namespace id that this queue belongs to\n+   */\n+  public static String getNamespaceId(String queueTableName) {\n+    // last three parts are namespaceId, appName and flow\n+    String[] parts = queueTableName.split(\"\\\\.\");\n+    String namespaceId;\n+    if (parts.length == 6) {\n+      // cdap.<namespace>.system.queue.<app>.<flow>\n+      namespaceId = parts[1];\n+    } else {\n+      throw new IllegalArgumentException(String.format(\"Unexpected format for queue table name. \" +\n+                                                         \"Expected 'cdap.<namespace>.system.queue.<app>.<flow>'\" +\n+                                                         \"Received '%s'\",\n+                                                       queueTableName));\n+    }\n+    return namespaceId;\n+  }\n+\n+  /**\n+   * @param queueTableName actual queue table name\n+   * @return app name this queue belongs to\n+   */\n+  public static String getApplicationName(String queueTableName) {\n+    // last three parts are namespaceId (optional - in which case it will be the default namespace), appName and flow\n+    String[] parts = queueTableName.split(\"\\\\.\");\n+    return parts[parts.length - 2];\n+  }\n+\n+  /**\n+   * @param queueTableName actual queue table name\n+   * @return flow name this queue belongs to\n+   */\n+  public static String getFlowName(String queueTableName) {\n+    // last three parts are namespaceId (optional - in which case it will be the default namespace), appName and flow\n+    String[] parts = queueTableName.split(\"\\\\.\");\n+    return parts[parts.length - 1];\n+  }\n+\n+\n+  /**\n+   * This determines the actual table name from the table name prefix and the name of the queue.\n+   * @param queueName The name of the queue.\n+   * @return the full name of the table that holds this queue.\n+   */\n+  public String getActualTableName(QueueName queueName) {\n+    if (queueName.isQueue()) {\n+      // <root namespace>.<queue namespace>.system.queue.<app>.<flow>\n+      return getTableNameForFlow(queueName.getFirstComponent(),\n+                                 queueName.getSecondComponent(),\n+                                 queueName.getThirdComponent());\n+    } else {\n+      throw new IllegalArgumentException(\"'\" + queueName + \"' is not a valid name for a queue.\");\n+    }\n+  }\n+\n+  protected String getTableNameForFlow(String namespaceId, String app, String flow) {\n+    String tablePrefix = getTableNamePrefix(namespaceId);\n+    String tableName = tablePrefix + \".\" + app + \".\" + flow;\n+    return HBaseTableUtil.getHBaseTableName(tableName);\n+  }\n+\n+  public String getTableNamePrefix(String namespaceId) {\n+    // returns String with format:  '<root namespace>.<namespaceId>.system.(stream|queue)'\n+    String tablePrefix = namespace.namespace(Id.DatasetInstance.from(namespaceId,\n+                                                                     unqualifiedTableNamePrefix)).getId();\n+    return HBaseTableUtil.getHBaseTableName(tablePrefix);\n+  }\n+\n+  public String getConfigTableName(QueueName queueName) {\n+    return getConfigTableName(queueName.getFirstComponent());\n+  }\n+\n+  public String getConfigTableName(String namespaceId) {","path":"cdap-data-fabric/src/main/java/co/cask/cdap/data2/transaction/queue/AbstractQueueAdmin.java","position":116,"original_position":116,"commit_id":"83a50f95d0ce2f0ace7a77066712cec9335b7dcc","original_commit_id":"83a50f95d0ce2f0ace7a77066712cec9335b7dcc","user":{"login":"anwar6953","id":2440977,"avatar_url":"https://avatars.githubusercontent.com/u/2440977?v=3","gravatar_id":"","url":"https://api.github.com/users/anwar6953","html_url":"https://github.com/anwar6953","followers_url":"https://api.github.com/users/anwar6953/followers","following_url":"https://api.github.com/users/anwar6953/following{/other_user}","gists_url":"https://api.github.com/users/anwar6953/gists{/gist_id}","starred_url":"https://api.github.com/users/anwar6953/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anwar6953/subscriptions","organizations_url":"https://api.github.com/users/anwar6953/orgs","repos_url":"https://api.github.com/users/anwar6953/repos","events_url":"https://api.github.com/users/anwar6953/events{/privacy}","received_events_url":"https://api.github.com/users/anwar6953/received_events","type":"User","site_admin":false},"body":"no; used outside the package.","created_at":"2015-02-24T06:07:26Z","updated_at":"2015-02-24T06:07:26Z","html_url":"https://github.com/caskdata/cdap/pull/1406#discussion_r25230811","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/1406","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/25230811"},"html":{"href":"https://github.com/caskdata/cdap/pull/1406#discussion_r25230811"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1406"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/1406","id":29866820,"html_url":"https://github.com/caskdata/cdap/pull/1406","diff_url":"https://github.com/caskdata/cdap/pull/1406.diff","patch_url":"https://github.com/caskdata/cdap/pull/1406.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/1406","number":1406,"state":"open","locked":false,"title":"Feature/queue config table per namespace","user":{"login":"anwar6953","id":2440977,"avatar_url":"https://avatars.githubusercontent.com/u/2440977?v=3","gravatar_id":"","url":"https://api.github.com/users/anwar6953","html_url":"https://github.com/anwar6953","followers_url":"https://api.github.com/users/anwar6953/followers","following_url":"https://api.github.com/users/anwar6953/following{/other_user}","gists_url":"https://api.github.com/users/anwar6953/gists{/gist_id}","starred_url":"https://api.github.com/users/anwar6953/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anwar6953/subscriptions","organizations_url":"https://api.github.com/users/anwar6953/orgs","repos_url":"https://api.github.com/users/anwar6953/repos","events_url":"https://api.github.com/users/anwar6953/events{/privacy}","received_events_url":"https://api.github.com/users/anwar6953/received_events","type":"User","site_admin":false},"body":"Each namespace now has its own queue config table.\r\nThis will be useful in backwards compatability during upgrade to 2.8.\r\n\r\nQueue data table and config table will use TableId object when integrated with HBase namespaces.\r\n\r\nNote that this is branched off of (and depends on):\r\nhttps://github.com/caskdata/cdap/pull/1387\r\nTo see the diff between these two PRs: https://github.com/caskdata/cdap/compare/update-queue-table-names...feature/queue-config-table-per-namespace\r\n\r\nResolves: https://issues.cask.co/browse/CDAP-1422\r\nCompletes: https://issues.cask.co/browse/CDAP-1167\r\nBUILD: http://builds.cask.co/browse/CDAP-DUT873-7","created_at":"2015-02-24T02:43:53Z","updated_at":"2015-02-24T06:07:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ca977065f0f944ab964edd439d6498438081de86","assignee":null,"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":14,"closed_issues":78,"state":"open","created_at":"2015-01-21T01:15:14Z","updated_at":"2015-02-24T06:04:59Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/1406/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/1406/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/1406/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/83a50f95d0ce2f0ace7a77066712cec9335b7dcc","head":{"label":"caskdata:feature/queue-config-table-per-namespace","ref":"feature/queue-config-table-per-namespace","sha":"83a50f95d0ce2f0ace7a77066712cec9335b7dcc","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-24T06:04:59Z","pushed_at":"2015-02-24T06:05:02Z","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":784015,"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":24,"forks":9,"open_issues":24,"watchers":27,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"27db5bdc33fc837969d178e54b3625c1c9054dde","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-24T06:04:59Z","pushed_at":"2015-02-24T06:05:02Z","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":784015,"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":24,"forks":9,"open_issues":24,"watchers":27,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1406"},"html":{"href":"https://github.com/caskdata/cdap/pull/1406"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/1406"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/1406/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1406/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1406/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/83a50f95d0ce2f0ace7a77066712cec9335b7dcc"}}}}