3434import org .apache .hadoop .yarn .conf .YarnConfiguration ;
3535import org .slf4j .Logger ;
3636import org .slf4j .LoggerFactory ;
37- import sun .rmi .runtime .Log ;
3837
3938import java .io .File ;
4039import java .io .IOException ;
@@ -56,8 +55,6 @@ public class PerJobClusterClientBuilder {
5655
5756 private static final Logger LOG = LoggerFactory .getLogger (PerJobClusterClientBuilder .class );
5857
59- private static String SECURITY = "hadoop.security.authorization" ;
60-
6158 private static String KEYTAB = "security.kerberos.login.keytab" ;
6259
6360 private static String PRINCIPAL = "security.kerberos.login.principal" ;
@@ -74,15 +71,10 @@ public void init(String yarnConfDir, Properties conf) throws IOException {
7471
7572 yarnConf = YarnConfLoader .getYarnConf (yarnConfDir );
7673
77- Boolean security = yarnConf .getBoolean (SECURITY , false );
78-
79- String keytab = (String ) conf .get (KEYTAB );
80- String principal = (String ) conf .get (PRINCIPAL );
81- if (security && !Strings .isNullOrEmpty (keytab )){
82- UserGroupInformation .setConfiguration (yarnConf );
83- UserGroupInformation .loginUserFromKeytab (keytab , principal );
84- LOG .info ("login successfully! keytab: " + keytab + "principal: " + principal );
85- LOG .info ("UGI: " + UserGroupInformation .getCurrentUser ());
74+ if (openKerberos (conf )){
75+ String keytab = (String ) conf .get (KEYTAB );
76+ String principal = (String ) conf .get (PRINCIPAL );
77+ login (yarnConf , keytab , principal );
8678 }
8779
8880 yarnClient = YarnClient .createYarnClient ();
@@ -168,4 +160,21 @@ private AbstractYarnClusterDescriptor getClusterDescriptor(
168160 yarnClient ,
169161 false );
170162 }
163+
164+ private boolean openKerberos (Properties conf ){
165+ String keytab = (String ) conf .get (KEYTAB );
166+ String principal = (String ) conf .get (PRINCIPAL );
167+ if (StringUtils .isNotBlank (keytab ) && StringUtils .isNotBlank (principal )){
168+ return true ;
169+ } else {
170+ return false ;
171+ }
172+ }
173+
174+ private void login (org .apache .hadoop .conf .Configuration conf , String keytab , String principal ) throws IOException {
175+ UserGroupInformation .setConfiguration (conf );
176+ UserGroupInformation .loginUserFromKeytab (keytab , principal );
177+ LOG .info ("login successfully! keytab: " + keytab + "principal: " + principal );
178+ LOG .info ("UGI: " + UserGroupInformation .getCurrentUser ());
179+ }
171180}
0 commit comments