Skip to content

Instantly share code, notes, and snippets.

@grkvlt
Last active August 29, 2015 14:28
Show Gist options
  • Save grkvlt/a65314ba3e620abfed88 to your computer and use it in GitHub Desktop.
Save grkvlt/a65314ba3e620abfed88 to your computer and use it in GitHub Desktop.
Example Java Cluster
# this Apache Brooklyn blueprint will deploy an example Java service cluster
brooklyn.catalog:
version: 1.1.0-PREVIEW.20150818
items:
- id: host
item:
type: brooklyn.entity.basic.VanillaSoftwareProcess
name: Host
# TODO validate this early on
download.url: $brooklyn:config("app.download.url")
provisioning.properties:
osFamily: ubuntu
launch.command: |
# install java if necessary, at least java 8
sudo -E -n -S -- sudo apt-get install oracle-java8-set-default || echo "WARN: could not install Java, may fail subsequently"
# create the start script
cat > start.sh << EOF
. ~/bin/java-use-v8 || echo "Extra script to install Java 8 is not available here"
nohup java -jar ${JAR_FILE:-*.jar} &
echo \$! > "$PID_FILE"
sleep 5
EOF
chmod +x start.sh
# best-effort install to restart on reboot
sudo -E -n -S -- cp start.sh /etc/rc.local || echo "WARN: could not install to /etc/rc.local, will not restart on machine reboot"
./start.sh
shell.env:
# TODO this should only apply to launch
JAR_FILE: $brooklyn:config("jar.filename")
PEERS: $brooklyn:config("peers.urls")
SUBNET_ADDRESS: $brooklyn:attributeWhenReady("host.subnet.address")
APP_PORT: $brooklyn:config("app.port")
brooklyn.config:
peers.urls: ""
app.port: 8000
jar.filename: ""
brooklyn.enrichers:
- type: brooklyn.enricher.basic.Transformer
brooklyn.config:
uniqueTag: url-generator
# TODO if not up or any not available, then set null
enricher.sourceSensor: $brooklyn:sensor("service.isUp")
enricher.targetSensor: $brooklyn:sensor("app.url")
enricher.targetValue: $brooklyn:formatString("http://%s:%s/",
$brooklyn:attributeWhenReady("host.subnet.hostname"),
$brooklyn:config("app.port"))
- type: brooklyn.enricher.basic.Propagator
brooklyn.config:
uniqueTag: propagate-main-uri
sensorMapping:
$brooklyn:sensor("app.url"): $brooklyn:sensor("brooklyn.entity.basic.Attributes", "main.uri")
- type: brooklyn.enricher.basic.Propagator
brooklyn.config:
uniqueTag: propagate-datastore-url
sensorMapping:
$brooklyn:sensor("app.url"): $brooklyn:sensor("org.apache.brooklyn.entity.database.DatastoreMixins", "datastore.url")
- id: app-cluster
item:
type: brooklyn.entity.group.DynamicCluster
name: Cluster
id: app-cluster
firstMemberSpec:
$brooklyn:entitySpec:
type: host
name: First Host
memberSpec:
$brooklyn:entitySpec:
type: host
brooklyn.config:
peers.urls: $brooklyn:entity("app-cluster").attributeWhenReady("app.peers.urls.comma_separated.max_3")
brooklyn.enrichers:
- type: brooklyn.enricher.basic.Aggregator
brooklyn.config:
uniqueTag: url-aggregator
enricher.aggregator.excludeBlank: true
enricher.aggregating.fromMembers: true
enricher.sourceSensor: $brooklyn:sensor("app.url")
enricher.targetSensor: $brooklyn:sensor("app.peers.urls.list")
- type: brooklyn.enricher.basic.Joiner
brooklyn.config:
uniqueTag: url-joiner
enricher.sourceSensor: $brooklyn:sensor("app.peers.urls.list")
enricher.targetSensor: $brooklyn:sensor("app.peers.urls.comma_separated.max_3")
separator: ","
maximum: 3
- type: brooklyn.enricher.basic.Joiner
brooklyn.config:
uniqueTag: url-main
enricher.sourceSensor: $brooklyn:sensor("app.peers.urls.list")
enricher.targetSensor: $brooklyn:sensor("brooklyn.entity.basic.Attributes", "main.uri")
quote: false
maximum: 1
- id: app-cluster-example
itemType: template
item:
name: My App Cluster
services:
- type: app-cluster
location:
jclouds:softlayer:
region: sjc01
# identity and credential must be set unless they are specified in your brooklyn.properties
# identity: XXX
# credential: XXX
brooklyn.config:
cluster.initial.size: 3
app.download.url: http://hostname:port/path/to/target/with-dependencies.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment