Add Bronze Get Started demo scripts
[it/dep.git] / demos / bronze / xapp-ts.sh
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) 2020 AT&T Intellectual Property.                             #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17
18 #set -x
19
20 acknowledge() {
21   echo "$1"
22   read  -n 1 -p "Press any key to continue" mainmenuinput
23   echo
24 }
25
26
27 echo "This script demonstrates the phase one of the Bronze release Traffic Steering use case."
28 DIRNAME="/tmp/tsflow-$(date +%Y%m%d%H%M)"
29 mkdir $DIRNAME
30 cd $DIRNAME
31
32 echo "===>  Generating xApp on-boarding file"
33 echo '{
34   "config-file.json_url": "https://gerrit.o-ran-sc.org/r/gitweb?p=ric-app/qp.git;a=blob_plain;f=xapp-descriptor/config.json;hb=HEAD" 
35 }' > onboard.qp.url
36 echo '{
37   "config-file.json_url": "https://gerrit.o-ran-sc.org/r/gitweb?p=ric-app/qp-driver.git;a=blob_plain;f=xapp-descriptor/config.json;hb=HEAD"
38 }' > onboard.qpd.url
39 echo '{
40   "config-file.json_url": "https://gerrit.o-ran-sc.org/r/gitweb?p=ric-app/ts.git;a=blob_plain;f=xapp-descriptor/config.json;hb=HEAD"
41 }' > onboard.ts.url
42
43
44 echo "===>  On-boarding xApps"
45 curl --location --request POST "http://$(hostname):32080/onboard/api/v1/onboard/download" \
46      --header 'Content-Type: application/json' --data-binary "@./onboard.ts.url"
47 curl --location --request POST "http://$(hostname):32080/onboard/api/v1/onboard/download" \
48      --header 'Content-Type: application/json' --data-binary "@./onboard.qp.url"
49 curl --location --request POST "http://$(hostname):32080/onboard/api/v1/onboard/download" \
50      --header 'Content-Type: application/json' --data-binary "@./onboard.qpd.url"
51
52 echo "======> Listing on boarded xApps"
53 curl --location --request GET "http://$(hostname):32080/onboard/api/v1/charts"
54
55
56 echo "====>  Deploy xApps"
57 curl --location --request POST "http://$(hostname):32080/appmgr/ric/v1/xapps" \
58      --header 'Content-Type: application/json' --data-raw '{"xappName": "qp"}'
59 # response: {"instances":null,"name":"qp","status":"deployed","version":"1.0"}
60
61 curl --location --request POST "http://$(hostname):32080/appmgr/ric/v1/xapps" \
62      --header 'Content-Type: application/json' --data-raw '{"xappName": "qpdriver"}'
63 # response: {"instances":null,"name":"qpdriver","status":"deployed","version":"1.0"}
64
65 curl --location --request POST "http://$(hostname):32080/appmgr/ric/v1/xapps" \
66      --header 'Content-Type: application/json' --data-raw '{"xappName": "trafficxapp"}'
67 # response: {"instances":null,"name":"trafficxapp","status":"deployed","version":"1.0"}
68
69 echo "======> Status of xApps"
70 kubectl get pods -n ricxapp
71
72 POD_QP=""
73 POD_QPD=""
74 POD_TS=""
75 while [ -z $POD_QP ] || [ -z $POD_QPD ] || [ -z $POD_TS ]; do
76   echo "Not all new xApp pods are in running state."
77   sleep 5
78   POD_QP=$(kubectl get pods -n ricxapp | grep Running | grep "\-qp\-" | cut -f1 -d ' ')
79   POD_QPD=$(kubectl get pods -n ricxapp | grep Running | grep "\-qpdriver\-" | cut -f1 -d ' ')
80   POD_TS=$(kubectl get pods -n ricxapp | grep Running | grep "\-trafficxapp\-" | cut -f1 -d ' ')
81 done
82
83
84 POD_A1=$(kubectl get pods -n ricplt | grep Running | grep "\-a1mediator\-" | cut -f1 -d ' ')
85 echo "To view the logs of the A1 midiator, run the following "
86 echo "command in a separate terminal window:"
87 echo "  kubectl logs -f -n ricplt $POD_A1"
88
89 echo "To view the logs of the traffic steering xapp, run the following "
90 echo "command in a separate terminal window:"
91 echo "  kubectl logs -f -n ricplt $POD_TS"
92
93 acknowledge ""
94
95
96 # populate DB
97 echo "===> Inject DBaas with testing data for Traffic Steering test"
98 if [ ! -e ts ]; then
99   git clone http://gerrit.o-ran-sc.org/r/ric-xapp/ts
100 fi
101 pushd "$(pwd)"
102 cd ts/test/populatedb
103 ./populate_db.sh
104 popd
105
106
107 echo "====>  Pushing policy type to A1"
108 POLICY_TYPE_ID="20008"
109 cat << EOF > ts-policy-type-${POLICY_TYPE_ID}.json
110 {
111   "name": "tsapolicy",
112   "description": "tsa parameters",
113   "policy_type_id": ${POLICY_TYPE_ID},
114   "create_schema": {
115     "\$schema": "http://json-schema.org/draft-07/schema#",
116     "title": "TS Policy",
117     "description": "TS policy type",
118     "type": "object",
119     "properties": {
120       "threshold": {
121         "type": "integer",
122         "default": 0
123       }
124     },
125     "additionalProperties": false
126   }
127 }
128 EOF
129
130 acknowledge "The next command will create a new policy type.  Watch the logs of A1 Mediator"
131
132 curl -v -X PUT "http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}" \
133   -H "accept: application/json" -H "Content-Type: application/json" \
134   -d @./ts-policy-type-${POLICY_TYPE_ID}.json
135 # expect to see a 201
136
137 echo "======> Listing policy types"
138 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
139   http://$(hostname):32080/a1mediator/a1-p/policytypes
140
141 acknowledge "The next command will create a new policy instance.  Watch the logs of A1 Mediator and TS xApp"
142
143 POLICY_ID="tsapolicy145"
144 echo "===> Deploy policy ID of ${POLICY_ID}" of policy type ${POLICY_TYPE_ID}"
145 curl -X PUT --header "Content-Type: application/json" \
146   --data "{\"threshold\" : 5}" \
147   http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies/${POLICY_ID}
148
149 # get policy instances
150 echo "======> Listing policy instances"
151 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
152   http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
153
154 echo "Watch how TS processes the data retrieved from RNIB in TS logs"
155 acknowledge "After done we will start the removal process"
156
157
158 echo "===> Deleting policy instance"
159 acknowledge "The next command will delete a policy instance.  Watch the logs of A1 Mediator andd TS xApp"
160 curl -X DELETE --header "Content-Type: application/json" --header "accept: application/json" \
161   http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies/${POLICY_ID}
162
163 echo "======> Listing policy instances"
164 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
165   http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
166
167 echo "===> Deleting policy type $POLICY_TYPE_ID"
168 acknowledge "The next command will delete a policy type.  Watch the logs of TS xApp"
169 curl -X DELETE -H "accept: application/json" -H "Content-Type: application/json" \
170   "http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}"
171
172 echo "======> Listing policy types"
173 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
174   http://$(hostname):32080/a1mediator/a1-p/policytypes
175
176
177 echo "===> Unddeploy the xApps"
178 acknowledge "The next command will delete the TS, QP, and DPQ xApps."
179 curl -H "Content-Type: application/json" -X DELETE \
180   http://$(hostname):32080/appmgr/ric/v1/xapps/trafficxapp
181 curl -H "Content-Type: application/json" -X DELETE \
182   http://$(hostname):32080/appmgr/ric/v1/xapps/qp
183 curl -H "Content-Type: application/json" -X DELETE \
184   http://$(hostname):32080/appmgr/ric/v1/xapps/qpdriver
185
186 echo "======> Listing xApps"
187 kubectl get pods -n ricxapp
188