Skip to content

Commit 4b642e1

Browse files
committed
refactory code and add killme in backend
1 parent 4414306 commit 4b642e1

File tree

8 files changed

+184
-97
lines changed

8 files changed

+184
-97
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
distrbuted-shell
1+
distributed-shell
22
================
33

44
A real distributed shell for yarn
@@ -8,7 +8,7 @@ simple usgae:
88
1) mvn package
99
2) export HADOOP_YARN_HOME=/apache2.2.0/hadoop-2.2.0
1010
export HADOOP_VERSION=2.2.0
11-
3) cp ./target/distributed-shell-1.0-SNAPSHOT.jar $HADOOP_YARN_HOME
11+
3) cp ./target/distributed-shell-0.1.jar $HADOOP_YARN_HOME
1212
4) cd $HADOOP_YARN_HOME
1313

1414
### Unmanaged mode
@@ -28,7 +28,7 @@ $ bin/hadoop jar distributed-shell-1.0-SNAPSHOT.jar com.hortonworks.simpleyarnap
2828

2929

3030
Use mvn eclipse:eclipse to generate eclipse project
31-
Currently this is only developed and tested in Mac os X10.9
31+
Currently this is only developed and tested in Mac os X10.9 with Eclipse 4.2
3232

3333
### how to test webshell
3434
`mvn exec:java -Dexec.mainClass=com.codeboy.dshell.webshell.WebShellServer`

src/main/java/com/codeboy/dshell/ApplicationMaster.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import org.apache.hadoop.yarn.client.api.NMClient;
77
import org.apache.hadoop.yarn.conf.YarnConfiguration;
88

9-
import com.codeboy.dshell.webshell.WebShellServer;
10-
119
public class ApplicationMaster {
1210

1311
private static final ApplicationMaster INSTANCE = new ApplicationMaster();
@@ -20,12 +18,13 @@ public static void main(String[] args) throws Exception {
2018
ApplicationMaster.INSTANCE.start(args);
2119
}
2220

21+
2322
private void start(String[] args) throws Exception {
24-
final String command = args[0];
25-
final int n = Integer.valueOf(args[1]);
26-
23+
final String port = args[0];
24+
2725
// Initialize clients to ResourceManager and NodeManagers
2826
Configuration conf = new YarnConfiguration();
27+
2928
// talk to resource manager
3029
AMRMClient<ContainerRequest> rmClient = AMRMClient.createAMRMClient();
3130
rmClient.init(conf);
@@ -41,9 +40,11 @@ private void start(String[] args) throws Exception {
4140
// registerApplicationMaster
4241
// resourceManager.registerApplicationMaster(appMasterHostname,
4342
// appMasterRpcPort, appMasterTrackingUrl);
44-
WebShellServer.INTANCE.start();
43+
//start the web shell server
44+
ApplicationMasterTrackingUI.startWebShellServer();
4545

46-
rmClient.registerApplicationMaster(WebShellServer.AM_HOST, WebShellServer.AM_PORT, WebShellServer.URL);
46+
rmClient.registerApplicationMaster(ApplicationMasterTrackingUI.AM_HOST,
47+
ApplicationMasterTrackingUI.AM_TRACKING_PORT, ApplicationMasterTrackingUI.AM_TRACKING_URL);
4748
// System.out.println("registerApplicationMaster 1");
4849
// rmClient.registerApplicationMaster("", 1, "");
4950

src/main/java/com/codeboy/dshell/Client.java renamed to src/main/java/com/codeboy/dshell/ApplicationMasterClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.apache.hadoop.yarn.util.Records;
3030

3131

32-
public class Client {
32+
public class ApplicationMasterClient {
3333

3434
Configuration conf = new YarnConfiguration();
3535

@@ -131,7 +131,7 @@ private void setupAppMasterEnv(Map<String, String> appMasterEnv) {
131131
}
132132

133133
public static void main(String[] args) throws Exception {
134-
Client c = new Client();
134+
ApplicationMasterClient c = new ApplicationMasterClient();
135135
c.run(args);
136136
}
137137
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.codeboy.dshell;
2+
3+
import com.codeboy.dshell.common.MasterNode;
4+
import com.codeboy.dshell.webshell.WebShellServer;
5+
6+
7+
public class ApplicationMasterTrackingUI {
8+
9+
public static final String AM_HOST = "localhost";
10+
11+
public static final int AM_TRACKING_PORT = 8898;
12+
13+
public static final String AM_TRACKING_PATH = "/distributedshell";
14+
15+
public static final String AM_TRACKING_URL = AM_HOST + ":" + AM_TRACKING_PORT + AM_TRACKING_PATH;
16+
17+
//one jvm , one instance
18+
public static void startWebShellServer() throws Exception {
19+
MasterNode masterNode= new MasterNode(AM_TRACKING_PATH,AM_HOST,AM_TRACKING_PORT+"",System.getProperty("user.name"));
20+
new WebShellServer(masterNode).start();
21+
}
22+
23+
24+
}

src/main/java/com/codeboy/dshell/common/DistributedNode.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ public class DistributedNode {
44

55
String host;
66
String port;
7-
String shellServiceURLPath;
8-
97
String userName;
108

11-
public DistributedNode(String host, String port,
12-
String shellServiceURLPath, String userName) {
9+
public DistributedNode(String host, String port, String userName) {
1310
super();
1411
this.host = host;
1512
this.port = port;
16-
this.shellServiceURLPath = shellServiceURLPath;
1713
this.userName = userName;
1814
}
1915

@@ -33,14 +29,6 @@ public void setPort(String port) {
3329
this.port = port;
3430
}
3531

36-
public String getShellServiceURLPath() {
37-
return shellServiceURLPath;
38-
}
39-
40-
public void setShellServiceURLPath(String shellServiceURLPath) {
41-
this.shellServiceURLPath = shellServiceURLPath;
42-
}
43-
4432
public String getUserName() {
4533
return userName;
4634
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codeboy.dshell.common;
2+
3+
public class MasterNode extends DistributedNode {
4+
5+
private String mainPageURLPath;
6+
7+
public MasterNode(String mainPageURLPath, String host, String port ,String userName) {
8+
super(host, port, userName);
9+
this.mainPageURLPath = mainPageURLPath;
10+
}
11+
12+
// like /distributedpath
13+
public String getMainPageURLPath() {
14+
return mainPageURLPath;
15+
}
16+
17+
// like localhost:8898/distributedpath
18+
public String getMainPageURL() {
19+
return getHttpBaseURL()+ mainPageURLPath;
20+
}
21+
}

0 commit comments

Comments
 (0)