本文整理匯總了Java中org.apache.hadoop.yarn.client.api.YarnClientApplication.getApplicationSubmissionContext方法的典型用法代碼示例。如果您正苦於以下問題:Java YarnClientApplication.getApplicationSubmissionContext方法的具體用法?Java YarnClientApplication.getApplicationSubmissionContext怎麽用?Java YarnClientApplication.getApplicationSubmissionContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.yarn.client.api.YarnClientApplication
的用法示例。
在下文中一共展示了YarnClientApplication.getApplicationSubmissionContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: submitApplication
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
ApplicationId submitApplication(
YarnClientApplication app,
String appName,
ContainerLaunchContext launchContext,
Resource resource,
String queue) throws Exception {
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
appContext.setApplicationName(appName);
appContext.setApplicationTags(new HashSet<>());
appContext.setAMContainerSpec(launchContext);
appContext.setResource(resource);
appContext.setQueue(queue);
return yarnClient.submitApplication(appContext);
}
示例2: setupAM
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
private ApplicationSubmissionContext setupAM(YarnClientApplication clientApp) {
ApplicationSubmissionContext appContext = clientApp.getApplicationSubmissionContext();
// already happens inside Hadoop but to be consistent
appContext.setApplicationId(clientApp.getNewApplicationResponse().getApplicationId());
appContext.setApplicationName(clientCfg.appName());
appContext.setAMContainerSpec(createContainerContext());
appContext.setResource(YarnCompat.resource(client.getConfiguration(), clientCfg.amMem(), clientCfg.amVCores()));
appContext.setPriority(Priority.newInstance(clientCfg.amPriority()));
appContext.setQueue(clientCfg.amQueue());
appContext.setApplicationType(clientCfg.appType());
YarnCompat.setApplicationTags(appContext, clientCfg.appTags());
return appContext;
}
示例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: UnmanagedAmYarnSubmissionHelper
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
UnmanagedAmYarnSubmissionHelper(
final YarnConfiguration yarnConfiguration,
final YarnProxyUser yarnProxyUser,
final SecurityTokenProvider tokenProvider) throws IOException, YarnException {
this.tokenProvider = tokenProvider;
this.yarnProxyUser = yarnProxyUser;
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 UNMANAGED Application ID from YARN.");
final ContainerLaunchContext launchContext = YarnTypes.getContainerLaunchContext(
Collections.<String>emptyList(), Collections.<String, LocalResource>emptyMap(), tokenProvider.getTokens());
final YarnClientApplication yarnClientApplication = this.yarnClient.createApplication();
this.applicationSubmissionContext = yarnClientApplication.getApplicationSubmissionContext();
this.applicationSubmissionContext.setAMContainerSpec(launchContext);
this.applicationSubmissionContext.setUnmanagedAM(true);
this.applicationId = this.applicationSubmissionContext.getApplicationId();
LOG.log(Level.INFO, "YARN UNMANAGED Application ID: {0}", this.applicationId);
}
示例8: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
public void run(String[] args) throws Exception {
YarnConfiguration conf = new YarnConfiguration();
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
String cryptopath = "";
final String zonepaths = args[0];
final String exclasspath = args[1];
final String globalKMS = args.length == 2 ? "localhost:16000" : args[2];
final String pluginURI = conf.get(NuCypherExtRpcServer.NUCYPHER_EXT_NAMENODE_SERVICE_RPC_ADDRESS_KEY,
InetSocketAddress.createUnresolved(new URI(conf.get("fs.defaultFS")).getHost(),
NuCypherExtRpcServer.DEFAULT_PORT).toString());
String providers = conf.get(KEY_PROVIDER_PATH);
YarnClientApplication app = yarnClient.createApplication();
ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
amContainer.setCommands(
Collections.singletonList(
//"/usr/bin/java"+
Environment.JAVA_HOME.$$() + "/bin/java" +
" -Xmx1024M"+
" ApplicationMasterKMS"+
" " + zonepaths +
" " + exclasspath +
" " + globalKMS +
" " + providers +
" " + pluginURI +
" 1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout" +
" 2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr"));
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
ApplicationId appId = appContext.getApplicationId();
LocalResource appMasterJar = Records.newRecord(LocalResource.class);
// setupAppMasterJar(jarPath, appMasterJar);
Map<String, LocalResource> localResources = new HashMap<>();
//localResources.put("prkeyrotation.jar", appMasterJar);
setupExtJar(exclasspath, localResources, appId.toString());
amContainer.setLocalResources(localResources);
Map<String, String> appMasterEnv = new HashMap<String, String>();
setupAppMasterEnv(appMasterEnv, exclasspath);
amContainer.setEnvironment(appMasterEnv);
Resource capability = Records.newRecord(Resource.class);
capability.setMemory(1024);
capability.setVirtualCores(1);
appContext.setApplicationName("prkeyrotation");
appContext.setAMContainerSpec(amContainer);
appContext.setResource(capability);
appContext.setQueue("default");
System.out.println("Submitting application "+appId);
yarnClient.submitApplication(appContext);
ApplicationReport appReport = yarnClient.getApplicationReport(appId);
YarnApplicationState appState = appReport.getYarnApplicationState();
while (appState != YarnApplicationState.FINISHED &&
appState != YarnApplicationState.KILLED &&
appState != YarnApplicationState.FAILED) {
Thread.sleep(100);
appReport = yarnClient.getApplicationReport(appId);
appState = appReport.getYarnApplicationState();
}
System.out.println("Application " + appId + " finished with " +
" state " + appState +
" at " + appReport.getFinishTime());
}
示例9: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
private void run(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Usage: [options] [commands..]");
System.out.println("options: [-file filename] [-appcp appClasspath]");
return;
}
this.initArgs(args);
// Create yarnClient
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
// Create application via yarnClient
YarnClientApplication app = yarnClient.createApplication();
// Set up the container launch context for the application master
ContainerLaunchContext amContainer = Records
.newRecord(ContainerLaunchContext.class);
ApplicationSubmissionContext appContext = app
.getApplicationSubmissionContext();
// Submit application
ApplicationId appId = appContext.getApplicationId();
//add ctrl+c signal handler
CtrlCHandler handler = new CtrlCHandler(appId, yarnClient);
Signal intSignal = new Signal("INT");
Signal.handle(intSignal, handler);
// setup security token
amContainer.setTokens(this.setupTokens());
// setup cache-files and environment variables
amContainer.setLocalResources(this.setupCacheFiles(appId));
amContainer.setEnvironment(this.getEnvironment());
String cmd = Environment.JAVA_HOME.$$() + "/bin/java"
+ " -Xmx900m"
+ " org.apache.hadoop.yarn.dmlc.ApplicationMaster"
+ this.cacheFileArg + ' ' + this.appArgs + " 1>"
+ ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout"
+ " 2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr";
LOG.debug(cmd);
amContainer.setCommands(Collections.singletonList(cmd));
// Set up resource type requirements for ApplicationMaster
Resource capability = Records.newRecord(Resource.class);
capability.setMemory(1024);
capability.setVirtualCores(1);
LOG.info("jobname=" + this.jobName + ",username=" + this.userName);
appContext.setApplicationName(jobName + ":DMLC-YARN");
appContext.setAMContainerSpec(amContainer);
appContext.setResource(capability);
appContext.setQueue(queue);
//appContext.setUser(userName);
LOG.info("Submitting application " + appId);
yarnClient.submitApplication(appContext);
ApplicationReport appReport = yarnClient.getApplicationReport(appId);
YarnApplicationState appState = appReport.getYarnApplicationState();
while (appState != YarnApplicationState.FINISHED
&& appState != YarnApplicationState.KILLED
&& appState != YarnApplicationState.FAILED) {
Thread.sleep(100);
appReport = yarnClient.getApplicationReport(appId);
appState = appReport.getYarnApplicationState();
}
System.out.println("Application " + appId + " finished with"
+ " state " + appState + " at " + appReport.getFinishTime());
if (!appReport.getFinalApplicationStatus().equals(
FinalApplicationStatus.SUCCEEDED)) {
System.err.println(appReport.getDiagnostics());
System.out.println("Available queues:");
for (QueueInfo q : yarnClient.getAllQueues()) {
System.out.println(q.getQueueName());
}
yarnClient.killApplication(appId);
}
}
示例10: 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;
}
示例11: 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();
}
示例12: 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;
}
示例13: run
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
public void run(String[] args) throws Exception {
final String command = args[0];
final int n = Integer.valueOf(args[1]);
//No need to upload jar since the class is already include in the classpath
//final Path jarPath = new Path(args[2]);
// Create yarnClient
Configuration conf = new YarnConfiguration(miniYarnCluster.getConfig());
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
// Create application via yarnClient
YarnClientApplication app = yarnClient.createApplication();
// Set up the container launch context for the application master
ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
// amContainer.setCommands(
// Collections.singletonList(
// "java -Xmx128M " +
// HelloApplicationMaster.class.getName() +
// " " + command +
// " " + String.valueOf(n) +
// " 1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout" +
// " 2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr"
// )
// );
amContainer.setCommands(
Collections.singletonList(
command +
" 1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout" +
" 2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr"
)
);
// Setup jar for ApplicationMaster
LocalResource appMasterJar = Records.newRecord(LocalResource.class);
//setupAppMasterJar(jarPath, appMasterJar);
//amContainer.setLocalResources(Collections.singletonMap("simpleapp.jar", appMasterJar));
System.out.println("Setup CLASSPATH for ApplicationMaster") ;
Map<String, String> appMasterEnv = new HashMap<String, String>();
setupAppMasterEnv(appMasterEnv);
amContainer.setEnvironment(appMasterEnv);
System.out.println("Set up resource type requirements for ApplicationMaster") ;
Resource resource = Records.newRecord(Resource.class);
resource.setMemory(256);
resource.setVirtualCores(1);
System.out.println("Finally, set-up ApplicationSubmissionContext for the application");
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
appContext.setApplicationName("simple-yarn-app"); // application name
appContext.setAMContainerSpec(amContainer);
appContext.setResource(resource);
appContext.setQueue("default"); // queue
// Submit application
ApplicationId appId = appContext.getApplicationId();
System.out.println("Submitting application " + appId);
yarnClient.submitApplication(appContext);
ApplicationReport appReport = yarnClient.getApplicationReport(appId);
YarnApplicationState appState = appReport.getYarnApplicationState();
while (appState != YarnApplicationState.FINISHED &&
appState != YarnApplicationState.KILLED &&
appState != YarnApplicationState.FAILED) {
Thread.sleep(100);
appReport = yarnClient.getApplicationReport(appId);
appState = appReport.getYarnApplicationState();
}
assertEquals(YarnApplicationState.FINISHED, appState) ;
System.out.println(
"Application " + appId + " finished with state " + appState +
" at " + appReport.getFinishTime()
);
}
示例14: 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);
}
示例15: launch
import org.apache.hadoop.yarn.client.api.YarnClientApplication; //導入方法依賴的package包/類
/**
* Main getLaunchContext function for launch this application
*
* @return true if application completed successfully
* @throws java.io.IOException
* @throws org.apache.hadoop.yarn.exceptions.YarnException
*/
private void launch() throws IOException, YarnException {
LOG.info("Running Client");
yarnClient.start();
displayClusterSummary();
// Get a new application id
YarnClientApplication app = yarnClient.createApplication();
// validate resource capacity for launch an application amster
validateResourceForAM(app);
// set the application name
ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
appContext.setApplicationName(appName);
// Set up the container launch context for the application master
setupAMContainerLaunchContext(appContext);
// 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);
// TODO - what is the range for priority? how to decide?
pri.setPriority(amPriority);
appContext.setPriority(pri);
// Set the queue to which this application is to be submitted in the RM
appContext.setQueue(amQueue);
// 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);
// TODO
// Try submitting the same request again
// app submission failure?
// Monitor the application
// return monitorApplication(appId);
}