JackWangCS commented on a change in pull request #14841:
URL: https://github.com/apache/flink/pull/14841#discussion_r633702422



##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/security/HadoopDelegationTokenManager.java
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.yarn.security;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import 
org.apache.flink.runtime.security.delegationtokens.HadoopDelegationTokenConfiguration;
+import 
org.apache.flink.runtime.security.delegationtokens.HadoopDelegationTokenProvider;
+
+import org.apache.hadoop.security.Credentials;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+
+/**
+ * HadoopDelegationTokenManager is responsible for managing delegation tokens. 
It can be used to
+ * obtain delegation tokens by calling `obtainDelegationTokens` method.
+ */
+public class HadoopDelegationTokenManager {
+    private static final Logger LOG = 
LoggerFactory.getLogger(HadoopDelegationTokenManager.class);
+
+    private final HadoopDelegationTokenConfiguration hadoopDelegationTokenConf;
+    private final List<HadoopDelegationTokenProvider> delegationTokenProviders;
+
+    public HadoopDelegationTokenManager(
+            HadoopDelegationTokenConfiguration hadoopDelegationTokenConf) {
+        this.hadoopDelegationTokenConf = hadoopDelegationTokenConf;
+        delegationTokenProviders = loadProviders();
+    }
+
+    /**
+     * Obtain delegation tokens using HadoopDelegationProviders, and store 
them in the give
+     * credentials.
+     *
+     * @param credentials Credentials object where to store the delegation 
tokens.
+     */
+    public void obtainDelegationTokens(Credentials credentials) {
+        delegationTokenProviders.forEach(
+                provider -> {
+                    if (provider.delegationTokensRequired()) {
+                        provider.obtainDelegationTokens(credentials);
+                    } else {
+                        LOG.info(
+                                "Service {} does not need to require a token,",
+                                provider.serviceName());
+                    }
+                });
+    }
+
+    private List<HadoopDelegationTokenProvider> loadProviders() {
+        ServiceLoader<HadoopDelegationTokenProvider> serviceLoader =
+                ServiceLoader.load(HadoopDelegationTokenProvider.class);
+
+        List<HadoopDelegationTokenProvider> providers = new ArrayList<>();
+
+        Iterator<HadoopDelegationTokenProvider> providerIterator = 
serviceLoader.iterator();
+        providerIterator.forEachRemaining(
+                provider -> {
+                    try {
+                        provider.init(hadoopDelegationTokenConf);

Review comment:
       I added a debug log for this, I don't want to print log in a verbose 
way. For each provider, it will print some information about this.
   
   ```
   
   INFO  org.apache.flink.yarn.Utils                                  [] - 
Obtaining delegation tokens...
   DEBUG  org.apache.flink.yarn.security.HadoopDelegationTokenManager  [] - 
Delegation provider hbase loaded and initialized
   DEBUG org.apache.flink.yarn.security.HadoopDelegationTokenManager  [] - 
Delegation provider hadoopfs loaded and initialized
   INFO  org.apache.flink.yarn.security.HBaseDelegationTokenProvider  [] - 
HBase is not available (not packaged with this application): 
ClassNotFoundException : "org.apache.hadoop.hbase.HBaseConfiguration".
   INFO  org.apache.flink.yarn.security.HadoopDelegationTokenManager  [] - 
Service hbase does not need to require a token.
   INFO  org.apache.flink.yarn.security.HadoopFSDelegationTokenProvider [] - 
Getting FS token for: viewfs://cluster14/ with renewer yarn
   INFO  org.apache.hadoop.hdfs.DFSClient                             [] - 
Created token for test: HDFS_DELEGATION_TOKEN owner=test, renewer=yarn, 
realUser=, issueDate=1621268501397, maxDate=1621873301397, 
sequenceNumber=26153859, masterKeyId=726 on ha-hdfs:apstore
   INFO  org.apache.hadoop.hdfs.DFSClient                             [] - 
Created token for test: HDFS_DELEGATION_TOKEN owner=test, renewer=yarn, 
realUser=, issueDate=1621268501434, maxDate=1621873301434, 
sequenceNumber=10388618, masterKeyId=252 on ha-hdfs:warehousextab
   INFO  org.apache.hadoop.hdfs.DFSClient                             [] - 
Created token for test: HDFS_DELEGATION_TOKEN owner=test, renewer=yarn, 
realUser=, issueDate=1621268501489, maxDate=1621873301489, 
sequenceNumber=86464794, masterKeyId=729 on ha-hdfs:warehousestore
   INFO  org.apache.hadoop.hdfs.DFSClient                             [] - 
Created token for test: HDFS_DELEGATION_TOKEN owner=test, renewer=yarn, 
realUser=, issueDate=1621268501506, maxDate=1621873301506, 
sequenceNumber=10343224, masterKeyId=255 on ha-hdfs:warehousextac
   INFO  org.apache.hadoop.hdfs.DFSClient                             [] - 
Created token for test: HDFS_DELEGATION_TOKEN owner=test, renewer=yarn, 
realUser=, issueDate=1621268501524, maxDate=1621873301524, 
sequenceNumber=10340707, masterKeyId=249 on ha-hdfs:warehousextaa
   INFO  org.apache.hadoop.hdfs.DFSClient                             [] - 
Created token for test: HDFS_DELEGATION_TOKEN owner=test, renewer=yarn, 
realUser=, issueDate=1621268501528, maxDate=1621873301528, 
sequenceNumber=421001249, masterKeyId=714 on ha-hdfs:beaconstore
   INFO  org.apache.flink.yarn.YarnClusterDescriptor                  [] - 
Submitting application master application_1620874570676_200951
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to