Skip to content

Commit

Permalink
Move to a POM based project for OSGi bundle generation
Browse files Browse the repository at this point in the history
  • Loading branch information
grkvlt committed Dec 14, 2016
1 parent 978bfdb commit 83261dd
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Brooklyn DNS Entities
=====================

# Overview

Expand All @@ -7,7 +9,6 @@ This pattern can work in any cloud or in containers, and is extremely configurab
To use, nodes simply advertise `brooklyn_dns.enabled` and will automatically be placed under DNS management,
either using /etc/hosts or a dedicated BIND DNS server.


## Synchronizing /etc/hosts

One approach is to have Brooklyn update the `/etc/hosts` on all the servers you are interested in,
Expand All @@ -16,20 +17,20 @@ containing the IPs and hostnames for all the servers you're interested in.
To use this, install the `brooklyn-dns-etc-hosts-generator.bom` to your catalog,
then simply add this to your blueprint:

```
```YAML
- type: brooklyn-dns-etc-hosts-generator
```
And then add this bit of config to every entity (or ancestor whose children you're interested in):
```
```YAML
brooklyn.config:
# tells the etc-hosts-generator to manage DNS on this server
brooklyn_dns.enabled: true
```
As an example, see [brooklyn-dns-etc-hosts-sample.yaml](brooklyn-dns-etc-hosts-sample.yaml).
As an example, see [etc-hosts-generator-example.yaml](examples/etc-hosts-generator-example.yaml).
## Using Your Own DNS Server
Expand All @@ -44,10 +45,7 @@ You can have VMs registered with that DNS server by setting `brooklyn_dns.enable
And you can tell VMs to use the BIND DNS server by adding
`brooklyn-dns-registration-hook` as a child to the machine entity.

This is illustrated in
[brooklyn-dns-bind-and-registration-sample.yaml](brooklyn-dns-bind-and-registration-sample.yaml).


This is illustrated in [bind-and-registration-example.yaml](examples/bind-and-registration-example.yaml).

## When to Use Which?

Expand All @@ -60,7 +58,6 @@ it involves standing up an extra BIND server.
(Note that you can share a BIND server among multiple applications,
and the approach could be extended to work with any DNS services which expose a REST API.)


# Future Work

This is all TODO:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ brooklyn.catalog:

items:
- id: brooklyn-dns-bind-server
name: "Brooklyn DNS BIND Server"
description: |
A BIND server which will automatically pick up any entity
with the 'brooklyn_dns.enabled' config key set to true
itemType: entity
iconUrl: classpath://io.brooklyn.dns:icons/dns.png
item:

type: org.apache.brooklyn.entity.network.bind.BindDnsServer
name: Brooklyn DNS BIND Server
iconUrl: http://blog.webhostpython.com/wp-content/uploads/2015/09/dns.jpg
description: A BIND server which will automatically pick up any entity with brooklyn_dns.enabled true
id: brooklyn-dns-bind-server
name: "brooklyn-dns-bind-server"

brooklyn.parameters:
- name: brooklyn_dns.domain
label: Domain name
label: "Domain Name"
description: |
The domain name suffix to use for generated hostnames
default: brooklyn.local
default: "brooklyn.local"

- name: brooklyn_dns.hosts.filter.config
label: Filtering config key
label: "Filtering Config Key"
description: |
The name of the config key set on other entities to indicate that this server
should pick up their address
Expand Down Expand Up @@ -72,50 +74,44 @@ brooklyn.catalog:
bind.sensor.hostname: $brooklyn:config("brooklyn_dns.hosts.basename.sensor")
bind.sensor.address: $brooklyn:config("brooklyn_dns.hosts.address.sensor")

filter:
$brooklyn:object:
type: com.google.common.base.Predicates
factoryMethod.name: "and"
factoryMethod.args:
- $brooklyn:object:
type: org.apache.brooklyn.core.entity.EntityPredicates
factoryMethod.name: "applicationIdEqualTo"
factoryMethod.args:
- $brooklyn:attributeWhenReady("application.id")
- $brooklyn:config("brooklyn_dns.entityfilter")

# TODO remove below this line when Aug brooklyn-library PR is merged
filter: $brooklyn:config("brooklyn_dns.entityfilter")

# TODO remove when Aug brooklyn-library PR is merged
namedConfTemplate:
https://raw.githubusercontent.com/ahgittin/brooklyn-library/bind-dns-improvements/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.conf

# TODO remove when Aug brooklyn-library PR is merged
brooklyn.initializers:
- type: org.apache.brooklyn.core.sensor.StaticSensor
brooklyn.config:
name: bind.serial
static.value: 201608001
namedConfTemplate:
https://raw.githubusercontent.com/ahgittin/brooklyn-library/bind-dns-improvements/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.conf
- type: org.apache.brooklyn.core.sensor.StaticSensor
brooklyn.config:
name: bind.serial
static.value: 201608001

- id: brooklyn-dns-registration-hook
name: "Brooklyn DNS Registration Hook"
description: |
Configures the VM to register with and use the DNS server located at the
brooklyn_dns.address config key (IP address string)
itemType: entity
iconUrl: classpath://io.brooklyn.dns:icons/dns.png
item:
type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
name: "Brooklyn DNS Registration Hook"
iconUrl: http://blog.webhostpython.com/wp-content/uploads/2015/09/dns.jpg
description: |
Configures the VM to register with and use the DNS server located at the
brooklyn_dns.address config key (IP address string)
id: brooklyn-dns-registration-hook
name: "brooklyn-dns-registration-hook"

brooklyn.parameters:
- name: brooklyn_dns.domain
label: "Domain Name"
description: |
The domain name suffix to use for generated hostnames
default: brooklyn.local
default: "brooklyn.local"

- name: brooklyn_dns.address
label: "DNS Server Address"
description: |
The address of the DNS server to put in resolv.conf, often an expression such as
'$brooklyn:entity("brooklyn_dns-bind-server").attributeWhenReady("host.address")'
(that is the default so if your BIND DNS server entity has id
'$brooklyn:entity("brooklyn-dns-bind-server").attributeWhenReady("host.address")'
(which is the default, so if your BIND DNS server entity has id
'brooklyn-dns-bind-server' and is accessible on its public IP address,
this config can be omitted)
default: $brooklyn:entity("brooklyn-dns-bind-server").attributeWhenReady("host.address")
Expand All @@ -130,11 +126,11 @@ brooklyn.catalog:
MY_HOSTNAME: $brooklyn:attributeWhenReady("brooklyn_dns.host.name")

install.command: |
# put at front of resolv.conf
( echo nameserver ${BROOKLYN_DNS_SERVER_ADDRESS} ; cat /etc/resolv.conf ) | sudo tee /etc/resolv.conf
# also put in this head file if resolvconf is used (to autogen the file above)
# put our nameserver at the front of resolv.conf
( echo "nameserver ${BROOKLYN_DNS_SERVER_ADDRESS}" ; cat /etc/resolv.conf ) | sudo tee /etc/resolv.conf
# also put in the head file if resolvconf is used to autogenerate the file above
if [ -f /etc/resolvconf/resolv.conf.d/head ] ; then
( echo nameserver ${BROOKLYN_DNS_SERVER_ADDRESS} ; cat /etc/resolvconf/resolv.conf.d/head ) | sudo tee /etc/resolvconf/resolv.conf.d/head
( echo "nameserver ${BROOKLYN_DNS_SERVER_ADDRESS}" ; cat /etc/resolvconf/resolv.conf.d/head ) | sudo tee /etc/resolvconf/resolv.conf.d/head
sudo resolvconf -u
fi

Expand Down
4 changes: 4 additions & 0 deletions catalog/brooklyn-dns/catalog.bom
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
brooklyn.catalog:
items:
- classpath://io.brooklyn.dns:brooklyn-dns/bind-and-registration.bom
- classpath://io.brooklyn.dns:brooklyn-dns/etc-hosts-generator.bom
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
brooklyn.catalog:
version: "0.2.0-SNAPSHOT" # BROOKLYN_DNS_VERSION
description: |
Entity that generates an '/etc/hosts' file containing the addresses
of a group of entities that have the 'brooklyn_dns.enabled' config key set.
Entities for working with BIND and DNS servers
publish:
overview: README.md
license_code: APACHE-2.0
license_url: http://www.apache.org/licenses/LICENSE-2.0.txt

items:
- id: brooklyn-dns-etc-hosts-generator
name: "Brooklyn DNS /etc/hosts Generator"
description: |
Entity that generates an '/etc/hosts' file containing the addresses
of a group of entities that have the 'brooklyn_dns.enabled' config key set.
itemType: entity
iconUrl: classpath://io.brooklyn.dns:icons/dns.png
item:
type: org.apache.brooklyn.entity.group.DynamicGroup
name: Brooklyn DNS /etc/hosts Generation Group
iconUrl: http://blog.webhostpython.com/wp-content/uploads/2015/09/dns.jpg
id: brooklyn-dns-etc-hosts-generator
name: "brooklyn-dns-etc-hosts-generator"

brooklyn.parameters:
- name: brooklyn_dns.domain
Expand Down Expand Up @@ -59,7 +62,7 @@ brooklyn.catalog:
type: org.apache.brooklyn.core.entity.EntityPredicates
factoryMethod.name: "configEqualTo"
factoryMethod.args:
- "brooklyn_dns.enabled"
- $brooklyn:config("brooklyn_dns.hosts.filter.config")
- true

- name: brooklyn_dns.overwrite
Expand Down Expand Up @@ -116,16 +119,13 @@ brooklyn.catalog:
Updates /etc/hosts file on all members
executionTarget: MEMBERS
shell.env:
HOST_ADDRESSES:
$brooklyn:attributeWhenReady("host.addresses")
DOMAIN_NAME:
$brooklyn:entity("brooklyn-dns-etc-hosts-generator").config("brooklyn_dns.domain")
ENTITY_ID:
$brooklyn:entity("brooklyn-dns-etc-hosts-generator").attributeWhenReady("entity.id")
OVERWRITE_HOSTS_FILE:
$brooklyn:entity("brooklyn-dns-etc-hosts-generator").config("brooklyn_dns.overwrite")
HOST_ADDRESSES: $brooklyn:attributeWhenReady("host.addresses")
DOMAIN_NAME: $brooklyn:config("brooklyn_dns.domain")
ENTITY_ID: $brooklyn:attributeWhenReady("entity.id")
OVERWRITE_HOSTS_FILE: $brooklyn:config("brooklyn_dns.overwrite")
command: |
# use this strategy to prevent concurrent write conflicts
( # use this strategy to prevent concurrent write conflicts
flock 9
tmp_file="/tmp/etc_hosts.$$"
id=$(echo ${ENTITY_ID} | tr 'a-z' 'A-Z')
if [ "${OVERWRITE_HOSTS_FILE}" == "false" ] ; then
Expand All @@ -141,3 +141,4 @@ brooklyn.catalog:
echo "# END_BROOKLYN_${id}_MANAGED_HOSTS"
) >> ${tmp_file}
sudo mv ${tmp_file} /etc/hosts
) 9>> /tmp/brooklyn_dns.${ENTITY_ID}.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ location: ibm-bluebox-sng-pub

brooklyn.config:
# custom domain
brooklyn_dns.domain: "brooklyn.demo.local"
brooklyn_dns.domain: "brooklyn.example.org"

# use private subnet address (not public), both for DNS's IP put in resolv.conf and for nodes' IPs in DNS
brooklyn_dns.address: $brooklyn:entity("brooklyn_dns-bind-server").attributeWhenReady("host.subnet.address")
brooklyn_dns.hosts.address.sensor: host.subnet.address
brooklyn_dns.address: $brooklyn:entity("example-bind-server").attributeWhenReady("host.subnet.address")
brooklyn_dns.hosts.address.sensor: "host.subnet.address"

services:
# this is the DNS server
- type: brooklyn-dns-bind-server
id: example-bind-server
name: "Example BIND Server"

# and a sample server which uses the DNS server
# and a example server which uses the DNS server
- type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
name: "Sample Server which gets DNS"
name: "Example Server which uses DNS"

brooklyn.config:
# this is the magic which registers us with the DNS server above
Expand All @@ -30,7 +32,7 @@ services:
# (you can also publish the full hostname for easier access, as done in brooklyn-dns-registration-hook)

# wait for DNS before launching
launch.latch: $brooklyn:entity("brooklyn_dns-bind-server").attributeWhenReady("service.isUp")
launch.latch: $brooklyn:entity("example-bind-server").attributeWhenReady("service.isUp")

launch.command: |
echo "(just a sample; we're running if we can ping ourselves on the generated hostname)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ location: ibm-bluebox-sng-pub

brooklyn.config:
# custom domain
brooklyn_dns.domain: "brooklyn.demo.local"
brooklyn_dns.domain: "brooklyn.example.local"

# use subnet IP address instead of public
brooklyn_dns.hosts.address.sensor: host.subnet.address
Expand All @@ -13,15 +13,15 @@ services:
- type: brooklyn-dns-etc-hosts-generator

- type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
name: Brooklyn Node s1 (pinging s2)
name: "Brooklyn Node s1 (pinging s2)"
id: s1

brooklyn.config:
# tells the etc-hosts-generator to manage DNS on this server
brooklyn_dns.enabled: true

shell.env:
S2_HOSTNAME: $brooklyn:entity("s2").entityId()
S2_HOSTNAME: $brooklyn:entity("s2").attributeWhenReady("entity.id")

launch.command: |
echo "(nothing needed to make this run, it's only the checkRunning we care about)"
Expand All @@ -31,15 +31,15 @@ services:
- type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
name: Brooklyn Node s2 (pinging s1)
name: "Brooklyn Node s2 (pinging s1)"
id: s2

brooklyn.config:
# tells the etc-hosts-generator to manage DNS on this server
brooklyn_dns.enabled: true

shell.env:
S1_HOSTNAME: $brooklyn:entity("s1").entityId()
S1_HOSTNAME: $brooklyn:entity("s1").attributeWhenReady("entity.id")

launch.command: |
echo "(nothing needed to make this run, it's only the checkRunning we care about)"
Expand Down
Loading

0 comments on commit 83261dd

Please sign in to comment.