19
19
package org .apache .hadoop .yarn .server .resourcemanager ;
20
20
21
21
import java .util .ArrayList ;
22
+ import java .util .Collections ;
22
23
import java .util .List ;
23
24
24
25
import org .apache .hadoop .conf .Configuration ;
25
26
import org .apache .hadoop .yarn .api .records .ApplicationAttemptId ;
26
- import org .apache .hadoop .yarn .api .records .ApplicationId ;
27
27
import org .apache .hadoop .yarn .api .records .ContainerId ;
28
28
import org .apache .hadoop .yarn .api .records .ContainerState ;
29
29
import org .apache .hadoop .yarn .api .records .ContainerStatus ;
35
35
import org .apache .hadoop .yarn .server .resourcemanager .DecommissioningNodesWatcher .DecommissioningNodeStatus ;
36
36
import org .apache .hadoop .yarn .server .resourcemanager .rmapp .RMApp ;
37
37
import org .apache .hadoop .yarn .server .resourcemanager .rmapp .RMAppState ;
38
- import org .apache .hadoop .yarn .server .resourcemanager .rmnode .RMNode ;
38
+ import org .apache .hadoop .yarn .server .resourcemanager .rmnode .RMNodeImpl ;
39
+ import org .apache .hadoop .yarn .server .resourcemanager .rmnode .RMNodeStatusEvent ;
39
40
import org .junit .After ;
40
41
import org .junit .Assert ;
41
42
import org .junit .Test ;
@@ -58,38 +59,106 @@ public void testDecommissioningNodesWatcher() throws Exception {
58
59
new DecommissioningNodesWatcher (rm .getRMContext ());
59
60
60
61
MockNM nm1 = rm .registerNode ("host1:1234" , 10240 );
61
- RMNode node1 = rm .getRMContext ().getRMNodes ().get (nm1 .getNodeId ());
62
+ RMNodeImpl node1 =
63
+ (RMNodeImpl ) rm .getRMContext ().getRMNodes ().get (nm1 .getNodeId ());
62
64
NodeId id1 = nm1 .getNodeId ();
63
65
64
66
rm .waitForState (id1 , NodeState .RUNNING );
65
- Assert .assertFalse (watcher .checkReadyToBeDecommissioned (id1 ));
66
67
67
68
RMApp app = rm .submitApp (2000 );
68
69
MockAM am = MockRM .launchAndRegisterAM (app , rm , nm1 );
69
70
71
+ NodeStatus nodeStatus = createNodeStatus (id1 , app , 3 );
72
+ node1 .handle (new RMNodeStatusEvent (nm1 .getNodeId (), nodeStatus ));
73
+
70
74
// Setup nm1 as DECOMMISSIONING for DecommissioningNodesWatcher.
71
75
rm .sendNodeGracefulDecommission (nm1 ,
72
76
YarnConfiguration .DEFAULT_RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT );
73
77
rm .waitForState (id1 , NodeState .DECOMMISSIONING );
74
78
75
79
// Update status with decreasing number of running containers until 0.
76
- watcher .update (node1 , createNodeStatus (id1 , app , 12 ));
77
- watcher .update (node1 , createNodeStatus (id1 , app , 11 ));
80
+ nodeStatus = createNodeStatus (id1 , app , 3 );
81
+ node1 .handle (new RMNodeStatusEvent (nm1 .getNodeId (), nodeStatus ));
82
+ watcher .update (node1 , nodeStatus );
83
+
84
+ nodeStatus = createNodeStatus (id1 , app , 2 );
85
+ node1 .handle (new RMNodeStatusEvent (nm1 .getNodeId (), nodeStatus ));
86
+ watcher .update (node1 , nodeStatus );
78
87
Assert .assertFalse (watcher .checkReadyToBeDecommissioned (id1 ));
79
88
80
- watcher .update (node1 , createNodeStatus (id1 , app , 1 ));
89
+ nodeStatus = createNodeStatus (id1 , app , 1 );
90
+ node1 .handle (new RMNodeStatusEvent (nm1 .getNodeId (), nodeStatus ));
91
+ watcher .update (node1 , nodeStatus );
81
92
Assert .assertEquals (DecommissioningNodeStatus .WAIT_CONTAINER ,
82
- watcher .checkDecommissioningStatus (id1 ));
93
+ watcher .checkDecommissioningStatus (id1 ));
94
+
95
+ nodeStatus = createNodeStatus (id1 , app , 0 );
96
+ watcher .update (node1 , nodeStatus );
97
+ node1 .handle (new RMNodeStatusEvent (nm1 .getNodeId (), nodeStatus ));
98
+ Assert .assertEquals (DecommissioningNodeStatus .WAIT_APP ,
99
+ watcher .checkDecommissioningStatus (id1 ));
100
+
101
+ // Set app to be FINISHED and verified DecommissioningNodeStatus is READY.
102
+ MockRM .finishAMAndVerifyAppState (app , rm , nm1 , am );
103
+ rm .waitForState (app .getApplicationId (), RMAppState .FINISHED );
104
+ watcher .update (node1 , nodeStatus );
105
+ Assert .assertEquals (DecommissioningNodeStatus .READY ,
106
+ watcher .checkDecommissioningStatus (id1 ));
107
+ }
108
+
109
+ @ Test
110
+ public void testDecommissioningNodesWatcherWithPreviousRunningApps ()
111
+ throws Exception {
112
+ Configuration conf = new Configuration ();
113
+ conf .set (YarnConfiguration .RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT , "40" );
114
+
115
+ rm = new MockRM (conf );
116
+ rm .start ();
117
+
118
+ DecommissioningNodesWatcher watcher =
119
+ new DecommissioningNodesWatcher (rm .getRMContext ());
120
+
121
+ MockNM nm1 = rm .registerNode ("host1:1234" , 10240 );
122
+ RMNodeImpl node1 =
123
+ (RMNodeImpl ) rm .getRMContext ().getRMNodes ().get (nm1 .getNodeId ());
124
+ NodeId id1 = nm1 .getNodeId ();
125
+
126
+ rm .waitForState (id1 , NodeState .RUNNING );
127
+
128
+ RMApp app = rm .submitApp (2000 );
129
+ MockAM am = MockRM .launchAndRegisterAM (app , rm , nm1 );
83
130
84
- watcher .update (node1 , createNodeStatus (id1 , app , 0 ));
131
+ NodeStatus nodeStatus = createNodeStatus (id1 , app , 3 );
132
+ node1 .handle (new RMNodeStatusEvent (nm1 .getNodeId (), nodeStatus ));
133
+
134
+ Assert .assertEquals (1 , node1 .getRunningApps ().size ());
135
+
136
+ // update node with 0 running containers
137
+ nodeStatus = createNodeStatus (id1 , app , 0 );
138
+ node1 .handle (new RMNodeStatusEvent (nm1 .getNodeId (), nodeStatus ));
139
+
140
+ Assert .assertEquals (1 , node1 .getRunningApps ().size ());
141
+
142
+ // Setup nm1 as DECOMMISSIONING for DecommissioningNodesWatcher. Right now
143
+ // there is no container running on the node.
144
+ rm .sendNodeGracefulDecommission (nm1 ,
145
+ YarnConfiguration .DEFAULT_RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT );
146
+ rm .waitForState (id1 , NodeState .DECOMMISSIONING );
147
+
148
+ // we should still get WAIT_APP as container for a running app previously
149
+ // ran on this node.
150
+ watcher .update (node1 , nodeStatus );
151
+ Assert .assertFalse (watcher .checkReadyToBeDecommissioned (id1 ));
85
152
Assert .assertEquals (DecommissioningNodeStatus .WAIT_APP ,
86
- watcher .checkDecommissioningStatus (id1 ));
153
+ watcher .checkDecommissioningStatus (id1 ));
87
154
88
155
// Set app to be FINISHED and verified DecommissioningNodeStatus is READY.
89
156
MockRM .finishAMAndVerifyAppState (app , rm , nm1 , am );
90
157
rm .waitForState (app .getApplicationId (), RMAppState .FINISHED );
158
+ Assert .assertEquals (0 , node1 .getRunningApps ().size ());
159
+ watcher .update (node1 , nodeStatus );
91
160
Assert .assertEquals (DecommissioningNodeStatus .READY ,
92
- watcher .checkDecommissioningStatus (id1 ));
161
+ watcher .checkDecommissioningStatus (id1 ));
93
162
}
94
163
95
164
@ After
@@ -103,7 +172,7 @@ private NodeStatus createNodeStatus(
103
172
NodeId nodeId , RMApp app , int numRunningContainers ) {
104
173
return NodeStatus .newInstance (
105
174
nodeId , 0 , getContainerStatuses (app , numRunningContainers ),
106
- new ArrayList < ApplicationId > (),
175
+ Collections . emptyList (),
107
176
NodeHealthStatus .newInstance (
108
177
true , "" , System .currentTimeMillis () - 1000 ),
109
178
null , null , null );
@@ -113,17 +182,17 @@ private NodeStatus createNodeStatus(
113
182
// where numRunningContainers are RUNNING.
114
183
private List <ContainerStatus > getContainerStatuses (
115
184
RMApp app , int numRunningContainers ) {
116
- // Total 12 containers
117
- final int total = 12 ;
185
+ // Total 3 containers
186
+ final int total = 3 ;
118
187
numRunningContainers = Math .min (total , numRunningContainers );
119
188
List <ContainerStatus > output = new ArrayList <ContainerStatus >();
120
189
for (int i = 0 ; i < total ; i ++) {
121
190
ContainerState cstate = (i >= numRunningContainers )?
122
191
ContainerState .COMPLETE : ContainerState .RUNNING ;
123
192
output .add (ContainerStatus .newInstance (
124
193
ContainerId .newContainerId (
125
- ApplicationAttemptId .newInstance (app .getApplicationId (), i ), 1 ),
126
- cstate , "Dummy " , 0 ));
194
+ ApplicationAttemptId .newInstance (app .getApplicationId (), 0 ), i ),
195
+ cstate , "" , 0 ));
127
196
}
128
197
return output ;
129
198
}
0 commit comments