Replies: 2 comments 4 replies
-
I like it. More implications:
|
Beta Was this translation helpful? Give feedback.
-
As soon as we introduce the concept that node So once we have introduced such properties where nodes are first-class values, the obvious next step would be syntax to turn There are two ways to go (perhaps for TOSCA 3.0?):
Embracing is what we do in HPE DSD, and it is an extremely powerful concept - and it is relatively easy for users to understand. For example, the current substitution mapping mechanism is hard for users to understand and we have had to introduce syntax to handle cardinality of relationships between nodes in the surrounding graph to nodes inside the substitution. The problem is really that those collections of nodes have no good name that you can refer to and manipulate using functions, but with node-type properties, you have a property name, and expressing the relationships is quite easy. |
Beta Was this translation helpful? Give feedback.
-
In our current version of TOSCA path expressions:
get_property
andget_attribute
functions use the special wordSELF
to refer to the context in which the expression is evaluated. Actually, there are two different possible instances forSELF
:SELF
would the instance itself, a node representation or a relationship representation. (Side note: from the current documentation it's not clear to me ifSELF
is always either a node or a relationship, or whether it would refer to the current capability if it's called within a capability property value assignment. If it's the latter, then how do we "escape" the capability and refer to the containing node?)node_filter
,SELF
is a candidate node. We are thus expecting the whole expression to be evaluated multiple times, once per candidate. There is an implicit loop. Note that the expression still refers only to one instance per call.$value
function. This refers not to the entity but the value assignment.To support a rich event model in TOSCA with expressive trigger conditions and target entities, I think we need to enhance the grammar. It's also an opportunity to make it more unified and coherent.
Entity Referral Functions
Currently TOSCA path is only usable within value retrieval functions (e.g.
$get_property
). Let's separate the two uses.These are the core graph traversal functions. There are structured as "from a starting point".
Without arguments (magic word)
$self
is the current single contextual entity. It always is associated with a specific entity type: nodes, relationships, capabilities, groups, policies, and interfaces. Arguments work like our current TOSCA path language. The name of the function refers to the starting point of graph traversal, not to the returned entity type, which otherwise depends on our graph expression. Examples:Note that this does elevate entities in TOSCA to become something like values (actually: references), as they are now being returned from functions. I suggested elsewhere that we can go one step further and make entity references into 1st-class values. It's not necessary for the rest of my proposal, but I'll just throw in an example here:
We'd probably usually prefer to use a relationship in a case like this, but entity references can be used for event handlers (see #153), e.g. we might want to send an entire entity as an input to an event handler, or as a parameter in a user-defined function.
Value Retrieval Functions
The first argument is (almost) always an entity returned by one of the entity referral functions above, so we can do the same as we do now. Examples:
There's one function that doesn't accept an entity as the first argument,
$value
(for data validation):Entity Selection Functions
These gather zero or more entities of a specific type.
Each of these functions creates an implicit loop, where the calling context of the "condition" (a boolean sub-expression) is a candidate entity. If the expression is resolved to "true", the candidate is added to the selection. We would use
$self
within the condition expressionto refer to that candidate.
Entity selection functions would be used to select targets for sending events (see discussion #153). And also instead of the current
node_filter
grammar for requirements:Anywhere an entity selection is expected, a single entity referral can be used instead to refer to a selection of just one, for simple use cases.
Reimagining Groups
Entity selection functions introduce an interesting new way to think of groups. Maybe instead of being a static list of members they can use a selection function. Such "dynamic" groups would be recalculated every time they are referenced. They can also be used instead of repeated references to selectors:
But ... do we really need groups anymore? Their functionality can be replaced entirely with a node which has a "contains" relationship to its members. The new entity selection functions can allow us to do this especially easily:
(The
$has_relationship
function accepts a source node, a relationship type, and a target node.)Obviously policy targets would work the same way:
Handler Result Functions
These are functions like
$all_handlers_succeeded
and$any_handler_failed
that I referred to in discussion #153. This post is already long, so I will elaborate on this topic in the future as we get through this beginning.Textual Syntax?
As we grow and enrich our expression language, the current syntax is becoming painful. All those nested YAML
{ }
and[ ]
start to look like LISP soup (in a bad way). Maybe it's time to switch to a text-based expression language where we can use more familiar symbols.Here's an example using
.
for path-based traversal (starting with$self
) and:
for property retrieval. It's the expression above written in a more manageable way:{ $nodes: "(. is_a App) & (.:my-capacity > 100 gb) & (.CAPABILITY.machine:machine-type = 'vm')" }
We can possibly even support both syntax types for different reasons. For example the "textual syntax" might only be used for entity reference and selection (proposed name: "TOSCA Path Traversal Language" or "PTL"), the rest of the function calls would be the same:
{ $get_property: ".CAPABILITY:machine:machine-type" }
Beta Was this translation helpful? Give feedback.
All reactions