/root/doris/be/src/io/hdfs_builder.h
| Line | Count | Source | 
| 1 |  | // Licensed to the Apache Software Foundation (ASF) under one | 
| 2 |  | // or more contributor license agreements.  See the NOTICE file | 
| 3 |  | // distributed with this work for additional information | 
| 4 |  | // regarding copyright ownership.  The ASF licenses this file | 
| 5 |  | // to you under the Apache License, Version 2.0 (the | 
| 6 |  | // "License"); you may not use this file except in compliance | 
| 7 |  | // with the License.  You may obtain a copy of the License at | 
| 8 |  | // | 
| 9 |  | //   http://www.apache.org/licenses/LICENSE-2.0 | 
| 10 |  | // | 
| 11 |  | // Unless required by applicable law or agreed to in writing, | 
| 12 |  | // software distributed under the License is distributed on an | 
| 13 |  | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
| 14 |  | // KIND, either express or implied.  See the License for the | 
| 15 |  | // specific language governing permissions and limitations | 
| 16 |  | // under the License. | 
| 17 |  |  | 
| 18 |  | #pragma once | 
| 19 |  |  | 
| 20 |  | #include <gen_cpp/PlanNodes_types.h> | 
| 21 |  |  | 
| 22 |  | #include <map> | 
| 23 |  | #include <string> | 
| 24 |  |  | 
| 25 |  | #include "common/status.h" | 
| 26 |  | #include "io/fs/hdfs.h" // IWYU pragma: keep | 
| 27 |  |  | 
| 28 |  | struct hdfsBuilder; | 
| 29 |  |  | 
| 30 |  | namespace doris { | 
| 31 |  |  | 
| 32 |  | const std::string FS_KEY = "fs.defaultFS"; | 
| 33 |  | const std::string USER = "hadoop.username"; | 
| 34 |  | const std::string KERBEROS_PRINCIPAL = "hadoop.kerberos.principal"; | 
| 35 |  | const std::string KERBEROS_KEYTAB = "hadoop.kerberos.keytab"; | 
| 36 |  | const std::string HADOOP_SECURITY_AUTHENTICATION = "hadoop.security.authentication"; | 
| 37 |  | const std::string FALLBACK_TO_SIMPLE_AUTH_ALLOWED = "ipc.client.fallback-to-simple-auth-allowed"; | 
| 38 |  | const std::string TRUE_VALUE = "true"; | 
| 39 |  |  | 
| 40 |  | class HDFSCommonBuilder { | 
| 41 |  |     friend Status create_hdfs_builder(const THdfsParams& hdfsParams, const std::string& fs_name, | 
| 42 |  |                                       HDFSCommonBuilder* builder); | 
| 43 |  |     friend Status create_hdfs_builder(const std::map<std::string, std::string>& properties, | 
| 44 |  |                                       HDFSCommonBuilder* builder); | 
| 45 |  |  | 
| 46 |  | public: | 
| 47 | 0 |     HDFSCommonBuilder() {} | 
| 48 | 0 |     ~HDFSCommonBuilder() { | 
| 49 |  | #ifdef USE_LIBHDFS3 | 
| 50 |  |         // for hadoop hdfs, the hdfs_builder will be freed in hdfsConnect | 
| 51 |  |         if (hdfs_builder != nullptr) { | 
| 52 |  |             hdfsFreeBuilder(hdfs_builder); | 
| 53 |  |         } | 
| 54 |  | #endif | 
| 55 | 0 |     } | 
| 56 |  |  | 
| 57 |  |     // Must call this to init hdfs_builder first. | 
| 58 |  |     Status init_hdfs_builder(); | 
| 59 |  |  | 
| 60 | 0 |     hdfsBuilder* get() { return hdfs_builder; } | 
| 61 | 0 |     bool is_kerberos() const { return kerberos_login; } | 
| 62 |  |     Status check_krb_params(); | 
| 63 |  |  | 
| 64 |  |     Status set_kerberos_ticket_cache(); | 
| 65 |  |     void set_hdfs_conf(const std::string& key, const std::string& val); | 
| 66 |  |     std::string get_hdfs_conf_value(const std::string& key, const std::string& default_val) const; | 
| 67 |  |     void set_hdfs_conf_to_hdfs_builder(); | 
| 68 |  |  | 
| 69 |  | private: | 
| 70 |  |     hdfsBuilder* hdfs_builder = nullptr; | 
| 71 |  |     bool kerberos_login {false}; | 
| 72 |  |  | 
| 73 |  |     // We should save these info from thrift, | 
| 74 |  |     // so that the lifecycle of these will same as hdfs_builder | 
| 75 |  |     std::string fs_name; | 
| 76 |  |     std::string hadoop_user; | 
| 77 |  |     std::string hdfs_kerberos_keytab; | 
| 78 |  |     std::string hdfs_kerberos_principal; | 
| 79 |  |     std::unordered_map<std::string, std::string> hdfs_conf; | 
| 80 |  | }; | 
| 81 |  |  | 
| 82 |  | THdfsParams parse_properties(const std::map<std::string, std::string>& properties); | 
| 83 |  |  | 
| 84 |  | Status create_hdfs_builder(const THdfsParams& hdfsParams, HDFSCommonBuilder* builder); | 
| 85 |  | Status create_hdfs_builder(const std::map<std::string, std::string>& properties, | 
| 86 |  |                            HDFSCommonBuilder* builder); | 
| 87 |  |  | 
| 88 |  | } // namespace doris |