blob: aa5b2a7c413c454427e32beb02cf549e928f93f3 [file] [log] [blame]
marekpl03472762018-09-11 17:03:29 +02001description: Heat template for HV-VES simulator deployment
2
3heat_template_version: 2013-05-23
4
5parameters:
6 name: { description: Instance name, label: Name, type: string, default: hv-ves_sim }
7 flavor_name: { description: Instance flavor to be used, label: Flavor Name, type: string }
8 image_name: { description: Ubuntu 16.04 image to be used, label: Image Name, type: string }
9 private_net_id: { description: Private network id, label: Private Network ID, type: string }
10 private_subnet_id: { description: Private subnetwork id, label: Private Subnetwork ID, type: string }
11 public_net_id: { description: Public network id, label: Public Network ID, type: string }
12 security_group: { description: Security group to be used, label: Security Groups, type: string, default: default }
13 key_pair: { description: Key pair, label: Key Pair, type: string }
14 proxy: { description: Proxy, label: Proxy, type: string, default: "" }
15 mode: { description: Mode - standalone or integrated to ONAP (values - 'standalone' or 'onap'), label: Mode, type: string, default: "standalone" }
16 hvves_ip: { description: HV-VES IP, label: HV-VES IP, type: string, default: "" }
17 hvves_port: { description: HV-VES Port, label: HV-VES Port, type: string, default: "" }
18 nexus_port: { description: ONAP Nexus Port, label: ONAP Nexus Port, type: string }
19
20resources:
21 hvves-sim:
22 type: OS::Nova::Server
23 properties:
24 name: { get_param: name }
25 image: { get_param: image_name }
26 flavor: { get_param: flavor_name }
27 key_name: { get_param: key_pair }
28 networks:
29 - port: { get_resource: hvves-sim_port }
30 user_data_format: RAW
31 user_data:
32 str_replace:
33 template: |
34 #!/bin/bash
35
36 set_versions () {
37 DOCKER_VERSION=17.03
38 DOCKER_COMPOSE_VERSION=1.22.0
39 PROTOBUF_VERSION=3.6.1
40 }
41
42 enable_root_ssh () {
43 sed -i 's/PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
44 sed -i 's/PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
45 service sshd restart
46 echo -e "onap\nonap" | passwd root
47 }
48
49 update_os () {
50 rm -rf /var/lib/apt/lists/*
51 apt-get clean
52 apt-get update
53 }
54
55 docker_install_configure () {
56 curl "https://releases.rancher.com/install-docker/$DOCKER_VERSION.sh" | sh
57 mkdir -p /etc/systemd/system/docker.service.d/
58 cat > /etc/systemd/system/docker.service.d/docker.conf << EOF
59 [Service]
60 ExecStart=
61 ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry=nexus3.onap.org:$nexus_port
62 Environment="HTTP_PROXY=$proxy"
63 EOF
64 systemctl daemon-reload
65 systemctl restart docker
66 apt-mark hold docker-ce
67 docker login -u docker -p docker nexus3.onap.org:$nexus_port
68 }
69
70 docker_compose_install () {
71 curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
72 chmod +x /usr/local/bin/docker-compose
73 }
74
75 protobuf_install () {
76 apt-get install -y unzip
77 cd ~;curl -OL "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-x86_64.zip"
78 unzip ~/protoc-$PROTOBUF_VERSION-linux-x86_64.zip -d ~/protoc3
79 mv ~/protoc3/bin/* /usr/local/bin/
80 mv ~/protoc3/include/* /usr/local/include/
81 chown "$USER":"$USER" /usr/local/bin/protoc
82 chown -R "$USER":"$USER" /usr/local/include/google
83 rm -rf ~/protoc3
84 rm -f ~/protoc-$PROTOBUF_VERSION-linux-x86_64.zip
85 }
86
87 proto_files_checkout () {
88 mkdir -p ~/hv-ves_sim/proto;cd ~/hv-ves_sim/proto;wget "https://gerrit.onap.org/r/gitweb?p=dcaegen2/collectors/hv-ves.git;a=blob_plain;f=hv-collector-domain/src/main/proto/event/VesEvent.proto;hb=HEAD" -O VesEvent.proto;wget "https://gerrit.onap.org/r/gitweb?p=dcaegen2/collectors/hv-ves.git;a=blob_plain;f=hv-collector-domain/src/main/proto/measurements/HVMeasFields.proto;hb=HEAD" -O HVMeasFields.proto;wget "https://gerrit.onap.org/r/gitweb?p=dcaegen2/collectors/hv-ves.git;a=blob_plain;f=hv-collector-domain/src/main/proto/measurements/MeasDataCollection.proto;hb=HEAD" -O MeasDataCollection.proto
89 }
90
91 kafkacat_install () {
92 apt-get -y install kafkacat
93 }
94
95 hvves_sim_yml_checkout () {
96 cd ~/hv-ves_sim/;wget "https://gerrit.onap.org/r/gitweb?p=dcaegen2/collectors/hv-ves.git;a=blob_plain;f=docker-compose.yml;hb=HEAD" -O docker-compose.yml;sed -i "s/image: o/image: nexus3.onap.org:$nexus_port\/o/g" docker-compose.yml
97 }
98
99 dcae_simulator_disable () {
100 cd ~/hv-ves_sim/;sed -i '/ dcae-app-simulator/,$d' docker-compose.yml
101 }
102
103 generate_certs () {
104 apt-get -y install make
105 mkdir ~/hv-ves_sim/ssl
106 cd ~/hv-ves_sim/ssl;wget "https://gerrit.onap.org/r/gitweb?p=dcaegen2/collectors/hv-ves.git;a=blob_plain;f=ssl/Makefile;hb=HEAD" -O Makefile
107 cd ~/hv-ves_sim/ssl;make FILE=client
108 cd ~/hv-ves_sim/ssl;make FILE=server
109 }
110
111 start_simulator_env () {
112 if [ "$mode" == "standalone" ]
113 then
114 echo -e "127.0.0.1\tconsul" >> /etc/hosts
115 cd ~/hv-ves_sim;nohup docker-compose up &> ~/hv-ves_sim/docker-compose.log &
116 for i in {0..300}
117 do
118 sim=`grep -q "Started xNF Simulator API server" ~/hv-ves_sim/docker-compose.log ; echo $?`
119 if [ $sim -eq 0 ]
120 then
121 echo '{"kafkaBootstrapServers": "kafka:9092","routing":[{"fromDomain":11,"toTopic":"ves_hvRanMeas"}]}' | curl -X PUT -d @- http://consul:8500/v1/kv/veshv-config -H "Content-Type:application/json"
122 else
123 sleep 3s
124 fi
125 done
126 elif [ "$mode" == "onap" ]
127 then
128 docker pull "nexus3.onap.org:$nexus_port/onap/org.onap.dcaegen2.collectors.hv-ves.hv-collector-xnf-simulator:latest"
129 cd ~/hv-ves_sim;nohup docker run -p "6062:6062/tcp" -v "$(pwd)/ssl/:/etc/ves-hv/" -i "nexus3.onap.org:$nexus_port/onap/org.onap.dcaegen2.collectors.hv-ves.hv-collector-xnf-simulator:latest" "./run-java.sh run --listen-port 6062 --ves-host $hvves_ip --ves-port $hvves_port" &> ~/hv-ves_sim/docker.log &
130 else
131 exit 1
132 fi
133 }
134
135 simulator_script_create () {
136 cat > ~/hv-ves_sim/simulator.sh << EOF
137 #!/bin/bash
138
139 input_parameters () {
140 option=\$1
141 file=\$2
142 }
143
144 help () {
145 echo -e "Usage: simulator.sh [send] [message]"
146 }
147
148 send_message () {
149 if [[ -z \$1 ]] || [[ -z \$2 ]]
150 then
151 echo "Input parameter(s) empty."
152 help
153 exit 1
154 elif [[ \$1 == "send" ]] && [[ -n \$2 ]]
155 then
156 curl -X POST -d @\$2 http://localhost:6062/simulator/async -H "Content-Type:application/json"
157 else
158 help
159 fi
160 }
161
162 main () {
163 input_parameters "\$1" "\$2"
164 send_message "\$option" "\$file"
165 }
166
167 main "\$1" "\$2"
168 EOF
169 chmod +x ~/hv-ves_sim/simulator.sh
170
171 }
172
173 message_samples_checkout () {
174 mkdir ~/hv-ves_sim/samples
175 cd ~/hv-ves_sim/samples ; wget "https://gerrit.onap.org/r/gitweb?p=integration.git;a=blob_plain;f=test/csit/tests/dcaegen2-collectors-hv-ves/testcases/resources/scenarios/authorization/xnf-valid-messages-request.json;hb=HEAD" -O xnf-valid-messages-request.json ; wget "https://gerrit.onap.org/r/gitweb?p=integration.git;a=blob_plain;f=test/csit/tests/dcaegen2-collectors-hv-ves/testcases/resources/scenarios/invalid-gpb-data/xnf-invalid-gpb-data-request.json;hb=HEAD" -O xnf-invalid-gpb-data-request.json ; wget "https://gerrit.onap.org/r/gitweb?p=integration.git;a=blob_plain;f=test/csit/tests/dcaegen2-collectors-hv-ves/testcases/resources/scenarios/multiple-simulators-payload/xnf-simulator-smaller-valid-request.json;hb=HEAD" -O xnf-simulator-smaller-valid-request.json
176 }
177
178 set_versions
179 enable_root_ssh
180 update_os
181 docker_install_configure
182 docker_compose_install
183 protobuf_install
184 proto_files_checkout
185 kafkacat_install
186 hvves_sim_yml_checkout
187 dcae_simulator_disable
188 generate_certs
189 start_simulator_env
190 simulator_script_create
191 message_samples_checkout
192
193 params:
194 $proxy: { get_param: proxy }
195 $mode: { get_param: mode }
196 $hvves_ip: { get_param: hvves_ip }
197 $hvves_port: { get_param: hvves_port }
198 $nexus_port: { get_param: nexus_port }
199 hvves-sim_port:
200 type: OS::Neutron::Port
201 properties:
202 network_id: { get_param: private_net_id }
203 security_groups:
204 - { get_param: security_group }
205 fixed_ips:
206 - subnet_id: { get_param: private_subnet_id }
207 hvves-sim_public:
208 type: OS::Neutron::FloatingIP
209 properties:
210 floating_network_id: { get_param: public_net_id }
211 port_id: { get_resource: hvves-sim_port }
212
213outputs:
214 hvves-sim_private_ip:
215 description: HV-VES simulator private IP
216 value: { get_attr: [ hvves-sim, first_address ] }
217 hvves-sim_public_ip:
218 description: HV-VES simualtor floating IP
219 value: { get_attr: [ hvves-sim_public, floating_ip_address ] }