Added log messages thoughout modules
This commit is contained in:
parent
026d70fba6
commit
d83ce70951
@ -118,6 +118,8 @@ def read_and_validate_config(paths, required_fields):
|
||||
"""
|
||||
config = read_config(paths)
|
||||
if not validate_config(config, required_fields):
|
||||
raise KeyError('The config dictionary does not contain ' +
|
||||
'all the required fields')
|
||||
message = 'The config dictionary does not contain ' + \
|
||||
'all the required fields'
|
||||
log.critical(message)
|
||||
raise KeyError(message)
|
||||
return config
|
||||
|
11
neat/db.py
11
neat/db.py
@ -40,6 +40,7 @@ class Database(object):
|
||||
self.hosts = hosts
|
||||
self.vms = vms
|
||||
self.vm_resource_usage = vm_resource_usage
|
||||
log.debug('Instantiated a Database object')
|
||||
|
||||
@contract
|
||||
def select_cpu_mhz_for_vm(self, uuid, n):
|
||||
@ -96,8 +97,9 @@ class Database(object):
|
||||
sel = select([self.vms.c.id]).where(self.vms.c.uuid == uuid)
|
||||
row = self.connection.execute(sel).fetchone()
|
||||
if row is None:
|
||||
return self.vms.insert().execute(uuid=uuid). \
|
||||
inserted_primary_key[0]
|
||||
id = self.vms.insert().execute(uuid=uuid).inserted_primary_key[0]
|
||||
log.info('Created a new DB record for a VM %s, id=%d', uuid, id)
|
||||
return id
|
||||
else:
|
||||
return row['id']
|
||||
|
||||
@ -136,10 +138,13 @@ class Database(object):
|
||||
where(self.hosts.c.hostname == hostname)
|
||||
row = self.connection.execute(sel).fetchone()
|
||||
if row is None:
|
||||
return self.hosts.insert().execute(
|
||||
id = self.hosts.insert().execute(
|
||||
hostname=hostname,
|
||||
cpu_mhz=cpu_mhz,
|
||||
ram=ram).inserted_primary_key[0]
|
||||
log.info('Created a new DB record for a host %s, id=%d',
|
||||
hostname, id)
|
||||
return id
|
||||
else:
|
||||
self.connection.execute(self.hosts.update().
|
||||
where(self.hosts.c.id == row['id']).
|
||||
|
@ -57,5 +57,7 @@ def init_db(sql_connection):
|
||||
|
||||
metadata.create_all()
|
||||
connection = engine.connect()
|
||||
db = Database(connection, hosts, vms, vm_resource_usage)
|
||||
|
||||
return Database(connection, hosts, vms, vm_resource_usage)
|
||||
log.info('Initialized a DB connection to %s', sql_connection)
|
||||
return db
|
||||
|
@ -102,7 +102,9 @@ def raise_error(status_code):
|
||||
:type status_code: int
|
||||
"""
|
||||
if status_code in ERRORS:
|
||||
log.error('REST service: %s', ERRORS[status_code])
|
||||
raise bottle.HTTPResponse(ERRORS[status_code], status_code)
|
||||
log.error('REST service: Unknown error')
|
||||
raise bottle.HTTPResponse('Unknown error', 500)
|
||||
|
||||
|
||||
@ -131,6 +133,7 @@ def validate_params(config, params):
|
||||
sha1(params['password']).hexdigest() != config['admin_password']:
|
||||
raise_error(403)
|
||||
return False
|
||||
log.debug('Request parameters validated')
|
||||
return True
|
||||
|
||||
|
||||
@ -143,8 +146,11 @@ def start():
|
||||
bottle.app().state = {
|
||||
'config': config,
|
||||
'state': init_state(config)}
|
||||
bottle.run(host=config['global_manager_host'],
|
||||
port=config['global_manager_port'])
|
||||
|
||||
host = config['global_manager_host']
|
||||
port = config['global_manager_port']
|
||||
log.info('Starting the global manager listening to %s:%s', host, port)
|
||||
bottle.run(host=host, port=port)
|
||||
|
||||
|
||||
@contract
|
||||
@ -166,11 +172,13 @@ def service():
|
||||
state = bottle.app().state
|
||||
validate_params(state['config'], params)
|
||||
if params['reason'] == 0:
|
||||
log.info('Processing an underload of a host %s', params['host'])
|
||||
execute_underload(
|
||||
state['config'],
|
||||
state['state'],
|
||||
params['host'])
|
||||
else:
|
||||
log.info('Processing an overload, VMs: %s', str(params['vm_uuids']))
|
||||
execute_overload(
|
||||
state['config'],
|
||||
state['state'],
|
||||
@ -179,10 +187,10 @@ def service():
|
||||
|
||||
@bottle.route('/', method='ANY')
|
||||
def error():
|
||||
raise bottle.HTTPResponse(
|
||||
'Method not allowed: the request has been made' +
|
||||
'with a method other than the only supported PUT',
|
||||
405)
|
||||
message = 'Method not allowed: the request has been made' + \
|
||||
'with a method other than the only supported PUT'
|
||||
log.error('REST service: %s', message)
|
||||
raise bottle.HTTPResponse(message, 405)
|
||||
|
||||
|
||||
@contract
|
||||
@ -298,6 +306,9 @@ def execute_underload(config, state, host):
|
||||
vm_placement_state)
|
||||
state['vm_placement_state'] = vm_placement_state
|
||||
|
||||
if log.isEnabledFor(logging.INFO):
|
||||
log.info('Underload: obtained a new placement %s', str(placement))
|
||||
|
||||
# TODO: initiate VM migrations according to the obtained placement
|
||||
# Switch of the underloaded host when the migrations are completed
|
||||
|
||||
@ -475,6 +486,9 @@ def execute_overload(config, state, vm_uuids):
|
||||
vm_placement_state)
|
||||
state['vm_placement_state'] = vm_placement_state
|
||||
|
||||
if log.isEnabledFor(logging.INFO):
|
||||
log.info('Overload: obtained a new placement %s', str(placement))
|
||||
|
||||
# Switch on the inactive hosts required to accommodate the VMs
|
||||
# TODO: initiate VM migrations according to the obtained placement
|
||||
|
||||
|
@ -113,6 +113,7 @@ def start():
|
||||
"""
|
||||
config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
|
||||
REQUIRED_FIELDS)
|
||||
log.info('Starting the data collector')
|
||||
return common.start(
|
||||
init_state,
|
||||
execute,
|
||||
@ -132,8 +133,9 @@ def init_state(config):
|
||||
"""
|
||||
vir_connection = libvirt.openReadOnly(None)
|
||||
if vir_connection is None:
|
||||
print 'Failed to open connection to the hypervisor'
|
||||
sys.exit(1)
|
||||
message = 'Failed to open a connection to the hypervisor'
|
||||
log.critical(message)
|
||||
raise OSError(message)
|
||||
|
||||
hostname = vir_connection.getHostname()
|
||||
host_cpu_mhz, host_ram = get_host_characteristics(vir_connection)
|
||||
@ -210,6 +212,8 @@ def execute(config, state):
|
||||
state['previous_cpu_time'] = cpu_time
|
||||
append_data_locally(path, cpu_mhz, data_length)
|
||||
append_data_remotely(config.get('db'), cpu_mhz)
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.debug('Collected new data: %s', str(cpu_mhz))
|
||||
return state
|
||||
|
||||
|
||||
|
@ -123,6 +123,7 @@ def start():
|
||||
"""
|
||||
config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
|
||||
REQUIRED_FIELDS)
|
||||
log.info('Starting the local manager')
|
||||
return common.start(
|
||||
init_state,
|
||||
execute,
|
||||
@ -142,8 +143,10 @@ def init_state(config):
|
||||
"""
|
||||
vir_connection = libvirt.openReadOnly(None)
|
||||
if vir_connection is None:
|
||||
print 'Failed to open connection to the hypervisor'
|
||||
sys.exit(1)
|
||||
message = 'Failed to open a connection to the hypervisor'
|
||||
log.critical(message)
|
||||
raise OSError(message)
|
||||
|
||||
physical_cpu_mhz_total = common.physical_cpu_mhz_total(vir_connection)
|
||||
return {'previous_time': 0,
|
||||
'vir_connect': vir_connection,
|
||||
@ -249,6 +252,7 @@ def execute(config, state):
|
||||
state['underload_detection_state'] = underload_detection_state
|
||||
|
||||
if underload:
|
||||
log.info('Underload detected')
|
||||
# Send a request to the global manager with the host name
|
||||
pass
|
||||
else:
|
||||
@ -256,6 +260,7 @@ def execute(config, state):
|
||||
host_cpu_utilization, overload_detection_state)
|
||||
state['overload_detection_state'] = overload_detection_state
|
||||
if overload:
|
||||
log.info('Overload detected')
|
||||
vms = vm_selection(
|
||||
host_cpu_utilization, vm_ram, vm_selection_state)
|
||||
# send a request to the global manager
|
||||
|
Loading…
x
Reference in New Issue
Block a user