|
29 | 29 | import org.apache.flink.yarn.AbstractYarnClusterDescriptor; |
30 | 30 | import org.apache.flink.yarn.YarnClusterDescriptor; |
31 | 31 | import org.apache.hadoop.fs.Path; |
| 32 | +import org.apache.hadoop.security.UserGroupInformation; |
32 | 33 | import org.apache.hadoop.yarn.client.api.YarnClient; |
33 | 34 | import org.apache.hadoop.yarn.conf.YarnConfiguration; |
| 35 | +import org.slf4j.Logger; |
| 36 | +import org.slf4j.LoggerFactory; |
| 37 | +import sun.rmi.runtime.Log; |
34 | 38 |
|
35 | 39 | import java.io.File; |
| 40 | +import java.io.IOException; |
36 | 41 | import java.net.MalformedURLException; |
37 | 42 | import java.net.URL; |
38 | 43 | import java.util.ArrayList; |
|
48 | 53 | */ |
49 | 54 |
|
50 | 55 | public class PerJobClusterClientBuilder { |
| 56 | + |
| 57 | + private static final Logger LOG = LoggerFactory.getLogger(PerJobClusterClientBuilder.class); |
| 58 | + |
| 59 | + private static String SECURITY = "hadoop.security.authorization"; |
| 60 | + |
| 61 | + private static String KEYTAB = "security.kerberos.login.keytab"; |
| 62 | + |
| 63 | + private static String PRINCIPAL = "security.kerberos.login.principal"; |
| 64 | + |
51 | 65 | private YarnClient yarnClient; |
52 | 66 |
|
53 | 67 | private YarnConfiguration yarnConf; |
54 | 68 |
|
55 | | - public void init(String yarnConfDir){ |
| 69 | + public void init(String yarnConfDir, Properties conf) throws IOException { |
| 70 | + |
56 | 71 | if(Strings.isNullOrEmpty(yarnConfDir)) { |
57 | 72 | throw new RuntimeException("parameters of yarn is required"); |
58 | 73 | } |
59 | 74 |
|
60 | 75 | yarnConf = YarnConfLoader.getYarnConf(yarnConfDir); |
| 76 | + |
| 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()); |
| 86 | + } |
| 87 | + |
61 | 88 | yarnClient = YarnClient.createYarnClient(); |
62 | 89 | yarnClient.init(yarnConf); |
63 | 90 | yarnClient.start(); |
|
0 commit comments