{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/28494487","id":28494487,"diff_hunk":"@@ -0,0 +1,87 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of 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,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.shuffle\n+\n+import org.apache.spark.SparkConf\n+import org.apache.spark.SecurityManager\n+import org.apache.spark.network.netty.SparkTransportConf\n+import org.apache.spark.network.shuffle.ExternalShuffleBlockHandler\n+import org.apache.spark.network.TransportContext\n+import org.apache.spark.network.sasl.SaslRpcHandler\n+import org.apache.spark.network.server.TransportServer\n+import org.apache.spark.Logging\n+import org.apache.spark.util.Utils\n+import sun.misc.Signal\n+import sun.misc.SignalHandler\n+import java.util.concurrent.CountDownLatch\n+\n+/**\n+ * A main class for runing the external shuffle service. This follows\n+ * closely how [[org.apache.spark.deploy.worker.StandaloneWorkerShuffleService]] works.\n+ *\n+ * @note This adds handlers for SIGINT and SIGTERM to terminate gracefully.\n+ */\n+object ExternalShuffleService extends Logging {\n+  @volatile\n+  private var server: TransportServer = _\n+\n+  private val barrier = new CountDownLatch(1)\n+\n+  def main(args: Array[String]): Unit = {\n+    val sparkConf = new SparkConf\n+    Utils.loadDefaultSparkProperties(sparkConf)\n+    val securityManager = new SecurityManager(sparkConf)\n+\n+    val port = sparkConf.getInt(\"spark.shuffle.service.port\", 7337)\n+    val useSasl = securityManager.isAuthenticationEnabled()\n+\n+    val transportConf = SparkTransportConf.fromSparkConf(sparkConf, numUsableCores = 0)\n+    val blockHandler = new ExternalShuffleBlockHandler(transportConf)\n+\n+    val transportContext: TransportContext = {\n+      val handler = if (useSasl) new SaslRpcHandler(blockHandler, securityManager) else blockHandler\n+      new TransportContext(transportConf, handler)\n+    }\n+\n+    installSignalHandlers()\n+\n+    logInfo(s\"Starting external shuffle service on port $port (authentication: $useSasl)\")\n+    server = transportContext.createServer(port)\n+\n+    // keep running until the process is terminated by SIGTERM or SIGINT\n+    barrier.await()\n+  }\n+\n+  private def installSignalHandlers() = {\n+    new SigIntHandler(\"INT\")\n+    new SigIntHandler(\"TERM\")","path":"core/src/main/scala/org/apache/spark/shuffle/ExternalShuffleService.scala","position":72,"original_position":72,"commit_id":"69c0f861888f7760d0757597b1ef4006339cdb7e","original_commit_id":"69c0f861888f7760d0757597b1ef4006339cdb7e","user":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?v=3","gravatar_id":"","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"body":"Sure. I just followed what's done in other services, but I'm happy to switch to shutdown hooks.","created_at":"2015-04-16T09:14:43Z","updated_at":"2015-04-16T09:14:43Z","html_url":"https://github.com/apache/spark/pull/4990#discussion_r28494487","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/4990","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/28494487"},"html":{"href":"https://github.com/apache/spark/pull/4990#discussion_r28494487"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/4990"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/4990","id":31007236,"html_url":"https://github.com/apache/spark/pull/4990","diff_url":"https://github.com/apache/spark/pull/4990.diff","patch_url":"https://github.com/apache/spark/pull/4990.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/4990","number":4990,"state":"open","locked":false,"title":"[SPARK-4286][MESOS] Add an external shuffle service that can be run as a daemon.","user":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?v=3","gravatar_id":"","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"body":"This allows Mesos deployments to use the shuffle service (and implicitly dynamic allocation). It does so by adding a new \"main\" class and two corresponding scripts in `sbin`:\r\n\r\n- `sbin/start-shuffle-service.sh`\r\n- `sbin/stop-shuffle-service.sh`\r\n\r\nSpecific options can be passed in `SPARK_SHUFFLE_OPTS`.\r\n\r\nThis is picking up work from #3861 /cc @tnachen","created_at":"2015-03-12T04:16:57Z","updated_at":"2015-04-16T09:14:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f9653a84e0c2f83ceec24bcc41944dacd869524a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/4990/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/4990/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/4990/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/69c0f861888f7760d0757597b1ef4006339cdb7e","head":{"label":"dragos:feature/external-shuffle-service","ref":"feature/external-shuffle-service","sha":"69c0f861888f7760d0757597b1ef4006339cdb7e","user":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?v=3","gravatar_id":"","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"repo":{"id":29976503,"name":"spark","full_name":"dragos/spark","owner":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?v=3","gravatar_id":"","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dragos/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/dragos/spark","forks_url":"https://api.github.com/repos/dragos/spark/forks","keys_url":"https://api.github.com/repos/dragos/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dragos/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dragos/spark/teams","hooks_url":"https://api.github.com/repos/dragos/spark/hooks","issue_events_url":"https://api.github.com/repos/dragos/spark/issues/events{/number}","events_url":"https://api.github.com/repos/dragos/spark/events","assignees_url":"https://api.github.com/repos/dragos/spark/assignees{/user}","branches_url":"https://api.github.com/repos/dragos/spark/branches{/branch}","tags_url":"https://api.github.com/repos/dragos/spark/tags","blobs_url":"https://api.github.com/repos/dragos/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dragos/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dragos/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/dragos/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dragos/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/dragos/spark/languages","stargazers_url":"https://api.github.com/repos/dragos/spark/stargazers","contributors_url":"https://api.github.com/repos/dragos/spark/contributors","subscribers_url":"https://api.github.com/repos/dragos/spark/subscribers","subscription_url":"https://api.github.com/repos/dragos/spark/subscription","commits_url":"https://api.github.com/repos/dragos/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/dragos/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/dragos/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/dragos/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/dragos/spark/contents/{+path}","compare_url":"https://api.github.com/repos/dragos/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dragos/spark/merges","archive_url":"https://api.github.com/repos/dragos/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dragos/spark/downloads","issues_url":"https://api.github.com/repos/dragos/spark/issues{/number}","pulls_url":"https://api.github.com/repos/dragos/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/dragos/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/dragos/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dragos/spark/labels{/name}","releases_url":"https://api.github.com/repos/dragos/spark/releases{/id}","created_at":"2015-01-28T16:25:56Z","updated_at":"2015-01-28T16:26:12Z","pushed_at":"2015-04-15T19:10:23Z","git_url":"git://github.com/dragos/spark.git","ssh_url":"git@github.com:dragos/spark.git","clone_url":"https://github.com/dragos/spark.git","svn_url":"https://github.com/dragos/spark","homepage":null,"size":99161,"stargazers_count":0,"watchers_count":0,"language":"Scala","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":"master"}},"base":{"label":"apache:master","ref":"master","sha":"cd3b68d93a01f11bd3d5a441b341cb33d227e900","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-04-16T07:35:27Z","pushed_at":"2015-04-16T08:42:57Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1502668,"stargazers_count":3632,"watchers_count":3632,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3128,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":291,"forks":3128,"open_issues":291,"watchers":3632,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/4990"},"html":{"href":"https://github.com/apache/spark/pull/4990"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/4990"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/4990/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/4990/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/4990/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/69c0f861888f7760d0757597b1ef4006339cdb7e"}}}}