2424import static org .mockito .Mockito .isNull ;
2525
2626import java .util .Arrays ;
27- import java .util .List ;
28- import java .util .Map ;
2927
30- import com .google .common .collect .Maps ;
31- import org .apache .commons .compress .utils .Lists ;
3228import org .apache .hadoop .fs .CommonConfigurationKeys ;
3329import org .apache .hadoop .security .GroupMappingServiceProvider ;
3430import org .apache .hadoop .security .Groups ;
3935import org .apache .hadoop .yarn .server .resourcemanager .placement .QueueMapping .MappingType ;
4036import org .apache .hadoop .yarn .server .resourcemanager .placement .QueueMapping .QueueMappingBuilder ;
4137import org .apache .hadoop .yarn .server .resourcemanager .placement .TestUserGroupMappingPlacementRule .QueueMappingTestData .QueueMappingTestDataBuilder ;
42- import org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .AbstractCSQueue ;
4338import org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .CapacitySchedulerQueueManager ;
44- import org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .LeafQueue ;
45- import org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .ManagedParentQueue ;
46- import org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .ParentQueue ;
4739import org .apache .hadoop .yarn .server .resourcemanager .scheduler .fair .PrimaryGroupMapping ;
4840import org .apache .hadoop .yarn .server .resourcemanager .scheduler .fair .SimpleGroupsMapping ;
4941import org .apache .hadoop .yarn .util .Records ;
@@ -57,141 +49,6 @@ public class TestUserGroupMappingPlacementRule {
5749 private static final Logger LOG =
5850 LoggerFactory .getLogger (TestUserGroupMappingPlacementRule .class );
5951
60- private static class MockQueueHierarchyBuilder {
61- private static final String ROOT = "root" ;
62- private static final String QUEUE_SEP = "." ;
63- private List <String > queuePaths = Lists .newArrayList ();
64- private List <String > managedParentQueues = Lists .newArrayList ();
65- private CapacitySchedulerQueueManager queueManager ;
66-
67- public static MockQueueHierarchyBuilder create () {
68- return new MockQueueHierarchyBuilder ();
69- }
70-
71- public MockQueueHierarchyBuilder withQueueManager (
72- CapacitySchedulerQueueManager queueManager ) {
73- this .queueManager = queueManager ;
74- return this ;
75- }
76-
77- public MockQueueHierarchyBuilder withQueue (String queue ) {
78- this .queuePaths .add (queue );
79- return this ;
80- }
81-
82- public MockQueueHierarchyBuilder withManagedParentQueue (
83- String managedQueue ) {
84- this .managedParentQueues .add (managedQueue );
85- return this ;
86- }
87-
88- public void build () {
89- if (this .queueManager == null ) {
90- throw new IllegalStateException (
91- "QueueManager instance is not provided!" );
92- }
93-
94- for (String managedParentQueue : managedParentQueues ) {
95- if (!queuePaths .contains (managedParentQueue )) {
96- queuePaths .add (managedParentQueue );
97- } else {
98- throw new IllegalStateException ("Cannot add a managed parent " +
99- "and a simple queue with the same path" );
100- }
101- }
102-
103- Map <String , AbstractCSQueue > queues = Maps .newHashMap ();
104- for (String queuePath : queuePaths ) {
105- LOG .info ("Processing queue path: " + queuePath );
106- addQueues (queues , queuePath );
107- }
108- }
109-
110- private void addQueues (Map <String , AbstractCSQueue > queues ,
111- String queuePath ) {
112- final String [] pathComponents = queuePath .split ("\\ " + QUEUE_SEP );
113-
114- String currentQueuePath = "" ;
115- for (int i = 0 ; i < pathComponents .length ; ++i ) {
116- boolean isLeaf = i == pathComponents .length - 1 ;
117- String queueName = pathComponents [i ];
118- String parentPath = currentQueuePath ;
119- currentQueuePath += currentQueuePath .equals ("" ) ?
120- queueName : QUEUE_SEP + queueName ;
121-
122- if (managedParentQueues .contains (parentPath ) && !isLeaf ) {
123- throw new IllegalStateException ("Cannot add a queue under " +
124- "managed parent" );
125- }
126- if (!queues .containsKey (currentQueuePath )) {
127- ParentQueue parentQueue = (ParentQueue ) queues .get (parentPath );
128- AbstractCSQueue queue = createQueue (parentQueue , queueName ,
129- currentQueuePath , isLeaf );
130- queues .put (currentQueuePath , queue );
131- }
132- }
133- }
134-
135- private AbstractCSQueue createQueue (ParentQueue parentQueue ,
136- String queueName , String currentQueuePath , boolean isLeaf ) {
137- if (queueName .equals (ROOT )) {
138- return createRootQueue (ROOT );
139- } else if (managedParentQueues .contains (currentQueuePath )) {
140- return addManagedParentQueueAsChildOf (parentQueue , queueName );
141- } else if (isLeaf ) {
142- return addLeafQueueAsChildOf (parentQueue , queueName );
143- } else {
144- return addParentQueueAsChildOf (parentQueue , queueName );
145- }
146- }
147-
148- private AbstractCSQueue createRootQueue (String rootQueueName ) {
149- ParentQueue root = mock (ParentQueue .class );
150- when (root .getQueuePath ()).thenReturn (rootQueueName );
151- when (queueManager .getQueue (rootQueueName )).thenReturn (root );
152- when (queueManager .getQueueByFullName (rootQueueName )).thenReturn (root );
153- return root ;
154- }
155-
156- private AbstractCSQueue addParentQueueAsChildOf (ParentQueue parent ,
157- String queueName ) {
158- ParentQueue queue = mock (ParentQueue .class );
159- setQueueFields (parent , queue , queueName );
160- return queue ;
161- }
162-
163- private AbstractCSQueue addManagedParentQueueAsChildOf (ParentQueue parent ,
164- String queueName ) {
165- ManagedParentQueue queue = mock (ManagedParentQueue .class );
166- setQueueFields (parent , queue , queueName );
167- return queue ;
168- }
169-
170- private AbstractCSQueue addLeafQueueAsChildOf (ParentQueue parent ,
171- String queueName ) {
172- LeafQueue queue = mock (LeafQueue .class );
173- setQueueFields (parent , queue , queueName );
174- return queue ;
175- }
176-
177- private void setQueueFields (ParentQueue parent , AbstractCSQueue newQueue ,
178- String queueName ) {
179- String fullPathOfQueue = parent .getQueuePath () + QUEUE_SEP + queueName ;
180- addQueueToQueueManager (queueName , newQueue , fullPathOfQueue );
181-
182- when (newQueue .getParent ()).thenReturn (parent );
183- when (newQueue .getQueuePath ()).thenReturn (fullPathOfQueue );
184- when (newQueue .getQueueName ()).thenReturn (queueName );
185- }
186-
187- private void addQueueToQueueManager (String queueName , AbstractCSQueue queue ,
188- String fullPathOfQueue ) {
189- when (queueManager .getQueue (queueName )).thenReturn (queue );
190- when (queueManager .getQueue (fullPathOfQueue )).thenReturn (queue );
191- when (queueManager .getQueueByFullName (fullPathOfQueue )).thenReturn (queue );
192- }
193- }
194-
19552 YarnConfiguration conf = new YarnConfiguration ();
19653
19754 @ Before
0 commit comments