SlideShare a Scribd company logo


YarnClient client = YarnClient.createYarnClient();
Configuration conf = new Configuration();
client.init(conf);
client.start();
YarnClientApplication app = client.createApplication();
ApplicationSubmissionContext appContext =
app.getApplicationSubmissionContext();
ApplicationId appId = appContext.getApplicationId();
//
appContext.setApplicationName(appName);
// AM memory, vcore
Resource resource = Records.newRecord(Resource.class);
resource.setMemory(amMemory);
resource.setVirtualCores(amVcore);
appContext.setResource(resource);
Map<String, LocalResource> localResources = new HashMap<>();
ContainerLaunchContext container = Records.newRecord(ContainerLaunchContext.class);

FileSystem fs = FileSystem.get(conf);

// HDFS Jar
fs.copyFromLocalFile(new Path(src), new Path(distPath));

// Jar
FileStatus status = fs.getFileStatus(distPath);
LocalResource localResource = LocalResource.newInstance(
ConverterUtils.getYarnUrlFromURI(dist.toUri()),
LocalResourceType.FILE, LocalResourceVisibility.APPLICATION,
status.getLen(), status.getModificationTime());
localResources.put(distJar, localResource);
container.setLocalResources(localResources);
Map<String, String> env = new HashMap<>();
LocalResource appJar = localResources.get(distJar);
Path jarPath= new Path(distPath);

env.put(“jar_path”, distPath);
env.put(“jar_length”, Long.toString(status.getLen()));
env.put(“jar_timestamp”,
Long.toString(status.getModificationTime()));
StringBuilder classPath =
new StringBuilder(Environment.CLASSPATH.$$())
.append(ApplicationConstants.CLASS_PATH_SEPARATOR).append("./*");
// ※ Hadoop classpath
env.put(“classpath”, classPath.toString());
container.setEnviroment(env);
StringBuilder sb = new StringBuilder();
sb.appned(Environment.JAVA_HOME.$$() + “/bin/java ”)
.append("-Xmx" + amMemory + "m ")
.append("jp.classmethod.yarn_app.MyApplicationMaster ")
.append("…") //
.append("> " + ApplicationConstants.LOG_DIR_EXPANSION_VAR
+ "/AppMaster.stdout ")
.append("2> " + ApplicationConstants.LOG_DIR_EXPANSION_VAR
+ "/AppMaster.stdout ");
List<String> cmd = new ArrayList<>();
cmd.append(sb.toString());
container.setCommands(cmd);
appContext.setAMContainerSpec(container);
client.submitApplication();
while(true) {
ApplicationReport report = client.getApplicationReport(appId);
YarnApplicationState appState =
report.getYarnApplicationState();
FinalApplicationStatus finStatus =
report.getFinalApplicationStatus();
if (YarnApplicationState.FINISHED == appState &&
FinalApplicationStatus.SUCCESS == finStatus) {
//
} else {
//
}
Thread.sleep(1000);
}
Configuration conf = new Configuration();
// (ex. attempId )
ContainerId containerId =
ConverterUtils.toContainerId(
envs.get(ApplicationConstants.Environment.CONTAINER_ID.name()));
ApplicationAttemptId attemptId =
containerId.getApplicationAttemptId();
AMRMClient<ContainerRequest> client =
AMRMClient.createAMRMClient();
client.init(conf);
client.start();
// ApplicationMaster
client.registerApplicationMaster("", 0, "");
//
for (i = 0; i < totalContainerSize; i++) {
ContainerRequest containerReq =
new ContainerRequest(capability, null, null, priority);
client.addContainerRequest(containerReq);
}
NMClient nmClient = NMClient.createNMClient();
nmClient.init(conf);
nmClient.start();
//
//
int allocatedContainers = 0;
int complitedConttainers = 0;
while(completedContainers < totalContainerSize) {
AllocateResponse response =
amRMClient.allocate(completedContainers / totalContainerSize);
for (Container container : response.getAllocatedContainers()) {
allocatedContainers++;
ContainerLaunchContext appContainer = … // ※ container
nmClient.startContainer(container, appContainer);
}
completedContainers +=
response.getCompletedContainersStatuses().size();
Thread.sleep(100);
}
ContainerLaunchContext appContainer =
Records.newRecord(ContainerLaunchContext.class);
// jar
appContainer.setLocalRecources(
Collections.singletonMap("appJar", appJar);
appContainer.setEnviroment(env);
// Container java
appContainer.setCommands("$JAVA_HOME/bin/java" + "…");
//
client.unregisterApplicationMaster(
FinalApplicationStatus.SUCCEEDED, "", "");
How to create Yarn Application #cmdevio2017
How to create Yarn Application #cmdevio2017
How to create Yarn Application #cmdevio2017
How to create Yarn Application #cmdevio2017
How to create Yarn Application #cmdevio2017
How to create Yarn Application #cmdevio2017
How to create Yarn Application #cmdevio2017

More Related Content

What's hot

Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
Thomas Weinert
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programming
Casear Chu
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
Sebastian Marek
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
Thomas Weinert
 
Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope Rpx
Paris, France
 

What's hot (20)

vfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent tests
 
Docker tips & tricks
Docker  tips & tricksDocker  tips & tricks
Docker tips & tricks
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
Streaming using Kafka Flink & Elasticsearch
Streaming using Kafka Flink & ElasticsearchStreaming using Kafka Flink & Elasticsearch
Streaming using Kafka Flink & Elasticsearch
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programming
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
 
25437 pertemuan25(hitcounter)
25437 pertemuan25(hitcounter)25437 pertemuan25(hitcounter)
25437 pertemuan25(hitcounter)
 
PuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbqueryPuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbquery
 
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
 
OpenStack Log Mining
OpenStack Log MiningOpenStack Log Mining
OpenStack Log Mining
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
Cocoa勉強会23-識別情報の変換〜文字エンコードとデータタイプ
Cocoa勉強会23-識別情報の変換〜文字エンコードとデータタイプCocoa勉強会23-識別情報の変換〜文字エンコードとデータタイプ
Cocoa勉強会23-識別情報の変換〜文字エンコードとデータタイプ
 
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
 
Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope Rpx
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstraction
 
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
 
Asynchonicity: concurrency. A tale of
Asynchonicity: concurrency. A tale ofAsynchonicity: concurrency. A tale of
Asynchonicity: concurrency. A tale of
 

Similar to How to create Yarn Application #cmdevio2017

HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
Remy Sharp
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
Deependra Ariyadewa
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)
Fabien Potencier
 
Introduction to the New Asynchronous API in the .NET Driver
Introduction to the New Asynchronous API in the .NET DriverIntroduction to the New Asynchronous API in the .NET Driver
Introduction to the New Asynchronous API in the .NET Driver
MongoDB
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event Dispatcher
Sarah El-Atm
 

Similar to How to create Yarn Application #cmdevio2017 (20)

Symfony internals [english]
Symfony internals [english]Symfony internals [english]
Symfony internals [english]
 
09 data storage, backup and roaming
09   data storage, backup and roaming09   data storage, backup and roaming
09 data storage, backup and roaming
 
Harnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache TwillHarnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache Twill
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in Heaven
 
Dpilot - Source Code with Snapshots
Dpilot - Source Code with SnapshotsDpilot - Source Code with Snapshots
Dpilot - Source Code with Snapshots
 
Pengenalan blaast platform sdk
Pengenalan blaast platform sdkPengenalan blaast platform sdk
Pengenalan blaast platform sdk
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Nodejs do teste de unidade ao de integração
Nodejs  do teste de unidade ao de integraçãoNodejs  do teste de unidade ao de integração
Nodejs do teste de unidade ao de integração
 
Windows 8 metro applications
Windows 8 metro applicationsWindows 8 metro applications
Windows 8 metro applications
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
Filesystem abstractions and msg queue sergeev - symfony camp 2018
Filesystem abstractions and msg queue   sergeev - symfony camp 2018Filesystem abstractions and msg queue   sergeev - symfony camp 2018
Filesystem abstractions and msg queue sergeev - symfony camp 2018
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)
 
OpenCMIS Part 1
OpenCMIS Part 1OpenCMIS Part 1
OpenCMIS Part 1
 
Spring data iii
Spring data iiiSpring data iii
Spring data iii
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
20150319 testotipsio
20150319 testotipsio20150319 testotipsio
20150319 testotipsio
 
Introduction to the New Asynchronous API in the .NET Driver
Introduction to the New Asynchronous API in the .NET DriverIntroduction to the New Asynchronous API in the .NET Driver
Introduction to the New Asynchronous API in the .NET Driver
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event Dispatcher
 

More from __john_smith__

初心者向けに機械学習のハンズオンセミナーをしてわかったこと
初心者向けに機械学習のハンズオンセミナーをしてわかったこと初心者向けに機械学習のハンズオンセミナーをしてわかったこと
初心者向けに機械学習のハンズオンセミナーをしてわかったこと
__john_smith__
 

More from __john_smith__ (17)

全部Excelだけで実現しようとして後悔するデータ分析 2nd Edition
全部Excelだけで実現しようとして後悔するデータ分析 2nd Edition 全部Excelだけで実現しようとして後悔するデータ分析 2nd Edition
全部Excelだけで実現しようとして後悔するデータ分析 2nd Edition
 
全部Excelでやろうとして後悔するデータ分析
全部Excelでやろうとして後悔するデータ分析全部Excelでやろうとして後悔するデータ分析
全部Excelでやろうとして後悔するデータ分析
 
PoCで終わらせない!データ分析・AI活用
PoCで終わらせない!データ分析・AI活用PoCで終わらせない!データ分析・AI活用
PoCで終わらせない!データ分析・AI活用
 
ML Sagemaker Dev.IO
ML Sagemaker Dev.IOML Sagemaker Dev.IO
ML Sagemaker Dev.IO
 
Amazon SageMakerでゼロからはじめる機械学習入門
Amazon SageMakerでゼロからはじめる機械学習入門Amazon SageMakerでゼロからはじめる機械学習入門
Amazon SageMakerでゼロからはじめる機械学習入門
 
Alteryx UG3 LT #alteryx_ug
Alteryx UG3 LT #alteryx_ugAlteryx UG3 LT #alteryx_ug
Alteryx UG3 LT #alteryx_ug
 
Alteryx Inspire2017 新製品&新機能紹介
Alteryx Inspire2017 新製品&新機能紹介Alteryx Inspire2017 新製品&新機能紹介
Alteryx Inspire2017 新製品&新機能紹介
 
Alteryxでkaggleに挑戦する #alteryx #alteryx_ug
Alteryxでkaggleに挑戦する #alteryx #alteryx_ugAlteryxでkaggleに挑戦する #alteryx #alteryx_ug
Alteryxでkaggleに挑戦する #alteryx #alteryx_ug
 
初心者向けに機械学習のハンズオンセミナーをしてわかったこと
初心者向けに機械学習のハンズオンセミナーをしてわかったこと初心者向けに機械学習のハンズオンセミナーをしてわかったこと
初心者向けに機械学習のハンズオンセミナーをしてわかったこと
 
この素晴らしいSQLに祝福を!
この素晴らしいSQLに祝福を!この素晴らしいSQLに祝福を!
この素晴らしいSQLに祝福を!
 
Javado2
Javado2Javado2
Javado2
 
Jubatus hack2
Jubatus hack2Jubatus hack2
Jubatus hack2
 
5分でわかる 怖くない機械学習
5分でわかる 怖くない機械学習5分でわかる 怖くない機械学習
5分でわかる 怖くない機械学習
 
LSTMで話題分類
LSTMで話題分類LSTMで話題分類
LSTMで話題分類
 
初心者向け「凛ちゃん」
初心者向け「凛ちゃん」初心者向け「凛ちゃん」
初心者向け「凛ちゃん」
 
SparkRをつかってみた(Japan.R)
SparkRをつかってみた(Japan.R)SparkRをつかってみた(Japan.R)
SparkRをつかってみた(Japan.R)
 
Jubatus Hackathon
Jubatus HackathonJubatus Hackathon
Jubatus Hackathon
 

Recently uploaded

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docxThe Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
 

How to create Yarn Application #cmdevio2017

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. YarnClient client = YarnClient.createYarnClient(); Configuration conf = new Configuration(); client.init(conf); client.start(); YarnClientApplication app = client.createApplication(); ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext(); ApplicationId appId = appContext.getApplicationId();
  • 17. // appContext.setApplicationName(appName); // AM memory, vcore Resource resource = Records.newRecord(Resource.class); resource.setMemory(amMemory); resource.setVirtualCores(amVcore); appContext.setResource(resource);
  • 18. Map<String, LocalResource> localResources = new HashMap<>(); ContainerLaunchContext container = Records.newRecord(ContainerLaunchContext.class);
 FileSystem fs = FileSystem.get(conf);
 // HDFS Jar fs.copyFromLocalFile(new Path(src), new Path(distPath));
 // Jar FileStatus status = fs.getFileStatus(distPath); LocalResource localResource = LocalResource.newInstance( ConverterUtils.getYarnUrlFromURI(dist.toUri()), LocalResourceType.FILE, LocalResourceVisibility.APPLICATION, status.getLen(), status.getModificationTime()); localResources.put(distJar, localResource); container.setLocalResources(localResources);
  • 19. Map<String, String> env = new HashMap<>(); LocalResource appJar = localResources.get(distJar); Path jarPath= new Path(distPath);
 env.put(“jar_path”, distPath); env.put(“jar_length”, Long.toString(status.getLen())); env.put(“jar_timestamp”, Long.toString(status.getModificationTime())); StringBuilder classPath = new StringBuilder(Environment.CLASSPATH.$$()) .append(ApplicationConstants.CLASS_PATH_SEPARATOR).append("./*"); // ※ Hadoop classpath env.put(“classpath”, classPath.toString()); container.setEnviroment(env);
  • 20. StringBuilder sb = new StringBuilder(); sb.appned(Environment.JAVA_HOME.$$() + “/bin/java ”) .append("-Xmx" + amMemory + "m ") .append("jp.classmethod.yarn_app.MyApplicationMaster ") .append("…") // .append("> " + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/AppMaster.stdout ") .append("2> " + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/AppMaster.stdout "); List<String> cmd = new ArrayList<>(); cmd.append(sb.toString()); container.setCommands(cmd); appContext.setAMContainerSpec(container);
  • 22. while(true) { ApplicationReport report = client.getApplicationReport(appId); YarnApplicationState appState = report.getYarnApplicationState(); FinalApplicationStatus finStatus = report.getFinalApplicationStatus(); if (YarnApplicationState.FINISHED == appState && FinalApplicationStatus.SUCCESS == finStatus) { // } else { // } Thread.sleep(1000); }
  • 23.
  • 24.
  • 25.
  • 26. Configuration conf = new Configuration(); // (ex. attempId ) ContainerId containerId = ConverterUtils.toContainerId( envs.get(ApplicationConstants.Environment.CONTAINER_ID.name())); ApplicationAttemptId attemptId = containerId.getApplicationAttemptId();
  • 27. AMRMClient<ContainerRequest> client = AMRMClient.createAMRMClient(); client.init(conf); client.start(); // ApplicationMaster client.registerApplicationMaster("", 0, ""); // for (i = 0; i < totalContainerSize; i++) { ContainerRequest containerReq = new ContainerRequest(capability, null, null, priority); client.addContainerRequest(containerReq); }
  • 28. NMClient nmClient = NMClient.createNMClient(); nmClient.init(conf); nmClient.start(); // // int allocatedContainers = 0; int complitedConttainers = 0;
  • 29. while(completedContainers < totalContainerSize) { AllocateResponse response = amRMClient.allocate(completedContainers / totalContainerSize); for (Container container : response.getAllocatedContainers()) { allocatedContainers++; ContainerLaunchContext appContainer = … // ※ container nmClient.startContainer(container, appContainer); } completedContainers += response.getCompletedContainersStatuses().size(); Thread.sleep(100); }
  • 30. ContainerLaunchContext appContainer = Records.newRecord(ContainerLaunchContext.class); // jar appContainer.setLocalRecources( Collections.singletonMap("appJar", appJar); appContainer.setEnviroment(env); // Container java appContainer.setCommands("$JAVA_HOME/bin/java" + "…");