Skip to content

Commit 815cde9

Browse files
YARN-6971. Clean up different ways to create resources. Contributed by Riya Khandelwal
1 parent 29f2230 commit 815cde9

File tree

38 files changed

+170
-162
lines changed

38 files changed

+170
-162
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
import org.apache.hadoop.yarn.util.Clock;
149149
import org.apache.hadoop.yarn.util.ControlledClock;
150150
import org.apache.hadoop.yarn.util.Records;
151+
import org.apache.hadoop.yarn.util.resource.Resources;
151152
import org.apache.hadoop.yarn.util.SystemClock;
152153
import org.junit.jupiter.api.AfterEach;
153154
import org.junit.jupiter.api.Assertions;
@@ -502,8 +503,8 @@ public void testPreemptReducers() throws Exception {
502503
0, 0, 0, 0, 0, 0, "jobfile", null, false, ""));
503504
MyContainerAllocator allocator = new MyContainerAllocator(rm, conf,
504505
appAttemptId, mockJob, SystemClock.getInstance());
505-
allocator.setMapResourceRequest(BuilderUtils.newResource(1024, 1));
506-
allocator.setReduceResourceRequest(BuilderUtils.newResource(1024, 1));
506+
allocator.setMapResourceRequest(Resources.createResource(1024));
507+
allocator.setReduceResourceRequest(Resources.createResource(1024));
507508
RMContainerAllocator.AssignedRequests assignedRequests =
508509
allocator.getAssignedRequests();
509510
RMContainerAllocator.ScheduledRequests scheduledRequests =
@@ -557,8 +558,8 @@ public void testNonAggressivelyPreemptReducers() throws Exception {
557558
clock.setTime(1);
558559
MyContainerAllocator allocator = new MyContainerAllocator(rm, conf,
559560
appAttemptId, mockJob, clock);
560-
allocator.setMapResourceRequest(BuilderUtils.newResource(1024, 1));
561-
allocator.setReduceResourceRequest(BuilderUtils.newResource(1024, 1));
561+
allocator.setMapResourceRequest(Resources.createResource(1024));
562+
allocator.setReduceResourceRequest(Resources.createResource(1024));
562563
RMContainerAllocator.AssignedRequests assignedRequests =
563564
allocator.getAssignedRequests();
564565
RMContainerAllocator.ScheduledRequests scheduledRequests =
@@ -622,8 +623,8 @@ public void testUnconditionalPreemptReducers() throws Exception {
622623
clock.setTime(1);
623624
MyContainerAllocator allocator = new MyContainerAllocator(rm, conf,
624625
appAttemptId, mockJob, clock);
625-
allocator.setMapResourceRequest(BuilderUtils.newResource(1024, 1));
626-
allocator.setReduceResourceRequest(BuilderUtils.newResource(1024, 1));
626+
allocator.setMapResourceRequest(Resources.createResource(1024));
627+
allocator.setReduceResourceRequest(Resources.createResource(1024));
627628
RMContainerAllocator.AssignedRequests assignedRequests =
628629
allocator.getAssignedRequests();
629630
RMContainerAllocator.ScheduledRequests scheduledRequests =
@@ -2205,8 +2206,8 @@ public void testReduceScheduling() throws Exception {
22052206
int scheduledReduces = 0;
22062207
int assignedMaps = 2;
22072208
int assignedReduces = 0;
2208-
Resource mapResourceReqt = BuilderUtils.newResource(1024, 1);
2209-
Resource reduceResourceReqt = BuilderUtils.newResource(2 * 1024, 1);
2209+
Resource mapResourceReqt = Resources.createResource(1024);
2210+
Resource reduceResourceReqt = Resources.createResource(2 * 1024);
22102211
int numPendingReduces = 4;
22112212
float maxReduceRampupLimit = 0.5f;
22122213
float reduceSlowStart = 0.2f;
@@ -2241,7 +2242,7 @@ public void testReduceScheduling() throws Exception {
22412242
verify(allocator, never()).scheduleAllReduces();
22422243

22432244
succeededMaps = 3;
2244-
doReturn(BuilderUtils.newResource(0, 0)).when(allocator).getResourceLimit();
2245+
doReturn(Resources.createResource(0)).when(allocator).getResourceLimit();
22452246
allocator.scheduleReduces(
22462247
totalMaps, succeededMaps,
22472248
scheduledMaps, scheduledReduces,
@@ -2252,7 +2253,7 @@ public void testReduceScheduling() throws Exception {
22522253
verify(allocator, times(1)).setIsReduceStarted(true);
22532254

22542255
// Test reduce ramp-up
2255-
doReturn(BuilderUtils.newResource(100 * 1024, 100 * 1)).when(allocator)
2256+
doReturn(Resources.createResource(100 * 1024, 100 * 1)).when(allocator)
22562257
.getResourceLimit();
22572258
allocator.scheduleReduces(
22582259
totalMaps, succeededMaps,
@@ -2266,7 +2267,7 @@ public void testReduceScheduling() throws Exception {
22662267

22672268
// Test reduce ramp-down
22682269
scheduledReduces = 3;
2269-
doReturn(BuilderUtils.newResource(10 * 1024, 10 * 1)).when(allocator)
2270+
doReturn(Resources.createResource(10 * 1024, 10 * 1)).when(allocator)
22702271
.getResourceLimit();
22712272
allocator.scheduleReduces(
22722273
totalMaps, succeededMaps,
@@ -2282,7 +2283,7 @@ public void testReduceScheduling() throws Exception {
22822283
// should be invoked twice.
22832284
scheduledMaps = 2;
22842285
assignedReduces = 2;
2285-
doReturn(BuilderUtils.newResource(10 * 1024, 10 * 1)).when(allocator)
2286+
doReturn(Resources.createResource(10 * 1024, 10 * 1)).when(allocator)
22862287
.getResourceLimit();
22872288
allocator.scheduleReduces(
22882289
totalMaps, succeededMaps,
@@ -2300,7 +2301,7 @@ public void testReduceScheduling() throws Exception {
23002301
// Test ramp-down when enough memory but not enough cpu resource
23012302
scheduledMaps = 10;
23022303
assignedReduces = 0;
2303-
doReturn(BuilderUtils.newResource(100 * 1024, 5 * 1)).when(allocator)
2304+
doReturn(Resources.createResource(100 * 1024, 5 * 1)).when(allocator)
23042305
.getResourceLimit();
23052306
allocator.scheduleReduces(totalMaps, succeededMaps, scheduledMaps,
23062307
scheduledReduces, assignedMaps, assignedReduces, mapResourceReqt,
@@ -2309,7 +2310,7 @@ public void testReduceScheduling() throws Exception {
23092310
verify(allocator, times(3)).rampDownReduces(anyInt());
23102311

23112312
// Test ramp-down when enough cpu but not enough memory resource
2312-
doReturn(BuilderUtils.newResource(10 * 1024, 100 * 1)).when(allocator)
2313+
doReturn(Resources.createResource(10 * 1024, 100 * 1)).when(allocator)
23132314
.getResourceLimit();
23142315
allocator.scheduleReduces(totalMaps, succeededMaps, scheduledMaps,
23152316
scheduledReduces, assignedMaps, assignedReduces, mapResourceReqt,

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/uam/UnmanagedApplicationManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
import org.apache.hadoop.yarn.security.AMRMTokenIdentifier;
6363
import org.apache.hadoop.yarn.server.AMHeartbeatRequestHandler;
6464
import org.apache.hadoop.yarn.server.AMRMClientRelayer;
65-
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
6665
import org.apache.hadoop.yarn.util.AsyncCallback;
6766
import org.apache.hadoop.yarn.util.ConverterUtils;
67+
import org.apache.hadoop.yarn.util.resource.Resources;
6868
import org.slf4j.Logger;
6969
import org.slf4j.LoggerFactory;
7070

@@ -426,7 +426,7 @@ private void submitUnmanagedApp(ApplicationId appId)
426426

427427
ContainerLaunchContext amContainer =
428428
this.recordFactory.newRecordInstance(ContainerLaunchContext.class);
429-
Resource resource = BuilderUtils.newResource(1024, 1);
429+
Resource resource = Resources.createResource(1024);
430430
context.setResource(resource);
431431
context.setAMContainerSpec(amContainer);
432432
submitRequest.setApplicationSubmissionContext(context);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeStatusUpdater.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
119119
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
120120
import org.apache.hadoop.yarn.server.utils.YarnServerBuilderUtils;
121+
import org.apache.hadoop.yarn.util.resource.Resources;
121122
import org.junit.After;
122123
import org.junit.Assert;
123124
import org.junit.Before;
@@ -243,7 +244,7 @@ public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
243244
ContainerId.newContainerId(appAttemptID, heartBeatID.get());
244245
ContainerLaunchContext launchContext = recordFactory
245246
.newRecordInstance(ContainerLaunchContext.class);
246-
Resource resource = BuilderUtils.newResource(2, 1);
247+
Resource resource = Resources.createResource(2, 1);
247248
long currentTime = System.currentTimeMillis();
248249
String user = "testUser";
249250
ContainerTokenIdentifier containerToken = BuilderUtils
@@ -286,7 +287,7 @@ public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
286287
.newRecordInstance(ContainerLaunchContext.class);
287288
long currentTime = System.currentTimeMillis();
288289
String user = "testUser";
289-
Resource resource = BuilderUtils.newResource(3, 1);
290+
Resource resource = Resources.createResource(3, 1);
290291
ContainerTokenIdentifier containerToken = BuilderUtils
291292
.newContainerTokenIdentifier(BuilderUtils.newContainerToken(
292293
secondContainerID, 0, InetAddress.getByName("localhost")
@@ -990,7 +991,7 @@ public void testRemovePreviousCompletedContainersFromContext() throws Exception
990991
ContainerId cId = ContainerId.newContainerId(appAttemptId, 1);
991992
Token containerToken =
992993
BuilderUtils.newContainerToken(cId, 0, "anyHost", 1234, "anyUser",
993-
BuilderUtils.newResource(1024, 1), 0, 123,
994+
Resources.createResource(1024), 0, 123,
994995
"password".getBytes(), 0);
995996
Container anyCompletedContainer = new ContainerImpl(conf, null,
996997
null, null, null,
@@ -1012,7 +1013,7 @@ public org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Cont
10121013
ContainerId.newContainerId(appAttemptId, 3);
10131014
Token runningContainerToken =
10141015
BuilderUtils.newContainerToken(runningContainerId, 0, "anyHost",
1015-
1234, "anyUser", BuilderUtils.newResource(1024, 1), 0, 123,
1016+
1234, "anyUser", Resources.createResource(1024), 0, 123,
10161017
"password".getBytes(), 0);
10171018
Container runningContainer =
10181019
new ContainerImpl(conf, null, null, null, null,
@@ -1071,7 +1072,7 @@ public void testCompletedContainersIsRecentlyStopped() throws Exception {
10711072
ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
10721073
Token containerToken =
10731074
BuilderUtils.newContainerToken(containerId, 0, "host", 1234, "user",
1074-
BuilderUtils.newResource(1024, 1), 0, 123,
1075+
Resources.createResource(1024), 0, 123,
10751076
"password".getBytes(), 0);
10761077

10771078
Container completedContainer = new ContainerImpl(conf, null,
@@ -1110,7 +1111,7 @@ public void testCleanedupApplicationContainerCleanup() throws IOException {
11101111
ContainerId cId = ContainerId.newContainerId(appAttemptId, 1);
11111112
Token containerToken =
11121113
BuilderUtils.newContainerToken(cId, 0, "anyHost", 1234, "anyUser",
1113-
BuilderUtils.newResource(1024, 1), 0, 123,
1114+
Resources.createResource(1024), 0, 123,
11141115
"password".getBytes(), 0);
11151116
Container anyCompletedContainer = new ContainerImpl(conf, null,
11161117
null, null, null,

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM;
9494
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
9595
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
96+
import org.apache.hadoop.yarn.util.resource.Resources;
9697
import org.junit.After;
9798
import org.junit.Assert;
9899
import org.junit.Before;
@@ -439,7 +440,7 @@ public static Token createContainerToken(ContainerId cId, long rmIdentifier,
439440
NMContainerTokenSecretManager containerTokenSecretManager,
440441
LogAggregationContext logAggregationContext)
441442
throws IOException {
442-
Resource r = BuilderUtils.newResource(1024, 1);
443+
Resource r = Resources.createResource(1024);
443444
return createContainerToken(cId, rmIdentifier, nodeId, user, r,
444445
containerTokenSecretManager, logAggregationContext);
445446
}
@@ -449,7 +450,7 @@ public static Token createContainerToken(ContainerId cId, long rmIdentifier,
449450
NMContainerTokenSecretManager containerTokenSecretManager,
450451
LogAggregationContext logAggregationContext, ContainerType containerType)
451452
throws IOException {
452-
Resource r = BuilderUtils.newResource(1024, 1);
453+
Resource r = Resources.createResource(1024);
453454
return createContainerToken(cId, rmIdentifier, nodeId, user, r,
454455
containerTokenSecretManager, logAggregationContext, containerType);
455456
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
import org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService;
107107
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
108108
import org.apache.hadoop.yarn.util.ControlledClock;
109+
import org.apache.hadoop.yarn.util.resource.Resources;
109110
import org.junit.Assert;
110111
import org.junit.Test;
111112
import org.mockito.ArgumentMatcher;
@@ -1391,7 +1392,7 @@ protected void scheduleContainer(Container container) {
13911392
cId = BuilderUtils.newContainerId(appId, 1, timestamp, id);
13921393
when(mockContainer.getId()).thenReturn(cId);
13931394

1394-
Resource resource = BuilderUtils.newResource(1024, 1);
1395+
Resource resource = Resources.createResource(1024);
13951396
when(mockContainer.getResource()).thenReturn(resource);
13961397
String host = "127.0.0.1";
13971398
int port = 1234;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
import org.apache.hadoop.yarn.util.AuxiliaryServiceHelper;
127127
import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin;
128128
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin;
129+
import org.apache.hadoop.yarn.util.resource.Resources;
129130
import org.junit.Assert;
130131
import org.junit.Assume;
131132
import org.junit.Before;
@@ -1481,7 +1482,7 @@ public void handle(Event event) {
14811482

14821483
protected Token createContainerToken(ContainerId cId, Priority priority,
14831484
long createTime) throws InvalidToken {
1484-
Resource r = BuilderUtils.newResource(1024, 1);
1485+
Resource r = Resources.createResource(1024);
14851486
ContainerTokenIdentifier containerTokenIdentifier =
14861487
new ContainerTokenIdentifier(cId, context.getNodeId().toString(), user,
14871488
r, System.currentTimeMillis() + 10000L, 123, DUMMY_RM_IDENTIFIER,

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
144144
import org.apache.hadoop.yarn.util.ConverterUtils;
145145
import org.apache.hadoop.yarn.util.Records;
146+
import org.apache.hadoop.yarn.util.resource.Resources;
146147
import org.junit.Assert;
147148
import org.junit.Test;
148149
import org.mockito.ArgumentCaptor;
@@ -2293,7 +2294,7 @@ private ContainerId createContainer(ApplicationAttemptId appAttemptId1,
22932294
long cId, ContainerType containerType) {
22942295
ContainerId containerId = BuilderUtils.newContainerId(appAttemptId1,
22952296
cId);
2296-
Resource r = BuilderUtils.newResource(1024, 1);
2297+
Resource r = Resources.createResource(1024);
22972298
ContainerTokenIdentifier containerToken = new ContainerTokenIdentifier(
22982299
containerId, context.getNodeId().toString(), user, r,
22992300
System.currentTimeMillis() + 100000L, 123, DUMMY_RM_IDENTIFIER,

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/TestContainersMonitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
import org.apache.hadoop.yarn.util.ProcfsBasedProcessTree;
8787
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin;
8888
import org.apache.hadoop.yarn.util.TestProcfsBasedProcessTree;
89+
import org.apache.hadoop.yarn.util.resource.Resources;
8990
import org.junit.Assert;
9091
import org.junit.Before;
9192
import org.junit.Test;
@@ -301,7 +302,7 @@ public void testContainerKillOnMemoryOverflow() throws IOException,
301302
commands.add("/bin/bash");
302303
commands.add(scriptFile.getAbsolutePath());
303304
containerLaunchContext.setCommands(commands);
304-
Resource r = BuilderUtils.newResource(0, 0);
305+
Resource r = Resources.createResource(0);
305306
ContainerTokenIdentifier containerIdentifier =
306307
new ContainerTokenIdentifier(cId, context.getNodeId().toString(), user,
307308
r, System.currentTimeMillis() + 120000, 123, DUMMY_RM_IDENTIFIER,

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerBehaviorCompatibility.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.apache.hadoop.yarn.api.records.ExecutionType;
2626
import org.apache.hadoop.yarn.conf.YarnConfiguration;
2727
import org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest;
28-
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
28+
import org.apache.hadoop.yarn.util.resource.Resources;
2929
import org.junit.Assert;
3030
import org.junit.Before;
3131
import org.junit.Test;
@@ -70,7 +70,7 @@ public void testForceStartGuaranteedContainersWhenOppContainerDisabled()
7070
// on the RM side it won't check vcores at all.
7171
list.add(StartContainerRequest.newInstance(containerLaunchContext,
7272
createContainerToken(createContainerId(0), DUMMY_RM_IDENTIFIER,
73-
context.getNodeId(), user, BuilderUtils.newResource(2048, 4),
73+
context.getNodeId(), user, Resources.createResource(2048, 4),
7474
context.getContainerTokenSecretManager(), null,
7575
ExecutionType.GUARANTEED)));
7676

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerOppContainersByResources.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest;
3434
import org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerSchedulerTest;
3535
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState;
36-
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
36+
import org.apache.hadoop.yarn.util.resource.Resources;
3737
import org.junit.Assert;
3838
import org.junit.Test;
3939

@@ -161,7 +161,7 @@ public void testKillOpportunisticWhenNoResourcesAvailable() throws Exception {
161161
recordFactory.newRecordInstance(ContainerLaunchContext.class),
162162
createContainerToken(createContainerId(0), DUMMY_RM_IDENTIFIER,
163163
context.getNodeId(),
164-
user, BuilderUtils.newResource(2048, 1),
164+
user, Resources.createResource(2048),
165165
context.getContainerTokenSecretManager(), null,
166166
ExecutionType.GUARANTEED)));
167167

@@ -170,7 +170,7 @@ public void testKillOpportunisticWhenNoResourcesAvailable() throws Exception {
170170
recordFactory.newRecordInstance(ContainerLaunchContext.class),
171171
createContainerToken(createContainerId(1), DUMMY_RM_IDENTIFIER,
172172
context.getNodeId(),
173-
user, BuilderUtils.newResource(2048, 1),
173+
user, Resources.createResource(2048),
174174
context.getContainerTokenSecretManager(), null,
175175
ExecutionType.OPPORTUNISTIC)));
176176

@@ -219,7 +219,7 @@ public void testOpportunisticRunsWhenResourcesAvailable() throws Exception {
219219
recordFactory.newRecordInstance(ContainerLaunchContext.class),
220220
createContainerToken(createContainerId(i), DUMMY_RM_IDENTIFIER,
221221
context.getNodeId(),
222-
user, BuilderUtils.newResource(512, 1),
222+
user, Resources.createResource(512),
223223
context.getContainerTokenSecretManager(), null,
224224
ExecutionType.OPPORTUNISTIC)));
225225
}

0 commit comments

Comments
 (0)