blob: 0a65a2e08f8f90c121b87e11bb7b75b5791f3c20 [file] [log] [blame]
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +08001#!/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:
28# ./prepareDmaapMsg.sh [dmaap-mr port] [a1-sim-OSC port] [a1-sim-STD port] [http/https]
29
30dmaa_mr_port=${1:-3904}
31a1_sim_OSC_port=${2:-30001}
32a1_sim_STD_port=${3:-30003}
33a1_sim_STD_v2_port=${4:-30005}
34httpx=${5:-"http"}
ecaiyanlinux331ccd82021-10-26 03:56:36 +020035SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +080036
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
40echo "using a1-sim-STD-v2 port: "$a1_sim_STD_v2_port
41echo "using protocol: "$httpx
42echo -e "\n"
43
44echo "dmaap-mr topics:"
45curl -skw %{http_code} $httpx://localhost:$dmaa_mr_port/topics/listAll
46echo -e "\n"
47
48echo "dmaap-mr create topic A1-POLICY-AGENT-READ:"
49curl -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\"}"
50echo -e "\n"
51
52echo "dmaap-mr create topic A1-POLICY-AGENT-WRITE:"
53curl -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\"}"
54echo -e "\n"
55
56echo "dmaap-mr topics:"
57curl -skw %{http_code} $httpx://localhost:$dmaa_mr_port/topics/listAll
58echo -e "\n"
59
60echo "ric1 version:"
61curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/interface
62echo -e "\n"
63
64echo "ric2 version:"
65curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/interface
66echo -e "\n"
67
68echo "ric3 version:"
69curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_v2_port/counter/interface
70echo -e "\n"
71
72echo "create policy type 1 to ric1:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +020073curl -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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +080074echo -e "\n"
75
76echo "create policy type 2 to ric3:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +020077curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_v2_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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +080078echo -e "\n"
79
80for i in {1..12}; do
81 echo "policy types from policy agent:"
BjornMagnussonXAaed5eb42022-10-24 17:35:48 +020082 curlString="curl -skw %{http_code} $httpx://localhost:8091/a1-policy/v2/policy-types"
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +080083 res=$($curlString)
84 echo "$res"
BjornMagnussonXAaed5eb42022-10-24 17:35:48 +020085 expect="{\"policytype_ids\":[\"1\",\"2\"]}200"
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +080086 if [ "$res" == "$expect" ]; then
87 echo -e "\n"
88 break;
89 else
90 sleep $i
91 fi
92done
93
94## Using PMS v1 interface
95echo "create service 1 to policy agent via dmaap_mr:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +020096curl -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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +080097echo -e "\n"
98
99echo "get result from mr of previous request:"
100curl -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 .
101echo -e "\n"
102
103echo "create policies to ric1 & ric2 & ric3 with type1 and service1 via dmaa_mr:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +0200104curl -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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +0800105echo -e "\n"
106
107echo "get result from mr of previous request:"
108curl -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 .
109echo -e "\n"
110
111echo "get policy from policy agent via dmaap_mr:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +0200112curl -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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +0800113echo -e "\n"
114
115echo "get result from mr of previous request:"
116curl -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 .
117echo -e "\n"
118
119## Using PMS v2 interface
120echo "create service 2 to policy agent via dmaap_mr:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +0200121curl -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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +0800122echo -e "\n"
123
124echo "get result from mr of previous request:"
125curl -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 .
126echo -e "\n"
127
128echo "create policies to ric1 & ric2 & ric3 with type1 and service1 via dmaa_mr:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +0200129curl -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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +0800130echo -e "\n"
131
132echo "get result from mr of previous request:"
133curl -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 .
134echo -e "\n"
135
136echo "get policy from policy agent via dmaap_mr:"
ecaiyanlinux331ccd82021-10-26 03:56:36 +0200137curl -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
ecaiyanlinuxf44c0a42021-05-31 20:04:53 +0800138echo -e "\n"
139
140echo "get result from mr of previous request:"
141curl -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 .
142echo -e "\n"
143
144## Get metric from rics
145echo "policy numbers from ric1:"
146curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/num_instances
147echo -e "\n"
148
149echo "policy numbers from ric2:"
150curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/num_instances
151echo -e "\n"
152
153echo "policy numbers from ric3:"
154curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_v2_port/counter/num_instances
155echo -e "\n"
156