|
1 | 1 |
|
2 | 2 | package org.apache.spark.network.yarn; |
3 | 3 |
|
| 4 | +import java.lang.Override; |
4 | 5 | import java.nio.ByteBuffer; |
5 | | -import java.sql.Timestamp; |
6 | | -import java.util.Date; |
7 | 6 |
|
| 7 | +import org.apache.spark.network.TransportContext; |
| 8 | +import org.apache.spark.network.server.RpcHandler; |
| 9 | +import org.apache.spark.network.shuffle.ExternalShuffleBlockHandler; |
| 10 | +import org.apache.spark.network.util.TransportConf; |
| 11 | +import org.apache.spark.network.util.SystemPropertyConfigProvider; |
| 12 | + |
| 13 | +import org.apache.hadoop.conf.Configuration; |
8 | 14 | import org.apache.hadoop.mapreduce.security.token.JobTokenSecretManager; |
9 | 15 | import org.apache.hadoop.yarn.api.records.ApplicationId; |
10 | 16 | import org.apache.hadoop.yarn.api.records.ContainerId; |
|
13 | 19 | import org.apache.hadoop.yarn.server.api.ApplicationTerminationContext; |
14 | 20 | import org.apache.hadoop.yarn.server.api.ContainerInitializationContext; |
15 | 21 | import org.apache.hadoop.yarn.server.api.ContainerTerminationContext; |
| 22 | +import org.slf4j.Logger; |
| 23 | +import org.slf4j.LoggerFactory; |
16 | 24 |
|
17 | 25 | /** |
18 | 26 | * External shuffle service used by Spark on Yarn. |
19 | 27 | */ |
20 | 28 | public class YarnShuffleService extends AuxiliaryService { |
21 | | - |
| 29 | + private final Logger logger = LoggerFactory.getLogger(YarnShuffleService.class); |
22 | 30 | private static final JobTokenSecretManager secretManager = new JobTokenSecretManager(); |
23 | 31 |
|
| 32 | + private static final String SPARK_SHUFFLE_SERVICE_PORT_KEY = "spark.shuffle.service.port"; |
| 33 | + private static final int DEFAULT_SPARK_SHUFFLE_SERVICE_PORT = 7337; |
| 34 | + |
24 | 35 | public YarnShuffleService() { |
25 | | - super("sparkshuffleservice"); |
26 | | - log("--- [ Welcome to YarnShuffleService v0.1 ] ---"); |
| 36 | + super("spark_shuffle"); |
| 37 | + logger.info("Initializing Yarn shuffle service for Spark"); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Start the shuffle server with the given configuration. |
| 42 | + */ |
| 43 | + @Override |
| 44 | + protected void serviceInit(Configuration conf) { |
| 45 | + try { |
| 46 | + int port = conf.getInt( |
| 47 | + SPARK_SHUFFLE_SERVICE_PORT_KEY, DEFAULT_SPARK_SHUFFLE_SERVICE_PORT); |
| 48 | + TransportConf transportConf = new TransportConf(new SystemPropertyConfigProvider()); |
| 49 | + RpcHandler rpcHandler = new ExternalShuffleBlockHandler(); |
| 50 | + TransportContext transportContext = new TransportContext(transportConf, rpcHandler); |
| 51 | + transportContext.createServer(port); |
| 52 | + } catch (Exception e) { |
| 53 | + logger.error("Exception in starting Yarn shuffle service for Spark!", e); |
| 54 | + } |
27 | 55 | } |
28 | 56 |
|
29 | 57 | @Override |
30 | 58 | public void initializeApplication(ApplicationInitializationContext context) { |
31 | 59 | ApplicationId appId = context.getApplicationId(); |
32 | | - log("Initializing application " + appId + "!"); |
| 60 | + logger.debug("Initializing application " + appId + "!"); |
33 | 61 | } |
34 | 62 |
|
35 | 63 | @Override |
36 | 64 | public void stopApplication(ApplicationTerminationContext context) { |
37 | 65 | ApplicationId appId = context.getApplicationId(); |
38 | | - log("Stopping application " + appId + "!"); |
| 66 | + logger.debug("Stopping application " + appId + "!"); |
39 | 67 | } |
40 | 68 |
|
41 | 69 | @Override |
42 | 70 | public ByteBuffer getMetaData() { |
43 | | - log("Getting meta data"); |
44 | | - return ByteBuffer.wrap("".getBytes()); |
| 71 | + logger.debug("Getting meta data"); |
| 72 | + return ByteBuffer.allocate(0); |
45 | 73 | } |
46 | 74 |
|
47 | 75 | @Override |
48 | 76 | public void initializeContainer(ContainerInitializationContext context) { |
49 | 77 | ContainerId containerId = context.getContainerId(); |
50 | | - log("Initializing container " + containerId + "!"); |
| 78 | + logger.debug("Initializing container " + containerId + "!"); |
51 | 79 | } |
52 | 80 |
|
53 | 81 | @Override |
54 | 82 | public void stopContainer(ContainerTerminationContext context) { |
55 | 83 | ContainerId containerId = context.getContainerId(); |
56 | | - log("Stopping container " + containerId + "!"); |
57 | | - } |
58 | | - |
59 | | - private void log(String msg) { |
60 | | - Timestamp timestamp = new Timestamp(new Date().getTime()); |
61 | | - System.out.println("* org.apache.spark.YarnShuffleService " + timestamp + ": " + msg); |
| 84 | + logger.debug("Stopping container " + containerId + "!"); |
62 | 85 | } |
63 | 86 | } |
0 commit comments