diff --git a/examples/riak/haproxy_riak_config.yaml b/examples/riak/haproxy_riak_config.yaml new file mode 100644 index 00000000..2a044693 --- /dev/null +++ b/examples/riak/haproxy_riak_config.yaml @@ -0,0 +1,50 @@ +id: haproxy_riak_config + +resources: + - id: haproxy_riak_config_http + from: resources/haproxy_service_config + tags: ['service=riak', 'protocol=http'] + values: + listen_port: {{http_listen_port}} + protocol: 'http' + name: 'riak_haproxy_http' + backends:server: + {% for riak in riaks %} + - {{riak}}::riak_hostname + {% endfor %} + backends:port: + {% for riak in riaks %} + - {{riak}}::riak_port_http + {% endfor %} + + - id: haproxy_riak_config_pb + from: resources/haproxy_service_config + tags: ['service=riak', 'protocol=tcp'] + values: + listen_port: {{pb_listen_port}} + protocol: 'tcp' + name: 'riak_haproxy_pb' + backends:server: + {% for riak in riaks %} + - {{riak}}::riak_hostname + {% endfor %} + backends:port: + {% for riak in riaks %} + - {{riak}}::riak_port_pb + {% endfor %} + +updates: + - with_tags: ['resource=haproxy_config'] + values: + config:protocol: + - haproxy_riak_config_http::protocol + - haproxy_riak_config_pb::protocol + config:listen_port: + - haproxy_riak_config_http::listen_port + - haproxy_riak_config_pb::listen_port + config:name: + - haproxy_riak_config_http::name + - haproxy_riak_config_pb::name + config:backends: + - haproxy_riak_config_http::backends + - haproxy_riak_config_pb::backends diff --git a/examples/riak/riak_service.yaml b/examples/riak/riak_service.yaml new file mode 100644 index 00000000..acf931d2 --- /dev/null +++ b/examples/riak/riak_service.yaml @@ -0,0 +1,61 @@ +id: riak_service + +resources: + - id: riak_service{{index}} + from: resources/riak_node + location: {{node}} + values: + riak_self_name: riak{{index}} + riak_hostname: riak_server{{index}}.solar + riak_name: riak{{index}}@riak_server{{index}}.solar + {% if join_to %} + join_to: {{join_to}}::riak_name + {% endif %} + ip: {{node}}::ip + +updates: + - with_tags: ['resource=hosts_file'] + values: + hosts:name: + - riak_service{{index}}::riak_hostname::NO_EVENTS + hosts:ip: + - riak_service{{index}}::ip::NO_EVENTS + + - with_tags: ['resource=haproxy_service_config', 'service=riak', 'protocol=http'] + values: + backends:server: + - riak_service{{index}}::riak_hostname + backends:port: + - riak_service{{index}}::riak_port_http + + - with_tags: ['resource=haproxy_service_config', 'service=riak', 'protocol=tcp'] + values: + backends:server: + - riak_service{{index}}::riak_hostname + backends:port: + - riak_service{{index}}::riak_port_pb + +events: + - type: depends_on + parent: + with_tags: ['resource=hosts_file', 'location={{node}}'] + action: run + state: success + depend_action: riak_service{{index}}.run + +{% if join_to %} + - type: react_on + parent_action: riak_service{{index}}.run + state: success + depend_action: riak_service{{index}}.join + + - type: react_on + parent_action: riak_service{{index}}.leave + state: success + depend_action: riak_service{{index}}.join + + - type: react_on + parent_action: riak_service{{index}}.join + state: success + depend_action: {{join_to}}.commit +{% endif %} diff --git a/templates/haproxy.yaml b/templates/haproxy.yaml new file mode 100644 index 00000000..9372b3d8 --- /dev/null +++ b/templates/haproxy.yaml @@ -0,0 +1,46 @@ +id: haproxy + +resources: + - id: haproxy_config{{index}} + from: resources/haproxy_config + location: {{node}} + values: + ip: '{{node}}::ip' + config:protocol: + {% for config in service_configs %} + - {{config}}::protocol + {% endfor %} + config:listen_port: + {% for config in service_configs %} + - {{config}}::listen_port + {% endfor %} + config:name: + {% for config in service_configs %} + - {{config}}::name + {% endfor %} + config:backends: + {% for config in service_configs %} + - {{config}}::backends + {% endfor %} + + - id: haproxy_service{{index}} + location: {{node}} + from: resources/haproxy_service + values: + ip: '{{node}}::ip' + +events: + - type: depends_on + parent_action: 'haproxy_service{{index}}.run' + state: 'success' + depend_action: 'haproxy_config{{index}}.run' + + - type: react_on + parent_action: 'haproxy_config{{index}}.run' + state: 'success' + depend_action: 'haproxy_service{{index}}.apply_config' + + - type: react_on + parent_action: 'haproxy_config{{index}}.update' + state: 'success' + depend_action: 'haproxy_service{{index}}.apply_config'