2013-09-22 60 views
1

http://hadoop.apache.org/docs/r2.1.0-beta/hadoop-yarn/hadoop-yarn-site/WritingYarnApplications.htmlContainerLaunchContext.setResource()的Hadoop紗的缺失

我儘量讓這個例子從上面link.but工作得很好,我不能編譯如下

Resource capability = Records.newRecord(Resource.class); 
capability.setMemory(512); 
amContainer.setResource(capability); 

// Set the container launch content into the 
// ApplicationSubmissionContext 
appContext.setAMContainerSpec(amContainer); 

amContainer代碼ContainerLaunchContext我的hadoop版本是2.1.0-beta。 我做了一些調查。我發現ContainerLaunchContext中沒有方法「setResource」

我對此有3個問題
1)該方法已被刪除或什麼?
2)如果方法已被刪除,我現在該怎麼辦?
3)有沒有關於紗線的任何文檔,因爲我發現網站上的doc很容易,我希望我可以得到一個手冊或其他東西。例如, capability.setMemory(512); 根據代碼中的註釋我不知道它是512k或512M。

回答

0

您可以通過commend爲ApplicationMaster設置可用內存。因此:

// Set the necessary command to execute the application master 
Vector<CharSequence> vargs = new Vector<CharSequence>(30); 
... 
vargs.add("-Xmx" + amMemory + "m"); // notice "m" indicating megabytes, you can use also -Xms combined with -Xmx 
... // transform vargs to String commands 
amContainer.setCommands(commands); 

這應該可以解決您的問題。至於3個問題。紗線是快速發展的軟件。我的建議忘記文檔,獲取源代碼並閱讀它。這將回答你很多問題。

+0

這不適合我。 – Dyin

+0

'資源能力= Records.newRecord(Resource.class); capability.setMemory(amMemory); appContext.setResource(capability); // ApplicationSubmissionContext' 試試這個 – alien01

+0

'ContainerLaunchContext'沒有函數'setResource'。 – Dyin

1

這實際上是對問題的恰當解決方案。先前的回答可能會導致執行不正

@Dyin我可能不適合在註釋;)驗證爲AppMaster 2.2.0和2.3.0

驅動程序設置資源:

ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext(); 
ApplicationId appId = appContext.getApplicationId(); 
appContext.setApplicationName(this.appName); 

// Set up the container launch context for the application master 
ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class); 

Resource capability = Records.newRecord(Resource.class); 
capability.setMemory(amMemory);   
appContext.setResource(capability); 

appContext.setAMContainerSpec(amContainer); 

Priority pri = Records.newRecord(Priority.class); 
pri.setPriority(amPriority); 
appContext.setPriority(pri); 

appContext.setQueue(amQueue); 

// Submit the application to the applications manager 
yarnClient.submitApplication(appContext); // this.yarnClient = YarnClient.createYarnClient(); 

在ApplicationMaster你這是怎麼應該爲容器(工人)指定資源。

private AMRMClient.ContainerRequest setupContainerAskForRM() { 
     // setup requirements for hosts 
     // using * as any host will do for the distributed shell app 
     // set the priority for the request 
     Priority pri = Records.newRecord(Priority.class); 
     pri.setPriority(requestPriority); 

     // Set up resource type requirements 
     // For now, only memory is supported so we set memory requirements 
     Resource capability = Records.newRecord(Resource.class); 
     capability.setMemory(containerMemory); 

     AMRMClient.ContainerRequest request = new AMRMClient.ContainerRequest(capability, null, null, 
       pri); 
     return request; 
    } 

在AppMaster

AMRMClientAsync.CallbackHandler allocListener = new RMCallbackHandler(); 
resourceManager = AMRMClientAsync.createAMRMClientAsync(1000, allocListener); 
resourceManager.init(conf); 
resourceManager.start(); 

for (int i = 0; i < numTotalContainers; ++i) { 
    AMRMClient.ContainerRequest containerAsk = setupContainerAskForRM(); 
    resourceManager.addContainerRequest(containerAsk); // 
} 

啓動容器 您可以使用原來的答案溶液(java的CMD)部分的run()或main()方法,但它只是在頂部的櫻桃。無論如何,它應該工作。

+0

這幫了我!謝謝!另外,安裝2​​.3.0。 – Dyin