YARN-78. Changed UnManagedAM application to use YarnClient. Contributed by Bikas Saha.

svn merge --ignore-ancestry -c 1383705 ../../trunk/


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1383706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vinod Kumar Vavilapalli 2012-09-12 00:50:25 +00:00
parent 8644881db7
commit ddf8691f03
3 changed files with 85 additions and 106 deletions

View File

@ -8,6 +8,9 @@ Release 2.0.3-alpha - Unreleased
IMPROVEMENTS IMPROVEMENTS
YARN-78. Changed UnManagedAM application to use YarnClient. (Bikas Saha via
vinodkv)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -56,6 +56,10 @@
<artifactId>hadoop-yarn-server-common</artifactId> <artifactId>hadoop-yarn-server-common</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId> <artifactId>hadoop-mapreduce-client-core</artifactId>

View File

@ -22,7 +22,6 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Map; import java.util.Map;
@ -37,12 +36,7 @@
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.ApplicationConstants; import org.apache.hadoop.yarn.api.ApplicationConstants;
import org.apache.hadoop.yarn.api.ClientRMProtocol;
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest;
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse;
import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest;
import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse;
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.ApplicationReport; import org.apache.hadoop.yarn.api.records.ApplicationReport;
@ -51,9 +45,9 @@
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus; import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
import org.apache.hadoop.yarn.api.records.Priority; import org.apache.hadoop.yarn.api.records.Priority;
import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.client.YarnClientImpl;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnRemoteException; import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
import org.apache.hadoop.yarn.ipc.YarnRPC;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
/** /**
@ -73,11 +67,8 @@ public class UnmanagedAMLauncher {
private Configuration conf; private Configuration conf;
// RPC to communicate to RM
private YarnRPC rpc;
// Handle to talk to the Resource Manager/Applications Manager // Handle to talk to the Resource Manager/Applications Manager
private ClientRMProtocol rmClient; private YarnClientImpl rmClient;
// Application master specific info to register a new Application with RM/ASM // Application master specific info to register a new Application with RM/ASM
private String appName = ""; private String appName = "";
@ -114,7 +105,6 @@ public static void main(String[] args) {
public UnmanagedAMLauncher(Configuration conf) throws Exception { public UnmanagedAMLauncher(Configuration conf) throws Exception {
// Set up RPC // Set up RPC
this.conf = conf; this.conf = conf;
rpc = YarnRPC.create(conf);
} }
public UnmanagedAMLauncher() throws Exception { public UnmanagedAMLauncher() throws Exception {
@ -163,25 +153,11 @@ public boolean init(String[] args) throws ParseException {
"No cmd specified for application master"); "No cmd specified for application master");
} }
return true;
}
private void connectToRM() throws IOException {
YarnConfiguration yarnConf = new YarnConfiguration(conf); YarnConfiguration yarnConf = new YarnConfiguration(conf);
InetSocketAddress rmAddress = yarnConf.getSocketAddr( rmClient = new YarnClientImpl();
YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, rmClient.init(yarnConf);
YarnConfiguration.DEFAULT_RM_PORT);
LOG.info("Connecting to ResourceManager at " + rmAddress);
rmClient = ((ClientRMProtocol) rpc.getProxy(ClientRMProtocol.class,
rmAddress, conf));
}
private GetNewApplicationResponse getApplication() throws YarnRemoteException { return true;
GetNewApplicationRequest request = Records
.newRecord(GetNewApplicationRequest.class);
GetNewApplicationResponse response = rmClient.getNewApplication(request);
LOG.info("Got new application id=" + response.getApplicationId());
return response;
} }
public void launchAM(ApplicationAttemptId attemptId) throws IOException { public void launchAM(ApplicationAttemptId attemptId) throws IOException {
@ -280,75 +256,76 @@ public boolean run() throws IOException {
LOG.info("Starting Client"); LOG.info("Starting Client");
// Connect to ResourceManager // Connect to ResourceManager
connectToRM(); rmClient.start();
assert (rmClient != null); try {
// Get a new application id
GetNewApplicationResponse newApp = rmClient.getNewApplication();
ApplicationId appId = newApp.getApplicationId();
// Get a new application id // Create launch context for app master
GetNewApplicationResponse newApp = getApplication(); LOG.info("Setting up application submission context for ASM");
ApplicationId appId = newApp.getApplicationId(); ApplicationSubmissionContext appContext = Records
.newRecord(ApplicationSubmissionContext.class);
// Create launch context for app master // set the application id
LOG.info("Setting up application submission context for ASM"); appContext.setApplicationId(appId);
ApplicationSubmissionContext appContext = Records // set the application name
.newRecord(ApplicationSubmissionContext.class); appContext.setApplicationName(appName);
// set the application id // Set the priority for the application master
appContext.setApplicationId(appId); Priority pri = Records.newRecord(Priority.class);
// set the application name pri.setPriority(amPriority);
appContext.setApplicationName(appName); appContext.setPriority(pri);
// Set the priority for the application master // Set the queue to which this application is to be submitted in the RM
Priority pri = Records.newRecord(Priority.class); appContext.setQueue(amQueue);
pri.setPriority(amPriority);
appContext.setPriority(pri);
// Set the queue to which this application is to be submitted in the RM // Set up the container launch context for the application master
appContext.setQueue(amQueue); ContainerLaunchContext amContainer = Records
.newRecord(ContainerLaunchContext.class);
appContext.setAMContainerSpec(amContainer);
// Set up the container launch context for the application master // unmanaged AM
ContainerLaunchContext amContainer = Records appContext.setUnmanagedAM(true);
.newRecord(ContainerLaunchContext.class); LOG.info("Setting unmanaged AM");
appContext.setAMContainerSpec(amContainer);
// unmanaged AM // Submit the application to the applications manager
appContext.setUnmanagedAM(true); LOG.info("Submitting application to ASM");
LOG.info("Setting unmanaged AM"); rmClient.submitApplication(appContext);
// Create the request to send to the applications manager // Monitor the application to wait for launch state
SubmitApplicationRequest appRequest = Records ApplicationReport appReport = monitorApplication(appId,
.newRecord(SubmitApplicationRequest.class); EnumSet.of(YarnApplicationState.ACCEPTED));
appRequest.setApplicationSubmissionContext(appContext); ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId();
LOG.info("Launching application with id: " + attemptId);
// Submit the application to the applications manager // launch AM
LOG.info("Submitting application to ASM"); launchAM(attemptId);
rmClient.submitApplication(appRequest);
// Monitor the application to wait for launch state // Monitor the application for end state
ApplicationReport appReport = monitorApplication(appId, appReport = monitorApplication(appId, EnumSet.of(
EnumSet.of(YarnApplicationState.ACCEPTED)); YarnApplicationState.KILLED, YarnApplicationState.FAILED,
ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId(); YarnApplicationState.FINISHED));
LOG.info("Launching application with id: " + attemptId); YarnApplicationState appState = appReport.getYarnApplicationState();
FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus();
// launch AM LOG.info("App ended with state: " + appReport.getYarnApplicationState()
launchAM(attemptId); + " and status: " + appStatus);
// Monitor the application for end state boolean success;
appReport = monitorApplication(appId, EnumSet.of( if (YarnApplicationState.FINISHED == appState
YarnApplicationState.KILLED, YarnApplicationState.FAILED, && FinalApplicationStatus.SUCCEEDED == appStatus) {
YarnApplicationState.FINISHED)); LOG.info("Application has completed successfully.");
YarnApplicationState appState = appReport.getYarnApplicationState(); success = true;
FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus(); } else {
LOG.info("Application did finished unsuccessfully." + " YarnState="
+ appState.toString() + ", FinalStatus=" + appStatus.toString());
success = false;
}
LOG.info("App ended with state: " + appReport.getYarnApplicationState() return success;
+ " and status: " + appStatus); } finally {
if (YarnApplicationState.FINISHED == appState rmClient.stop();
&& FinalApplicationStatus.SUCCEEDED == appStatus) {
LOG.info("Application has completed successfully.");
return true;
} else {
LOG.info("Application did finished unsuccessfully." + " YarnState="
+ appState.toString() + ", FinalStatus=" + appStatus.toString());
return false;
} }
} }
@ -374,12 +351,7 @@ private ApplicationReport monitorApplication(ApplicationId appId,
} }
// Get application report for the appId we are interested in // Get application report for the appId we are interested in
GetApplicationReportRequest reportRequest = Records ApplicationReport report = rmClient.getApplicationReport(appId);
.newRecord(GetApplicationReportRequest.class);
reportRequest.setApplicationId(appId);
GetApplicationReportResponse reportResponse = rmClient
.getApplicationReport(reportRequest);
ApplicationReport report = reportResponse.getApplicationReport();
LOG.info("Got application report from ASM for" + ", appId=" LOG.info("Got application report from ASM for" + ", appId="
+ appId.getId() + ", appAttemptId=" + appId.getId() + ", appAttemptId="