本文整理匯總了Java中org.apache.hadoop.yarn.client.api.YarnClientApplication.getNewApplicationResponse方法的典型用法代碼示例。如果您正苦於以下問題:Java YarnClientApplication.getNewApplicationResponse方法的具體用法?Java YarnClientApplication.getNewApplicationResponse怎麽用?Java YarnClientApplication.getNewApplicationResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.yarn.client.api.YarnClientApplication
的用法示例。
在下文中一共展示了YarnClientApplication.getNewApplicationResponse方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
public boolean run() throws YarnException, IOException {
yarnClient.start();
YarnClientApplication client = yarnClient.createApplication();
GetNewApplicationResponse appResponse = client.getNewApplicationResponse();
appId = appResponse.getApplicationId();
LOG.info("Applicatoin ID = {}", appId);
int maxMemory = appResponse.getMaximumResourceCapability().getMemory();
int maxVCores = appResponse.getMaximumResourceCapability().getVirtualCores();
LOG.info("Max memory = {} and max vcores = {}", maxMemory, maxVCores);
YarnClusterMetrics clusterMetrics =
yarnClient.getYarnClusterMetrics();
LOG.info("Number of NodeManagers = {}", clusterMetrics.getNumNodeManagers());
List<NodeReport> nodeReports = yarnClient.getNodeReports(NodeState.RUNNING);
for (NodeReport node : nodeReports) {
LOG.info("Node ID = {}, address = {}, containers = {}", node.getNodeId(), node.getHttpAddress(),
node.getNumContainers());
}
List<QueueInfo> queueList = yarnClient.getAllQueues();
for (QueueInfo queue : queueList) {
LOG.info("Available queue: {} with capacity {} to {}", queue.getQueueName(), queue.getCapacity(),
queue.getMaximumCapacity());
}
return true;
}
示例2: validateResourceForAM
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
/**
* If we do not have min/max, we may not be able to correctly request
* the required resources from the RM for the app master
* Memory ask has to be a multiple of min and less than max.
* Dump out information about cluster capability as seen by the resource manager
* @param app
*/
private void validateResourceForAM(YarnClientApplication app) {
GetNewApplicationResponse appResponse = app.getNewApplicationResponse();
// TODO get min/max resource capabilities from RM and change memory ask if needed
int maxMem = appResponse.getMaximumResourceCapability().getMemory();
LOG.info("Max mem capabililty of resources in this cluster " + maxMem);
// A resource ask cannot exceed the max.
if (amMemory > maxMem) {
LOG.info("AM memory specified above max threshold of cluster. Using max value."
+ ", specified=" + amMemory
+ ", max=" + maxMem);
amMemory = maxMem;
}
int maxVCores = appResponse.getMaximumResourceCapability().getVirtualCores();
LOG.info("Max virtual cores capabililty of resources in this cluster " + maxVCores);
if (amVCores > maxVCores) {
LOG.info("AM virtual cores specified above max threshold of cluster. "
+ "Using max value." + ", specified=" + amVCores
+ ", max=" + maxVCores);
amVCores = maxVCores;
}
}
示例3: setupAndSubmitApplication
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
/**
* Setup and submit the Gobblin Yarn application.
*
* @throws IOException if there's anything wrong setting up and submitting the Yarn application
* @throws YarnException if there's anything wrong setting up and submitting the Yarn application
*/
private ApplicationId setupAndSubmitApplication() throws IOException, YarnException {
YarnClientApplication gobblinYarnApp = this.yarnClient.createApplication();
ApplicationSubmissionContext appSubmissionContext = gobblinYarnApp.getApplicationSubmissionContext();
ApplicationId applicationId = appSubmissionContext.getApplicationId();
GetNewApplicationResponse newApplicationResponse = gobblinYarnApp.getNewApplicationResponse();
// Set up resource type requirements for ApplicationMaster
Resource resource = prepareContainerResource(newApplicationResponse);
// Add lib jars, and jars and files that the ApplicationMaster need as LocalResources
Map<String, LocalResource> appMasterLocalResources = addAppMasterLocalResources(applicationId);
ContainerLaunchContext amContainerLaunchContext = Records.newRecord(ContainerLaunchContext.class);
amContainerLaunchContext.setLocalResources(appMasterLocalResources);
amContainerLaunchContext.setEnvironment(YarnHelixUtils.getEnvironmentVariables(this.yarnConfiguration));
amContainerLaunchContext.setCommands(Lists.newArrayList(buildApplicationMasterCommand(resource.getMemory())));
if (UserGroupInformation.isSecurityEnabled()) {
setupSecurityTokens(amContainerLaunchContext);
}
// Setup the application submission context
appSubmissionContext.setApplicationName(this.applicationName);
appSubmissionContext.setResource(resource);
appSubmissionContext.setQueue(this.appQueueName);
appSubmissionContext.setPriority(Priority.newInstance(0));
appSubmissionContext.setAMContainerSpec(amContainerLaunchContext);
// Also setup container local resources by copying local jars and files the container need to HDFS
addContainerLocalResources(applicationId);
// Submit the application
LOGGER.info("Submitting application " + applicationId);
this.yarnClient.submitApplication(appSubmissionContext);
return applicationId;
}
示例4: startUp
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
@Override
protected void startUp() throws IOException {
this.yarnClient = yarnClientFactory.connect();
YarnClientApplication clientApp = getNewApplication();
GetNewApplicationResponse newApp = clientApp.getNewApplicationResponse();
ContainerLaunchContextFactory clcFactory = new ContainerLaunchContextFactory(newApp.getMaximumResourceCapability());
ApplicationSubmissionContext appContext = clientApp.getApplicationSubmissionContext();
this.applicationId = appContext.getApplicationId();
appContext.setApplicationName(parameters.getApplicationName());
// Setup the container for the application master.
ContainerLaunchParameters appMasterParams = parameters.getApplicationMasterParameters(applicationId);
ContainerLaunchContext clc = clcFactory.create(appMasterParams);
appContext.setResource(clcFactory.createResource(appMasterParams));
appContext.setAMContainerSpec(clc);
appContext.setQueue(parameters.getQueue());
appContext.setPriority(clcFactory.createPriority(appMasterParams.getPriority()));
submitApplication(appContext);
// Make sure we stop the application in the case that it isn't done already.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if (YarnClientServiceImpl.this.isRunning()) {
YarnClientServiceImpl.this.stop();
}
}
});
stopwatch.start();
}
示例5: createLauncher
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
@Override
public ProcessLauncher<ApplicationId> createLauncher(TwillSpecification twillSpec) throws Exception {
// Request for new application
YarnClientApplication application = yarnClient.createApplication();
final GetNewApplicationResponse response = application.getNewApplicationResponse();
final ApplicationId appId = response.getApplicationId();
// Setup the context for application submission
final ApplicationSubmissionContext appSubmissionContext = application.getApplicationSubmissionContext();
appSubmissionContext.setApplicationId(appId);
appSubmissionContext.setApplicationName(twillSpec.getName());
ApplicationSubmitter submitter = new ApplicationSubmitter() {
@Override
public ProcessController<YarnApplicationReport> submit(YarnLaunchContext context, Resource capability) {
ContainerLaunchContext launchContext = context.getLaunchContext();
addRMToken(launchContext);
appSubmissionContext.setAMContainerSpec(launchContext);
appSubmissionContext.setResource(adjustMemory(response, capability));
appSubmissionContext.setMaxAppAttempts(2);
try {
yarnClient.submitApplication(appSubmissionContext);
return new ProcessControllerImpl(yarnClient, appId);
} catch (Exception e) {
LOG.error("Failed to submit application {}", appId, e);
throw Throwables.propagate(e);
}
}
};
return new ApplicationMasterProcessLauncher(appId, submitter);
}
示例6: YarnSubmissionHelper
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
public YarnSubmissionHelper(final YarnConfiguration yarnConfiguration,
final REEFFileNames fileNames,
final ClasspathProvider classpath,
final YarnProxyUser yarnProxyUser,
final SecurityTokenProvider tokenProvider,
final boolean isUnmanaged,
final List<String> commandPrefixList) throws IOException, YarnException {
this.classpath = classpath;
this.yarnProxyUser = yarnProxyUser;
this.isUnmanaged = isUnmanaged;
this.driverStdoutFilePath =
ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + fileNames.getDriverStdoutFileName();
this.driverStderrFilePath =
ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + fileNames.getDriverStderrFileName();
LOG.log(Level.FINE, "Initializing YARN Client");
this.yarnClient = YarnClient.createYarnClient();
this.yarnClient.init(yarnConfiguration);
this.yarnClient.start();
LOG.log(Level.FINE, "Initialized YARN Client");
LOG.log(Level.FINE, "Requesting Application ID from YARN.");
final YarnClientApplication yarnClientApplication = this.yarnClient.createApplication();
this.applicationResponse = yarnClientApplication.getNewApplicationResponse();
this.applicationSubmissionContext = yarnClientApplication.getApplicationSubmissionContext();
this.applicationSubmissionContext.setUnmanagedAM(isUnmanaged);
this.applicationId = this.applicationSubmissionContext.getApplicationId();
this.tokenProvider = tokenProvider;
this.commandPrefixList = commandPrefixList;
this.configurationFilePaths = Collections.singletonList(fileNames.getDriverConfigurationPath());
LOG.log(Level.INFO, "YARN Application ID: {0}", this.applicationId);
}
示例7: startPSServer
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
@Override
public void startPSServer() throws AngelException {
try {
setUser();
setLocalAddr();
Path stagingDir = AngelApps.getStagingDir(conf, userName);
// 2.get job id
yarnClient = YarnClient.createYarnClient();
YarnConfiguration yarnConf = new YarnConfiguration(conf);
yarnClient.init(yarnConf);
yarnClient.start();
YarnClientApplication newApp;
newApp = yarnClient.createApplication();
GetNewApplicationResponse newAppResponse = newApp.getNewApplicationResponse();
appId = newAppResponse.getApplicationId();
JobID jobId = TypeConverter.fromYarn(appId);
Path submitJobDir = new Path(stagingDir, appId.toString());
jtFs = submitJobDir.getFileSystem(conf);
conf.set("hadoop.http.filter.initializers",
"org.apache.hadoop.yarn.server.webproxy.amfilter.AmFilterInitializer");
conf.set(AngelConf.ANGEL_JOB_DIR, submitJobDir.toString());
conf.set(AngelConf.ANGEL_JOB_ID, jobId.toString());
setInputDirectory();
setOutputDirectory();
// Credentials credentials = new Credentials();
credentials.addAll(UserGroupInformation.getCurrentUser().getCredentials());
TokenCache.obtainTokensForNamenodes(credentials, new Path[] {submitJobDir}, conf);
checkParameters(conf);
handleDeprecatedParameters(conf);
// 4.copy resource files to hdfs
copyAndConfigureFiles(conf, submitJobDir, (short) 10);
// 5.write configuration to a xml file
Path submitJobFile = JobSubmissionFiles.getJobConfPath(submitJobDir);
TokenCache.cleanUpTokenReferral(conf);
writeConf(conf, submitJobFile);
// 6.create am container context
ApplicationSubmissionContext appContext =
createApplicationSubmissionContext(conf, submitJobDir, credentials, appId);
conf.set(AngelConf.ANGEL_JOB_LIBJARS, "");
// 7.Submit to ResourceManager
appId = yarnClient.submitApplication(appContext);
// 8.get app master client
updateMaster(10 * 60);
waitForAllPS(conf.getInt(AngelConf.ANGEL_PS_NUMBER, AngelConf.DEFAULT_ANGEL_PS_NUMBER));
LOG.info("start pss success");
} catch (Exception x) {
LOG.error("submit application to yarn failed.", x);
throw new AngelException(x);
}
}
示例8: submitAppContext
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
public ApplicationId submitAppContext() throws YarnException, IOException, InterruptedException {
yarnClient.start();
YarnClientApplication app = yarnClient.createApplication();
GetNewApplicationResponse appResponse = app.getNewApplicationResponse();
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
ApplicationId appId = appContext.getApplicationId();
appContext.setApplicationName(yacopConfig.getName());
Map<String, LocalResource> localResources = new HashMap<String, LocalResource>();
FileSystem fs = FileSystem.get(conf);
//upload the local docker image
if (yacopConfig.isEngineLocalImage()) {
boolean dockerImgUploaded = uploadDockerImage(fs, appId.toString(), yacopConfig.getEngineImage());
if (dockerImgUploaded) {
LOG.info("Local Docker image " + yacopConfig.getEngineImage() + " uploaded successfully");
} else {
LOG.info("Local Docker image " + yacopConfig.getEngineImage() + " upload failed, existing");
System.exit(3);
}
}
addToLocalResources(fs, appMasterJar, appMasterJarPath, appId.toString(), localResources, null);
configFile = serializeObj(appId, yacopConfig);
addToLocalResources(fs, configFile, configFilePath, appId.toString(), localResources, null);
Map<String, String> env = prepareEnv();
List<String> commands = prepareCommands();
ContainerLaunchContext amContainer = ContainerLaunchContext.newInstance(localResources, env, commands, null, null, null);
appContext.setAMContainerSpec(amContainer);
Resource capability = Resource.newInstance(amMemory, amVCores);
appContext.setResource(capability);
// set security tokens
if (UserGroupInformation.isSecurityEnabled()) {
Credentials credentials = new Credentials();
String tokenRenewer = conf.get(YarnConfiguration.RM_PRINCIPAL);
if (tokenRenewer == null || tokenRenewer.length() == 0) {
throw new IOException("Can't get Master Kerberos principal for the RM to use as renewer");
}
// For now, only getting tokens for the default file-system.
final Token<?> tokens[] = fs.addDelegationTokens(tokenRenewer, credentials);
if (tokens != null) {
for (Token<?> token : tokens) {
LOG.info("Got dt for " + fs.getUri() + "; " + token);
}
}
DataOutputBuffer dob = new DataOutputBuffer();
credentials.writeTokenStorageToStream(dob);
ByteBuffer fsTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
amContainer.setTokens(fsTokens);
}
Priority pri = Priority.newInstance(amPriority);
appContext.setPriority(pri);
appContext.setQueue(amQueue);
yarnClient.submitApplication(appContext);
return appId;
}
示例9: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
/**
* To submit an app to yarn cluster and monitor the status.
*/
public int run(String[] args) throws Exception {
LOG.info("Running Client");
this.yarnClient.start();
// request an application id from the RM. Get a new application id firstly.
YarnClientApplication app = this.yarnClient.createApplication();
GetNewApplicationResponse getNewAppResponse = app.getNewApplicationResponse();
// check cluster status.
checkPerNodeResourcesAvailable(getNewAppResponse);
// configure our request for an exec container
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
this.setAppId(appContext.getApplicationId());
LOG.info("Obtained new application ID: {}", this.getAppId());
// set app id and app name
appContext.setApplicationId(this.getAppId());
this.setAppName(getConf().get(GuaguaYarnConstants.GUAGUA_YARN_APP_NAME));
appContext.setApplicationName(this.getAppName());
prepareInputSplits();
// copy local resources to hdfs app folder
copyResourcesToFS();
appContext.setMaxAppAttempts(GuaguaYarnConstants.GUAGAU_APP_MASTER_DEFAULT_ATTMPTS);
appContext.setQueue(getConf().get(GuaguaYarnConstants.GUAGUA_YARN_QUEUE_NAME,
GuaguaYarnConstants.GUAGUA_YARN_DEFAULT_QUEUE_NAME));
Resource capability = Records.newRecord(Resource.class);
capability.setMemory(getConf().getInt(GuaguaYarnConstants.GUAGUA_YARN_MASTER_MEMORY,
GuaguaYarnConstants.GUAGUA_YARN_DEFAULT_MASTER_MEMORY));
capability.setVirtualCores(getConf().getInt(GuaguaYarnConstants.GUAGUA_YARN_MASTER_VCORES,
GuaguaYarnConstants.GUAGUA_YARN_MASTER_DEFAULT_VCORES));
appContext.setResource(capability);
// Set the priority for the application master
Priority pri = Records.newRecord(Priority.class);
pri.setPriority(getConf().getInt(GuaguaYarnConstants.GUAGUA_YARN_MASTER_PRIORITY,
GuaguaYarnConstants.GUAGUA_YARN_DEFAULT_PRIORITY));
appContext.setPriority(pri);
ContainerLaunchContext containerContext = buildContainerLaunchContext();
appContext.setAMContainerSpec(containerContext);
try {
LOG.info("Submitting application to ASM");
// obtain an "updated copy" of the appId for status checks/job kill later
this.setAppId(this.yarnClient.submitApplication(appContext));
LOG.info("Got new appId after submission : {}", getAppId());
} catch (YarnException yre) {
// try another time
LOG.info("Submitting application again to ASM");
// obtain an "updated copy" of the appId for status checks/job kill later
this.setAppId(this.yarnClient.submitApplication(appContext));
LOG.info("Got new appId after submission : {}", getAppId());
}
LOG.info("GuaguaAppMaster container request was submitted to ResourceManager for job: {}", getAppName());
return awaitYarnJobCompletion();
}
示例10: setupAndSubmitApplication
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
/**
* Setup and submit the Gobblin Yarn application.
*
* @throws IOException if there's anything wrong setting up and submitting the Yarn application
* @throws YarnException if there's anything wrong setting up and submitting the Yarn application
*/
@VisibleForTesting
ApplicationId setupAndSubmitApplication() throws IOException, YarnException {
YarnClientApplication gobblinYarnApp = this.yarnClient.createApplication();
ApplicationSubmissionContext appSubmissionContext = gobblinYarnApp.getApplicationSubmissionContext();
appSubmissionContext.setApplicationType(GOBBLIN_YARN_APPLICATION_TYPE);
ApplicationId applicationId = appSubmissionContext.getApplicationId();
GetNewApplicationResponse newApplicationResponse = gobblinYarnApp.getNewApplicationResponse();
// Set up resource type requirements for ApplicationMaster
Resource resource = prepareContainerResource(newApplicationResponse);
// Add lib jars, and jars and files that the ApplicationMaster need as LocalResources
Map<String, LocalResource> appMasterLocalResources = addAppMasterLocalResources(applicationId);
ContainerLaunchContext amContainerLaunchContext = Records.newRecord(ContainerLaunchContext.class);
amContainerLaunchContext.setLocalResources(appMasterLocalResources);
amContainerLaunchContext.setEnvironment(YarnHelixUtils.getEnvironmentVariables(this.yarnConfiguration));
amContainerLaunchContext.setCommands(Lists.newArrayList(buildApplicationMasterCommand(resource.getMemory())));
if (UserGroupInformation.isSecurityEnabled()) {
setupSecurityTokens(amContainerLaunchContext);
}
// Setup the application submission context
appSubmissionContext.setApplicationName(this.applicationName);
appSubmissionContext.setResource(resource);
appSubmissionContext.setQueue(this.appQueueName);
appSubmissionContext.setPriority(Priority.newInstance(0));
appSubmissionContext.setAMContainerSpec(amContainerLaunchContext);
// Also setup container local resources by copying local jars and files the container need to HDFS
addContainerLocalResources(applicationId);
// Submit the application
LOGGER.info("Submitting application " + applicationId);
this.yarnClient.submitApplication(appSubmissionContext);
LOGGER.info("Application successfully submitted and accepted");
ApplicationReport applicationReport = this.yarnClient.getApplicationReport(applicationId);
LOGGER.info("Application Name: " + applicationReport.getName());
LOGGER.info("Application Tracking URL: " + applicationReport.getTrackingUrl());
LOGGER.info("Application User: " + applicationReport.getUser() + " Queue: " + applicationReport.getQueue());
return applicationId;
}
示例11: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
/**
* Main run function for the client
* @return true if application completed successfully
* @throws java.io.IOException
* @throws org.apache.hadoop.yarn.exceptions.YarnException
*/
public boolean run() throws IOException, YarnException {
LOG.info("Running Client");
yarnClient.start();
// Get a new application id
YarnClientApplication app = yarnClient.createApplication();
GetNewApplicationResponse appResponse = app.getNewApplicationResponse();
int maxMem = appResponse.getMaximumResourceCapability().getMemory();
LOG.info("Max mem capabililty of resources in this cluster " + maxMem);
// A resource ask cannot exceed the max.
if (amMemory > maxMem) {
LOG.info("AM memory specified above max threshold of cluster. Using max value."
+ ", specified=" + amMemory
+ ", max=" + maxMem);
amMemory = maxMem;
}
int maxVCores = appResponse.getMaximumResourceCapability().getVirtualCores();
LOG.info("Max virtual cores capabililty of resources in this cluster " + maxVCores);
if (amVCores > maxVCores) {
LOG.info("AM virtual cores specified above max threshold of cluster. "
+ "Using max value." + ", specified=" + amVCores
+ ", max=" + maxVCores);
amVCores = maxVCores;
}
// set the application name
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
ApplicationId appId = appContext.getApplicationId();
appContext.setApplicationName(appName);
// Set up resource type requirements
// For now, both memory and vcores are supported, so we set memory and
// vcores requirements
Resource capability = Records.newRecord(Resource.class);
capability.setMemory(amMemory);
capability.setVirtualCores(amVCores);
appContext.setResource(capability);
// Set the priority for the application master
Priority pri = Records.newRecord(Priority.class);
pri.setPriority(amPriority);
appContext.setPriority(pri);
// Set the queue to which this application is to be submitted in the RM
appContext.setQueue(amQueue);
// Set the ContainerLaunchContext to describe the Container ith which the ApplicationMaster is launched.
appContext.setAMContainerSpec(getAMContainerSpec(appId.getId()));
// Submit the application to the applications manager
// SubmitApplicationResponse submitResp = applicationsManager.submitApplication(appRequest);
// Ignore the response as either a valid response object is returned on success
// or an exception thrown to denote some form of a failure
LOG.info("Submitting application to ASM");
yarnClient.submitApplication(appContext);
// Monitor the application
return monitorApplication(appId);
}
示例12: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
public boolean run() throws IOException, YarnException {
LOG.info("calling run.");
yarnClient.start();
// YarnClientApplication is used to populate:
// 1. GetNewApplication Response
// 2. ApplicationSubmissionContext
YarnClientApplication app = yarnClient.createApplication();
// GetNewApplicationResponse can be used to determined resources available.
GetNewApplicationResponse appResponse = app.getNewApplicationResponse();
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
ApplicationId appId = appContext.getApplicationId();
appContext.setApplicationName(this.appname);
// Set up the container launch context for AM.
ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
LocalResource appMasterJar;
appMasterJar = this.setupAppMasterJar(this.hdfsJar);
amContainer.setLocalResources(
Collections.singletonMap("ae_master.jar", appMasterJar));
// Set up CLASSPATH for ApplicationMaster
Map<String, String> appMasterEnv = new HashMap<String, String>();
setupAppMasterEnv(appMasterEnv);
amContainer.setEnvironment(appMasterEnv);
// Set up resource requirements for ApplicationMaster
Resource capability = Records.newRecord(Resource.class);
capability.setMemory(this.applicationMasterMem);
capability.setVirtualCores(1); //TODO: Can we really setVirtualCores ?
amContainer.setCommands(Collections.singletonList(this.getCommand()));
// put everything together.
appContext.setAMContainerSpec(amContainer);
appContext.setResource(capability);
appContext.setQueue("default"); // TODO: Need to investigate more on queuing an scheduling.
// Submit application
yarnClient.submitApplication(appContext);
return this.monitorApplication(appId);
}
示例13: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
public ApplicationId run() throws IOException, YarnException {
LOG.info("calling run.");
yarnClient.start();
// YarnClientApplication is used to populate:
// 1. GetNewApplication Response
// 2. ApplicationSubmissionContext
YarnClientApplication app = yarnClient.createApplication();
// GetNewApplicationResponse can be used to determined resources available.
GetNewApplicationResponse appResponse = app.getNewApplicationResponse();
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
this.appId = appContext.getApplicationId();
appContext.setApplicationName(this.appname);
// Set up the container launch context for AM.
ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
LocalResource appMasterJar;
FileSystem fs = FileSystem.get(this.conf);
amContainer.setLocalResources(
Collections.singletonMap("master.jar",
Util.newYarnAppResource(fs, new Path(this.hdfsJar), LocalResourceType.FILE,
LocalResourceVisibility.APPLICATION)));
// Set up CLASSPATH for ApplicationMaster
Map<String, String> appMasterEnv = new HashMap<String, String>();
setupAppMasterEnv(appMasterEnv);
amContainer.setEnvironment(appMasterEnv);
// Set up resource requirements for ApplicationMaster
Resource capability = Records.newRecord(Resource.class);
capability.setMemory(this.applicationMasterMem);
capability.setVirtualCores(1); //TODO: Can we really setVirtualCores ?
amContainer.setCommands(Collections.singletonList(this.getAppMasterCommand()));
// put everything together.
appContext.setAMContainerSpec(amContainer);
appContext.setResource(capability);
appContext.setQueue("default"); // TODO: Need to investigate more on queuing an scheduling.
// Submit application
yarnClient.submitApplication(appContext);
LOG.info("APPID: "+this.appId.toString());
return this.appId;
//return this.monitorApplication(appId);
}