2 ################################################################################
3 # Copyright (c) 2020 AT&T Intellectual Property. #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 ################################################################################
22 read -n 1 -p "Press any key to continue, or CTRL-C to abort" mainmenuinput
27 acknowledge "This script demonstrates the deployment of HelloWorld xApp."
28 DIRNAME="/tmp/tsflow-$(date +%Y%m%d%H%M)"
32 echo "===> Generating xApp on-boarding file"
34 "config-file.json_url": "https://gerrit.o-ran-sc.org/r/gitweb?p=ric-app/hw.git;a=blob_plain;f=init/config-file.json;hb=HEAD"
38 echo "===> On-boarding xApps"
39 curl --location --request POST "http://$(hostname):32080/onboard/api/v1/onboard/download" \
40 --header 'Content-Type: application/json' --data-binary "@./onboard.hw.url"
41 acknowledge "A \"Created\" status indicates on-boarding successful."
43 echo "======> Listing on boarded xApps"
44 curl --location --request GET "http://$(hostname):32080/onboard/api/v1/charts"
45 acknowledge "Verify that the on-boarded xApp indeed is listed."
47 echo "===> Deploy xApps"
48 curl --location --request POST "http://$(hostname):32080/appmgr/ric/v1/xapps" \
49 --header 'Content-Type: application/json' --data-raw '{"xappName": "hwxapp"}'
50 acknowledge "A \"deployed\" status indicates that the xApp has been deployed."
51 # response: {"instances":null,"name":"trafficxapp","status":"deployed","version":"1.0"}
54 echo -n "Waiting for all newly deployed xApp pod(s) reaching running state."
55 while [ -z $POD_HW ]; do
58 POD_HW=$(kubectl get pods -n ricxapp | grep Running | grep "\-hwxapp\-" | cut -f1 -d ' ')
60 echo && echo "Now all newly deployed xApp(s) have reached running state"
62 echo && echo "======> Status of xApps"
63 kubectl get pods -n ricxapp
65 POD_A1=$(kubectl get pods -n ricplt | grep Running | grep "\-a1mediator\-" | cut -f1 -d ' ')
67 echo "To view the logs of the A1 midiator, run the following "
68 echo "command in a separate terminal window:"
69 echo " kubectl logs -f -n ricplt $POD_A1"
71 echo "To view the logs of the Hello World xapp, run the following "
72 echo "command in a separate terminal window:"
73 echo " kubectl logs -f -n ricxapp $POD_HW"
75 acknowledge "When ready, "
79 echo "====> Pushing policy type to A1"
81 cat << EOF > hw-policy-type-${POLICY_TYPE_ID}.json
84 "description": "Hellow World policy type",
85 "policy_type_id": ${POLICY_TYPE_ID},
87 "\$schema": "http://json-schema.org/draft-07/schema#",
89 "description": "HW policy type",
97 "additionalProperties": false
101 echo "A policy type definition file hw-policy-type-${POLICY_TYPE_ID}.json has been created."
102 echo && acknowledge "The next command will create a new policy type via A1 Mediator using this definition file. Watch the logs of A1 Mediator."
103 curl -v -X PUT "http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}" \
104 -H "accept: application/json" -H "Content-Type: application/json" \
105 -d @./hw-policy-type-${POLICY_TYPE_ID}.json
106 # expect to see a 201
107 acknowledge "A 201 response indicates that the new policy type has been created."
109 echo && echo "======> Listing policy types"
110 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
111 http://$(hostname):32080/a1mediator/a1-p/policytypes
112 acknowledge "Verify that the policy type ${POLICY_TYPE_ID} is in the listing."
115 echo && acknowledge "The next command will create a new policy instance of the newly created policy type. Watch the logs of A1 Mediator and HW xApp."
116 POLICY_ID="hwpolicy321"
117 echo && echo "===> Deploy policy ID of ${POLICY_ID} of policy type ${POLICY_TYPE_ID}"
118 curl -v -X PUT --header "Content-Type: application/json" \
119 --data "{\"threshold\" : 9}" \
120 http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies/${POLICY_ID}
121 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."
123 # get policy instances
124 echo && echo "======> Listing policy instances of policy type ${POLICY_TYPE_ID}"
125 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
126 http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
127 acknowledge "Verify that the new policy instance appears in the policy list"
130 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 HW xApp, policy type, and policy instance from the Near RT RIC"
132 echo && echo "===> Deleting policy instance ${POLICY_ID} of type ${POLICY_TYPE_ID}"
133 acknowledge "The next command will delete a policy instance. Watch the logs of A1 Mediator andd HW xApp"
134 curl -X DELETE --header "Content-Type: application/json" --header "accept: application/json" \
135 http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies/${POLICY_ID}
138 echo && echo "======> Listing policy instances"
139 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
140 http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
142 echo && echo "===> Deleting policy type $POLICY_TYPE_ID"
143 acknowledge "The next command will delete a policy type. Watch the logs of TS xApp"
144 curl -X DELETE -H "accept: application/json" -H "Content-Type: application/json" \
145 "http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}"
148 echo && echo "======> Listing policy types"
149 curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
150 http://$(hostname):32080/a1mediator/a1-p/policytypes
153 echo && echo "===> Undeploy the xApps"
154 acknowledge "The next command will delete the HW xApp."
155 curl -H "Content-Type: application/json" -X DELETE \
156 http://$(hostname):32080/appmgr/ric/v1/xapps/hwxapp
159 echo && echo "======> Listing xApps"
160 kubectl get pods -n ricxapp
163 echo "That is all folks. Thanks!"