Coverage Report

Created: 2024-11-20 18:15

/root/doris/be/src/io/hdfs_builder.h
Line
Count
Source (jump to first uncovered line)
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 TICKET_CACHE_PATH = "/tmp/krb5cc_doris_";
37
38
class HDFSCommonBuilder {
39
    friend Status create_hdfs_builder(const THdfsParams& hdfsParams, const std::string& fs_name,
40
                                      HDFSCommonBuilder* builder);
41
    friend Status create_hdfs_builder(const std::map<std::string, std::string>& properties,
42
                                      HDFSCommonBuilder* builder);
43
44
public:
45
0
    HDFSCommonBuilder() {}
46
0
    ~HDFSCommonBuilder() {
47
#ifdef USE_LIBHDFS3
48
        // for hadoop hdfs, the hdfs_builder will be freed in hdfsConnect
49
        if (hdfs_builder != nullptr) {
50
            hdfsFreeBuilder(hdfs_builder);
51
        }
52
#endif
53
0
    }
54
55
    // Must call this to init hdfs_builder first.
56
    Status init_hdfs_builder();
57
58
0
    hdfsBuilder* get() { return hdfs_builder; }
59
0
    bool is_kerberos() const { return kerberos_login; }
60
    Status check_krb_params();
61
62
private:
63
    hdfsBuilder* hdfs_builder = nullptr;
64
    bool kerberos_login {false};
65
    std::string hdfs_kerberos_keytab;
66
    std::string hdfs_kerberos_principal;
67
};
68
69
THdfsParams parse_properties(const std::map<std::string, std::string>& properties);
70
71
Status create_hdfs_builder(const THdfsParams& hdfsParams, HDFSCommonBuilder* builder);
72
Status create_hdfs_builder(const std::map<std::string, std::string>& properties,
73
                           HDFSCommonBuilder* builder);
74
75
} // namespace doris