/** * 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. */ #include "common/hdfs_configuration.h" #include "common/logging.h" #include #ifndef DEFAULT_SCHEME #define DEFAULT_SCHEME "hdfs://" #endif namespace hdfs { // Constructs a configuration with no search path and no resources loaded HdfsConfiguration::HdfsConfiguration() : Configuration() {} // Constructs a configuration with a copy of the input data HdfsConfiguration::HdfsConfiguration(ConfigMap &src_map) : Configuration(src_map) {} HdfsConfiguration::HdfsConfiguration(const ConfigMap &src_map) : Configuration(src_map) {} std::vector HdfsConfiguration::GetDefaultFilenames() { auto result = Configuration::GetDefaultFilenames(); result.push_back("hdfs-site.xml"); return result; } // Sets a value iff the optional has a value template void OptionalSet(T& target, optional value) { if (value) target = *value; } std::vector SplitOnComma(const std::string &s, bool include_empty_strings) { std::vector res; std::string buf; for(unsigned int i=0;i 0) res.push_back(buf); return res; } std::string RemoveSpaces(const std::string &str) { std::string res; for(unsigned int i=0; i str) { if(!str) return ""; if(str.value().find("://") == std::string::npos) return DEFAULT_SCHEME + str.value(); return str.value(); } // It's either use this, goto, or a lot of returns w/ status checks struct ha_parse_error : public std::exception { std::string desc; ha_parse_error(const std::string &val) : desc(val) {}; const char *what() const noexcept override { return desc.c_str(); }; }; std::vector HdfsConfiguration::LookupNameService(const std::string &nameservice) { LOG_TRACE(kRPC, << "HDFSConfiguration@" << this << "::LookupNameService( nameservice=" << nameservice<< " ) called"); std::vector namenodes; try { // Find namenodes that belong to nameservice std::vector namenode_ids; { std::string service_nodes = std::string("dfs.ha.namenodes.") + nameservice; optional namenode_list = Get(service_nodes); if(namenode_list) namenode_ids = SplitOnComma(namenode_list.value(), false); else throw ha_parse_error("unable to find " + service_nodes); for(unsigned int i=0; i dfs_nameservices = Get("dfs.nameservices"); if(dfs_nameservices) { std::string nameservice = dfs_nameservices.value(); std::vector all_services = SplitOnComma(nameservice, false); // Look up nodes for each nameservice so that FileSystem object can support // multiple nameservices by ID. for(const std::string &service : all_services) { if(service.empty()) continue; LOG_DEBUG(kFileSystem, << "Parsing info for nameservice: " << service); std::vector nodes = LookupNameService(service); if(nodes.empty()) { LOG_WARN(kFileSystem, << "Nameservice \"" << service << "\" declared in config but nodes aren't"); } else { result.services[service] = nodes; } } } optional authentication_value = Get(kHadoopSecurityAuthenticationKey); if (authentication_value ) { std::string fixed_case_value = fixCase(authentication_value.value()); if (fixed_case_value == fixCase(kHadoopSecurityAuthentication_kerberos)) result.authentication = Options::kKerberos; else result.authentication = Options::kSimple; } return result; } }