blob: 31604fd383ade6525e44e798c58063c35de19da2 [file] [log] [blame]
Lusheng Ji37534a52020-08-02 21:25:26 -04001#!/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
20acknowledge() {
21 echo "$1"
22 read -n 1 -p "Press any key to continue, or CTRL-C to abort" mainmenuinput
23 echo
24}
25
26
27acknowledge "This script demonstrates the deployment of HelloWorld xApp."
28DIRNAME="/tmp/tsflow-$(date +%Y%m%d%H%M)"
29mkdir $DIRNAME
30cd $DIRNAME
31
32echo "===> Generating xApp on-boarding file"
33echo '{
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"
35}' > onboard.hw.url
36
37
38echo "===> On-boarding xApps"
39curl --location --request POST "http://$(hostname):32080/onboard/api/v1/onboard/download" \
40 --header 'Content-Type: application/json' --data-binary "@./onboard.hw.url"
41acknowledge "A \"Created\" status indicates on-boarding successful."
42
43echo "======> Listing on boarded xApps"
44curl --location --request GET "http://$(hostname):32080/onboard/api/v1/charts"
45acknowledge "Verify that the on-boarded xApp indeed is listed."
46
47echo "===> Deploy xApps"
48curl --location --request POST "http://$(hostname):32080/appmgr/ric/v1/xapps" \
49 --header 'Content-Type: application/json' --data-raw '{"xappName": "hwxapp"}'
50acknowledge "A \"deployed\" status indicates that the xApp has been deployed."
51# response: {"instances":null,"name":"trafficxapp","status":"deployed","version":"1.0"}
52
53POD_HW=""
54echo -n "Waiting for all newly deployed xApp pod(s) reaching running state."
55while [ -z $POD_HW ]; do
56 echo -n "."
57 sleep 5
58 POD_HW=$(kubectl get pods -n ricxapp | grep Running | grep "\-hwxapp\-" | cut -f1 -d ' ')
59done
60echo && echo "Now all newly deployed xApp(s) have reached running state"
61
62echo && echo "======> Status of xApps"
63kubectl get pods -n ricxapp
64
65POD_A1=$(kubectl get pods -n ricplt | grep Running | grep "\-a1mediator\-" | cut -f1 -d ' ')
66echo
67echo "To view the logs of the A1 midiator, run the following "
68echo "command in a separate terminal window:"
69echo " kubectl logs -f -n ricplt $POD_A1"
70
71echo "To view the logs of the Hello World xapp, run the following "
72echo "command in a separate terminal window:"
73echo " kubectl logs -f -n ricxapp $POD_HW"
74
75acknowledge "When ready, "
76
77
78
79echo "====> Pushing policy type to A1"
80POLICY_TYPE_ID="1"
81cat << EOF > hw-policy-type-${POLICY_TYPE_ID}.json
82{
83 "name": "hwpolicy",
84 "description": "Hellow World policy type",
85 "policy_type_id": ${POLICY_TYPE_ID},
86 "create_schema": {
87 "\$schema": "http://json-schema.org/draft-07/schema#",
88 "title": "HW Policy",
89 "description": "HW policy type",
90 "type": "object",
91 "properties": {
92 "threshold": {
93 "type": "integer",
94 "default": 0
95 }
96 },
97 "additionalProperties": false
98 }
99}
100EOF
101echo "A policy type definition file hw-policy-type-${POLICY_TYPE_ID}.json has been created."
102echo && acknowledge "The next command will create a new policy type via A1 Mediator using this definition file. Watch the logs of A1 Mediator."
103curl -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
107acknowledge "A 201 response indicates that the new policy type has been created."
108
109echo && echo "======> Listing policy types"
110curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
111 http://$(hostname):32080/a1mediator/a1-p/policytypes
112acknowledge "Verify that the policy type ${POLICY_TYPE_ID} is in the listing."
113
114
115echo && 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."
116POLICY_ID="hwpolicy321"
117echo && echo "===> Deploy policy ID of ${POLICY_ID} of policy type ${POLICY_TYPE_ID}"
118curl -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}
121acknowledge "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."
122
123# get policy instances
124echo && echo "======> Listing policy instances of policy type ${POLICY_TYPE_ID}"
125curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
126 http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
127acknowledge "Verify that the new policy instance appears in the policy list"
128
129
130echo && 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"
131
132echo && echo "===> Deleting policy instance ${POLICY_ID} of type ${POLICY_TYPE_ID}"
133acknowledge "The next command will delete a policy instance. Watch the logs of A1 Mediator andd HW xApp"
134curl -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}
136sleep 5
137
138echo && echo "======> Listing policy instances"
139curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
140 http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}/policies
141
142echo && echo "===> Deleting policy type $POLICY_TYPE_ID"
143acknowledge "The next command will delete a policy type. Watch the logs of TS xApp"
144curl -X DELETE -H "accept: application/json" -H "Content-Type: application/json" \
145 "http://$(hostname):32080/a1mediator/a1-p/policytypes/${POLICY_TYPE_ID}"
146sleep 5
147
148echo && echo "======> Listing policy types"
149curl -X GET --header "Content-Type: application/json" --header "accept: application/json" \
150 http://$(hostname):32080/a1mediator/a1-p/policytypes
151
152
153echo && echo "===> Undeploy the xApps"
154acknowledge "The next command will delete the HW xApp."
155curl -H "Content-Type: application/json" -X DELETE \
156 http://$(hostname):32080/appmgr/ric/v1/xapps/hwxapp
157sleep 5
158
159echo && echo "======> Listing xApps"
160kubectl get pods -n ricxapp
161
162echo
163echo "That is all folks. Thanks!"