tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0

metadata:
  template_name: Flame CLMC Alerts Integration Test
  sfc: MS_Template_1
  sfci: MS_I1


# Import own definitions of nodes, capabilities and policy syntax.
imports:
  - flame_definitions-0.1.7.yaml

# Starting the template

## Topology
topology_template:
  node_templates:
    database:
      type: eu.ict-flame.nodes.ServiceFunction
      capabilities:
        host:
          properties:
            num_cpus: 2
            mem_size: 4096 MB
            disk_size: 10 GB
      properties:
        hypervisor: kvm
        image_url: http://cdimage.debian.org/cdimage/openstack/current-9/debian-9-openstack-amd64.qcow2
        fqdn:
          - db.app.ict-flame.eu


    frontend:
      type: eu.ict-flame.nodes.ServiceFunction
      capabilities:
        host:
          properties:
            num_cpus: 2
            disk_size: 10 GB
            mem_size: 4096 MB
      properties:
        hypervisor: kvm
        image_url: http://cdimage.debian.org/cdimage/openstack/current-9/debian-9-openstack-amd64.qcow2
        fqdn:
          - frontend.app.ict-flame.eu
          - www.app.ict-flame.eu

  policies:
    - init:
        type: eu.ict-flame.policies.InitialPolicy
        description: Start the nodes initially
        properties:
          parent: service_paid
        triggers:
          inital_trigger:
            condition:
              constraint: initialise
            action:
              frontend:
                -
                  fqdn: frontend.app.ict-flame.eu
                  lifecycle_actions:
                    London: eu.ict-flame.sfe.state.lifecycle.connected
                    Bristol: eu.ict-flame.sfe.state.lifecycle.booted
                    Manchester: eu.ict-flame.sfe.state.lifecycle.connected
              database:
                -
                  fqdn: db.app.ict-flame.eu
                  lifecycle_actions:
                    London: eu.ict-flame.sfe.state.lifecycle.connected

    - scale_nginx_policy:
        type: eu.ict-flame.policies.StateChange
        properties:
          parent: service_paid
        triggers:
          tigger_a:
            condition:
              constraint: clmc::high_requests
            action:
              frontend:
                -
                  fqdn: frontend.app.ict-flame.eu
                  lifecycle_actions:
                    Bristol: eu.ict-flame.sfe.state.lifecycle.connected
          tigger_b:
            condition:
              constraint: clmc::high_cpu_usage
              period: 600 # integer required, unit: seconds
            action:
              frontend:
              - fqdn: frontend.app.ict-flame.eu
                lifecycle_actions:
                  Bristol: eu.ict-flame.sfe.state.lifecycle.connected
          tigger_c:
            condition:
              constraint: clmc::increase_in_active_requests
              period: 600 # integer required, unit: seconds
            action:
              frontend:
              - fqdn: frontend.app.ict-flame.eu
                lifecycle_actions:
                  Bristol: eu.ict-flame.sfe.state.lifecycle.connected

    - deadman_policy:
        type: eu.ict-flame.policies.StateChange
        properties:
          parent: service_paid
        triggers:
          tigger_a:
            condition:
              constraint: clmc::no_measurements
            action:
              frontend:
                -
                  fqdn: frontend.app.ict-flame.eu
                  lifecycle_actions:
                    Bristol: eu.ict-flame.sfe.state.lifecycle.connected

    - service_paid:
        type: eu.ict-flame.policies.StateChange
        description: Check outstanding payments. If there are outstanding payments, we shutdown the deployed service.
        triggers:
          not_paid_trigger:
            description: Check if the payment is late
            condition:
              constraint: clmc-user-db::serviceIsNotPaid  # this will be ignored, source must be clmc
              period: 3600 # integer required, unit: seconds
            action:
              frontend:
                -
                  fqdn: frontend.app.ict-flame.eu
                  lifecycle_actions:
                    London: eu.ict-flame.sfe.state.lifecycle.shutdown
                    Bristol: eu.ict-flame.sfe.state.lifecycle.shutdown
                    Manchester: eu.ict-flame.sfe.state.lifecycle.shutdown
              database:
                -
                  fqdn: db.app.ict-flame.eu
                  lifecycle_action:
                    London: eu.ict-flame.sfe.state.lifecycle.shutdown
