blob: 5e8b2d5acb4ea4780b620107d20a403b3a213e39 [file] [log] [blame]
Pawel Kadlubanski8d0066e2018-05-11 14:35:43 +02001#!/usr/bin/env bash
2
3set -euo pipefail
4
5CONTAINER_NAME=pnf-simulator
6CONFIG_FILE_PATH=/config/body.json
Pawel Kadlubanski8ad02132018-05-24 12:30:11 +02007SIMULATOR_DOCKER_HUB=nexus3.onap.org:10003/onap
Pawel Kadlubanski8d0066e2018-05-11 14:35:43 +02008SIMULATOR_TAG=latest
9
10function main(){
11
12 COMMAND=${1:-"help"}
13
14 case $COMMAND in
15 "build")
16 build_image;;
17 "start")
18 start_simulator $2 $CONFIG_FILE_PATH $SIMULATOR_DOCKER_HUB/pnf-simulator:$SIMULATOR_TAG;;
19 "start-dev")
20 start_simulator $2 $CONFIG_FILE_PATH pnf-simulator:$SIMULATOR_TAG;;
21 "stop")
22 stop_simulator;;
23 "status")
24 print_status;;
25 "logs")
26 get_logs;;
27 "help")
28 print_help;;
29 *)
30 print_help;;
31 esac
32}
33
34function build_image(){
35 if [ -f pom.xml ]; then
36 mvn clean package
37 else
38 echo "pom.xml file not found"
39 exit 1
40 fi
41}
42
43function start_simulator(){
44
45 stop_and_remove_container || true
46
47 if [ $(docker run -d --name $CONTAINER_NAME -v $(pwd):/config -e VES_ADDRESS=$1 -e CONFIG_FILE_PATH=$2 $3) > /dev/null ]; then
48 echo "Simulator started"
49 else
50 echo "Failed to start simulator"
51 fi
52}
53
54function stop_and_remove_container(){
55 docker rm -f $CONTAINER_NAME 1> /dev/null
56}
57
58function stop_simulator(){
59 if [ $(docker kill $CONTAINER_NAME) > /dev/null ]; then
60 echo "Simulator stopped"
61 else
62 echo "Failed to stop simulator"
63 fi
64
65}
66
67function print_status(){
68cat << EndOfMessage
69
70Simulator container status:
71
72$(docker ps -a -f name=$CONTAINER_NAME)
73
74EndOfMessage
75}
76
77function print_help(){
78cat << EndOfMessage
79
80Available options:
81build - locally builds simulator image from existing code
82start <ves-url> - starts simulator using remote docker image and connects to given VES server
83start-dev <ves-url> - starts simulator using local docker image and connects to given VES server
84stop - stops simulator
85status - prints container status
86logs - prints logs
87help - prints this message
88
89Starting simulation:
90Use "./simulator.sh start". It will download required docker image from the internet and start simulator using body.json file
91
92To stop simulation use "./simulator.sh stop" command. To check simulator's status use "./simulator.sh status".
93If you want to change message parameters simply edit body.json file then run simulator again.
94
95FOR DEVELOPERS
961. Build local simulator image using "./simulator.sh build"
972. Run simulation with "./simulator.sh start-dev"
98
99If you change the source code you have to rebuild image with "./simulator.sh build" and run "./simulator.sh start-dev" again
100
101EndOfMessage
102}
103
104function get_logs(){
105 docker logs --tail all $CONTAINER_NAME
106}
107
108main $@