Skip to content

Commit

Permalink
change RPC error into warning
Browse files Browse the repository at this point in the history
  • Loading branch information
julien6387 committed Aug 10, 2017
1 parent 52e5c0a commit 3085c52
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
15 changes: 5 additions & 10 deletions supvisors/process.py
Expand Up @@ -200,15 +200,6 @@ def state(self):
def state(self, new_state):
if self._state != new_state:
self._state = new_state
self.log_process_state()

def log_process_state(self):
""" Log the process name and state, adding the addresses when any. """
log_trace = 'Process {} is {}'.format(self.namespec(),
self.state_string())
if self.addresses:
log_trace += ' at {}'.format(list(self.addresses))
self.logger.info(log_trace)

def conflicting(self):
""" Return True if the process is in a conflicting state (more than one
Expand Down Expand Up @@ -340,7 +331,11 @@ def update_status(self, address, new_state, expected):
self.state = new_state
self.expected_exit = expected
# log the new status
self.log_process_state()
log_trace = 'Process {} is {}'.format(self.namespec(),
self.state_string())
if self.addresses:
log_trace += ' at {}'.format(list(self.addresses))
self.logger.info(log_trace)

def evaluate_conflict(self):
""" Gets a synthetic state if several processes are in a RUNNING-like
Expand Down
54 changes: 36 additions & 18 deletions supvisors/viewhandler.py
Expand Up @@ -40,7 +40,8 @@ class ViewHandler(object):
The choice of the statistics is made through class attributes
for the moment because it would take too much place on the URL.
An change may be done later to use a short code that would be discriminating."""
An change may be done later to use a short code that would be
discriminating. """

# static attributes for statistics selection
period_stats = None
Expand Down Expand Up @@ -77,17 +78,23 @@ def write_nav(self, root, address=None, appli=None):
""" Write the navigation menu. """
server_port = self.server_port()
# update navigation addresses
iterator = root.findmeld('address_li_mid').repeat(self.supvisors.address_mapper.addresses)
iterator = root.findmeld('address_li_mid').repeat(
self.supvisors.address_mapper.addresses)
for li_elt, item in iterator:
status = self.supvisors.context.addresses[item]
# set element class
li_elt.attrib['class'] = status.state_string() + (' active' if item == address else '')
li_elt.attrib['class'] = status.state_string() + (
' active' if item == address else '')
# set hyperlink attributes
elt = li_elt.findmeld('address_a_mid')
if status.state == AddressStates.RUNNING:
# go to web page located on address, so as to reuse Supervisor StatusView
elt.attributes(href='http://{}:{}/procaddress.html'.format(item, server_port))
elt.attrib['class'] = 'on' + (' master' if item == self.supvisors.context.master_address else '')
# go to web page located on address, so as to reuse Supervisor
# StatusView
elt.attributes(href='http://{}:{}/procaddress.html'.format(
item, server_port))
elt.attrib['class'] = 'on' + \
(' master' if item == self.supvisors.context.master_address
else '')
else:
elt.attrib['class'] = 'off'
elt.content(item)
Expand All @@ -113,7 +120,8 @@ def write_periods(self, root):
""" Write configured periods for statistics. """
# init period if necessary
if ViewHandler.period_stats is None:
ViewHandler.period_stats = next(iter(self.supvisors.options.stats_periods))
ViewHandler.period_stats = next(iter(
self.supvisors.options.stats_periods))
# render periods
iterator = root.findmeld('period_li_mid').repeat(
self.supvisors.options.stats_periods)
Expand All @@ -124,7 +132,9 @@ def write_periods(self, root):
elt.attrib['class'] = "button off active"
else:
elt.attributes(href='{}?{}period={}'
.format(self.page_name, self.url_context(), period))
.format(self.page_name,
self.url_context(),
period))
elt.content('{}s'.format(period))

def write_common_process_status(self, tr_elt, item):
Expand Down Expand Up @@ -218,8 +228,10 @@ def write_process_statistics(self, root):
stats_elt = root.findmeld('pstats_div_mid')
# get data from statistics module iaw period selection
if ViewHandler.namespec_stats:
nbcores, proc_stats = self.get_process_stats(ViewHandler.namespec_stats)
if proc_stats and (len(proc_stats[0]) > 0 or len(proc_stats[1]) > 0):
nbcores, proc_stats = self.get_process_stats(
ViewHandler.namespec_stats)
if proc_stats and (len(proc_stats[0]) > 0 or \
len(proc_stats[1]) > 0):
# set titles
elt = stats_elt.findmeld('process_h_mid')
elt.content(ViewHandler.namespec_stats)
Expand Down Expand Up @@ -300,21 +312,24 @@ def handle_parameters(self):
self.logger.info('statistics period set to %d' % period)
ViewHandler.period_stats = period
else:
self.message(error_message('Incorrect period: {}'.format(period_string)))
self.message(error_message('Incorrect period: {}'.format(
period_string)))
# update process statistics selection
process_name = form.get('processname')
if process_name:
_, proc_stats = self.get_process_stats(process_name)
if proc_stats:
if ViewHandler.namespec_stats != process_name:
self.logger.info('select detailed Process statistics for %s' % process_name)
self.logger.info('select detailed Process statistics '\
'for %s' % process_name)
ViewHandler.namespec_stats = process_name
else:
self.message(error_message('Incorrect stats processname: {}'
.format(process_name)))

def handle_action(self):
""" Handling of the actions requested from the Supvisors Address web page. """
""" Handling of the actions requested from the Supvisors Address web
page. """
form = self.context.form
action = form.get('action')
if action:
Expand Down Expand Up @@ -354,11 +369,13 @@ def url_context(self):
return ''

def get_process_status(self, namespec):
""" Get the ProcessStatus instance related to the process named namespec. """
""" Get the ProcessStatus instance related to the process named
namespec. """
try:
return self.supvisors.context.processes[namespec]
except KeyError:
self.logger.debug('failed to get ProcessStatus from {}'.format(namespec))
self.logger.debug('failed to get ProcessStatus from {}'.format(
namespec))

def server_port(self):
""" Get the port number of the web server. """
Expand All @@ -381,18 +398,19 @@ def sort_processes_by_config(self, processes):
for process in processes})
for application_name in application_list:
# get supervisor configuration for application
group_config = self.supvisors.info_source.get_group_config(application_name)
group_config = self.supvisors.info_source.get_group_config(
application_name)
# get process name ordering in this configuration
ordering = [proc.name for proc in group_config.process_configs]
# add processes known to supervisor, using the same ordering
sorted_processes.extend(sorted([proc for proc in processes
if proc['application_name'] == application_name and \
proc['process_name'] in ordering],
key=lambda x: ordering.index(x['process_name'])))
# add processes unknown to supervisor, using the alphabetical ordering
# add processes unknown to supervisor, using the alphabetical
# ordering
sorted_processes.extend(sorted([proc for proc in processes
if proc['application_name'] == application_name and \
proc['process_name'] not in ordering],
key=lambda x: x['process_name']))
return sorted_processes

8 changes: 5 additions & 3 deletions supvisors/webutils.py
Expand Up @@ -3,13 +3,13 @@

# ======================================================================
# Copyright 2016 Julien LE CLEACH
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -31,6 +31,8 @@ def format_gravity_message(message):
if 'ERROR' in message:
message = message.replace('ERROR: ', '')
gravity = Error
elif 'unexpected rpc fault' in message:
gravity = Warn
else:
gravity = Info
return gravity, message
Expand Down

0 comments on commit 3085c52

Please sign in to comment.