-
Notifications
You must be signed in to change notification settings - Fork 1
/
drbd.mysql-example.bom
141 lines (136 loc) · 6.08 KB
/
drbd.mysql-example.bom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
brooklyn.catalog:
version: "1.0.0-SNAPSHOT" # BROOKLYN_DRBD_VERSION
description: |
This is an example DRBD database application. MySQL instances are mirrored on DRBD with Jetty runners pointing at the primary
publish:
license_code: Apache-2.0
items:
- id: example-drbd-mysql
item:
type: org.apache.brooklyn.entity.database.mysql.MySqlNode
brooklyn.config:
mysql.password: s0m3rand0mp4ss
latch.install: $brooklyn:parent().parent().attributeWhenReady("service.isUp")
# customize will set the data directory to the drbd one, so block until we are primary
latch.customize: $brooklyn:parent().sibling("drbd-node").attributeWhenReady("is.active.primary")
mysql.datadir: /mnt
- id: initial-example-drbd-mysql
item:
type: example-drbd-mysql
id: initial-db
brooklyn.config:
datastore.creation.script.url: https://github.com/apache/brooklyn-library/raw/master/examples/simple-web-cluster/src/main/resources/visitors-creation-script.sql
- id: drbd-database
name: DRBD Database
itemType: template
iconUrl: "https://s3.eu-central-1.amazonaws.com/misc-csft/drbd.jpg"
license: Apache-2.0
item:
booklyn.config:
defaultDisplayName: DRBD Database
services:
- type: drbd-pair
brooklyn.config:
propagatingSensor: $brooklyn:sensor("datastore.url")
nodeSpecification:
$brooklyn:entitySpec:
- type: example-drbd-mysql
initialNodeSpecification:
$brooklyn:entitySpec:
- type: initial-example-drbd-mysql
- type: cluster
id: webapp
name: "Webapp"
brooklyn.enrichers:
- type: org.apache.brooklyn.enricher.stock.Propagator
brooklyn.config:
enricher.suppressDuplicates: true
producer: $brooklyn:entity("drbd-pair")
propagating:
- drbd.all.started
brooklyn.config:
cluster.initial.size: 2
dynamiccluster.memberspec:
$brooklyn:entitySpec:
type: jetty-runner
id: jetty-runner
name: Jetty Runner App
brooklyn.enrichers:
- type: org.apache.brooklyn.enricher.stock.Propagator
brooklyn.config:
enricher.suppressDuplicates: true
producer: $brooklyn:entity("drbd-pair")
propagating:
- datastore.url
- type: org.apache.brooklyn.enricher.stock.Transformer
brooklyn.config:
enricher.suppressDuplicates: true
enricher.triggerSensors:
- $brooklyn:sensor("datastore.url")
enricher.targetSensor: $brooklyn:sensor("additionalJavaParams")
enricher.targetValue:
$brooklyn:formatString:
- "-Dbrooklyn.example.db.url=jdbc:%s%s?user=%s&password=%s"
- $brooklyn:attributeWhenReady("datastore.url")
- "visitors"
- "brooklyn"
- "br00k11n"
brooklyn.initializers:
- type: org.apache.brooklyn.core.effector.ssh.SshCommandEffector
brooklyn.config:
name: redeployDB
description: |
Redeploys the application
shell.env:
additionalJavaParams: $brooklyn:attributeWhenReady("additionalJavaParams")
#serviceIsUp: $brooklyn:attributeWhenReady("service.isUp")
command: |
cd ~
if [ ! -f "jetty-runner.pid" ]; then
echo "Not yet started"
exit 0;
fi
CURR_PARAMS=`cat ~/params.txt`
if [ "${additionalJavaParams}" == "" ] || [ "${additionalJavaParams}" == "${CURR_PARAMS}" ]; then
exit 0;
fi
(
flock -x -w 10 200 || exit 0
echo 1
if [ -n "${additionalJavaParams}" ]; then
echo ${additionalJavaParams} > ~/params.txt
fi
echo 2
kill `cat ~/jetty-runner.pid` || true
echo 3
nohup java `cat ~/params.txt` -jar ~/jetty-runner.jar ~/run.war --port 8080 2>&1 & echo $! > ~/jetty-runner.pid
echo 4
) 200>/tmp/.drbdlockfile
rm /tmp/.drbdlockfile || true
brooklyn.policies:
- type: org.apache.brooklyn.policy.InvokeEffectorOnSensorChange
brooklyn.config:
sensor: $brooklyn:sensor("additionalJavaParams")
effector: redeployDB
brooklyn.config:
latch.install: $brooklyn:entity("webapp").attributeWhenReady("drbd.all.started")
war.url: http://search.maven.org/remotecontent?filepath=org/apache/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.9.0/brooklyn-example-hello-world-sql-webapp-0.9.0.war
additional.java.params: $brooklyn:attributeWhenReady("additionalJavaParams")