Memcache support. !!! NOT TESTED !!!
This commit is contained in:
parent
39fad5700f
commit
c7a18267cc
9
debian/changelog
vendored
9
debian/changelog
vendored
@ -1,3 +1,12 @@
|
|||||||
|
surok (0.7.4~rc1) testing; urgency=medium
|
||||||
|
|
||||||
|
* !!! WARNING !!! NOT TESTED
|
||||||
|
* Memcache support
|
||||||
|
* Some fixes
|
||||||
|
* New dependencies
|
||||||
|
|
||||||
|
-- Denis Zheleztsov <difrex.punk@gmail.com> Sun, 06 Nov 2016 23:01:05 +0300
|
||||||
|
|
||||||
surok (0.7-3) jessie; urgency=medium
|
surok (0.7-3) jessie; urgency=medium
|
||||||
|
|
||||||
* Small fix in marathon restart
|
* Small fix in marathon restart
|
||||||
|
2
debian/control
vendored
2
debian/control
vendored
@ -8,5 +8,5 @@ Vcs-Git: https://github.com/Difrex/surok
|
|||||||
|
|
||||||
Package: surok
|
Package: surok
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: python3-jinja2, python3-dnsq, python3-requests
|
Depends: python3-jinja2, python3-dnsq, python3-requests, python3-memcache
|
||||||
Description: Service discovery for Apache Mesos clusters
|
Description: Service discovery for Apache Mesos clusters
|
||||||
|
@ -24,9 +24,25 @@ def get_old(name, service_conf):
|
|||||||
|
|
||||||
|
|
||||||
# Get old discovered servers from memcache
|
# Get old discovered servers from memcache
|
||||||
def get_old_from_memcache(mc, name, service_conf):
|
def get_old_from_memcache(mc, name, app_hosts):
|
||||||
mc_servers_key = 'surok_' + name + '_servers'
|
mc_servers_key = 'surok_' + name + '_servers'
|
||||||
|
new_servers = []
|
||||||
old_servers = mc.get(mc_servers_key)
|
old_servers = mc.get(mc_servers_key)
|
||||||
|
for service in app_hosts:
|
||||||
|
for server in app_hosts[service]:
|
||||||
|
new_servers.append(server['name'] + ':' + server['port'])
|
||||||
|
|
||||||
|
for server in new_servers:
|
||||||
|
if server not in old_servers:
|
||||||
|
write_confs_to_memcache(mc, new_servers, mc_servers_key)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
# Write to memcache
|
||||||
|
def write_confs_to_memcache(mc, servers, key):
|
||||||
|
mc.set(key, servers)
|
||||||
|
|
||||||
|
|
||||||
def write_lock(name, service_conf):
|
def write_lock(name, service_conf):
|
||||||
@ -50,6 +66,7 @@ def do_reload(service_conf, app_conf):
|
|||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
|
||||||
|
# !!! NEED REFACTORING !!!
|
||||||
def reload_conf(service_conf, app_conf, conf, app_hosts):
|
def reload_conf(service_conf, app_conf, conf, app_hosts):
|
||||||
|
|
||||||
# Check first loop
|
# Check first loop
|
||||||
@ -61,6 +78,7 @@ def reload_conf(service_conf, app_conf, conf, app_hosts):
|
|||||||
|
|
||||||
# Check marathon enabled in configuration
|
# Check marathon enabled in configuration
|
||||||
if conf['marathon']['enabled'] is True:
|
if conf['marathon']['enabled'] is True:
|
||||||
|
if get_old(app_conf['conf_name'], service_conf) != 1:
|
||||||
restart_self_in_marathon(conf['marathon'])
|
restart_self_in_marathon(conf['marathon'])
|
||||||
|
|
||||||
# Check memcache
|
# Check memcache
|
||||||
@ -73,7 +91,11 @@ def reload_conf(service_conf, app_conf, conf, app_hosts):
|
|||||||
logging.info('Discovery of Memcached not implemented')
|
logging.info('Discovery of Memcached not implemented')
|
||||||
|
|
||||||
mc = memcache.Client(conf['memcached']['hosts'])
|
mc = memcache.Client(conf['memcached']['hosts'])
|
||||||
get_old_from_memcache(mc, name, service_conf)
|
if get_old_from_memcache(mc, app_conf['conf_name'], service_conf) != 1:
|
||||||
|
stdout = do_reload(service_conf, app_conf)
|
||||||
|
logging.info(stdout)
|
||||||
|
return True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.warning('DEPRECATED main conf file. Please use new syntax!')
|
logging.warning('DEPRECATED main conf file. Please use new syntax!')
|
||||||
# End of memcache block
|
# End of memcache block
|
||||||
@ -82,13 +104,13 @@ def reload_conf(service_conf, app_conf, conf, app_hosts):
|
|||||||
if get_old(app_conf['conf_name'], service_conf) != 1:
|
if get_old(app_conf['conf_name'], service_conf) != 1:
|
||||||
stdout = do_reload(service_conf, app_conf)
|
stdout = do_reload(service_conf, app_conf)
|
||||||
logging.info(stdout)
|
logging.info(stdout)
|
||||||
return
|
return True
|
||||||
else:
|
else:
|
||||||
if conf['loglevel'] == 'debug':
|
if conf['loglevel'] == 'debug':
|
||||||
logging.debug('Same config ' +
|
logging.debug('Same config ' +
|
||||||
app_conf['conf_name'] +
|
app_conf['conf_name'] +
|
||||||
' Skip reload')
|
' Skip reload')
|
||||||
return
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Do POST request to marathon API
|
# Do POST request to marathon API
|
||||||
|
Loading…
Reference in New Issue
Block a user