1818
1919import org .apache .hadoop .conf .Configuration ;
2020import org .apache .hadoop .security .authorize .AccessControlList ;
21- import org .apache .hadoop .util .StringUtils ;
2221import org .apache .hadoop .yarn .api .records .QueueACL ;
23- import org .junit .Assert ;
2422import org .junit .Test ;
2523
2624import static org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .CapacitySchedulerConfiguration .ROOT ;
2725import static org .apache .hadoop .yarn .server .resourcemanager .scheduler .capacity .CapacitySchedulerConfiguration .getQueuePrefix ;
26+ import static org .junit .Assert .assertFalse ;
27+ import static org .junit .Assert .assertTrue ;
2828
2929public class TestCapacitySchedulerConfiguration {
3030
31+ private CapacitySchedulerConfiguration createDefaultCsConf () {
32+ return new CapacitySchedulerConfiguration (new Configuration (false ), false );
33+ }
34+
35+ private AccessControlList getSubmitAcl (CapacitySchedulerConfiguration csConf , String queue ) {
36+ return csConf .getAcl (queue , QueueACL .SUBMIT_APPLICATIONS );
37+ }
38+
39+ private void setSubmitAppsConfig (CapacitySchedulerConfiguration csConf , String queue , String value ) {
40+ csConf .set (getSubmitAppsConfigKey (queue ), value );
41+ }
42+
43+ private String getSubmitAppsConfigKey (String queue ) {
44+ return getQueuePrefix (queue ) + "acl_submit_applications" ;
45+ }
46+
3147 @ Test
3248 public void testDefaultSubmitACLForRootAllAllowed () {
33- CapacitySchedulerConfiguration csConf =
34- new CapacitySchedulerConfiguration (new Configuration (false ), false );
49+ CapacitySchedulerConfiguration csConf = createDefaultCsConf ();
3550 AccessControlList acl = csConf .getAcl (ROOT , QueueACL .SUBMIT_APPLICATIONS );
36- Assert . assertTrue (acl .getUsers ().isEmpty ());
37- Assert . assertTrue (acl .getGroups ().isEmpty ());
38- Assert . assertTrue (acl .isAllAllowed ());
51+ assertTrue (acl .getUsers ().isEmpty ());
52+ assertTrue (acl .getGroups ().isEmpty ());
53+ assertTrue (acl .isAllAllowed ());
3954 }
4055
4156 @ Test
4257 public void testDefaultSubmitACLForRootChildNoneAllowed () {
43- CapacitySchedulerConfiguration csConf =
44- new CapacitySchedulerConfiguration (new Configuration (false ), false );
45- AccessControlList acl = csConf .getAcl (ROOT + ".test" , QueueACL .SUBMIT_APPLICATIONS );
46- Assert .assertTrue (acl .getUsers ().isEmpty ());
47- Assert .assertTrue (acl .getGroups ().isEmpty ());
48- Assert .assertFalse (acl .isAllAllowed ());
58+ CapacitySchedulerConfiguration csConf = createDefaultCsConf ();
59+ AccessControlList acl = getSubmitAcl (csConf , ROOT + ".test" );
60+ assertTrue (acl .getUsers ().isEmpty ());
61+ assertTrue (acl .getGroups ().isEmpty ());
62+ assertFalse (acl .isAllAllowed ());
4963 }
5064
5165 @ Test
5266 public void testSpecifiedEmptySubmitACLForRoot () {
53- CapacitySchedulerConfiguration csConf =
54- new CapacitySchedulerConfiguration (new Configuration (false ), false );
55- String configKey = getQueuePrefix (ROOT ) + "acl_submit_applications" ;
56- csConf .set (configKey , "" );
67+ CapacitySchedulerConfiguration csConf = createDefaultCsConf ();
68+ setSubmitAppsConfig (csConf , ROOT , "" );
5769 AccessControlList acl = csConf .getAcl (ROOT , QueueACL .SUBMIT_APPLICATIONS );
58- Assert . assertTrue (acl .getUsers ().isEmpty ());
59- Assert . assertTrue (acl .getGroups ().isEmpty ());
60- Assert . assertFalse (acl .isAllAllowed ());
70+ assertTrue (acl .getUsers ().isEmpty ());
71+ assertTrue (acl .getGroups ().isEmpty ());
72+ assertFalse (acl .isAllAllowed ());
6173 }
6274
6375 @ Test
6476 public void testSpecifiedEmptySubmitACLForRootIsNotInherited () {
65- CapacitySchedulerConfiguration csConf =
66- new CapacitySchedulerConfiguration (new Configuration (false ), false );
67- String configKey = getQueuePrefix (ROOT ) + "acl_submit_applications" ;
68- csConf .set (configKey , "" );
69- AccessControlList acl = csConf .getAcl (ROOT + ".test" , QueueACL .SUBMIT_APPLICATIONS );
70- Assert .assertTrue (acl .getUsers ().isEmpty ());
71- Assert .assertTrue (acl .getGroups ().isEmpty ());
72- Assert .assertFalse (acl .isAllAllowed ());
77+ CapacitySchedulerConfiguration csConf = createDefaultCsConf ();
78+ setSubmitAppsConfig (csConf , ROOT , "" );
79+ AccessControlList acl = getSubmitAcl (csConf , ROOT + ".test" );
80+ assertTrue (acl .getUsers ().isEmpty ());
81+ assertTrue (acl .getGroups ().isEmpty ());
82+ assertFalse (acl .isAllAllowed ());
7383 }
84+
7485}
0 commit comments