Skip to content

Commit

Permalink
Merge "Initial Support for Health Check service"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jan 11, 2016
2 parents 2d0085e + 4877e2a commit a30ba0a
Show file tree
Hide file tree
Showing 33 changed files with 1,546 additions and 129 deletions.
3 changes: 3 additions & 0 deletions src/ifmap/ifmap_graph_walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ void IFMapGraphWalker::AddNodesToWhitelist() {
traversal_white_list_->include_vertex.insert("loadbalancer-member");
traversal_white_list_->include_vertex.insert("loadbalancer-healthmonitor");
traversal_white_list_->include_vertex.insert("subnet");
traversal_white_list_->include_vertex.insert("service-health-check");
}

void IFMapGraphWalker::AddLinksToWhitelist() {
Expand Down Expand Up @@ -473,5 +474,7 @@ void IFMapGraphWalker::AddLinksToWhitelist() {
// getting the pool from. EG: public-network (might not have any VMs)
traversal_white_list_->include_edge.insert(
"source=floating-ip-pool,target=virtual-network");
traversal_white_list_->include_edge.insert(
"source=virtual-machine-interface,target=service-health-check");
}

20 changes: 19 additions & 1 deletion src/vnsw/agent/cmn/agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <oper/operdb_init.h>
#include <oper/config_manager.h>
#include <oper/interface_common.h>
#include <oper/health_check.h>
#include <oper/metadata_ip.h>
#include <oper/multicast.h>
#include <oper/nexthop.h>
#include <oper/mirror_table.h>
Expand Down Expand Up @@ -427,7 +429,7 @@ Agent::Agent() :
instance_id_(g_vns_constants.INSTANCE_ID_DEFAULT),
module_type_(Module::VROUTER_AGENT), db_(NULL),
task_scheduler_(NULL), agent_init_(NULL), fabric_vrf_(NULL),
intf_table_(NULL),
intf_table_(NULL), health_check_table_(NULL), metadata_ip_allocator_(NULL),
nh_table_(NULL), uc_rt_table_(NULL), mc_rt_table_(NULL), vrf_table_(NULL),
vm_table_(NULL), vn_table_(NULL), sg_table_(NULL), mpls_table_(NULL),
acl_table_(NULL), mirror_table_(NULL), vrf_assign_table_(NULL),
Expand Down Expand Up @@ -557,6 +559,22 @@ void Agent::set_flow_stats_manager(FlowStatsManager *aging_module) {
flow_stats_manager_ = aging_module;
}

HealthCheckTable *Agent::health_check_table() const {
return health_check_table_;
}

void Agent::set_health_check_table(HealthCheckTable *table) {
health_check_table_ = table;
}

MetaDataIpAllocator *Agent::metadata_ip_allocator() const {
return metadata_ip_allocator_.get();
}

void Agent::set_metadata_ip_allocator(MetaDataIpAllocator *allocator) {
metadata_ip_allocator_.reset(allocator);
}

PktModule *Agent::pkt() const {
return pkt_;
}
Expand Down
15 changes: 15 additions & 0 deletions src/vnsw/agent/cmn/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AgentInit;
class AgentStatsCollector;
class FlowStatsCollector;
class FlowStatsManager;
class MetaDataIpAllocator;
namespace OVSDB {
class OvsdbClient;
};
Expand Down Expand Up @@ -125,12 +126,18 @@ typedef boost::intrusive_ptr<const PhysicalDeviceVn> PhysicalDeviceVnConstRef;
void intrusive_ptr_release(const PhysicalDeviceVn *p);
void intrusive_ptr_add_ref(const PhysicalDeviceVn *p);

class HealthCheckService;
typedef boost::intrusive_ptr<HealthCheckService> HealthCheckServiceRef;
void intrusive_ptr_release(const HealthCheckService* p);
void intrusive_ptr_add_ref(const HealthCheckService* p);

//class SecurityGroup;
typedef std::vector<int> SecurityGroupList;
typedef std::vector<std::string> CommunityList;

class AgentDBTable;
class InterfaceTable;
class HealthCheckTable;
class NextHopTable;
class VmTable;
class VnTable;
Expand Down Expand Up @@ -747,6 +754,12 @@ class Agent {
FlowStatsManager *flow_stats_manager() const;
void set_flow_stats_manager(FlowStatsManager *fsc);

HealthCheckTable *health_check_table() const;
void set_health_check_table(HealthCheckTable *table);

MetaDataIpAllocator *metadata_ip_allocator() const;
void set_metadata_ip_allocator(MetaDataIpAllocator *allocator);

PktModule *pkt() const;
void set_pkt(PktModule *pkt);

Expand Down Expand Up @@ -1002,6 +1015,8 @@ class Agent {
AgentInit *agent_init_;
VrfEntry *fabric_vrf_;
InterfaceTable *intf_table_;
HealthCheckTable *health_check_table_;
std::auto_ptr<MetaDataIpAllocator> metadata_ip_allocator_;
NextHopTable *nh_table_;
InetUnicastAgentRouteTable *uc_rt_table_;
Inet4MulticastAgentRouteTable *mc_rt_table_;
Expand Down
6 changes: 6 additions & 0 deletions src/vnsw/agent/cmn/index_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class IndexVector {
entries_.resize(index + kGrowSize);
}

// TODO(prabhjot) need to enable assertion below
// currently disabled due to some issue with MPLS
// label allocation
// index should not be already in use
// assert(bitmap_[index] == 1);

bitmap_.set(index, 0);
entries_[index] = entry;
return index;
Expand Down
2 changes: 2 additions & 0 deletions src/vnsw/agent/contrail/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ doc_files += env['AGENT_FLOW_DOC_FILES']

# Please update sandesh/common/vns.sandesh on process name change
env.Alias('install', env.Install(env['INSTALL_BIN'], contrail_vrouter_agent))
env.Alias('install', env.Install(env['INSTALL_EXAMPLE'],
'contrail_vrouter_agent_health_check.py'))
env.Alias('install', env.Install(env['INSTALL_CONF'],
'../contrail-vrouter-agent.conf'))
env.Alias('install',
Expand Down
117 changes: 117 additions & 0 deletions src/vnsw/agent/contrail/contrail_vrouter_agent_health_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/python
#
# Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
#

import os
import sys
from threading import Event
from subprocess import call
from optparse import OptionParser

class HealthCheckBase():
def __init__(self, event, ip, timer, timeout, retries, uri):
self.event = event
self.ip = ip
self.timer = timer
self.timeout = timeout
self.retries = retries
self.uri = uri;
self.retries_done = 0
self.initial = True
self.ret = 0
self.stop = False
self.dev_null_fd = open(os.devnull, 'w')

def start(self):
while (self.initial or (not self.event.wait(self.timer))):
if (self.stop == False):
ret = self.execute_util(self.ip, self.timeout, self.uri,
self.dev_null_fd)
self.retries_done += 1
if ret != 0 and self.retries_done != self.retries:
# ignore by restoring previous response,
# till number of retries are completed
ret = self.ret
else:
self.retries_done = 0
# TODO(prabhjot) need to add log for every transaction
if self.initial == True or ret != self.ret:
# TODO(prabhjot) currently script uses failure to
# write to stdout as a mechanism to identify parent
# process close and exit, eventually we should
# restore below line to optimize unneccessary message
# exchange on the stdout pipe
# self.initial = False
self.ret = ret
if self.ret == 0:
sys.stdout.write("Success\n")
sys.stdout.flush()
else:
sys.stdout.write("Failure\n")
sys.stdout.flush()

def execute_util(self, ip, timeout, uri, out_fd):
sys.stderr.write("Error: health check method not defined!\n")
sys.stderr.flush()
# pause script and stop retrying
self.stop = True
self.retries = 1
return 1

class HealthCheckPing(HealthCheckBase):
def execute_util(self, ip, timeout, uri, out_fd):
return call(["ping", "-c2", "-W" + str(timeout), ip], stdout=out_fd,
stderr=out_fd)

class HealthCheckHttp(HealthCheckBase):
def execute_util(self, ip, timeout, uri, out_fd):
return call(["curl", "-m" + str(timeout), "http://" + ip + "/" + uri],
stdout=out_fd, stderr=out_fd)

def HealthCheckService(x):
return {
"ping": HealthCheckPing,
"Ping": HealthCheckPing,
"PING": HealthCheckPing,
"http": HealthCheckHttp,
"Http": HealthCheckHttp,
"HTTP": HealthCheckHttp,
}.get(x, HealthCheckBase) #[x]

parser = OptionParser()
parser.add_option("-m", "--method", dest="method",
help="method to do Health Check (Ping/Http)",
metavar="METHOD")
parser.add_option("-d", "--destip", dest="dest_ip",
help="Destination IP to run Health Check", metavar="IP",
default="")
parser.add_option("-i", "--interval", dest="interval", type="int",
help="Health Check interval in seconds", metavar="TIME",
default="2")
parser.add_option("-t", "--timeout", dest="timeout", type="int",
help="Health Check timeout in seconds", metavar="TIME",
default="1")
parser.add_option("-r", "--retries", dest="retries", type="int",
help="Number of retries to be done to declare error",
metavar="COUNT", default="2")
parser.add_option("-u", "--uri", dest="uri",
help="Additional indentifier for Health Check object",
metavar="STRING", default="")
(option, args) = parser.parse_args()

if option.interval < 1:
option.interval = 1

if option.timeout < 1:
option.timeout = 1

if option.retries < 1:
option.retries = 1

timerEvent = Event()
service = HealthCheckService(option.method)(timerEvent, option.dest_ip,
option.interval, option.timeout,
option.retries, option.uri)
service.start()

2 changes: 2 additions & 0 deletions src/vnsw/agent/oper/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ vnswoperdb = env.Library('vnswoperdb',
'config_manager.cc',
'evpn_route.cc',
'global_vrouter.cc',
'health_check.cc',
'ifmap_dependency_manager.cc',
'inet_interface.cc',
'inet4_multicast_route.cc',
Expand All @@ -47,6 +48,7 @@ vnswoperdb = env.Library('vnswoperdb',
'loadbalancer_pool.cc',
'loadbalancer_pool_info.cc',
'logical_interface.cc',
'metadata_ip.cc',
'mirror_table.cc',
'mpls.cc',
'multicast.cc',
Expand Down
38 changes: 38 additions & 0 deletions src/vnsw/agent/oper/agent.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ struct ItfSandeshData {
49: optional string ipv4_active;
50: list<string> fixed_ip4_list;
51: list<string> fixed_ip6_list;
52: optional string health_check_active;
53: optional string metadata_ip_active;
}

struct VnIpamData {
Expand Down Expand Up @@ -1326,3 +1328,39 @@ response sandesh IFMapNodePolicyResp {
request sandesh IFMapNodePolicyReq {
1: string node;
}

traceobject sandesh HealthCheckTrace {
1: string log;
}

struct HealthCheckInstanceSandeshData {
1: string vm_interface (link="ItfReq");
2: string metadata_ip;
3: string service_ip;
4: string health_check_ip;
5: bool active;
6: bool running;
7: string last_update_time;
}

struct HealthCheckSandeshData {
1: string uuid;
2: string name;
3: string monitor_type;
4: string http_method;
5: string url_path;
6: string expected_codes;
7: u32 delay;
8: u32 timeout;
9: u32 max_retries;
10: list<HealthCheckInstanceSandeshData> inst_list;
}

request sandesh HealthCheckSandeshReq {
1: string uuid;
}

response sandesh HealthCheckSandeshResp {
1: list<HealthCheckSandeshData> hc_list;
}

34 changes: 34 additions & 0 deletions src/vnsw/agent/oper/agent_sandesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <oper/peer.h>
#include <oper/vrf.h>
#include <oper/interface_common.h>
#include <oper/health_check.h>
#include <oper/nexthop.h>
#include <oper/vn.h>
#include <oper/vm.h>
Expand Down Expand Up @@ -1058,3 +1059,36 @@ void VrouterObjectLimitsReq::HandleRequest() const {
resp->set_vrouter_object_limit(vr_limits);
resp->Response();
}

AgentHealthCheckSandesh::AgentHealthCheckSandesh(const std::string &context,
const std::string &u) :
AgentSandesh(context, ""), uuid_str_(u) {
boost::system::error_code ec;
uuid_ = StringToUuid(u);
}

DBTable *AgentHealthCheckSandesh::AgentGetTable() {
return static_cast<DBTable *>(Agent::GetInstance()->health_check_table());
}

void AgentHealthCheckSandesh::Alloc() {
resp_ = new HealthCheckSandeshResp();
}

bool AgentHealthCheckSandesh::Filter(const DBEntryBase *entry) {
const HealthCheckService *service =
dynamic_cast<const HealthCheckService *>(entry);
assert(service);

if (MatchUuid(uuid_str_ , uuid_, service->uuid()) == false)
return false;

return true;
}

bool AgentHealthCheckSandesh::FilterToArgs(AgentSandeshArguments *args) {
args->Add("uuid", uuid_str_);

return true;
}

17 changes: 17 additions & 0 deletions src/vnsw/agent/oper/agent_sandesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,21 @@ class AgentLoadBalancerV2Sandesh : public AgentSandesh {
void Alloc();
};

class AgentHealthCheckSandesh : public AgentSandesh {
public:
AgentHealthCheckSandesh(const std::string &context, const std::string &u);
~AgentHealthCheckSandesh() {}
virtual bool Filter(const DBEntryBase *entry);
virtual bool FilterToArgs(AgentSandeshArguments *args);

private:
friend class VnListReq;
DBTable *AgentGetTable();
void Alloc();
std::string uuid_str_;

boost::uuids::uuid uuid_;

};

#endif // vnsw_agent_sandesh_h_

0 comments on commit a30ba0a

Please sign in to comment.