Writing an Entity
Ways to write an entity
There are several ways to write a new entity:
- For Unix/Linux, write YAML blueprints, for example using a
VanillaSoftwareProcessand configuring it with your scripts.
- For Windows, write YAML blueprints using
VanillaWindowsProcessand configure the PowerShell scripts.
- For composite entities, use YAML to compose exiting types of entities (potentially overwriting parts of their configuration), and wire them together.
- Use Chef recipes.
- Use Salt formulas.
- Use Ansible playbooks.
- Write pure-java, extending existing base-classes. For example, the
GistGeneratorexample. These can use utilities such as
- Write pure-Java blueprints that extend
SoftwareProcess. However, the YAML approach is strongly recommended over this approach.
- Write pure-Java blueprints that compose together existing entities, for example to manage a cluster. Often this is possible in YAML and that approach is strongly recommended. However, sometimes the management logic may be so complex that it is easier to use Java.
The rest of this section covers writing an entity in pure-java (or other JVM languages).
Things To Know
All entities have an interface and an implementation. The methods on the interface are its effectors; the interface also defines its sensors.
Entities are created through the management context (rather than calling the
constructor directly). This returns a proxy for the entity rather than the real instance, which is important in a distributed management plane.
All entity implementations inherit from
AbstractEntity, often through one of the following:
SoftwareProcessImpl: if it's a software process
VanillaJavaAppImpl: if it's a plain-old-java app
JavaWebAppSoftwareProcessImpl: if it's a JVM-based web-app
AbstractGroupImpl: if it's a collection of other entities
Software-based processes tend to use drivers to install and
launch the remote processes onto locations which support that driver type.
AbstractSoftwareProcessSshDriver is a common driver superclass,
SshMachineLocation (a machine to which Brooklyn can ssh).
SoftwareProcess entities above (and some of the exemplars
listed at the end of this page) have their own dedicated drivers.
Finally, there are a collection of traits, such as
in the package
brooklyn.entity.trait. These provide common
sensors and effectors on entities, supplied as interfaces.
Choose one (or more) as appropriate.
So to get started:
- Create your entity interface, extending the appropriate selection from above, to define the effectors and sensors.
- Include an annotation like
@ImplementedBy(YourEntityImpl.class)on your interface, where
YourEntityImplwill be the class name for your entity implementation.
- Create your entity class, implementing your entity interface and extending the classes for your chosen entity super-types. Naming convention is a suffix "Impl" for the entity class, but this is not essential.
- Create a driver interface, again extending as appropriate (e.g.
SoftwareProcessDriver). The naming convention is to have a suffix "Driver".
- Create the driver class, implementing your driver interface, and again extending as appropriate.
Naming convention is to have a suffix "SshDriver" for an ssh-based implementation.
The correct driver implementation is found using this naming convention, or via custom
namings provided by the
- Wire the
public Class getDriverInterface()method in the entity implementation, to specify your driver interface.
- Provide the implementation of missing lifecycle methods in your driver class (details below)
- Connect the sensors from your entity (e.g. overriding
SoftwareProcessImpl).. See the sensor feeds, such as
Any JVM language can be used to write an entity. However use of pure Java is encouraged for entities in core brooklyn.
A few handy pointers will help make it easy to build your own entities. Check out some of the exemplar existing entities (note, some of the other entities use deprecated utilities and a deprecated class hierarchy; it is suggested to avoid these, looking at the ones below instead):
You might also find the following helpful: