Scale-in and Scale-out of mysql-innodb-cluster
Handle adding and removing units to the mysql-innodb-cluster. Change-Id: Ie658c42b095bcff822cdfb0b771d41704ddc85ea Closes-Bug: #1877546 Closes-Bug: #1874479
This commit is contained in:
parent
e61876310b
commit
5f87bb1dde
|
@ -0,0 +1,4 @@
|
|||
[gerrit]
|
||||
host=review.opendev.org
|
||||
port=29418
|
||||
project=openstack/charm-interface-mysql-innodb-cluster.git
|
|
@ -0,0 +1,4 @@
|
|||
- project:
|
||||
templates:
|
||||
- python35-charm-jobs
|
||||
- openstack-python3-ussuri-jobs
|
45
peers.py
45
peers.py
|
@ -14,6 +14,7 @@
|
|||
|
||||
from charms import reactive
|
||||
import charmhelpers.contrib.network.ip as ch_net_ip
|
||||
import charmhelpers.core as ch_core
|
||||
|
||||
|
||||
class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
||||
|
@ -36,7 +37,8 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
@property
|
||||
def peer_relation(self):
|
||||
# Get the first relation object as we only have one relation to peers
|
||||
return self.relations[0]
|
||||
for relation in self.relations:
|
||||
return relation
|
||||
|
||||
def available(self):
|
||||
if len(self.all_joined_units) < (self.minimum_cluster_size - 1):
|
||||
|
@ -50,6 +52,12 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
return False
|
||||
return True
|
||||
|
||||
def set_or_clear_available(self):
|
||||
if self.available():
|
||||
reactive.set_flag(self.expand_name('{endpoint_name}.available'))
|
||||
else:
|
||||
reactive.clear_flag(self.expand_name('{endpoint_name}.available'))
|
||||
|
||||
def clustered(self):
|
||||
if len(self.all_joined_units) < (self.minimum_cluster_size - 1):
|
||||
return False
|
||||
|
@ -60,8 +68,9 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
|
||||
@reactive.when('endpoint.{endpoint_name}.joined')
|
||||
def joined(self):
|
||||
reactive.set_flag(self.expand_name('{endpoint_name}.connected'))
|
||||
self.set_ingress_address()
|
||||
reactive.set_flag(self.expand_name('{endpoint_name}.connected'))
|
||||
self.set_or_clear_available()
|
||||
|
||||
@reactive.when('endpoint.{endpoint_name}.changed')
|
||||
def changed(self):
|
||||
|
@ -82,19 +91,14 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
for flag in flags:
|
||||
reactive.clear_flag(flag)
|
||||
|
||||
if self.available():
|
||||
reactive.set_flag(self.expand_name('{endpoint_name}.available'))
|
||||
else:
|
||||
reactive.clear_flag(self.expand_name('{endpoint_name}.available'))
|
||||
self.set_or_clear_available()
|
||||
|
||||
if self.clustered():
|
||||
reactive.set_flag(self.expand_name('{endpoint_name}.clustered'))
|
||||
else:
|
||||
reactive.clear_flag(self.expand_name('{endpoint_name}.clustered'))
|
||||
|
||||
@reactive.when_any('endpoint.{endpoint_name}.broken',
|
||||
'endpoint.{endpoint_name}.departed')
|
||||
def departed(self):
|
||||
def remove(self):
|
||||
flags = (
|
||||
self.expand_name('{endpoint_name}.connected'),
|
||||
self.expand_name('{endpoint_name}.available'),
|
||||
|
@ -102,6 +106,14 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
for flag in flags:
|
||||
reactive.clear_flag(flag)
|
||||
|
||||
@reactive.when('endpoint.{endpoint_name}.departed')
|
||||
def departed(self):
|
||||
self.remove()
|
||||
|
||||
@reactive.when('endpoint.{endpoint_name}.broken')
|
||||
def broken(self):
|
||||
self.remove()
|
||||
|
||||
def set_cluster_connection_info(
|
||||
self, cluster_address, cluster_user, cluster_password):
|
||||
"""Send cluster connection information to peers.
|
||||
|
@ -116,6 +128,11 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
:returns: None, this function is called for its side effect
|
||||
:rtype: None
|
||||
"""
|
||||
if not self.peer_relation:
|
||||
ch_core.hookenv.log(
|
||||
"No mysql-inndb-cluster peer relation: possibly departing.",
|
||||
"WARNING")
|
||||
return
|
||||
self.peer_relation.to_publish['cluster-address'] = cluster_address
|
||||
self.peer_relation.to_publish['cluster-user'] = cluster_user
|
||||
self.peer_relation.to_publish['cluster-password'] = cluster_password
|
||||
|
@ -127,6 +144,11 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
:returns: None, this function is called for its side effect
|
||||
:rtype: None
|
||||
"""
|
||||
if not self.peer_relation:
|
||||
ch_core.hookenv.log(
|
||||
"No mysql-inndb-cluster peer relation: possibly departing.",
|
||||
"WARNING")
|
||||
return
|
||||
self.peer_relation.to_publish['unit-configure-ready'] = True
|
||||
|
||||
def set_unit_clustered(self):
|
||||
|
@ -136,4 +158,9 @@ class MySQLInnoDBClusterPeer(reactive.Endpoint):
|
|||
:returns: None, this function is called for its side effect
|
||||
:rtype: None
|
||||
"""
|
||||
if not self.peer_relation:
|
||||
ch_core.hookenv.log(
|
||||
"No mysql-inndb-cluster peer relation: possibly departing.",
|
||||
"WARNING")
|
||||
return
|
||||
self.peer_relation.to_publish['unit-clustered'] = True
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
charms.reactive
|
||||
flake8>=2.2.4,<=2.4.1
|
||||
flake8>=2.2.4
|
||||
mock>=1.2
|
||||
stestr>=2.2.0
|
||||
git+https://github.com/openstack/charms.openstack.git#egg=charms.openstack
|
||||
|
|
|
@ -28,8 +28,9 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
|||
|
||||
"changed": (
|
||||
"endpoint.{endpoint_name}.changed",),
|
||||
"departed": ("endpoint.{endpoint_name}.broken",
|
||||
"endpoint.{endpoint_name}.departed",),
|
||||
"departed": ("endpoint.{endpoint_name}.departed",),
|
||||
|
||||
"broken": ("endpoint.{endpoint_name}.broken",),
|
||||
},
|
||||
}
|
||||
# test that the hooks were registered
|
||||
|
|
Loading…
Reference in New Issue