Skip to content

Commit 9bb5ac4

Browse files
committed
YARN-824. Added static factory methods to hadoop-yarn-client interfaces. Contributed by Jian He.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1493631 13f79535-47bb-0310-9956-ffa450edef68
1 parent d7fa7e2 commit 9bb5ac4

File tree

14 files changed

+164
-72
lines changed

14 files changed

+164
-72
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ Release 2.1.0-beta - UNRELEASED
169169
YARN-831. Removed minimum resource from GetNewApplicationResponse as a
170170
follow-up to YARN-787. (Jian He via acmurthy)
171171

172+
YARN-824. Added static factory methods to hadoop-yarn-client interfaces.
173+
(Jian He via acmurthy)
174+
172175
NEW FEATURES
173176

174177
YARN-482. FS: Extend SchedulingMode to intermediate queues.

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/Client.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
import org.apache.hadoop.yarn.api.records.Resource;
6161
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
6262
import org.apache.hadoop.yarn.api.records.YarnClusterMetrics;
63-
import org.apache.hadoop.yarn.client.YarnClientImpl;
63+
import org.apache.hadoop.yarn.client.YarnClient;
6464
import org.apache.hadoop.yarn.conf.YarnConfiguration;
6565
import org.apache.hadoop.yarn.exceptions.YarnException;
6666
import org.apache.hadoop.yarn.util.ConverterUtils;
@@ -99,13 +99,13 @@
9999
*/
100100
@InterfaceAudience.Public
101101
@InterfaceStability.Unstable
102-
public class Client extends YarnClientImpl {
102+
public class Client {
103103

104104
private static final Log LOG = LogFactory.getLog(Client.class);
105105

106106
// Configuration
107107
private Configuration conf;
108-
108+
private YarnClient yarnClient;
109109
// Application master specific info to register a new Application with RM/ASM
110110
private String appName = "";
111111
// App master priority
@@ -186,9 +186,10 @@ public static void main(String[] args) {
186186
/**
187187
*/
188188
public Client(Configuration conf) throws Exception {
189-
super();
189+
190190
this.conf = conf;
191-
init(conf);
191+
yarnClient = YarnClient.createYarnClient();
192+
yarnClient.init(conf);
192193
opts = new Options();
193194
opts.addOption("appname", true, "Application Name. Default value - DistributedShell");
194195
opts.addOption("priority", true, "Application Priority. Default 0");
@@ -317,13 +318,13 @@ public boolean init(String[] args) throws ParseException {
317318
public boolean run() throws IOException, YarnException {
318319

319320
LOG.info("Running Client");
320-
start();
321+
yarnClient.start();
321322

322-
YarnClusterMetrics clusterMetrics = super.getYarnClusterMetrics();
323+
YarnClusterMetrics clusterMetrics = yarnClient.getYarnClusterMetrics();
323324
LOG.info("Got Cluster metric info from ASM"
324325
+ ", numNodeManagers=" + clusterMetrics.getNumNodeManagers());
325326

326-
List<NodeReport> clusterNodeReports = super.getNodeReports();
327+
List<NodeReport> clusterNodeReports = yarnClient.getNodeReports();
327328
LOG.info("Got Cluster node info from ASM");
328329
for (NodeReport node : clusterNodeReports) {
329330
LOG.info("Got node report from ASM for"
@@ -333,15 +334,15 @@ public boolean run() throws IOException, YarnException {
333334
+ ", nodeNumContainers" + node.getNumContainers());
334335
}
335336

336-
QueueInfo queueInfo = super.getQueueInfo(this.amQueue);
337+
QueueInfo queueInfo = yarnClient.getQueueInfo(this.amQueue);
337338
LOG.info("Queue info"
338339
+ ", queueName=" + queueInfo.getQueueName()
339340
+ ", queueCurrentCapacity=" + queueInfo.getCurrentCapacity()
340341
+ ", queueMaxCapacity=" + queueInfo.getMaximumCapacity()
341342
+ ", queueApplicationCount=" + queueInfo.getApplications().size()
342343
+ ", queueChildQueueCount=" + queueInfo.getChildQueues().size());
343344

344-
List<QueueUserACLInfo> listAclInfo = super.getQueueAclsInfo();
345+
List<QueueUserACLInfo> listAclInfo = yarnClient.getQueueAclsInfo();
345346
for (QueueUserACLInfo aclInfo : listAclInfo) {
346347
for (QueueACL userAcl : aclInfo.getUserAcls()) {
347348
LOG.info("User ACL Info for Queue"
@@ -351,7 +352,7 @@ public boolean run() throws IOException, YarnException {
351352
}
352353

353354
// Get a new application id
354-
GetNewApplicationResponse newApp = super.getNewApplication();
355+
GetNewApplicationResponse newApp = yarnClient.getNewApplication();
355356
ApplicationId appId = newApp.getApplicationId();
356357

357358
// TODO get min/max resource capabilities from RM and change memory ask if needed
@@ -564,7 +565,7 @@ public boolean run() throws IOException, YarnException {
564565
// or an exception thrown to denote some form of a failure
565566
LOG.info("Submitting application to ASM");
566567

567-
super.submitApplication(appContext);
568+
yarnClient.submitApplication(appContext);
568569

569570
// TODO
570571
// Try submitting the same request again
@@ -596,7 +597,7 @@ private boolean monitorApplication(ApplicationId appId)
596597
}
597598

598599
// Get application report for the appId we are interested in
599-
ApplicationReport report = super.getApplicationReport(appId);
600+
ApplicationReport report = yarnClient.getApplicationReport(appId);
600601

601602
LOG.info("Got application report from ASM for"
602603
+ ", appId=" + appId.getId()
@@ -656,7 +657,7 @@ private void forceKillApplication(ApplicationId appId)
656657

657658
// Response can be ignored as it is non-null on success or
658659
// throws an exception in case of failures
659-
super.killApplication(appId);
660+
yarnClient.killApplication(appId);
660661
}
661662

662663
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/main/java/org/apache/hadoop/yarn/applications/unmanagedamlauncher/UnmanagedAMLauncher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
4949
import org.apache.hadoop.yarn.api.records.Priority;
5050
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
51+
import org.apache.hadoop.yarn.client.YarnClient;
5152
import org.apache.hadoop.yarn.client.YarnClientImpl;
5253
import org.apache.hadoop.yarn.conf.YarnConfiguration;
5354
import org.apache.hadoop.yarn.exceptions.YarnException;
@@ -72,7 +73,7 @@ public class UnmanagedAMLauncher {
7273
private Configuration conf;
7374

7475
// Handle to talk to the Resource Manager/Applications Manager
75-
private YarnClientImpl rmClient;
76+
private YarnClient rmClient;
7677

7778
// Application master specific info to register a new Application with RM/ASM
7879
private String appName = "";
@@ -160,7 +161,7 @@ public boolean init(String[] args) throws ParseException {
160161
}
161162

162163
YarnConfiguration yarnConf = new YarnConfiguration(conf);
163-
rmClient = new YarnClientImpl();
164+
rmClient = YarnClient.createYarnClient();
164165
rmClient.init(yarnConf);
165166

166167
return true;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/AMRMClient.java

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,48 @@
2424
import java.util.concurrent.ConcurrentMap;
2525

2626
import org.apache.hadoop.classification.InterfaceAudience;
27+
import org.apache.hadoop.classification.InterfaceAudience.Private;
28+
import org.apache.hadoop.classification.InterfaceAudience.Public;
2729
import org.apache.hadoop.classification.InterfaceStability;
2830
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
2931
import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
32+
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
3033
import org.apache.hadoop.yarn.api.records.ContainerId;
3134
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
3235
import org.apache.hadoop.yarn.api.records.Priority;
3336
import org.apache.hadoop.yarn.api.records.Resource;
3437
import org.apache.hadoop.yarn.api.records.Token;
3538
import org.apache.hadoop.yarn.exceptions.YarnException;
36-
import org.apache.hadoop.yarn.service.Service;
39+
import org.apache.hadoop.yarn.service.AbstractService;
3740

3841
import com.google.common.collect.ImmutableList;
3942

4043
@InterfaceAudience.Public
4144
@InterfaceStability.Unstable
42-
public interface AMRMClient<T extends AMRMClient.ContainerRequest> extends Service {
45+
public abstract class AMRMClient<T extends AMRMClient.ContainerRequest> extends
46+
AbstractService {
47+
48+
/**
49+
* Create a new instance of AMRMClient.
50+
* For usage:
51+
* <pre>
52+
* {@code
53+
* AMRMClient.<T>createAMRMClientContainerRequest(appAttemptId)
54+
* }</pre>
55+
* @param appAttemptId the appAttemptId associated with the AMRMClient
56+
* @return the newly create AMRMClient instance.
57+
*/
58+
@Public
59+
public static <T extends ContainerRequest> AMRMClient<T> createAMRMClient(
60+
ApplicationAttemptId appAttemptId) {
61+
AMRMClient<T> client = new AMRMClientImpl<T>(appAttemptId);
62+
return client;
63+
}
64+
65+
@Private
66+
protected AMRMClient(String name) {
67+
super(name);
68+
}
4369

4470
/**
4571
* Object to represent container request for resources. Scheduler
@@ -132,7 +158,7 @@ public StoredContainerRequest(Resource capability, String[] nodes,
132158
* @throws YarnException
133159
* @throws IOException
134160
*/
135-
public RegisterApplicationMasterResponse
161+
public abstract RegisterApplicationMasterResponse
136162
registerApplicationMaster(String appHostName,
137163
int appHostPort,
138164
String appTrackingUrl)
@@ -153,7 +179,7 @@ public StoredContainerRequest(Resource capability, String[] nodes,
153179
* @throws YarnException
154180
* @throws IOException
155181
*/
156-
public AllocateResponse allocate(float progressIndicator)
182+
public abstract AllocateResponse allocate(float progressIndicator)
157183
throws YarnException, IOException;
158184

159185
/**
@@ -164,7 +190,7 @@ public AllocateResponse allocate(float progressIndicator)
164190
* @throws YarnException
165191
* @throws IOException
166192
*/
167-
public void unregisterApplicationMaster(FinalApplicationStatus appStatus,
193+
public abstract void unregisterApplicationMaster(FinalApplicationStatus appStatus,
168194
String appMessage,
169195
String appTrackingUrl)
170196
throws YarnException, IOException;
@@ -173,7 +199,7 @@ public void unregisterApplicationMaster(FinalApplicationStatus appStatus,
173199
* Request containers for resources before calling <code>allocate</code>
174200
* @param req Resource request
175201
*/
176-
public void addContainerRequest(T req);
202+
public abstract void addContainerRequest(T req);
177203

178204
/**
179205
* Remove previous container request. The previous container request may have
@@ -182,7 +208,7 @@ public void unregisterApplicationMaster(FinalApplicationStatus appStatus,
182208
* even after the remove request
183209
* @param req Resource request
184210
*/
185-
public void removeContainerRequest(T req);
211+
public abstract void removeContainerRequest(T req);
186212

187213
/**
188214
* Release containers assigned by the Resource Manager. If the app cannot use
@@ -191,21 +217,21 @@ public void unregisterApplicationMaster(FinalApplicationStatus appStatus,
191217
* it still needs it. eg. it released non-local resources
192218
* @param containerId
193219
*/
194-
public void releaseAssignedContainer(ContainerId containerId);
220+
public abstract void releaseAssignedContainer(ContainerId containerId);
195221

196222
/**
197223
* Get the currently available resources in the cluster.
198224
* A valid value is available after a call to allocate has been made
199225
* @return Currently available resources
200226
*/
201-
public Resource getClusterAvailableResources();
227+
public abstract Resource getClusterAvailableResources();
202228

203229
/**
204230
* Get the current number of nodes in the cluster.
205231
* A valid values is available after a call to allocate has been made
206232
* @return Current number of nodes in the cluster
207233
*/
208-
public int getClusterNodeCount();
234+
public abstract int getClusterNodeCount();
209235

210236
/**
211237
* Get outstanding <code>StoredContainerRequest</code>s matching the given
@@ -218,7 +244,7 @@ public void unregisterApplicationMaster(FinalApplicationStatus appStatus,
218244
* collection, requests will be returned in the same order as they were added.
219245
* @return Collection of request matching the parameters
220246
*/
221-
public List<? extends Collection<T>> getMatchingRequests(
247+
public abstract List<? extends Collection<T>> getMatchingRequests(
222248
Priority priority,
223249
String resourceName,
224250
Resource capability);
@@ -231,5 +257,5 @@ public List<? extends Collection<T>> getMatchingRequests(
231257
* communicating with NodeManager (ex. NMClient) using NMTokens. If a new
232258
* NMToken is received for the same node manager then it will be replaced.
233259
*/
234-
public ConcurrentMap<String, Token> getNMTokens();
260+
public abstract ConcurrentMap<String, Token> getNMTokens();
235261
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/AMRMClientAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public AMRMClientAsync(ApplicationAttemptId id, int intervalMs,
120120

121121
@Private
122122
@VisibleForTesting
123-
public AMRMClientAsync(AMRMClient<T> client, int intervalMs,
123+
protected AMRMClientAsync(AMRMClient<T> client, int intervalMs,
124124
CallbackHandler callbackHandler) {
125125
super(AMRMClientAsync.class.getName());
126126
this.client = client;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/AMRMClientImpl.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,15 @@
6464
import org.apache.hadoop.yarn.factories.RecordFactory;
6565
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
6666
import org.apache.hadoop.yarn.ipc.YarnRPC;
67-
import org.apache.hadoop.yarn.service.AbstractService;
6867
import org.apache.hadoop.yarn.util.RackResolver;
6968

70-
import com.google.common.base.Joiner;
71-
7269
import com.google.common.annotations.VisibleForTesting;
70+
import com.google.common.base.Joiner;
7371

7472
// TODO check inputs for null etc. YARN-654
7573

7674
@Unstable
77-
public class AMRMClientImpl<T extends ContainerRequest>
78-
extends AbstractService implements AMRMClient<T> {
75+
public class AMRMClientImpl<T extends ContainerRequest> extends AMRMClient<T> {
7976

8077
private static final Log LOG = LogFactory.getLog(AMRMClientImpl.class);
8178

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/NMClient.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Map;
2424

2525
import org.apache.hadoop.classification.InterfaceAudience;
26+
import org.apache.hadoop.classification.InterfaceAudience.Private;
27+
import org.apache.hadoop.classification.InterfaceAudience.Public;
2628
import org.apache.hadoop.classification.InterfaceStability;
2729
import org.apache.hadoop.yarn.api.records.Container;
2830
import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -31,11 +33,34 @@
3133
import org.apache.hadoop.yarn.api.records.NodeId;
3234
import org.apache.hadoop.yarn.api.records.Token;
3335
import org.apache.hadoop.yarn.exceptions.YarnException;
34-
import org.apache.hadoop.yarn.service.Service;
36+
import org.apache.hadoop.yarn.service.AbstractService;
3537

3638
@InterfaceAudience.Public
3739
@InterfaceStability.Unstable
38-
public interface NMClient extends Service {
40+
public abstract class NMClient extends AbstractService {
41+
42+
/**
43+
* Create a new instance of NMClient.
44+
*/
45+
@Public
46+
public static NMClient createNMClient() {
47+
NMClient client = new NMClientImpl();
48+
return client;
49+
}
50+
51+
/**
52+
* Create a new instance of NMClient.
53+
*/
54+
@Public
55+
public static NMClient createNMClient(String name) {
56+
NMClient client = new NMClientImpl(name);
57+
return client;
58+
}
59+
60+
@Private
61+
protected NMClient(String name) {
62+
super(name);
63+
}
3964

4065
/**
4166
* <p>Start an allocated container.</p>
@@ -54,7 +79,7 @@ public interface NMClient extends Service {
5479
* @throws YarnException
5580
* @throws IOException
5681
*/
57-
Map<String, ByteBuffer> startContainer(Container container,
82+
public abstract Map<String, ByteBuffer> startContainer(Container container,
5883
ContainerLaunchContext containerLaunchContext)
5984
throws YarnException, IOException;
6085

@@ -68,7 +93,7 @@ Map<String, ByteBuffer> startContainer(Container container,
6893
* @throws YarnException
6994
* @throws IOException
7095
*/
71-
void stopContainer(ContainerId containerId, NodeId nodeId,
96+
public abstract void stopContainer(ContainerId containerId, NodeId nodeId,
7297
Token containerToken) throws YarnException, IOException;
7398

7499
/**
@@ -82,7 +107,7 @@ void stopContainer(ContainerId containerId, NodeId nodeId,
82107
* @throws YarnException
83108
* @throws IOException
84109
*/
85-
ContainerStatus getContainerStatus(ContainerId containerId, NodeId nodeId,
110+
public abstract ContainerStatus getContainerStatus(ContainerId containerId, NodeId nodeId,
86111
Token containerToken) throws YarnException, IOException;
87112

88113
/**
@@ -92,6 +117,6 @@ ContainerStatus getContainerStatus(ContainerId containerId, NodeId nodeId,
92117
*
93118
* @param enabled whether the feature is enabled or not
94119
*/
95-
void cleanupRunningContainersOnStop(boolean enabled);
120+
public abstract void cleanupRunningContainersOnStop(boolean enabled);
96121

97122
}

0 commit comments

Comments
 (0)