Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow custom configs with LBaaS
This fix commits the vrouter agent code to read
the custom_attributes from ifmap node and copy it
to config.json file which the haproxy parser
would read. Added missing '}'. Incorporating the
comments

Closes-Bug: #1475393
Change-Id: I6f22f4f537c97c48b2283971b2959c9be5931361
  • Loading branch information
Varun Lodaya authored and Varun Lodaya committed Aug 27, 2015
1 parent 7af3199 commit 53cc6cd
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/vnsw/agent/oper/loadbalancer.cc
Expand Up @@ -95,6 +95,7 @@ void Loadbalancer::CalculateProperties(DBGraph *graph, Properties *properties) {
autogen::LoadbalancerPool *pool =
static_cast<autogen::LoadbalancerPool *>(node_->GetObject());
properties->set_pool_properties(pool->properties());
properties->set_custom_attributes(pool->custom_attributes());

for (DBGraphVertex::adjacency_iterator iter = node_->begin(graph);
iter != node_->end(graph); ++iter) {
Expand Down
29 changes: 28 additions & 1 deletion src/vnsw/agent/oper/loadbalancer_config.cc
Expand Up @@ -118,7 +118,33 @@ void LoadbalancerConfig::GenerateHealthMonitors(
if (count) {
ostr << endl;
}
ostr << " ]" << endl;
ostr << " ]," << endl;
*out << ostr.str();
}

void LoadbalancerConfig::GenerateCustomAttributes(
ostream *out, const LoadbalancerProperties &props) const {
const std::vector<autogen::KeyValuePair>
&custom_attributes = props.custom_attributes();
ostringstream ostr;
autogen::KeyValuePairs::const_iterator curr_iter, next_iter, end_iter;
curr_iter = custom_attributes.begin();
end_iter = custom_attributes.end();

ostr << " \"custom-attributes\":{" << endl;

while (curr_iter != end_iter) {
next_iter = curr_iter + 1;
const autogen::KeyValuePair element = (*curr_iter);
ostr << " \"" << element.key << "\":\"" << element.value << "\"";
if (next_iter == end_iter) {
ostr << endl;
break;
}
ostr << "," << endl;
curr_iter = next_iter;
}
ostr << " }" << endl;
*out << ostr.str();
}

Expand All @@ -137,6 +163,7 @@ void LoadbalancerConfig::GenerateConfig(
GenerateVip(&fs, props);
GenerateMembers(&fs, props);
GenerateHealthMonitors(&fs, props);
GenerateCustomAttributes(&fs, props);
fs << "}" << endl;
fs.close();
}
2 changes: 2 additions & 0 deletions src/vnsw/agent/oper/loadbalancer_config.h
Expand Up @@ -29,6 +29,8 @@ class LoadbalancerConfig {
const LoadbalancerProperties &props) const;
void GenerateHealthMonitors(std::ostream *out,
const LoadbalancerProperties &props) const;
void GenerateCustomAttributes(std::ostream *out,
const LoadbalancerProperties &props) const;

Agent *agent_;

Expand Down
50 changes: 50 additions & 0 deletions src/vnsw/agent/oper/loadbalancer_properties.cc
Expand Up @@ -125,6 +125,48 @@ void MapDiff(const MapType &lhs, const MapType &rhs, Comparator comp,
}
}

int CustomAttributesCompare(const std::vector<autogen::KeyValuePair> &lhs,
const std::vector<autogen::KeyValuePair> &rhs) {
autogen::KeyValuePairs::const_iterator iter1 = lhs.begin();
autogen::KeyValuePairs::const_iterator iter2 = rhs.begin();
int ret = 0;

while (iter1 != lhs.end() && iter2 != rhs.end()) {
if ((ret = iter1->key.compare(iter2->key)) != 0) {
return ret;
}
if ((ret = iter1->value.compare(iter2->value)) != 0) {
return ret;
}
++iter1;
++iter2;
}

if (iter1 != lhs.end()) {
return 1;
}
if (iter2 != rhs.end()) {
return -1;
}
return 0;
}

void CustomAttributesDiff(const std::vector<autogen::KeyValuePair> &lhs,
const std::vector<autogen::KeyValuePair> &rhs,
std::stringstream *ss) {
autogen::KeyValuePairs::const_iterator iter1 = lhs.begin();
autogen::KeyValuePairs::const_iterator iter2 = rhs.begin();

while (iter1 != lhs.end()) {
*ss << " -" << iter1->key << ": " << iter1->value;
++iter1;
}
while (iter2 != rhs.end()) {
*ss << " +" << iter2->key << ": " << iter2->value;
++iter2;
}
}

#define COMPARE_PROPERTY(Xname) \
do { \
int res = compare(Xname, rhs.Xname); \
Expand Down Expand Up @@ -152,8 +194,14 @@ int LoadbalancerProperties::CompareTo(const LoadbalancerProperties &rhs) const {
}

result = MapCompare(monitors_, rhs.monitors_, CompareMonitor);
if (result) {
return result;
}

result = CustomAttributesCompare(custom_attributes_, rhs.custom_attributes_);
return result;
}

#undef COMPARE_PROPERTY

#define DIFF_PROPERTY(Xss, Xname)\
Expand Down Expand Up @@ -187,6 +235,8 @@ std::string LoadbalancerProperties::DiffString(
MapDiff(current->members_, members_, CompareMember, &ss);
ss << " Monitors:";
MapDiff(current->monitors_, monitors_, CompareMonitor, &ss);
ss << " Custom Attributes:";
CustomAttributesDiff(current->custom_attributes_, custom_attributes_, &ss);

return ss.str();
}
Expand Down
9 changes: 9 additions & 0 deletions src/vnsw/agent/oper/loadbalancer_properties.h
Expand Up @@ -62,12 +62,21 @@ class LoadbalancerProperties {
return &monitors_;
}

const std::vector<autogen::KeyValuePair> &custom_attributes() const {
return custom_attributes_;
}

void set_custom_attributes(const std::vector<autogen::KeyValuePair> &custom_attributes) {
custom_attributes_ = custom_attributes;
}

private:
autogen::LoadbalancerPoolType pool_;
boost::uuids::uuid vip_uuid_;
autogen::VirtualIpType vip_;
MemberMap members_;
HealthmonitorMap monitors_;
std::vector<autogen::KeyValuePair> custom_attributes_;
};

#endif // VNSW_AGENT_OPER_LOADBALANCER_PROPERTIES_H__

0 comments on commit 53cc6cd

Please sign in to comment.