Skip to content

Commit

Permalink
Merge "[service monitor] Introspect to reflect ha state - Link VM to …
Browse files Browse the repository at this point in the history
…SI during launch of nova vm - Fix spacing in db.py" into R1.10
  • Loading branch information
Zuul authored and Gerrit Code Review committed Oct 2, 2014
2 parents a2e34aa + fbc3a59 commit 20d5fba
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 112 deletions.
11 changes: 8 additions & 3 deletions src/config/common/svc_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
_VN_SNAT_SUBNET_CIDR = '100.64.0.0/29'

_CHECK_SVC_VM_HEALTH_INTERVAL = 30
_CHECK_CLEANUP_INTERVAL = 5

_VM_INSTANCE_TYPE = 'virtual-machine'
_NETNS_INSTANCE_TYPE = 'network-namespace'

_SNAT_SVC_TYPE = 'source-nat'
_LB_SVC_TYPE = 'loadbalancer'

_ACTIVE_LOCAL_PREFERENCE = 200
_STANDBY_LOCAL_PREFERENCE = 100

def get_management_if_str():
return _MGMT_STR

Expand Down Expand Up @@ -87,5 +89,8 @@ def get_lb_service_type():
def get_vm_health_interval():
return _CHECK_SVC_VM_HEALTH_INTERVAL

def get_cleanup_interval():
return _CHECK_CLEANUP_INTERVAL
def get_active_preference():
return _ACTIVE_LOCAL_PREFERENCE

def get_standby_preference():
return _STANDBY_LOCAL_PREFERENCE
10 changes: 6 additions & 4 deletions src/config/svc-monitor/svc_mon_introspect.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
struct ServiceInstanceVM {
1: string name;
2: string vr_name;
3: string ha;
}

struct ServiceInstance {
1: string name;
2: string si_type;
3: list<ServiceInstanceVM> vm_list;
4: list<string> left_vn;
5: list<string> right_vn;
6: list<string> management_vn;
3: string si_state;
4: list<ServiceInstanceVM> vm_list;
5: list<string> left_vn;
6: list<string> right_vn;
7: list<string> management_vn;
}

request sandesh ServiceInstanceList {
Expand Down
116 changes: 58 additions & 58 deletions src/config/svc-monitor/svc_monitor/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,61 +98,61 @@ def _db_list(self, table):

# initialize cassandra
def _cassandra_init(self):
server_idx = 0
num_dbnodes = len(self._args.cassandra_server_list)
connected = False

# Update connection info
self._logger.db_conn_status_update(ConnectionStatus.INIT,
self._args.cassandra_server_list)
while not connected:
try:
cass_server = self._args.cassandra_server_list[server_idx]
sys_mgr = SystemManager(cass_server)
connected = True
except Exception as e:
# Update connection info
self._logger.db_conn_status_update(ConnectionStatus.DOWN,
[cass_server], str(e))
server_idx = (server_idx + 1) % num_dbnodes
time.sleep(3)
# Update connection info
self._logger.db_conn_status_update(ConnectionStatus.UP,
self._args.cassandra_server_list)
if self._args.reset_config:
try:
sys_mgr.drop_keyspace(self._keyspace)
except pycassa.cassandra.ttypes.InvalidRequestException as e:
print "Warning! " + str(e)
try:
sys_mgr.create_keyspace(self._keyspace, SIMPLE_STRATEGY,
{'replication_factor': str(num_dbnodes)})
except pycassa.cassandra.ttypes.InvalidRequestException as e:
print "Warning! " + str(e)
# set up column families
column_families = [self._SVC_SI_CF]
for cf in column_families:
try:
sys_mgr.create_column_family(self._keyspace, cf)
except pycassa.cassandra.ttypes.InvalidRequestException as e:
print "Warning! " + str(e)
conn_pool = pycassa.ConnectionPool(self._keyspace,
self._args.cassandra_server_list,
max_overflow=10,
use_threadlocal=True,
prefill=True,
pool_size=10,
pool_timeout=30,
max_retries=-1,
timeout=0.5)
rd_consistency = pycassa.cassandra.ttypes.ConsistencyLevel.QUORUM
wr_consistency = pycassa.cassandra.ttypes.ConsistencyLevel.QUORUM
self._svc_si_cf = pycassa.ColumnFamily(conn_pool, self._SVC_SI_CF,
read_consistency_level=rd_consistency,
write_consistency_level=wr_consistency)
server_idx = 0
num_dbnodes = len(self._args.cassandra_server_list)
connected = False

# Update connection info
self._logger.db_conn_status_update(ConnectionStatus.INIT,
self._args.cassandra_server_list)
while not connected:
try:
cass_server = self._args.cassandra_server_list[server_idx]
sys_mgr = SystemManager(cass_server)
connected = True
except Exception as e:
# Update connection info
self._logger.db_conn_status_update(ConnectionStatus.DOWN,
[cass_server], str(e))
server_idx = (server_idx + 1) % num_dbnodes
time.sleep(3)

# Update connection info
self._logger.db_conn_status_update(ConnectionStatus.UP,
self._args.cassandra_server_list)

if self._args.reset_config:
try:
sys_mgr.drop_keyspace(self._keyspace)
except pycassa.cassandra.ttypes.InvalidRequestException as e:
print "Warning! " + str(e)

try:
sys_mgr.create_keyspace(self._keyspace, SIMPLE_STRATEGY,
{'replication_factor': str(num_dbnodes)})
except pycassa.cassandra.ttypes.InvalidRequestException as e:
print "Warning! " + str(e)

# set up column families
column_families = [self._SVC_SI_CF]
for cf in column_families:
try:
sys_mgr.create_column_family(self._keyspace, cf)
except pycassa.cassandra.ttypes.InvalidRequestException as e:
print "Warning! " + str(e)

conn_pool = pycassa.ConnectionPool(self._keyspace,
self._args.cassandra_server_list,
max_overflow=10,
use_threadlocal=True,
prefill=True,
pool_size=10,
pool_timeout=30,
max_retries=-1,
timeout=0.5)

rd_consistency = pycassa.cassandra.ttypes.ConsistencyLevel.QUORUM
wr_consistency = pycassa.cassandra.ttypes.ConsistencyLevel.QUORUM
self._svc_si_cf = pycassa.ColumnFamily(conn_pool, self._SVC_SI_CF,
read_consistency_level=rd_consistency,
write_consistency_level=wr_consistency)
31 changes: 22 additions & 9 deletions src/config/svc-monitor/svc_monitor/instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
from novaclient import client as nc
from novaclient import exceptions as nc_exc

_ACTIVE_LOCAL_PREFERENCE = 200
_STANDBY_LOCAL_PREFERENCE = 100

@six.add_metaclass(abc.ABCMeta)
class InstanceManager(object):

Expand Down Expand Up @@ -395,6 +392,22 @@ def _create_svc_vm(self, instance_name, image_name, nics,
availability_zone=avail_zone)
nova_vm.get()
self.logger.log('Created VM : ' + str(nova_vm))

# create vnc VM object and link to SI
try:
proj_obj = self._vnc_lib.project_read(
fq_name=si_obj.get_parent_fq_name())
vm_obj = VirtualMachine(nova_vm.id)
vm_obj.uuid = nova_vm.id
self._vnc_lib.virtual_machine_create(vm_obj)
except RefsExistError:
vm_obj = self._vnc_lib.virtual_machine_read(id=nova_vm.id)

vm_obj.add_service_instance(si_obj)
self._vnc_lib.virtual_machine_update(vm_obj)
self.logger.log("Info: VM %s updated SI %s" %
(vm_obj.get_fq_name_str(), si_obj.get_fq_name_str()))

return nova_vm

def create_service(self, st_obj, si_obj):
Expand Down Expand Up @@ -713,11 +726,11 @@ def _get_local_prefs(self, si_obj, max_instances):
local_prefs[inst_count] = int(si_db_entry[column])

if not local_prefs[0] and not local_prefs[1]:
local_prefs[0] = _ACTIVE_LOCAL_PREFERENCE
local_prefs[1] = _STANDBY_LOCAL_PREFERENCE
elif local_prefs[0] == _ACTIVE_LOCAL_PREFERENCE:
local_prefs[1] = _STANDBY_LOCAL_PREFERENCE
elif local_prefs[0] == _STANDBY_LOCAL_PREFERENCE:
local_prefs[1] = _ACTIVE_LOCAL_PREFERENCE
local_prefs[0] = svc_info.get_active_preference()
local_prefs[1] = svc_info.get_standby_preference()
elif local_prefs[0] == svc_info.get_active_preference():
local_prefs[1] = svc_info.get_standby_preference()
elif local_prefs[0] == svc_info.get_standby_preference():
local_prefs[1] = svc_info.get_active_preference()

return local_prefs
17 changes: 12 additions & 5 deletions src/config/svc-monitor/svc_monitor/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,23 @@ def sandesh_si_handle_request(self, req):

for si_fq_name_str, si in si_list or []:
sandesh_si = sandesh.ServiceInstance(
name=si_fq_name_str, si_type=si['instance_type'])
name=si_fq_name_str, si_type=si.get('instance_type', ''),
si_state=si.get('state', ''))

sandesh_vm_list = []
for idx in range(0, int(si.get('max-instances', '0'))):
prefix = self._db.get_vm_db_prefix(idx)
vm_name = si[prefix + 'name']
vm_uuid = si[prefix + 'uuid']
vm_name = si.get(prefix + 'name', '')
vm_uuid = si.get(prefix + 'uuid', '')
vm_str = ("%s: %s" % (vm_name, vm_uuid))
vm = sandesh.ServiceInstanceVM(
name=vm_str, vr_name=si.get(prefix+'vrouter', ''))
vr_name = si.get(prefix + 'vrouter', '')
ha = si.get(prefix + 'preference', '')
if int(ha) == svc_info.get_standby_preference():
ha_str = ("standby: %s" % (ha))
else:
ha_str = ("active: %s" % (ha))
vm = sandesh.ServiceInstanceVM(name=vm_str,
vr_name=vr_name, ha=ha_str)
sandesh_vm_list.append(vm)
sandesh_si.vm_list = list(sandesh_vm_list)

Expand Down
33 changes: 0 additions & 33 deletions src/config/svc-monitor/svc_monitor/svc_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,39 +368,6 @@ def _delmsg_virtual_machine_interface_route_table(self, idents):
if vmi_list is None:
self._vnc_lib.interface_route_table_delete(id=rt_obj.uuid)

def _addmsg_virtual_machine_interface_virtual_machine(self, idents):
vm_fq_str = idents['virtual-machine']
vmi_fq_str = idents['virtual-machine-interface']

try:
vm_obj = self._vnc_lib.virtual_machine_read(
fq_name_str=vm_fq_str)
vmi_obj = self._vnc_lib.virtual_machine_interface_read(
fq_name_str=vmi_fq_str)
except NoIdError:
return

# if already linked as service vm then return
si_list = vm_obj.get_service_instance_refs()
if si_list:
return

try:
si_uuid = vmi_obj.name.split('__')[-2]
except IndexError:
return

try:
si_obj = self._vnc_lib.service_instance_read(id=si_uuid)
except NoIdError:
return

# create service instance to service vm link
vm_obj.add_service_instance(si_obj)
self._vnc_lib.virtual_machine_update(vm_obj)
self.logger.log("Info: VM %s updated SI %s" %
(vm_obj.get_fq_name_str(), si_obj.get_fq_name_str()))

def _addmsg_service_instance_service_template(self, idents):
st_fq_str = idents['service-template']
si_fq_str = idents['service-instance']
Expand Down

0 comments on commit 20d5fba

Please sign in to comment.