Reorganize kafka module
[dcaegen2/collectors/hv-ves.git] / development / bin / xnf-simulation.sh
1 #!/usr/bin/env bash
2 # ============LICENSE_START=======================================================
3 # dcaegen2-collectors-veshv
4 # ================================================================================
5 # Copyright (C) 2018 NOKIA
6 # ================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=========================================================
19
20 set -euo pipefail
21
22 usage() {
23     echo "Send request to xnf-simulator"
24     echo "Usage: $0 [-h|--help] [-v|--verbose] [<xnf listen port> [<messages amount> [<messages type> [<xnf endpoint>]]]]"
25     echo ""
26     echo "Default values:"
27     echo "  - xnf listen port : 6062"
28     echo "  - messages amount : 1"
29     echo "  - messages type : VALID"
30     echo "  - xnf endpoint : simulator/async"
31     echo "Example invocations:"
32     echo "./xnf-simulation.sh -v 6062 1000 VALID"
33     exit 1
34 }
35
36 optspec=":vh-:" # catch v, h and -
37 while getopts "$optspec" arg; do
38     case "${arg}" in
39         -) # handle longopts
40             case "${OPTARG}" in
41                 verbose)
42                     VERBOSE=True
43                     ;;
44                 help)
45                     usage
46                     ;;
47                 *)
48                     echo "Unknown option --${OPTARG}" >&2
49                     usage
50                     ;;
51              esac
52              ;;
53         v)
54             VERBOSE=True
55             ;;
56         h)
57             usage
58             ;;
59         *)
60             echo "Unknown option -${OPTARG}" >&2
61             usage
62             ;;
63     esac
64 done
65 shift $((OPTIND-1))
66
67 XNF_PORT=${1:-6062}
68 MESSAGES_AMOUNT=${2:-1}
69 MESSAGES_TYPE=${3:-VALID}
70 XNF_ENDPOINT=simulator/async
71
72 if [ -n "${VERBOSE+x}" ]; then
73     echo "Requesting xnf-simulator on port ${XNF_PORT} to send ${MESSAGES_AMOUNT} messages of type ${MESSAGES_TYPE}"
74 fi
75
76 currentTimeMicros=$((`date +%s%N`/1000))
77 REQUEST_ID=$(curl --request POST -s --header 'Content-Type: application/json' localhost:${XNF_PORT}/${XNF_ENDPOINT} -d "
78 [
79   {
80     \"commonEventHeader\": {
81       \"version\": \"sample-version\",
82       \"domain\": \"perf3gpp\",
83       \"sequence\": 1,
84       \"priority\": 1,
85       \"eventId\": \"sample-event-id\",
86       \"eventName\": \"sample-event-name\",
87       \"eventType\": \"sample-event-type\",
88       \"startEpochMicrosec\": 120034455,
89       \"lastEpochMicrosec\": $currentTimeMicros,
90       \"nfNamingCode\": \"sample-nf-naming-code\",
91       \"nfcNamingCode\": \"sample-nfc-naming-code\",
92       \"reportingEntityId\": \"sample-reporting-entity-id\",
93       \"reportingEntityName\": \"sample-reporting-entity-name\",
94       \"sourceId\": \"sample-source-id\",
95       \"sourceName\": \"sample-source-name\",
96       \"vesEventListenerVersion\": \"7.2.0\"
97     },
98     \"messageType\": \"${MESSAGES_TYPE}\",
99     \"messagesAmount\": ${MESSAGES_AMOUNT}
100   }
101 ]")
102
103 if [ -n "${VERBOSE+x}" ]; then
104     echo -e "Request id: ${REQUEST_ID}\n"
105
106     echo "To check request status execute:"
107     echo "curl --request GET localhost:${XNF_PORT}/simulator/${REQUEST_ID}"
108     echo "To further debug you can try something similiar to:"
109     echo "docker ps -a | grep ${XNF_PORT} | awk '{ print \$1 }' | xargs docker logs"
110 else
111     echo "${REQUEST_ID}"
112 fi