Improvements for new policy API 17/106817/7
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Tue, 28 Apr 2020 20:48:05 +0000 (22:48 +0200)
committerMarco Platania <platania@research.att.com>
Mon, 11 May 2020 19:24:25 +0000 (19:24 +0000)
Improvements in demo scripts for new
API for policy, including scripts preparing
OOF for interaction with Policy API

Change-Id: Ifd28f6b2941d23dcab6699a71c536d8534fa7cf5
Issue-ID: INT-1465
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
tutorials/vFWDT/policies/rules/QueryPolicy_vFW_TD.json
tutorials/vFWDT/policies/rules/affinity_vFW_TD.json
tutorials/vFWDT/policies/rules/affinity_vFW_TD_push.json [new file with mode: 0755]
tutorials/vFWDT/policies/rules/dt-policies.sh [new file with mode: 0755]
tutorials/vFWDT/policies/rules/queryPolicy_vFW_TD_push.json [new file with mode: 0755]
tutorials/vFWDT/policies/rules/uploadPolicies.sh
tutorials/vFWDT/policies/rules/vnfPolicy_vFW_TD.json
tutorials/vFWDT/policies/rules/vnfPolicy_vFW_TD_push.json [new file with mode: 0755]
tutorials/vFWDT/policies/rules/vnfPolicy_vPGN_TD.json
tutorials/vFWDT/policies/rules/vnfPolicy_vPGN_TD_push.json [new file with mode: 0755]
tutorials/vFWDT/workflow/templates/osdfRequest.json

index 312ad65..c29e770 100644 (file)
@@ -1,46 +1,54 @@
 {
-    "service": "queryPolicy",
-    "policyName": "OSDF_DUBLIN.QueryPolicy_vFW_TD",
-    "description": "Query policy for vFW TD",
-    "templateVersion": "OpenSource.version.1",
-    "version": "OpenSource.version.1",
-    "priority": "3",
-    "riskType": "test",
-    "riskLevel": "2",
-    "guard": "False",
-    "content": {
-        "queryProperties": [
+    "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+    "topology_template": {
+        "policies": [
             {
-                "attribute": "customerLatitude",
-                "attribute_location": "customerLatitude",
-                "value": 1.1
-            },
-            {
-                "attribute": "customerLongitude",
-                "attribute_location": "customerLongitude",
-                "value": 2.2
-            },
-            {
-                "attribute": "chosen_region",
-                "attribute_location": "chosenRegion"
-            },
-            {
-                "attribute": "chosen_customer_id",
-                "attribute_location": "chosenCustomerId"
+                "OSDF_FRANKFURT.queryPolicy_vFW_TD": {
+                    "type": "onap.policies.optimization.service.QueryPolicy",
+                    "version": "1.0.0",
+                    "type_version": "1.0.0",
+                    "metadata": {
+                        "policy-id": "OSDF_FRANKFURT.queryPolicy_vFW_TD",
+                        "policy-version": 1
+                    },
+                    "properties": {
+                        "scope": [
+                            "OSDF_FRANKFURT"
+                        ],
+                        "services": [
+                            "vFW_TD"
+                        ],
+                        "resources": [
+                            "vFW-SINK",
+                            "vPGN"
+                        ],
+                        "geography": [
+                            "US"
+                        ],
+                        "identity": "vFW_TD_Query_Policy",
+                        "queryProperties": [
+                            {
+                                "attribute": "chosen_region",
+                                "attribute_location": "chosenRegion"
+                            },
+                            {
+                                "attribute": "chosen_customer_id",
+                                "attribute_location": "chosenCustomerId"
+                            },
+                            {
+                                "attribute": "customerLatitude",
+                                "attribute_location": "customerLatitude",
+                                "value": 1.1
+                            },
+                            {
+                                "attribute": "customerLongitude",
+                                "attribute_location": "customerLongitude",
+                                "value": 2.2
+                            }
+                        ]
+                    }
+                }
             }
-        ],
-        "policyScope": [
-            "td",
-            "us",
-            "vFW-SINK",
-            "vPGN"
-        ],
-        "policyType": "request_param_query",
-        "serviceName": "vFW_TD",
-        "identity": "vFW_TD_Query_Policy",
-        "resources": [
-            "vFW-SINK",
-            "vPGN"
         ]
     }
 }
index 590de1c..8f953fe 100644 (file)
@@ -1,29 +1,38 @@
 {
-    "service": "affinityPolicy",
-    "policyName": "OSDF_DUBLIN.Affinity_vFW_TD",
-    "description": "Affinity policy for vPGN Anchor and vFW destination point",
-    "templateVersion": "OpenSource.version.1",
-    "version": "OpenSource.version.1",
-    "priority": "3",
-    "riskType": "test",
-    "riskLevel": "2",
-    "guard": "False",
-    "content": {
-        "identity": "affinity_vFW_TD",
-        "policyScope": [
-            "td",
-            "us",
-            "vFW-SINK",
-            "vPGN"
-        ],
-        "affinityProperty": {
-            "qualifier": "same",
-            "category": "region"
-        },
-        "policyType": "zone",
-        "resources": [
-            "vFW-SINK",
-            "vPGN"
+    "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+    "topology_template": {
+        "policies": [
+            {
+                "OSDF_FRANKFURT.Affinity_vFW_TD": {
+                    "type": "onap.policies.optimization.resource.AffinityPolicy",
+                    "version": "1.0.0",
+                    "type_version": "1.0.0",
+                    "metadata": {
+                        "policy-id": "OSDF_FRANKFURT.Affinity_vFW_TD",
+                        "policy-version": 1
+                    },
+                    "properties": {
+                        "scope": [
+                            "OSDF_FRANKFURT",
+                            "TD"
+                        ],
+                        "resources": [
+                            "vFW-SINK",
+                            "vPGN"
+                        ],
+                        "geography": [
+                            "US",
+                            "INTERNATIONAL"
+                        ],
+                        "identity": "affinity_vFW_TD",
+                        "applicableResources": "any",
+                        "affinityProperties": {
+                            "qualifier": "same",
+                            "category": "region"
+                        }
+                    }
+                }
+            }
         ]
     }
 }
diff --git a/tutorials/vFWDT/policies/rules/affinity_vFW_TD_push.json b/tutorials/vFWDT/policies/rules/affinity_vFW_TD_push.json
new file mode 100755 (executable)
index 0000000..052f941
--- /dev/null
@@ -0,0 +1,8 @@
+{
+    "policies": [
+        {
+            "policy-id": "OSDF_FRANKFURT.Affinity_vFW_TD",
+            "policy-version": "1.0.0"
+        }
+    ]
+}
diff --git a/tutorials/vFWDT/policies/rules/dt-policies.sh b/tutorials/vFWDT/policies/rules/dt-policies.sh
new file mode 100755 (executable)
index 0000000..05d4882
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+# ============LICENSE_START=======================================================
+# Copyright (C) 2020 Orange
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ============LICENSE_END=========================================================
+
+echo -e '\n\nUploading Affinity Policy\n'
+curl --silent -i -k -X POST --user 'healthcheck:zb!XztG34' "https://policy-api:6969/policy/api/v1/policytypes/onap.policies.optimization.resource.AffinityPolicy/versions/1.0.0/policies" -H "X-ONAP-RequestID: e1763e61-9eef-4911-b952-1be1edd9812b" -H 'Content-Type: application/json' -d @/tmp/affinity_vFW_TD.json
+sleep 3
+echo -e '\n\nPushing Affinity Policy\n'
+curl --silent -k -i -X POST --user 'healthcheck:zb!XztG34' "https://policy-pap:6969/policy/pap/v1/pdps/policies" -H 'Content-Type: application/json' -H "Accept: application/json" -d @/tmp/affinity_vFW_TD_push.json
+sleep 3
+
+echo -e '\n\nUploading Query Policy\n'
+curl --silent -i -k -X POST --user 'healthcheck:zb!XztG34' "https://policy-api:6969/policy/api/v1/policytypes/onap.policies.optimization.service.QueryPolicy/versions/1.0.0/policies" -H "X-ONAP-RequestID: e1763e61-9eef-4911-b952-1be1edd9812b" -H 'Content-Type: application/json' -d @/tmp/QueryPolicy_vFW_TD.json
+sleep 3
+echo -e '\n\nPushing Query Policy\n'
+curl --silent -k -i -X POST --user 'healthcheck:zb!XztG34' "https://policy-pap:6969/policy/pap/v1/pdps/policies" -H 'Content-Type: application/json' -H "Accept: application/json" -d @/tmp/queryPolicy_vFW_TD_push.json
+sleep 3
+
+echo -e '\n\nUploading vFW VNF Policy\n'
+curl --silent -i -k -X POST --user 'healthcheck:zb!XztG34' "https://policy-api:6969/policy/api/v1/policytypes/onap.policies.optimization.resource.VnfPolicy/versions/1.0.0/policies" -H "X-ONAP-RequestID: e1763e61-9eef-4911-b952-1be1edd9812b" -H 'Content-Type: application/json' -d @/tmp/vnfPolicy_vFW_TD.json
+sleep 3
+echo -e '\n\nPushing vFW VNF Policy\n'
+curl --silent -k -i -X POST --user 'healthcheck:zb!XztG34' "https://policy-pap:6969/policy/pap/v1/pdps/policies" -H 'Content-Type: application/json' -H "Accept: application/json" -d @/tmp/vnfPolicy_vFW_TD_push.json
+sleep 3
+
+echo -e '\n\nUploading vPGN VNF Policy\n'
+curl --silent -i -k -X POST --user 'healthcheck:zb!XztG34' "https://policy-api:6969/policy/api/v1/policytypes/onap.policies.optimization.resource.VnfPolicy/versions/1.0.0/policies" -H "X-ONAP-RequestID: e1763e61-9eef-4911-b952-1be1edd9812b" -H 'Content-Type: application/json' -d @/tmp/vnfPolicy_vPGN_TD.json
+sleep 3
+echo -e '\n\nPushing vPGN VNF Policy\n'
+curl --silent -k -i -X POST --user 'healthcheck:zb!XztG34' "https://policy-pap:6969/policy/pap/v1/pdps/policies" -H 'Content-Type: application/json' -H "Accept: application/json" -d @/tmp/vnfPolicy_vPGN_TD_push.json
+
diff --git a/tutorials/vFWDT/policies/rules/queryPolicy_vFW_TD_push.json b/tutorials/vFWDT/policies/rules/queryPolicy_vFW_TD_push.json
new file mode 100755 (executable)
index 0000000..9977a73
--- /dev/null
@@ -0,0 +1,8 @@
+{
+    "policies": [
+        {
+            "policy-id": "OSDF_FRANKFURT.queryPolicy_vFW_TD",
+            "policy-version": "1.0.0"
+        }
+    ]
+}
index 7d1ccd1..58c7927 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 # ============LICENSE_START=======================================================
-# Copyright (C) 2019 Orange
+# Copyright (C) 2020 Orange
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 #
 # ============LICENSE_END=========================================================
 
-`./yq > /dev/null 2>&1`
-
-if [ $? -ne 0 ]; then
-       echo "Install yq"
-       wget -cO yq https://github.com/mikefarah/yq/releases/download/2.4.0/yq_linux_amd64
-       chmod 755 yq
-fi
-
-`jo -p n=1 > /dev/null 2>&1`
-
-if [ $? -ne 0 ]; then
-        echo "Install jo"
-        sudo add-apt-repository -y ppa:duggan/jo
-        sudo apt update
-        sudo apt install jo -y
-fi
-
-echo "Uploading policies"
-
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
-PDP=`kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep policy-pdp`
-
-echo $PDP
-CMD='createPolicy'
-MODE=$1
+API=`kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep policy-api`
 
-if [[ $MODE == "U" ]]; then
-       CMD='updatePolicy'
-fi
+`find $DIR/*.json | xargs -i{} kubectl cp {} onap/$API:/tmp/`
 
-echo $CMD
 SCRIPT="dt-policies.sh"
-echo "#!/bin/bash" > $SCRIPT
-
-for f in $DIR/*.json; do
-       NAME=`./yq r $f policyName`
-       SCOPE="$(cut -d'.' -f1 <<< $NAME )"
-       RULE=`cat $f`
-       BODY="\"$RULE\""
-       echo "Processing $NAME rule..";
-       echo "echo \"$NAME Policy\"" >> $SCRIPT
-       BODY=`jo -p configBody="$BODY" -p policyName=$NAME -p policyConfigType=MicroService -p onapName=SampleDemo -p policyScope=$SCOPE`
-       LINK="curl -k -v  -X PUT --header 'Content-Type: application/json' --header 'Accept: text/plain' --header 'ClientAuth: cHl0aG9uOnRlc3Q=' --header 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' --header 'Environment: TEST' -d '$BODY' 'https://localhost:8081/pdp/api/$CMD'"
-       LINK="${LINK/\"\\\"{\\n/\"{}"
-       LINK="${LINK/\\\"\"/\"}"
-       LINK="${LINK//\\n/ }"
-       echo "$LINK" >> $SCRIPT
-       BODY=`jo -p policyType=MicroService -p pdpGroup=default -p policyName=$NAME`
-       LINK="curl -k -v  -X PUT --header 'Content-Type: application/json' --header 'Accept: text/plain' --header 'ClientAuth: cHl0aG9uOnRlc3Q=' --header 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' --header 'Environment: TEST' -d '$BODY' 'https://localhost:8081/pdp/api/pushPolicy'"
-       echo "$LINK" >> $SCRIPT
-done
-
-`kubectl cp $SCRIPT onap/$PDP:/tmp/policy-install`
-`kubectl exec $PDP -- chmod 755 $SCRIPT`
-`kubectl exec $PDP -- ./$SCRIPT`
 
+kubectl cp $DIR/$SCRIPT onap/$API:/tmp/`
+kubectl exec $API -- chmod 755 /tmp/$SCRIPT`
+kubectl exec $API -- /tmp/$SCRIPT
index 240c732..71b5b2b 100644 (file)
@@ -1,44 +1,54 @@
 {
-    "service": "vnfPolicy",
-    "policyName": "OSDF_DUBLIN.vnfPolicy_vFW_TD",
-    "description": "vnfPolicy",
-    "templateVersion": "OpenSource.version.1",
-    "version": "OpenSource.version.1",
-    "priority": "6",
-    "riskType": "test",
-    "riskLevel": "3",
-    "guard": "False",
-    "content": {
-        "identity": "vnf_vFW_TD",
-        "policyScope": [
-            "td",
-            "us",
-            "vFW-SINK"
-        ],
-        "policyType": "vnfPolicy",
-        "resources": [
-            "vFW-SINK"
-        ],
-        "applicableResources": "any",
-        "vnfProperties": [
+    "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+    "topology_template": {
+        "policies": [
             {
-                "inventoryProvider": "aai",
-                "serviceType": "",
-                "inventoryType": "vfmodule",
-                "customerId": {
-                    "get_param": "chosen_customer_id"
-                },
-                "equipmentRole": "",
-                "attributes": {
-                    "orchestrationStatus": [
-                        "active"
-                    ],
-                    "provStatus": "ACTIVE",
-                    "cloudRegionId": {
-                        "get_param": "chosen_region"
+                "OSDF_FRANKFURT.vnfPolicy_vFW_TD": {
+                    "type": "onap.policies.optimization.resource.VnfPolicy",
+                    "version": "1.0.0",
+                    "type_version": "1.0.0",
+                    "metadata": {
+                        "policy-id": "OSDF_FRANKFURT.vnfPolicy_vFW_TD",
+                        "policy-version": 1
                     },
-                    "service_instance_id": {
-                        "get_param": "service_id"
+                    "properties": {
+                        "scope": [
+                            "OSDF_FRANKFURT",
+                            "TD"
+                        ],
+                        "resources": [
+                            "vFW-SINK"
+                        ],
+                        "geography": [
+                            "US"
+                        ],
+                        "identity": "vnf_vFW_TD",
+                        "applicableResources": "any",
+                        "vnfProperties": [
+                            {
+                                "inventoryProvider": "aai",
+                                "serviceType": "",
+                                "inventoryType": "vfmodule",
+                                "customerId": {
+                                    "get_param": "chosen_customer_id"
+                                },
+                                "equipmentRole": "",
+                                "attributes": {
+                                    "orchestrationStatus": [
+                                        "Active"
+                                    ],
+                                    "cloudRegionId": {
+                                        "get_param": "chosen_region"
+                                    },
+                                    "service_instance_id": {
+                                        "get_param": "service_id"
+                                    }
+                                },
+                                "passthroughAttributes": {
+                                    "td-role": "destination"
+                                }
+                            }
+                        ]
                     }
                 }
             }
diff --git a/tutorials/vFWDT/policies/rules/vnfPolicy_vFW_TD_push.json b/tutorials/vFWDT/policies/rules/vnfPolicy_vFW_TD_push.json
new file mode 100755 (executable)
index 0000000..cf97073
--- /dev/null
@@ -0,0 +1,8 @@
+{
+    "policies": [
+        {
+            "policy-id": "OSDF_FRANKFURT.vnfPolicy_vFW_TD",
+            "policy-version": "1.0.0"
+        }
+    ]
+}
index 277d7d0..6ae34e6 100644 (file)
@@ -1,44 +1,55 @@
 {
-    "service": "vnfPolicy",
-    "policyName": "OSDF_DUBLIN.vnfPolicy_vPGN_TD",
-    "description": "vnfPolicy",
-    "templateVersion": "OpenSource.version.1",
-    "version": "OpenSource.version.1",
-    "priority": "6",
-    "riskType": "test",
-    "riskLevel": "3",
-    "guard": "False",
-    "content": {
-        "identity": "vnf_vPGN_TD",
-        "policyScope": [
-            "td",
-            "us",
-            "vPGN"
-        ],
-        "policyType": "vnfPolicy",
-        "resources": [
-            "vPGN"
-        ],
-        "applicableResources": "any",
-        "vnfProperties": [
+    "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+    "topology_template": {
+        "policies": [
             {
-                "inventoryProvider": "aai",
-                "serviceType": "",
-                "inventoryType": "vfmodule",
-                "customerId": {
-                    "get_param": "chosen_customer_id"
-                },
-                "equipmentRole": "",
-                "attributes": {
-                    "orchestrationStatus": [
-                        "active"
-                    ],
-                    "provStatus": "ACTIVE",
-                    "cloudRegionId": {
-                        "get_param": "chosen_region"
+                "OSDF_FRANKFURT.vnfPolicy_vPGN_TD": {
+                    "type": "onap.policies.optimization.resource.VnfPolicy",
+                    "version": "1.0.0",
+                    "type_version": "1.0.0",
+                    "metadata": {
+                        "policy-id": "OSDF_FRANKFURT.vnfPolicy_vPGN_TD",
+                        "policy-version": 1
                     },
-                    "service_instance_id": {
-                        "get_param": "service_id"
+                    "properties": {
+                        "scope": [
+                            "OSDF_FRANKFURT",
+                            "TD"
+                        ],
+                        "resources": [
+                            "vPGN"
+                        ],
+                        "geography": [
+                            "US"
+                        ],
+                        "identity": "vnf_vPGN_TD",
+                        "applicableResources": "any",
+                        "vnfProperties": [
+                            {
+                                "inventoryProvider": "aai",
+                                "serviceType": "",
+                                "inventoryType": "vfmodule",
+                                "customerId": {
+                                    "get_param": "chosen_customer_id"
+                                },
+                                "equipmentRole": "",
+                                "unique": "False",
+                                "attributes": {
+                                    "orchestrationStatus": [
+                                        "Active"
+                                    ],
+                                    "cloudRegionId": {
+                                        "get_param": "chosen_region"
+                                    },
+                                    "service_instance_id": {
+                                        "get_param": "service_id"
+                                    }
+                                },
+                                "passthroughAttributes": {
+                                    "td-role": "anchor"
+                                }
+                            }
+                        ]
                     }
                 }
             }
diff --git a/tutorials/vFWDT/policies/rules/vnfPolicy_vPGN_TD_push.json b/tutorials/vFWDT/policies/rules/vnfPolicy_vPGN_TD_push.json
new file mode 100755 (executable)
index 0000000..074698e
--- /dev/null
@@ -0,0 +1,8 @@
+{
+    "policies": [
+        {
+            "policy-id": "OSDF_FRANKFURT.vnfPolicy_vPGN_TD",
+            "policy-version": "1.0.0"
+        }
+    ]
+}
index 1bd2ce5..61a0cd9 100644 (file)
@@ -44,7 +44,6 @@
             {
                 "resourceModuleName": "vPGN",
                 "serviceResourceId": "vPGN-XX",
-                "unique": "false",
                 "resourceModelInfo": {
                     "modelInvariantId": "f2f88e29-d571-49ef-aea3-b8d13900c16f",
                     "modelVersionId": "3ccebc76-66e1-47c8-aee9-98f30d08db97"
@@ -54,7 +53,7 @@
     },
     "serviceInfo": {
         "serviceInstanceId": "209fb01e-60ca-4325-b074-c5ad4e0499f8",
-        "serviceName": "TD",
+        "serviceName": "vFW_TD",
         "modelInfo": {
             "modelInvariantId": "TD-invariantId",
             "modelVersionId": "TD-versionId"