Policy type creation
Introduction
Tosca lab has 2 main scripts:
model_create.py - to create tosca model artifacts from component spec
policy_create.py - to create policy type artifacts from component spec
This page concentrates on usage of policy_create.py
Script policy_create.py creates data_type that can be used by policy_type.
In context of Closed Loop, policy type describes how to create microservice policy (maybe operation policy in future) in Clamp.
Policy types and Data types are extracted by Clamp from CSAR file created by SDC.
Control Loop Artifacts
CSAR package contains 3 artifacts required by Clamp to create closed loop:
DCEA_INVENTORY_BLUEPRINT - artifact describing how to deploy closed loop
policies.yml - contain policy types
data.yml - data types used by policy types (there is more of them inside it but those are not interesting for us)
Let's take a look what are dependencies between them:
To deploy* closed loop Clamp uses DCEA_INVENTORY_BLUEPRINT.
Each node that is deployed has to have specified it's policy type.
From Analytic Microservice perspective policy type is a scheme of how it's configuration should look like.
If node doesn't have specified policy type Clamp assumes it's default one onap.policy.monitoring.cdap.tca.hi.lo.app
Policy types described inside policies.yml can have sub-nodes. Those sub-nodes are data types. They're described inside artifact data.yml.
*It's simplification. Clamp requests DCAE to deploy microservice.
Tosca Lab policy create
Dublin constraint is that both data.yml and policies.yml are hardcoded and can't be changed/extended in runtime.
Script policy_create.py is able to create new policy type and data type that could be add to policies.yml and data.yml.
How policy_create.py works:
Script policy_create.py requires single spec file. Example spec files and microservice onboarding flow is described here MicroServices Onboarding in ONAP.
Full microservice spec is really large JSON. To simplify I've created simple microservice_spec.json. This spec contains only fields required by policy_create.py to create new policy type.
This spec lacks field required by model_create.py to create tosca model. It's just for policies (but could be easily extended)
To generate policy type out of it user has to run script policy_create.py using python. (This script is located inside <REPO>/sdc/dcae-d/tosca-lab/app/policy_create.py)
python policy_create.py -i ./microservice_spec.json -o ./output_policy.yaml
This command generate file output_policy.yaml.
Let's take a closer look
This file contains two main nodes
node_types - containing root node and policy.nodes.my_custom_policy_type. This node is actually a policy_type. In future it should derive from onap.policies.Monitoring instead of policy.nodes.Root
data_types - specifying data types (and sub-data types) used in node_type (policy_type)
Note: The default output_policy.yaml generated requires manual update before it can be used in rest of CL flow design. Follow steps documented here - Onboarding steps for DCAE MS through SDC/Policy/CLAMP (Dublin)#PolicyTypeCreation(Developmentphase) to make updates