java中launch方法,Java MockRM.launchAM方法代码示例

import org.apache.hadoop.yarn.server.resourcemanager.MockRM; //导入方法依赖的package包/类

@Test

public void testPriorityWithPendingApplications() throws Exception {

Configuration conf = new Configuration();

conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,

ResourceScheduler.class);

// Set Max Application Priority as 10

conf.setInt(YarnConfiguration.MAX_CLUSTER_LEVEL_APPLICATION_PRIORITY, 10);

MockRM rm = new MockRM(conf);

rm.start();

Priority appPriority1 = Priority.newInstance(5);

MockNM nm1 = rm.registerNode("127.0.0.1:1234", 8 * GB);

RMApp app1 = rm.submitApp(1 * GB, appPriority1);

// kick the scheduler, 1 GB given to AM1, remaining 7GB on nm1

MockAM am1 = MockRM.launchAM(app1, rm, nm1);

am1.registerAppAttempt();

// kick the scheduler, 7 containers will be allocated for App1

List allocated1 = am1.allocateAndWaitForContainers("127.0.0.1",

7, 1 * GB, nm1);

Assert.assertEquals(7, allocated1.size());

Assert.assertEquals(1 * GB, allocated1.get(0).getResource().getMemory());

// check node report, 8 GB used (1 AM and 7 containers) and 0 GB available

SchedulerNodeReport report_nm1 = rm.getResourceScheduler().getNodeReport(

nm1.getNodeId());

Assert.assertEquals(8 * GB, report_nm1.getUsedResource().getMemory());

Assert.assertEquals(0 * GB, report_nm1.getAvailableResource().getMemory());

// Submit the second app App2 with priority 7

Priority appPriority2 = Priority.newInstance(7);

RMApp app2 = rm.submitApp(1 * GB, appPriority2);

// Submit the third app App3 with priority 8

Priority appPriority3 = Priority.newInstance(8);

RMApp app3 = rm.submitApp(1 * GB, appPriority3);

// Submit the second app App4 with priority 6

Priority appPriority4 = Priority.newInstance(6);

RMApp app4 = rm.submitApp(1 * GB, appPriority4);

// Only one app can run as AM resource limit restricts it. Kill app1,

// If app3 (highest priority among rest) gets active, it indicates that

// priority is working with pendingApplications.

rm.killApp(app1.getApplicationId());

// kick the scheduler, app3 (high among pending) gets free space

MockAM am3 = MockRM.launchAM(app3, rm, nm1);

am3.registerAppAttempt();

// check node report, 1 GB used and 7 GB available

report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId());

Assert.assertEquals(1 * GB, report_nm1.getUsedResource().getMemory());

Assert.assertEquals(7 * GB, report_nm1.getAvailableResource().getMemory());

rm.stop();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值