1/********************************************************************
2 * Copyright (c) 2013 - 2014, Pivotal Inc.
3 * All rights reserved.
4 *
5 * Author: Zhanwei Wang
6 ********************************************************************/
7/********************************************************************
8 * 2014 -
9 * open source under Apache License Version 2.0
10 ********************************************************************/
11/**
12 * Licensed to the Apache Software Foundation (ASF) under one
13 * or more contributor license agreements. See the NOTICE file
14 * distributed with this work for additional information
15 * regarding copyright ownership. The ASF licenses this file
16 * to you under the Apache License, Version 2.0 (the
17 * "License"); you may not use this file except in compliance
18 * with the License. You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28#include "NamenodeInfo.h"
29#include "StringUtil.h"
30#include "XmlConfig.h"
31
32#include <string>
33#include <vector>
34
35using namespace Hdfs::Internal;
36
37namespace Hdfs {
38
39NamenodeInfo::NamenodeInfo() {
40}
41
42const char * DFS_NAMESERVICES = "dfs.nameservices";
43const char * DFS_NAMENODE_HA = "dfs.ha.namenodes";
44const char * DFS_NAMENODE_RPC_ADDRESS_KEY = "dfs.namenode.rpc-address";
45const char * DFS_NAMENODE_HTTP_ADDRESS_KEY = "dfs.namenode.http-address";
46
47std::vector<NamenodeInfo> NamenodeInfo::GetHANamenodeInfo(
48 const std::string & service, const Config & conf) {
49 std::vector<NamenodeInfo> retval;
50 std::string strNameNodes = StringTrim(
51 conf.getString(std::string(DFS_NAMENODE_HA) + "." + service));
52 std::vector<std::string> nns = StringSplit(strNameNodes, ",");
53 retval.resize(nns.size());
54
55 for (size_t i = 0; i < nns.size(); ++i) {
56 std::string dfsRpcAddress = StringTrim(
57 std::string(DFS_NAMENODE_RPC_ADDRESS_KEY) + "." + service + "."
58 + StringTrim(nns[i]));
59 std::string dfsHttpAddress = StringTrim(
60 std::string(DFS_NAMENODE_HTTP_ADDRESS_KEY) + "." + service + "."
61 + StringTrim(nns[i]));
62 retval[i].setRpcAddr(StringTrim(conf.getString(dfsRpcAddress, "")));
63 retval[i].setHttpAddr(StringTrim(conf.getString(dfsHttpAddress, "")));
64 }
65
66 return retval;
67}
68}
69