oasis-open / tosca-community-contributions

OASIS TC Open Repository: Manages TOSCA profiles, tests, and templates that are maintained by the TOSCA community. They are intended to be used as examples to help developers get started with TOSCA and to test compliance of TOSCA implementations with the standard.
https://github.com/oasis-open/tosca-community-contributions
Apache License 2.0
39 stars 25 forks source link

Add support for capability filters in requirement definitions (and requirement assignments) #118

Open lauwers opened 2 years ago

lauwers commented 2 years ago

Requirement definitions and assignments support a node_filter keyword to narrow down the set of target nodes that can be used to fulfill a requirement. This keyword presumes that the node type of the target node is provided (using the node keyword in the requirement definition or requirement assignment). When the node type is not specified, target filters can not be applied. To remedy this situation, we should add support for capability filters that narrow down the set of possible targets based on constraints on the values of the properties of the target capability. To harmonize support for node filters and capability filters, I propose that we introduce an extended notation for defining target capability type and target node types in requirement definitions as in the following example:

requirements:
  - provider:
      capability:
        type: ProviderCapability
        filter: 
          properties:
            performance: { equal: "high" }
      node:
        type: ServiceProvider
        filter:
          properties:
            vendor: { equal: "ACME" "

Similar syntax would be used inside the requirement assignment. Of course, if no filters are provided, the old single-line syntax should still work.

lauwers commented 1 year ago

Capability filter functionality is now fully supported using the new node_filter syntax described in https://docs.oasis-open.org/tosca/TOSCA/v2.0/csd05/TOSCA-v2.0-csd05.html#_Toc125468604. The following shows a complete capability filter example:

tosca_definitions_version: tosca_2_0

capability_types:
  ProviderCapability:
    properties:
      performance:
        type: string
        validation:
          $valid_values: [ $value, [ high, medium, low ] ]

relationship_types:
  ServedBy: {}

node_types:
  Server:
    capabilities:
      service:
        type: ProviderCapability

  Client:
    requirements:
      - server:
          capability: ProviderCapability
          relationship: ServedBy

service_template:
  node_templates:
    client:
      type: Client
      requirements:
        - server:
            node: Server
            node_filter:
              $equal:
                - $get_property: [ SELF, CAPABILITY, performance ]
                - high
    high_performance_server:
      type: Server
      capabilities:
        service:
          properties:
            performance: high

    low_performance_server:
      type: Server
      capabilities:
        service:
          properties:
            performance: low