Merge lp:~canonical-is-sa/charms/trusty/elasticsearch/trunk into lp:charms/trusty/elasticsearch

Proposed by Michael Foley
Status: Merged
Merged at revision: 40
Proposed branch: lp:~canonical-is-sa/charms/trusty/elasticsearch/trunk
Merge into: lp:charms/trusty/elasticsearch
Diff against target: 137 lines (+71/-0)
4 files modified
hooks/hooks.py (+55/-0)
metadata.yaml (+3/-0)
playbook.yaml (+10/-0)
roles/nrpe/tasks/main.yml (+3/-0)
To merge this branch: bzr merge lp:~canonical-is-sa/charms/trusty/elasticsearch/trunk
Reviewer Review Type Date Requested Status
Michael Nelson (community) Approve
charmers Pending
Review via email: mp+260027@code.launchpad.net

Description of the change

Add data relations for using block-storage-broker.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

Thanks Michael. Sorry for the delay, I've just ran the existing tests with this branch to ensure everything works as normal without block storage, and will be testing the blockstorage with a deployment.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added symlink 'hooks/data-relation-changed'
=== target is u'hooks.py'
=== added symlink 'hooks/data-relation-departed'
=== target is u'hooks.py'
=== added symlink 'hooks/data-relation-joined'
=== target is u'hooks.py'
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-07-08 13:38:52 +0000
+++ hooks/hooks.py 2015-05-25 04:21:12 +0000
@@ -5,13 +5,21 @@
5import charmhelpers.contrib.ansible5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd6import charmhelpers.payload.execd
7import charmhelpers.core.host7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
811
12mountpoint = '/srv/elasticsearch'
913
10hooks = charmhelpers.contrib.ansible.AnsibleHooks(14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
11 playbook_path='playbook.yaml',15 playbook_path='playbook.yaml',
12 default_hooks=[16 default_hooks=[
13 'config-changed',17 'config-changed',
14 'cluster-relation-joined',18 'cluster-relation-joined',
19 'data-relation-joined',
20 'data-relation-changed',
21 'data-relation-departed',
22 'data-relation-broken',
15 'peer-relation-joined',23 'peer-relation-joined',
16 'peer-relation-departed',24 'peer-relation-departed',
17 'nrpe-external-master-relation-changed',25 'nrpe-external-master-relation-changed',
@@ -39,5 +47,52 @@
39 '/usr/share/ansible')47 '/usr/share/ansible')
4048
4149
50@hooks.hook('data-relation-joined', 'data-relation-changed')
51def data_relation():
52 if hookenv.relation_get('mountpoint') == mountpoint:
53 # Other side of relation is ready
54 migrate_to_mount(mountpoint)
55 else:
56 # Other side not ready yet, provide mountpoint
57 hookenv.log('Requesting storage for {}'.format(mountpoint))
58 hookenv.relation_set(mountpoint=mountpoint)
59
60
61@hooks.hook('data-relation-departed', 'data-relation-broken')
62def data_relation_gone():
63 hookenv.log('Data relation no longer present, stopping elasticsearch.')
64 charmhelpers.core.host.service_stop('elasticsearch')
65
66
67def migrate_to_mount(new_path):
68 """Invoked when new mountpoint appears. This function safely migrates
69 elasticsearch data from local disk to persistent storage (only if needed)
70 """
71 old_path = '/var/lib/elasticsearch'
72 if os.path.islink(old_path):
73 hookenv.log('{} is already a symlink, skipping migration'.format(
74 old_path))
75 return True
76 # Ensure our new mountpoint is empty. Otherwise error and allow
77 # users to investigate and migrate manually
78 files = os.listdir(new_path)
79 try:
80 files.remove('lost+found')
81 except ValueError:
82 pass
83 if files:
84 raise RuntimeError('Persistent storage contains old data. '
85 'Please investigate and migrate data manually '
86 'to: {}'.format(new_path))
87 os.chmod(new_path, 0700)
88 charmhelpers.core.host.service_stop('elasticsearch')
89 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
90 os.path.join(new_path, ''),
91 options=['--archive'])
92 shutil.rmtree(old_path)
93 os.symlink(new_path, old_path)
94 charmhelpers.core.host.service_start('elasticsearch')
95
96
42if __name__ == "__main__":97if __name__ == "__main__":
43 hooks.execute(sys.argv)98 hooks.execute(sys.argv)
4499
=== modified file 'metadata.yaml'
--- metadata.yaml 2014-09-11 18:34:45 +0000
+++ metadata.yaml 2015-05-25 04:21:12 +0000
@@ -16,3 +16,6 @@
16 nrpe-external-master:16 nrpe-external-master:
17 interface: nrpe-external-master17 interface: nrpe-external-master
18 scope: container18 scope: container
19 data:
20 interface: block-storage
21 scope: container
1922
=== modified file 'playbook.yaml'
--- playbook.yaml 2014-10-31 03:43:31 +0000
+++ playbook.yaml 2015-05-25 04:21:12 +0000
@@ -60,3 +60,13 @@
60 cluster-name={{ cluster_name }}60 cluster-name={{ cluster_name }}
61 host={{ ansible_default_ipv4.address }}61 host={{ ansible_default_ipv4.address }}
62 port=920062 port=9200
63
64 # A bug in the ansible hooks() helper requires at least
65 # one task to be tagged.
66 - name: Empty task to keep ansible helper satisfied.
67 debug: msg="Noop ansible task."
68 tags:
69 - data-relation-joined
70 - data-relation-changed
71 - data-relation-departed
72 - data-relation-broken
6373
=== modified file 'roles/nrpe/tasks/main.yml'
--- roles/nrpe/tasks/main.yml 2014-04-08 13:25:50 +0000
+++ roles/nrpe/tasks/main.yml 2015-05-25 04:21:12 +0000
@@ -7,6 +7,7 @@
7 owner: nagios7 owner: nagios
8 group: nagios8 group: nagios
9 mode: 06449 mode: 0644
10 when: "'nagios_hostname' in current_relation"
1011
11- name: Write nagios check service definition for export.12- name: Write nagios check service definition for export.
12 tags:13 tags:
@@ -17,9 +18,11 @@
17 owner: nagios18 owner: nagios
18 group: nagios19 group: nagios
19 mode: 064420 mode: 0644
21 when: "'nagios_hostname' in current_relation"
2022
21- name: Trigger nrpe-external-master-relation-changed to restart.23- name: Trigger nrpe-external-master-relation-changed to restart.
22 tags:24 tags:
23 - nrpe-external-master-relation-changed25 - nrpe-external-master-relation-changed
24 command: >26 command: >
25 relation-set timestamp={{ ansible_date_time.iso8601_micro }}27 relation-set timestamp={{ ansible_date_time.iso8601_micro }}
28 when: "'nagios_hostname' in current_relation"

Subscribers

People subscribed via source and target branches