2525import static org .mockito .Mockito .mock ;
2626import static org .mockito .Mockito .when ;
2727
28+ import java .io .IOException ;
29+ import java .util .Arrays ;
30+
31+ import org .apache .hadoop .conf .Configuration ;
32+ import org .apache .hadoop .ha .HAServiceProtocol ;
2833import org .apache .hadoop .security .AccessControlException ;
2934import org .apache .hadoop .yarn .api .records .ApplicationAttemptId ;
3035import org .apache .hadoop .yarn .api .records .ApplicationId ;
3136import org .apache .hadoop .yarn .api .records .Priority ;
3237import org .apache .hadoop .yarn .api .records .QueueState ;
3338import org .apache .hadoop .yarn .api .records .Resource ;
39+ import org .apache .hadoop .yarn .conf .HAUtil ;
3440import org .apache .hadoop .yarn .conf .YarnConfiguration ;
3541import org .apache .hadoop .yarn .exceptions .YarnException ;
3642import org .apache .hadoop .yarn .nodelabels .CommonNodeLabelsManager ;
43+ import org .apache .hadoop .yarn .server .resourcemanager .MockRM ;
3744import org .apache .hadoop .yarn .server .resourcemanager .RMContext ;
45+ import org .apache .hadoop .yarn .server .resourcemanager .ResourceManager ;
3846import org .apache .hadoop .yarn .server .resourcemanager .scheduler .QueueStateManager ;
3947import org .apache .hadoop .yarn .server .resourcemanager .scheduler .common .fica .FiCaSchedulerApp ;
4048import org .apache .hadoop .yarn .util .resource .Resources ;
@@ -48,18 +56,22 @@ public class TestQueueStateManager {
4856 private static final String Q1 = "q1" ;
4957 private static final String Q2 = "q2" ;
5058 private static final String Q3 = "q3" ;
59+ private static final String Q4 = "q4" ;
5160
5261 private final static String Q1_PATH =
5362 CapacitySchedulerConfiguration .ROOT + "." + Q1 ;
5463 private final static String Q2_PATH =
5564 Q1_PATH + "." + Q2 ;
5665 private final static String Q3_PATH =
5766 Q1_PATH + "." + Q3 ;
67+ private final static String Q4_PATH =
68+ CapacitySchedulerConfiguration .ROOT + "." + Q4 ;
5869 private final static QueuePath ROOT_QUEUE_PATH =
5970 new QueuePath (CapacitySchedulerConfiguration .ROOT );
6071 private final static QueuePath Q1_QUEUE_PATH = new QueuePath (Q1_PATH );
6172 private final static QueuePath Q2_QUEUE_PATH = new QueuePath (Q2_PATH );
6273 private final static QueuePath Q3_QUEUE_PATH = new QueuePath (Q3_PATH );
74+ private final static QueuePath Q4_QUEUE_PATH = new QueuePath (Q4_PATH );
6375 private CapacityScheduler cs ;
6476 private YarnConfiguration conf ;
6577
@@ -147,6 +159,46 @@ public void testQueueStateManager() throws AccessControlException,
147159 assertEquals (QueueState .STOPPED , cs .getQueue (Q2 ).getState ());
148160 }
149161
162+ @ Test
163+ public void testRemoveQueueWithoutStopWhenFailover () throws IOException {
164+ Configuration configuration = new Configuration ();
165+ configuration .setClass (YarnConfiguration .RM_SCHEDULER , CapacityScheduler .class ,
166+ CapacityScheduler .class );
167+ configuration .setBoolean (YarnConfiguration .RM_HA_ENABLED , true );
168+ configuration .setBoolean (YarnConfiguration .AUTO_FAILOVER_ENABLED , false );
169+ configuration .set (YarnConfiguration .RM_HA_IDS , "rm1,rm2" );
170+ for (String confKey : YarnConfiguration
171+ .getServiceAddressConfKeys (configuration )) {
172+ configuration .set (HAUtil .addSuffix (confKey , "rm1" ), "1.1.1.1:1" );
173+ configuration .set (HAUtil .addSuffix (confKey , "rm2" ), "0.0.0.0:0" );
174+ }
175+ ResourceManager rm = new MockRM (configuration );
176+ rm .start ();
177+ assertEquals (HAServiceProtocol .HAServiceState .STANDBY ,
178+ rm .getRMContext ().getRMAdminService ().getServiceStatus ().getState ());
179+
180+ CapacitySchedulerConfiguration csConf =
181+ new CapacitySchedulerConfiguration ();
182+ csConf .setQueues (ROOT_QUEUE_PATH , new String [] {Q1 , Q4 });
183+ csConf .setCapacity (Q1_QUEUE_PATH , 100 );
184+ csConf .setCapacity (Q4_QUEUE_PATH , 0 );
185+
186+ conf = new YarnConfiguration (csConf );
187+ rm .getResourceScheduler ().reinitialize (conf , rm .getRMContext ());
188+
189+ assertTrue (Arrays .asList (((CapacityScheduler ) rm .getResourceScheduler ()).getConfiguration ()
190+ .get ("yarn.scheduler.capacity.root.queues" ).split ("," )).contains (Q1 ));
191+ assertTrue (Arrays .asList (((CapacityScheduler ) rm .getResourceScheduler ()).getConfiguration ()
192+ .get ("yarn.scheduler.capacity.root.queues" ).split ("," )).contains (Q4 ));
193+
194+ csConf .setQueues (ROOT_QUEUE_PATH , new String [] {Q1 });
195+ conf = new YarnConfiguration (csConf );
196+ rm .getResourceScheduler ().reinitialize (conf , rm .getRMContext ());
197+
198+ assertEquals (Q1 , ((CapacityScheduler ) rm .getResourceScheduler ()).getConfiguration ()
199+ .get ("yarn.scheduler.capacity.root.queues" ));
200+ }
201+
150202 private FiCaSchedulerApp getMockApplication (ApplicationId appId , String user ,
151203 Resource amResource ) {
152204 FiCaSchedulerApp application = mock (FiCaSchedulerApp .class );
0 commit comments