blob: 8e990c81f2974115bf709f93275e4d56153c26ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "clusterlist.h"
#include <vespa/config/helper/configgetter.hpp>
#include <sstream>
using namespace vespaclient;
VESPA_IMPLEMENT_EXCEPTION(VCClusterNotFoundException, vespalib::IllegalArgumentException);
ClusterList::Cluster::Cluster(const std::string& name, const std::string& configId)
: _name(name),
_configId(configId)
{}
ClusterList::Cluster::Cluster(const Cluster &) = default;
ClusterList::Cluster & ClusterList::Cluster::operator = (const Cluster &) = default;
ClusterList::Cluster::~Cluster() = default;
ClusterList::ClusterList()
{
configure(*config::ConfigGetter<cloud::config::ClusterListConfig>::getConfig("client"));
}
ClusterList::~ClusterList() {}
void
ClusterList::configure(const cloud::config::ClusterListConfig& config)
{
_contentClusters.clear();
for (uint32_t i = 0; i < config.storage.size(); i++) {
_contentClusters.push_back(
Cluster(config.storage[i].name, config.storage[i].configid));
}
}
std::string
ClusterList::getContentClusterList() const
{
std::ostringstream ost;
for (uint32_t j = 0; j < _contentClusters.size(); j++) {
if (j != 0) {
ost << ",";
}
ost << _contentClusters[j].getName();
}
return ost.str();
}
const ClusterList::Cluster&
ClusterList::verifyContentCluster(const std::string& cluster) const
{
if (cluster.length()) {
for (uint32_t j = 0; j < _contentClusters.size(); j++) {
if (_contentClusters[j].getName() == cluster) {
return _contentClusters[j];
}
}
std::ostringstream ost;
ost << "Cluster " << cluster
<< " has not been configured in the vespa cluster. Legal clusters are ["
<< getContentClusterList() << "]";
throw ClusterNotFoundException(ost.str());
} else if (_contentClusters.size() == 1) {
return _contentClusters[0];
} else {
std::ostringstream ost;
ost << "No content cluster specified. Legal clusters are [" << getContentClusterList() << "]";
throw ClusterNotFoundException(ost.str());
}
}
|