77import com .dtstack .flink .sql .side .AbstractSideTableInfo ;
88import com .dtstack .flink .sql .side .kudu .table .KuduSideTableInfo ;
99import com .dtstack .flink .sql .side .kudu .utils .KuduUtil ;
10+ import com .dtstack .flink .sql .util .KrbUtils ;
1011import com .dtstack .flink .sql .util .RowDataComplete ;
1112import com .google .common .base .Preconditions ;
1213import com .google .common .collect .Lists ;
1819import org .apache .flink .table .dataformat .BaseRow ;
1920import org .apache .flink .types .Row ;
2021import org .apache .flink .util .Collector ;
22+ import org .apache .hadoop .security .UserGroupInformation ;
2123import org .apache .kudu .ColumnSchema ;
2224import org .apache .kudu .Schema ;
2325import org .apache .kudu .client .KuduClient ;
3133import org .slf4j .Logger ;
3234import org .slf4j .LoggerFactory ;
3335
36+ import java .io .IOException ;
37+ import java .security .PrivilegedAction ;
3438import java .sql .SQLException ;
3539import java .util .Arrays ;
3640import java .util .Calendar ;
@@ -211,24 +215,8 @@ private String buildKey(Map<String, Object> val, List<String> equalFieldList) {
211215 private KuduScanner getConn (KuduSideTableInfo tableInfo ) {
212216 try {
213217 if (client == null ) {
214- String kuduMasters = tableInfo .getKuduMasters ();
215218 String tableName = tableInfo .getTableName ();
216- Integer workerCount = tableInfo .getWorkerCount ();
217- Integer defaultSocketReadTimeoutMs = tableInfo .getDefaultSocketReadTimeoutMs ();
218- Integer defaultOperationTimeoutMs = tableInfo .getDefaultOperationTimeoutMs ();
219-
220- Preconditions .checkNotNull (kuduMasters , "kuduMasters could not be null" );
221-
222- KuduClient .KuduClientBuilder kuduClientBuilder = new KuduClient .KuduClientBuilder (kuduMasters );
223- if (null != workerCount ) {
224- kuduClientBuilder .workerCount (workerCount );
225- }
226-
227- if (null != defaultOperationTimeoutMs ) {
228- kuduClientBuilder .defaultOperationTimeoutMs (defaultOperationTimeoutMs );
229- }
230- client = kuduClientBuilder .build ();
231-
219+ client = getClient (tableInfo );
232220 if (!client .tableExists (tableName )) {
233221 throw new IllegalArgumentException ("Table Open Failed , please check table exists" );
234222 }
@@ -243,7 +231,35 @@ private KuduScanner getConn(KuduSideTableInfo tableInfo) {
243231 }
244232 }
245233
234+ private KuduClient getClient (KuduSideTableInfo tableInfo ) throws IOException {
235+ String kuduMasters = tableInfo .getKuduMasters ();
236+ Integer workerCount = tableInfo .getWorkerCount ();
237+ Integer defaultOperationTimeoutMs = tableInfo .getDefaultOperationTimeoutMs ();
238+
239+ Preconditions .checkNotNull (kuduMasters , "kuduMasters could not be null" );
240+
241+ KuduClient .KuduClientBuilder kuduClientBuilder = new KuduClient .KuduClientBuilder (kuduMasters );
246242
243+ if (null != workerCount ) {
244+ kuduClientBuilder .workerCount (workerCount );
245+ }
246+
247+ if (null != defaultOperationTimeoutMs ) {
248+ kuduClientBuilder .defaultOperationTimeoutMs (defaultOperationTimeoutMs );
249+ }
250+
251+ if (tableInfo .isEnableKrb ()) {
252+ UserGroupInformation ugi = KrbUtils .getUgi (tableInfo .getPrincipal (), tableInfo .getKeytab (), tableInfo .getKrb5conf ());
253+ return ugi .doAs (new PrivilegedAction <KuduClient >() {
254+ @ Override
255+ public KuduClient run () {
256+ return kuduClientBuilder .build ();
257+ }
258+ });
259+ } else {
260+ return kuduClientBuilder .build ();
261+ }
262+ }
247263 /**
248264 * @param builder 创建AsyncKuduScanner对象
249265 * @param schema kudu中表约束
0 commit comments