Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use condition syntax in node filters and capability filters #121

Open
lauwers opened this issue Jul 1, 2022 · 2 comments
Open

Use condition syntax in node filters and capability filters #121

lauwers opened this issue Jul 1, 2022 · 2 comments

Comments

@lauwers
Copy link
Contributor

lauwers commented Jul 1, 2022

I have a need to define more complex requirement fulfillment logic than what can be expressed using node and capability filters. I believe the existing condition syntax could be used for this purpose. The following example shows how condition syntax could express anti-collocation behavior:

tosca_definitions_version: tosca_2_0

capability_types:
  Host:
    description: for hosting software components

relationship_types:
  HostedOn:
    description: relationship to hosting container

node_types:

  Host:
    properties:
      uuid:
        type: string
    capabilities:
      host:
        type: Host

  SoftwareComponent:
    requirements:
      - host:
          capability: Host
          relationship: HostedOn

service_template:

  node_templates:

    host1:
      type: Host
      properties:
        uuid: host.1
      
    host2:
      type: Host
      properties:
        uuid: host.2
      
    host3:
      type: Host
      properties:
        uuid: host.3
      
    software1:
      type: SoftwareComponent
      requirements:
        - host:
            node: Host

    software2:
      type: SoftwareComponent
      requirements:
        - host:
            node: Host
            filter:
              - not:
                  [TARGET, uuid] : { equal: [software1, RELATIONSHIP, host, TARGET, uuid ] }
@lauwers
Copy link
Contributor Author

lauwers commented Jul 2, 2022

My apologies, but I believe I have an error in the filter clause in the above example. I think the condition in the filter needs a get_property function to work correctly, as follows:

tosca_definitions_version: tosca_2_0

capability_types:
  Host:
    description: for hosting software components

relationship_types:
  HostedOn:
    description: relationship to hosting container

node_types:

  Host:
    properties:
      uuid:
        type: string
    capabilities:
      host:
        type: Host

  SoftwareComponent:
    requirements:
      - host:
          capability: Host
          relationship: HostedOn

service_template:

  node_templates:

    host1:
      type: Host
      properties:
        uuid: host.1
      
    host2:
      type: Host
      properties:
        uuid: host.2
      
    host3:
      type: Host
      properties:
        uuid: host.3
      
    software1:
      type: SoftwareComponent
      requirements:
        - host:
            node: Host

    software2:
      type: SoftwareComponent
      requirements:
        - host:
            node: Host
            filter:
              - not:
                  [TARGET, uuid] : { equal:  { get_property: [software1, RELATIONSHIP, host, TARGET, uuid ] } }

@lauwers
Copy link
Contributor Author

lauwers commented Feb 20, 2023

Node filters now use boolean expressions as documented in https://docs.oasis-open.org/tosca/TOSCA/v2.0/csd05/TOSCA-v2.0-csd05.html#_Toc125468604. Using this syntax, the example above would look as follows:

tosca_definitions_version: tosca_2_0

capability_types:
  Host: {}

relationship_types:
  HostedOn: {}

node_types:
  Host:
    properties:
      uuid:
        type: string
    capabilities:
      host:
        type: Host

  SoftwareComponent:
    requirements:
      - host:
          capability: Host
          relationship: HostedOn
          count_range: [1, 1]

service_template:
  node_templates:

    host1:
      type: Host
      properties:
        uuid: host.1
      
    host2:
      type: Host
      properties:
        uuid: host.2
      
    host3:
      type: Host
      properties:
        uuid: host.3
      
    software1:
      type: SoftwareComponent
      requirements:
        - host:
            node: Host

    software2:
      type: SoftwareComponent
      requirements:
        - host:
            node: Host
            node_filter:
              $not:
                $equal:
                  - $get_property: [SELF, TARGET, uuid]
                  - $get_property: [software1, RELATIONSHIP, host, TARGET, uuid] 

Of course, the example itself is a bit convoluted, since anti-collocation behavior should be specified instead using a declarative policy as suggested in Issue #141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant