sync helpers

This commit is contained in:
Kapil Thangavelu 2014-02-26 19:53:57 -05:00
parent 828a024602
commit 3b3b7f3d1e
4 changed files with 19 additions and 25 deletions

View File

@ -126,17 +126,17 @@ def determine_api_port(public_port):
return public_port - (i * 10)
def determine_apache_port(public_port):
def determine_haproxy_port(public_port):
'''
Description: Determine correct apache listening port based on public IP +
state of the cluster.
Description: Determine correct proxy listening port based on public IP +
existence of HTTPS reverse proxy.
public_port: int: standard public port for given service
returns: int: the correct listening port for the HAProxy service
'''
i = 0
if len(peer_units()) > 0 or is_clustered():
if https():
i += 1
return public_port - (i * 10)

View File

@ -27,9 +27,11 @@ from charmhelpers.core.hookenv import (
)
from charmhelpers.contrib.hahelpers.cluster import (
determine_apache_port,
determine_api_port,
determine_haproxy_port,
https,
is_clustered,
peer_units,
)
from charmhelpers.contrib.hahelpers.apache import (
@ -263,12 +265,7 @@ class AMQPContext(OSContextGenerator):
# Sufficient information found = break out!
break
# Used for active/active rabbitmq >= grizzly
if ('clustered' not in ctxt or relation_get('ha-vip-only') == 'True') and \
len(related_units(rid)) > 1:
if relation_get('ha_queues'):
ctxt['rabbitmq_ha_queues'] = relation_get('ha_queues')
else:
ctxt['rabbitmq_ha_queues'] = False
if 'clustered' not in ctxt and len(related_units(rid)) > 1:
rabbitmq_hosts = []
for unit in related_units(rid):
rabbitmq_hosts.append(relation_get('private-address',
@ -430,9 +427,11 @@ class ApacheSSLContext(OSContextGenerator):
'private_address': unit_get('private-address'),
'endpoints': []
}
for api_port in self.external_ports:
ext_port = determine_apache_port(api_port)
int_port = determine_api_port(api_port)
for ext_port in self.external_ports:
if peer_units() or is_clustered():
int_port = determine_haproxy_port(ext_port)
else:
int_port = determine_api_port(ext_port)
portmap = (int(ext_port), int(int_port))
ctxt['endpoints'].append(portmap)
return ctxt

View File

@ -8,8 +8,8 @@ global
defaults
log global
mode tcp
option tcplog
mode http
option httplog
option dontlognull
retries 3
timeout queue 1000
@ -29,6 +29,7 @@ listen stats :8888
{% for service, ports in service_ports.iteritems() -%}
listen {{ service }} 0.0.0.0:{{ ports[0] }}
balance roundrobin
option tcplog
{% for unit, address in units.iteritems() -%}
server {{ unit }} {{ address }}:{{ ports[1] }} check
{% endfor %}

View File

@ -194,7 +194,7 @@ def file_hash(path):
return None
def restart_on_change(restart_map, stopstart=False):
def restart_on_change(restart_map):
"""Restart services based on configuration files changing
This function is used a decorator, for example
@ -219,14 +219,8 @@ def restart_on_change(restart_map, stopstart=False):
for path in restart_map:
if checksums[path] != file_hash(path):
restarts += restart_map[path]
services_list = list(OrderedDict.fromkeys(restarts))
if not stopstart:
for service_name in services_list:
for service_name in list(OrderedDict.fromkeys(restarts)):
service('restart', service_name)
else:
for action in ['stop', 'start']:
for service_name in services_list:
service(action, service_name)
return wrapped_f
return wrap