Alexis de Talhouƫt | 5ce713e | 2017-12-07 15:58:25 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | if [ "$#" -ne 4 ]; then |
| 4 | echo "Usage: $(basename $0) <k8s-host> <policy-pdp-node-port> <policy-drools-node-port> <resource-id>" |
| 5 | exit 1 |
| 6 | fi |
| 7 | |
| 8 | K8S_HOST=$1 |
| 9 | POLICY_PDP_PORT=$2 |
| 10 | POLICY_DROOLS_PORT=$3 |
| 11 | RESOURCE_ID=$4 |
| 12 | |
| 13 | echo |
| 14 | echo |
| 15 | echo "Removing the vFW Policy from PDP.." |
| 16 | echo |
| 17 | echo |
| 18 | |
| 19 | curl -v -X DELETE --header 'Content-Type: application/json' --header 'Accept: text/plain' --header 'ClientAuth: cHl0aG9uOnRlc3Q=' --header 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' --header 'Environment: TEST' -d '{ |
| 20 | "pdpGroup": "default", |
| 21 | "policyComponent" : "PDP", |
| 22 | "policyName": "com.BRMSParamvFirewall", |
| 23 | "policyType": "BRMS_Param" |
| 24 | }' http://${K8S_HOST}:${POLICY_PDP_PORT}/pdp/api/deletePolicy |
| 25 | |
| 26 | sleep 20 |
| 27 | |
| 28 | echo |
| 29 | |
| 30 | echo |
| 31 | echo "Updating vFW Operational Policy .." |
| 32 | echo |
| 33 | |
| 34 | curl -v -X PUT --header 'Content-Type: application/json' --header 'Accept: text/plain' --header 'ClientAuth: cHl0aG9uOnRlc3Q=' --header 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' --header 'Environment: TEST' -d '{ |
| 35 | "policyConfigType": "BRMS_PARAM", |
| 36 | "policyName": "com.BRMSParamvFirewall", |
| 37 | "policyDescription": "BRMS Param vFirewall policy", |
| 38 | "policyScope": "com", |
| 39 | "attributes": { |
| 40 | "MATCHING": { |
| 41 | "controller": "amsterdam" |
| 42 | }, |
| 43 | "RULE": { |
| 44 | "templateName": "ClosedLoopControlName", |
| 45 | "closedLoopControlName": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a", |
| 46 | "controlLoopYaml": "controlLoop%3A%0D%0A++version%3A+2.0.0%0D%0A++controlLoopName%3A+ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a%0D%0A++trigger_policy%3A+unique-policy-id-1-modifyConfig%0D%0A++timeout%3A+1200%0D%0A++abatement%3A+false%0D%0A+%0D%0Apolicies%3A%0D%0A++-+id%3A+unique-policy-id-1-modifyConfig%0D%0A++++name%3A+modify+packet+gen+config%0D%0A++++description%3A%0D%0A++++actor%3A+APPC%0D%0A++++recipe%3A+ModifyConfig%0D%0A++++target%3A%0D%0A++++++%23+TBD+-+Cannot+be+known+until+instantiation+is+done%0D%0A++++++resourceID%3A+'${RESOURCE_ID}'%0D%0A++++++type%3A+VNF%0D%0A++++retry%3A+0%0D%0A++++timeout%3A+300%0D%0A++++success%3A+final_success%0D%0A++++failure%3A+final_failure%0D%0A++++failure_timeout%3A+final_failure_timeout%0D%0A++++failure_retries%3A+final_failure_retries%0D%0A++++failure_exception%3A+final_failure_exception%0D%0A++++failure_guard%3A+final_failure_guard" |
| 47 | } |
| 48 | } |
| 49 | }' http://${K8S_HOST}:${POLICY_PDP_PORT}/pdp/api/updatePolicy |
| 50 | |
| 51 | sleep 5 |
| 52 | |
| 53 | echo |
| 54 | echo |
| 55 | echo "Pushing the vFW Policy .." |
| 56 | echo |
| 57 | echo |
| 58 | |
| 59 | curl -v --silent -X PUT --header 'Content-Type: application/json' --header 'Accept: text/plain' --header 'ClientAuth: cHl0aG9uOnRlc3Q=' --header 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' --header 'Environment: TEST' -d '{ |
| 60 | "pdpGroup": "default", |
| 61 | "policyName": "com.BRMSParamvFirewall", |
| 62 | "policyType": "BRMS_Param" |
| 63 | }' http://${K8S_HOST}:${POLICY_PDP_PORT}/pdp/api/pushPolicy |
| 64 | |
| 65 | sleep 20 |
| 66 | |
| 67 | echo |
| 68 | echo |
| 69 | echo "Restarting PDP-D .." |
| 70 | echo |
| 71 | echo |
| 72 | |
| 73 | POD=$(kubectl --namespace onap-policy get pods | sed 's/ .*//'| grep drools) |
| 74 | kubectl --namespace onap-policy exec -it ${POD} -- bash -c "source /opt/app/policy/etc/profile.d/env.sh && policy stop && sleep 5 && policy start" |
| 75 | |
| 76 | sleep 20 |
| 77 | |
| 78 | echo |
| 79 | echo |
| 80 | echo "PDP-D amsterdam maven coordinates .." |
| 81 | echo |
| 82 | echo |
| 83 | |
| 84 | curl -vvv --silent --user @1b3rt:31nst31n -X GET http://${K8S_HOST}:${POLICY_DROOLS_PORT}/policy/pdp/engine/controllers/amsterdam/drools | python -m json.tool |
| 85 | |
| 86 | |
| 87 | echo |
| 88 | echo |
| 89 | echo "PDP-D control loop updated .." |
| 90 | echo |
| 91 | echo |
| 92 | |
| 93 | curl -v --silent --user @1b3rt:31nst31n -X GET http://${K8S_HOST}:${POLICY_DROOLS_PORT}/policy/pdp/engine/controllers/amsterdam/drools/facts/closedloop-amsterdam/org.onap.policy.controlloop.Params | python -m json.tool |