Skip to content

Commit 4037247

Browse files
committed
Clean arbiter/scheduler interface
1 parent de93bee commit 4037247

13 files changed

+102
-87
lines changed

alignak/daemons/schedulerdaemon.py

+3
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ def setup_new_conf(self):
473473
# Ok now we can load the retention data
474474
self.sched.retention_load()
475475

476+
# Log hosts/services initial states
477+
self.sched.log_initial_states()
478+
476479
# Create brok new conf
477480
brok = Brok({'type': 'new_conf', 'data': {}})
478481
self.sched.add_brok(brok)

alignak/dispatcher.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ def check_status_and_get_events(self):
304304
continue
305305

306306
try:
307-
daemon_link.statistics = daemon_link.get_daemon_stats(details=True)
307+
# Do not get the details to avoid overloading the communication
308+
daemon_link.statistics = daemon_link.get_daemon_stats(details=False)
308309
if daemon_link.statistics:
309310
daemon_link.statistics['_freshness'] = int(time.time())
310311
statistics[daemon_link.name] = daemon_link.statistics

alignak/http/arbiter_interface.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,17 @@ def monitoring_problems(self):
429429
:rtype: dict
430430
"""
431431
res = self.get_id()
432-
res.update(self.get_start_time())
433-
res.update(self.app.get_monitoring_problems())
432+
res['problems'] = {}
433+
for scheduler_link in self.app.conf.schedulers:
434+
print("Scheduler link: %s" % scheduler_link)
435+
sched_res = scheduler_link.con.get('monitoring_problems', wait=True)
436+
res['problems'][scheduler_link.name] = {}
437+
if '_freshness' in sched_res:
438+
res['problems'][scheduler_link.name].update({'_freshness': sched_res['_freshness']})
439+
if 'problems' in sched_res:
440+
res['problems'][scheduler_link.name].update({'problems': sched_res['problems']})
441+
res['_freshness'] = int(time.time())
442+
434443
return res
435444

436445
@cherrypy.expose
@@ -596,7 +605,8 @@ def object(self, o_type, o_name='None'):
596605
:rtype: str
597606
"""
598607
for scheduler_link in self.app.conf.schedulers:
599-
o_found = scheduler_link.get_object(o_type, o_name)
600-
if isinstance(o_found, dict) and 'content' in o_found:
601-
return o_found
608+
sched_res = scheduler_link.con.get('object', {'o_type': o_type, 'o_name': o_name},
609+
wait=True)
610+
if isinstance(sched_res, dict) and 'content' in sched_res:
611+
return sched_res
602612
return {'_status': u'ERR', '_message': u'Required %s not found.' % o_type}

alignak/http/scheduler_interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def fill_initial_broks(self, broker_name):
163163
"""
164164
with self.app.conf_lock:
165165
logger.info("A new broker just connected : %s", broker_name)
166-
return self.app.sched.fill_initial_broks(broker_name, with_logs=True)
166+
return self.app.sched.fill_initial_broks(broker_name)
167167

168168
@cherrypy.expose
169169
@cherrypy.tools.json_in()

alignak/modules/inner_retention.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ def hook_load_retention(self, scheduler):
139139
else:
140140
for host in response.values():
141141
hostname = host['name']
142-
service_key = 'key'
142+
service_key = 'services'
143143
if 'retention_services' in host:
144144
service_key = 'retention_services'
145145
if service_key in host:
146146
for service in host[service_key]:
147-
all_data[service_key][(host['host'], service)] = \
147+
all_data['services'][(host['name'], service)] = \
148148
host[service_key][service]
149149
all_data['hosts'][hostname] = host
150150

alignak/objects/satellitelink.py

+10-27
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ def get_initial_broks(self, broker_name):
781781
:type: bool
782782
"""
783783
logger.debug("Getting initial broks for %s, %s %s", self.name, self.alive, self.reachable)
784-
return self.con.get('fill_initial_broks', {'broker_name': broker_name}, wait='long')
784+
return self.con.get('fill_initial_broks', {'broker_name': broker_name}, wait=True)
785785

786786
@valid_connection()
787787
@communicate()
@@ -814,7 +814,7 @@ def put_conf(self, configuration, test=False):
814814
return True
815815
# ----------
816816

817-
return self.con.post('push_configuration', {'conf': configuration}, wait='long')
817+
return self.con.post('push_configuration', {'conf': configuration}, wait=True)
818818

819819
@valid_connection()
820820
@communicate()
@@ -885,7 +885,7 @@ def push_broks(self, broks):
885885
:rtype: bool
886886
"""
887887
logger.debug("[%s] Pushing %d broks", self.name, len(broks))
888-
return self.con.post('push_broks', {'broks': broks}, wait='long')
888+
return self.con.post('push_broks', {'broks': broks}, wait=True)
889889

890890
@valid_connection()
891891
@communicate()
@@ -903,7 +903,7 @@ def push_actions(self, actions, scheduler_instance_id):
903903
logger.debug("Pushing %d actions from %s", len(actions), scheduler_instance_id)
904904
return self.con.post('push_actions', {'actions': actions,
905905
'scheduler_instance_id': scheduler_instance_id},
906-
wait='long')
906+
wait=True)
907907

908908
@valid_connection()
909909
@communicate()
@@ -921,7 +921,7 @@ def push_results(self, results, scheduler_name):
921921
"""
922922
logger.debug("Pushing %d results", len(results))
923923
result = self.con.post('put_results', {'results': results, 'from': scheduler_name},
924-
wait='long')
924+
wait=True)
925925
return result
926926

927927
@valid_connection()
@@ -936,7 +936,7 @@ def push_external_commands(self, commands):
936936
:rtype: bool
937937
"""
938938
logger.debug("Pushing %d external commands", len(commands))
939-
return self.con.post('run_external_commands', {'cmds': commands}, wait='long')
939+
return self.con.post('run_external_commands', {'cmds': commands}, wait=True)
940940

941941
@valid_connection()
942942
@communicate()
@@ -947,7 +947,7 @@ def get_external_commands(self):
947947
:return: External Command list on success, [] on failure
948948
:rtype: list
949949
"""
950-
res = self.con.get('get_external_commands', wait=True)
950+
res = self.con.get('get_external_commands', wait=False)
951951
logger.debug("Got %d external commands from %s: %s", len(res), self.name, res)
952952
return unserialize(res, True)
953953

@@ -963,7 +963,7 @@ def get_broks(self, broker_name):
963963
:return: Broks list on success, [] on failure
964964
:rtype: list
965965
"""
966-
res = self.con.get('get_broks', {'broker_name': broker_name}, wait=True)
966+
res = self.con.get('get_broks', {'broker_name': broker_name}, wait=False)
967967
logger.debug("Got broks from %s: %s", self.name, res)
968968
return unserialize(res, True)
969969

@@ -976,7 +976,7 @@ def get_events(self):
976976
:return: Broks list on success, [] on failure
977977
:rtype: list
978978
"""
979-
res = self.con.get('get_events', wait=True)
979+
res = self.con.get('get_events', wait=False)
980980
logger.debug("Got events from %s: %s", self.name, res)
981981
return unserialize(res, True)
982982

@@ -991,7 +991,7 @@ def get_results(self, scheduler_instance_id):
991991
:rtype: list
992992
"""
993993
res = self.con.get('get_results', {'scheduler_instance_id': scheduler_instance_id},
994-
wait='long')
994+
wait=True)
995995
logger.debug("Got %d results from %s: %s", len(res), self.name, res)
996996
return res
997997

@@ -1010,23 +1010,6 @@ def get_actions(self, params):
10101010
logger.debug("Got actions from %s: %s", self.name, res)
10111011
return unserialize(res, True)
10121012

1013-
@valid_connection()
1014-
def get_object(self, o_type, o_name):
1015-
"""Send a HTTP request to the scheduler (GET /get_host)
1016-
Get host information from the scheduler.
1017-
Un-serialize data received.
1018-
1019-
:param o_type: searched object type
1020-
:type o_type: str
1021-
:param o_name: searched object name (or uuid)
1022-
:type o_name: str
1023-
:return: serialized object information
1024-
:rtype: str
1025-
"""
1026-
res = self.con.get('object', {'o_type': o_type, 'o_name': o_name}, wait=True)
1027-
logger.debug("Got an %s object from %s: %s", o_type, self.name, res)
1028-
return res
1029-
10301013

10311014
class SatelliteLinks(Items):
10321015
"""Class to handle serveral SatelliteLink"""

alignak/objects/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,9 @@ def raise_initial_state(self):
661661
:return: None
662662
"""
663663
log_level = 'info'
664-
if self.state == 'WARNING':
664+
if self.state in ['WARNING', 'UNREACHABLE']:
665665
log_level = 'warning'
666-
if self.state == 'CRITICAL':
666+
if self.state in ['CRITICAL', 'UNKNOWN']:
667667
log_level = 'error'
668668
if self.__class__.log_initial_states:
669669
brok = make_monitoring_log(

alignak/scheduler.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,16 @@ def retention_load(self, forced=False):
13931393
self.add(make_monitoring_log('INFO', 'RETENTION LOAD: %s' % self.my_daemon.name))
13941394
logger.info('Retention data loaded: %.2f seconds', time.time() - _t0)
13951395

1396+
def log_initial_states(self):
1397+
"""Log hosts and services initial state
1398+
1399+
:return: None
1400+
"""
1401+
if getattr(self.my_daemon, 'log_initial_states', False):
1402+
# Raise current state log
1403+
for elt in self.all_my_hosts_and_services():
1404+
elt.raise_initial_state()
1405+
13961406
def get_retention_data(self): # pylint: disable=too-many-branches,too-many-statements
13971407
# pylint: disable=too-many-locals
13981408
"""Get all hosts and services data to be sent to the retention storage.
@@ -1571,14 +1581,12 @@ def restore_retention_data_item(self, data, item):
15711581
item.notified_contacts = new_notified_contacts
15721582
item.notified_contacts_ids = new_notified_contacts_ids
15731583

1574-
def fill_initial_broks(self, broker_name, with_logs=False):
1584+
def fill_initial_broks(self, broker_name):
15751585
# pylint: disable=too-many-branches
15761586
"""Create initial broks for a specific broker
15771587
15781588
:param broker_name: broker name
15791589
:type broker_name: str
1580-
:param with_logs: tell if we raise some broks to log the initial states for hosts/services
1581-
:type with_logs: bool
15821590
:return: number of created broks
15831591
"""
15841592
broker_uuid = None
@@ -1632,14 +1640,6 @@ def fill_initial_broks(self, broker_name, with_logs=False):
16321640
brok = item.get_initial_status_brok(member_items)
16331641
self.add_brok(brok, broker_uuid)
16341642

1635-
# Only raises the all logs at the scheduler startup
1636-
if with_logs:
1637-
# Ask for INITIAL logs for services and hosts
1638-
for item in self.hosts:
1639-
item.raise_initial_state()
1640-
for item in self.services:
1641-
item.raise_initial_state()
1642-
16431643
# Add a brok to say that we finished all initial_pass
16441644
brok = Brok({'type': 'initial_broks_done', 'data': {'instance_id': self.instance_id}})
16451645
self.add_brok(brok, broker_uuid)
@@ -2107,13 +2107,15 @@ def get_scheduler_stats(self, details=False): # pylint: disable=unused-argument
21072107
'hosts': len(self.hosts),
21082108
'services': len(self.services),
21092109
'commands': [{'cmd': c, 'u_time': u_time, 's_time': s_time}, ...] (10 first)
2110+
'livesynthesis': {...}
21102111
}
21112112
21122113
:rtype: dict
21132114
"""
21142115
m_solver = MacroResolver()
21152116

21162117
res = {
2118+
'_freshness': int(time.time()),
21172119
'counters': {},
21182120
'latency': self.stats['latency'],
21192121
'monitored_objects': {},

tests/cfg/cfg_default_retention.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cfg_dir=default
22

3+
log_initial_states=true
4+
35
; --------------------------------------------------------------------
46
; Retention configuration
57
; ---

tests/test_a_properties_default.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class TestConfig(PropertiesTester, AlignakTest):
266266
('daemons_start_timeout', 1),
267267
('daemons_dispatch_timeout', 5),
268268
('daemons_new_conf_timeout', 1),
269-
('daemons_stop_timeout', 15),
269+
('daemons_stop_timeout', 5),
270270
('daemons_failure_kill', True),
271271

272272
('alignak_env', []),

tests/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_config_conf_inner_properties(self):
190190
# assert self._arbiter.conf.daemons_start_timeout == 1
191191
# Changed to 5 seconds for tests purpose
192192
assert self._arbiter.conf.daemons_start_timeout == 1
193-
assert self._arbiter.conf.daemons_stop_timeout == 15
193+
assert self._arbiter.conf.daemons_stop_timeout == 5
194194

195195
def test_config_conf_inner_properties_named_alignak(self):
196196
""" Default configuration with an alignak_name property

0 commit comments

Comments
 (0)