Skip to content

Instantly share code, notes, and snippets.

@grkvlt
Last active November 25, 2016 22:14
Show Gist options
  • Save grkvlt/59579e13c47aa89ff3fe504c9cd90d24 to your computer and use it in GitHub Desktop.
Save grkvlt/59579e13c47aa89ff3fe504c9cd90d24 to your computer and use it in GitHub Desktop.
Entity Query language Specification

Entity Query Language

Andrew kennedy; Cloudsoft; November 2016

This is a Brooklyn DSL enhancement to allow specifying entities in a blueprint using a query language similar to XPath 1 or JSONPath 2 that would give much greater flexibility than the current system.

Syntax

The basic EQL syntax is described in the following sections.

Selection

The identity of an entity can be specified by the 'entity.id' sensor, the 'catalog.id' sensor or its display name. The current entity is the context in which the query is executing. If the query is executed as part of a policy or enricher, the context is the owning entity.

./one

  • All entities named one that are siblings of the current entity

one

  • All entities named one that are siblings of the current entity

//one

  • All entities named one

.//one

  • All entities named one that are descendants of the current entity

/one

  • All top level entities named one

/*/one

  • All second level entities named one

//*

  • All entities

*

  • All siblings of the current entity

.

  • The current entity

..

  • The current entities parent

Relationships

one/two

  • All entities named two that are children of entities named one that are siblings of the current entity

one//two

  • All entities named two that are descendants of entities named one that are siblings of the current entity

one/*/two

  • All entities named two that are grand-children of entities named one that are siblings of the current entity

one/*

  • All entities that are children of entities named one that are siblings of the current entity

Numeric Indexing

one[0]

  • The first entity named one that is a sibling of the current entity

one[1]

  • The second entity named one that is a sibling of the current entity

one[*]

  • The last entity named one that is a sibling of the current entity

*[0]

  • The first entity that is a sibling of the current entity

/[0]

  • The first top-level entity

Configuration and Sensors

one(sensor)

  • All entities named one that are a sibling of the current entity and have sensor sensor set to a truth-like value

one(sensor=value)

  • All entities named one that are a sibling of the current entity and have sensor sensor set to value

one(@config)

  • All entities named one that are a sibling of the current entity and have config key config set to a truth-like value

one(@config=value)

  • All entities named one that are a sibling of the current entity and have config key config set to value

*(sensor=value)

  • All entities that are siblings of the current entity and have sensor sensor set to value

//*(sensor=value)

  • All entities that have sensor sensor set to value

//*(sensor=value)[0]

  • The first entity that has sensor sensor set to value

Examples

$brooklyn:query("/*/node-name(@config.key=value)/*[3]").attributeWhenReady("sensor.name")
  • The third child of any child of the root entity that is a named node-name with config config.key set to value.
$brooklyn:query("//cluster-name//service-name(service.isUp)")
  • The service-name entities that have the service.isUp sensor set and are descendants of cluster-name entites.

Implementation

This will be implemented as a new $brooklyn DSL command named query which will return the selected entity (or the first of the set of selected entities) as a DslComponent. Further implementation details are yet to be determined.

References

  1. https://www.w3.org/TR/xpath/
  2. http://goessner.net/articles/JsonPath/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment