blob: 4de374a60e3aacf0ec5b8a9eef2e973c1abf55ef [file] [log] [blame]
ecaiyanlinux845bc002020-08-12 12:57:09 +02001#!/bin/bash
2
3# ============LICENSE_START===============================================
4# Copyright (C) 2020 Nordix Foundation. All rights reserved.
5# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
19
20# The scripts in data/ will generate some dummy data in the running system.
21# It will create:
22# one policy type in a1-sim-OSC
23# one service in policy agent
24# one policy in a1-sim-OSC
25# one policy in a1-sim-STD
26
27# Run command:
ecaiyanlinuxdc962f42020-10-19 11:13:12 +020028# ./prepareDmaapMsg.sh [dmaap-mr port] [a1-sim-OSC port] [a1-sim-STD port] [http/https]
ecaiyanlinux845bc002020-08-12 12:57:09 +020029
30dmaa_mr_port=${1:-3904}
31a1_sim_OSC_port=${2:-30001}
32a1_sim_STD_port=${3:-30003}
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010033a1_sim_STD_v1_port=${4:-30005}
34httpx=${5:-"http"}
ecaiyanlinux586432b2021-10-25 15:24:37 +020035SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
ecaiyanlinux845bc002020-08-12 12:57:09 +020036
37echo "using dmaap-mr port: "$dmaa_mr_port
38echo "using a1-sim-OSC port: "$a1_sim_OSC_port
39echo "using a1-sim-STD port: "$a1_sim_STD_port
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010040echo "using a1-sim-STD-v1 port: "$a1_sim_STD_v1_port
ecaiyanlinux845bc002020-08-12 12:57:09 +020041echo "using protocol: "$httpx
42echo -e "\n"
43
44echo "dmaap-mr topics:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010045curl -skw %{http_code} $httpx://localhost:$dmaa_mr_port/topics/listAll
ecaiyanlinux845bc002020-08-12 12:57:09 +020046echo -e "\n"
47
48echo "dmaap-mr create topic A1-POLICY-AGENT-READ:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010049curl -skw %{http_code} -X POST "$httpx://localhost:$dmaa_mr_port/topics/create" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"topicName\": \"A1-POLICY-AGENT-READ\", \"topicDescription\": \"test topic\", \"partitionCount\": 1, \"replicationCount\": 1, \"transactionEnabled\": \"false\"}"
ecaiyanlinux845bc002020-08-12 12:57:09 +020050echo -e "\n"
51
52echo "dmaap-mr create topic A1-POLICY-AGENT-WRITE:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010053curl -skw %{http_code} -X POST "$httpx://localhost:$dmaa_mr_port/topics/create" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"topicName\": \"A1-POLICY-AGENT-WRITE\", \"topicDescription\": \"test topic\", \"partitionCount\": 1, \"replicationCount\": 1, \"transactionEnabled\": \"false\"}"
ecaiyanlinux845bc002020-08-12 12:57:09 +020054echo -e "\n"
55
56echo "dmaap-mr topics:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010057curl -skw %{http_code} $httpx://localhost:$dmaa_mr_port/topics/listAll
ecaiyanlinux845bc002020-08-12 12:57:09 +020058echo -e "\n"
59
60echo "ric1 version:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010061curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/interface
ecaiyanlinux845bc002020-08-12 12:57:09 +020062echo -e "\n"
63
64echo "ric2 version:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010065curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/interface
ecaiyanlinux845bc002020-08-12 12:57:09 +020066echo -e "\n"
67
68echo "create policy type 1 to ric1:"
ecaiyanlinux586432b2021-10-25 15:24:37 +020069curl -X PUT -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/policytype?id=1 -H Content-Type:application/json --data-binary @${SHELL_FOLDER}/testdata/OSC/policy_type.json
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010070echo -e "\n"
71
72echo "create policy type 2 to ric3:"
ecaiyanlinux586432b2021-10-25 15:24:37 +020073curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_v1_port/policytype?id=2 -X PUT -H Accept:application/json -H Content-Type:application/json -H X-Requested-With:XMLHttpRequest --data-binary @${SHELL_FOLDER}/testdata/v2/policy_type.json
ecaiyanlinux845bc002020-08-12 12:57:09 +020074echo -e "\n"
75
76for i in {1..12}; do
77 echo "policy types from policy agent:"
78 curlString="curl -skw %{http_code} $httpx://localhost:8081/policy_types"
79 res=$($curlString)
80 echo "$res"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010081 expect="[\"\",\"1\",\"2\"]200"
ecaiyanlinux845bc002020-08-12 12:57:09 +020082 if [ "$res" == "$expect" ]; then
83 echo -e "\n"
84 break;
85 else
86 sleep $i
87 fi
88done
89
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010090## Using PMS v1 interface
ecaiyanlinux845bc002020-08-12 12:57:09 +020091echo "create service 1 to policy agent via dmaap_mr:"
ecaiyanlinux586432b2021-10-25 15:24:37 +020092curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-READ/" --data-binary @${SHELL_FOLDER}/testdata/dmaap/v1/dmaap-msg-service-create.json
ecaiyanlinux845bc002020-08-12 12:57:09 +020093echo -e "\n"
94
ecaiyanlinuxe29568d2021-05-27 14:18:21 +080095echo "get result from mr of previous request:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010096curl -X GET "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
ecaiyanlinux845bc002020-08-12 12:57:09 +020097echo -e "\n"
98
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +010099echo "create policies to ric1 & ric2 & ric3 with type1 and service1 via dmaa_mr:"
ecaiyanlinux586432b2021-10-25 15:24:37 +0200100curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-READ/" --data-binary @${SHELL_FOLDER}/testdata/dmaap/v1/dmaap-msg-policy-create.json
ecaiyanlinux845bc002020-08-12 12:57:09 +0200101echo -e "\n"
102
ecaiyanlinuxe29568d2021-05-27 14:18:21 +0800103echo "get result from mr of previous request:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100104curl -X GET "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
ecaiyanlinux845bc002020-08-12 12:57:09 +0200105echo -e "\n"
106
107echo "get policy from policy agent via dmaap_mr:"
ecaiyanlinux586432b2021-10-25 15:24:37 +0200108curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-READ/" --data-binary @${SHELL_FOLDER}/testdata/dmaap/v1/dmaap-msg-policy-get.json
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100109echo -e "\n"
110
ecaiyanlinuxe29568d2021-05-27 14:18:21 +0800111echo "get result from mr of previous request:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100112curl -X GET "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
113echo -e "\n"
114
115## Using PMS v2 interface
116echo "create service 2 to policy agent via dmaap_mr:"
ecaiyanlinux586432b2021-10-25 15:24:37 +0200117curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-READ/" --data-binary @${SHELL_FOLDER}/testdata/dmaap/v2/dmaap-msg-service-create.json
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100118echo -e "\n"
119
ecaiyanlinuxe29568d2021-05-27 14:18:21 +0800120echo "get result from mr of previous request:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100121curl -X GET "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
122echo -e "\n"
123
124echo "create policies to ric1 & ric2 & ric3 with type1 and service1 via dmaa_mr:"
ecaiyanlinux586432b2021-10-25 15:24:37 +0200125curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-READ/" --data-binary @${SHELL_FOLDER}/testdata/dmaap/v2/dmaap-msg-policy-create.json
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100126echo -e "\n"
127
ecaiyanlinuxe29568d2021-05-27 14:18:21 +0800128echo "get result from mr of previous request:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100129curl -X GET "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
130echo -e "\n"
131
132echo "get policy from policy agent via dmaap_mr:"
ecaiyanlinux586432b2021-10-25 15:24:37 +0200133curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-READ/" --data-binary @${SHELL_FOLDER}/testdata/dmaap/v2/dmaap-msg-policy-get.json
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100134echo -e "\n"
135
ecaiyanlinuxe29568d2021-05-27 14:18:21 +0800136echo "get result from mr of previous request:"
ecaiyanlinux0b47c2b2021-02-03 16:24:33 +0100137curl -X GET "$httpx://localhost:$dmaa_mr_port/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
138echo -e "\n"
139
140## Get metric from rics
141echo "policy numbers from ric1:"
142curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/num_instances
143echo -e "\n"
144
145echo "policy numbers from ric2:"
146curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/num_instances
147echo -e "\n"
148
149echo "policy numbers from ric3:"
150curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_v1_port/counter/num_instances
151echo -e "\n"
152