Add Bronze Get Started demo scripts
[it/dep.git] / demos / bronze / a1-ric.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, or CTRL-C to abort" mainmenuinput
23   echo
24 }
25
26
27 echo "This scripts demonstrates the Bronze release Traffic Steering use case, as well as the RIC part of the SMO A1 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 three xApps: Traffic Steering, Quality Predictor, and Quality Predictor Driver."
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 acknowledge "A \"Created\" status indicates on-boarding successful."
52
53 echo "======> Listing on boarded xApps"
54 curl --location --request GET "http://$(hostname):32080/onboard/api/v1/charts"
55 acknowledge "Verify that the on-boarded xApps indeed are listed."
56
57 echo "====>  Deploy xApps"
58 curl --location --request POST "http://$(hostname):32080/appmgr/ric/v1/xapps" \
59      --header 'Content-Type: application/json' --data-raw '{"xappName": "qp"}'
60 # response: {"instances":null,"name":"qp","status":"deployed","version":"1.0"}
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 curl --location --request POST "http://$(hostname):32080/appmgr/ric/v1/xapps" \
65      --header 'Content-Type: application/json' --data-raw '{"xappName": "trafficxapp"}'
66 # response: {"instances":null,"name":"trafficxapp","status":"deployed","version":"1.0"}
67 acknowledge "A \"deployed\" status indicates that the xApp has been deployed."
68
69
70 echo "======> Status of xApps"
71 kubectl get pods -n ricxapp
72
73
74 echo -n "Waiting for all newly deployed xApp pod(s) reaching running state."
75 POD_QP=""
76 POD_QPD=""
77 POD_TS=""
78 while [ -z $POD_QP ] || [ -z $POD_QPD ] || [ -z $POD_TS ]; do
79   echo -n "."
80   sleep 5
81   POD_QP=$(kubectl get pods -n ricxapp | grep Running | grep "\-qp\-" | cut -f1 -d ' ')
82   POD_QPD=$(kubectl get pods -n ricxapp | grep Running | grep "\-qpdriver\-" | cut -f1 -d ' ')
83   POD_TS=$(kubectl get pods -n ricxapp | grep Running | grep "\-trafficxapp\-" | cut -f1 -d ' ')
84 done
85 echo && echo "Now all newly deployed xApp(s) have reached running state"
86
87
88 POD_A1=$(kubectl get pods -n ricplt | grep Running | grep "\-a1mediator\-" | cut -f1 -d ' ')
89 echo
90 echo "To view the logs of the A1 midiator, run the following "
91 echo "command in a separate terminal window:"
92 echo "  kubectl logs -f -n ricplt $POD_A1"
93
94 echo "To view the logs of the Traffic Steering xapp, run the following "
95 echo "command in a separate terminal window:"
96 echo "  kubectl logs -f -n ricxapp $POD_TS"
97
98 acknowledge "When ready, "
99
100
101 # populate DB
102 echo && echo "===> Inject DBaaS (RNIB) with testing data for Traffic Steering test"
103 if [ ! -e ts ]; then
104   git clone http://gerrit.o-ran-sc.org/r/ric-app/ts
105 fi
106 pushd "$(pwd)"
107 cd ts/test/populatedb
108 ./populate_db.sh
109 popd
110 acknowledge "RNIB populated.  The Traffic Steering xApp's log should inicate that it is reading RAN data.  When ready for the next step, "
111
112
113 POLICY_TYPE_ID="20008"
114 echo "====>  Creating policy type ${POLICY_TYPE_ID} via A1"
115 cat << EOF > ts-policy-type-${POLICY_TYPE_ID}.json
116 {
117   "name": "tsapolicy",
118   "description": "tsa parameters",
119   "policy_type_id": ${POLICY_TYPE_ID},
120   "create_schema": {
121     "\$schema": "http://json-schema.org/draft-07/schema#",
122     "title": "TS Policy",
123     "description": "TS policy type",
124     "type": "object",
125     "properties": {
126       "threshold": {
127         "type": "integer",
128         "default": 0
129       }
130     },
131     "additionalProperties": false
132   }
133 }
134 EOF
135 echo "A policy type definition file ts-policy-type-${POLICY_TYPE_ID}.json has been created."
136 echo && acknowledge "The next command will create a new policy type via A1 Mediator using this definition file.  Watch the logs of A1 Mediator for confirmation."
137
138
139 curl -v -X PUT "http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}" \
140   -H "accept: application/json" -H "Content-Type: application/json" \
141   -d @./ts-policy-type-${POLICY_TYPE_ID}.json
142 # expect to see a 201
143 acknowledge "A 201 response indicates that the new policy type has been created."
144
145
146 echo "======> Listing policy types"
147 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
148   http://$(hostname):32080/a1mediator/a1-p/policytypes
149 acknowledge "Verify that the policy type ${POLICY_TYPE_ID} is in the listing."
150
151 echo && acknowledge "The next steps will be carried out in the SMO cluster by the a1-smo.sh script.  After being suggested by the a1-smo.sh script to come back to tis script, " 
152
153 POLICY_ID="tsapolicy145"
154 if [ "${LOCAL_POLICY_INSTANCE}" = "Y" ]; then
155   echo && acknowledge "The next command will create a new policy instance.  Watch the logs of A1 Mediator and TS xApp"
156
157   echo "===> Deploy policy ID of ${POLICY_ID} of policy type ${POLICY_TYPE_ID}"
158   curl -X PUT --header "Content-Type: application/json" \
159     --data "{\"threshold\" : 5}" \
160     http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies/${POLICY_ID}
161   acknowledge "A 202 response indicates that the new policy instance has been created.  In additoin, A1 Mediator and HW xApp log would indicate that the new policy instance has been distributed from A1 Mediator to the xApp."
162
163
164   # get policy instances
165   echo "======> Listing policy instances"
166   curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
167     http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
168   acknowledge "Verify that the new policy instance appears in the policy list.  Also watch the A1 Mediator and TS xApp log for policyc distribution, and how TS xApp processes the RNIB data following the new policy instance (with updated treshold)."
169
170 fi
171
172
173 echo && acknowledge "The above sequence has completed the Hello World xApp on-boarding, deployment, and policy distribution demonstration.  The remaining part of the script cleans up the three xApps, and the policy type from the Near RT RIC"
174
175 if [ "${LOCAL_POLICY_INSTANCE}" = "Y" ]; then
176   echo && echo "===> Deleting policy instance ${POLICY_ID} of type ${POLICY_TYPE_ID}"
177   acknowledge "The next command will delete a policy instance.  Watch the logs of A1 Mediator andd TS xApp"
178   curl -X DELETE --header "Content-Type: application/json" --header "accept: application/json" \
179   http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies/${POLICY_ID}
180   sleep 5
181
182   echo && echo "======> Listing policy instances"
183   curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
184     http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
185 fi
186
187 echo && echo "===> Deleting policy type $POLICY_TYPE_ID"
188 acknowledge "The next command will delete a policy type.  Watch the logs of A1 Mediator."
189 curl -X DELETE -H "accept: application/json" -H "Content-Type: application/json" \
190   "http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}"
191 sleep 5
192
193 echo && echo "======> Listing policy types"
194 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
195   http://$(hostname):32080/a1mediator/a1-p/policytypes
196
197 echo && echo "===> Undeploy the xApps"
198 acknowledge "The next command will delete the TS, QP, and DPQ xApps."
199 curl -H "Content-Type: application/json" -X DELETE \
200   http://$(hostname):32080/appmgr/ric/v1/xapps/trafficxapp
201 curl -H "Content-Type: application/json" -X DELETE \
202   http://$(hostname):32080/appmgr/ric/v1/xapps/qp
203 curl -H "Content-Type: application/json" -X DELETE \
204   http://$(hostname):32080/appmgr/ric/v1/xapps/qpdriver
205 sleep 5
206
207 echo && echo "======> Listing xApps"
208 kubectl get pods -n ricxapp
209
210
211 echo
212 echo "That is all folks.  Thanks!"