blob: a3baeed9984bf5be9d37d4112d0b57d47fd1106a [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: "" }
marekpl32037f72018-10-08 10:59:20 +020015 mode: { description: Mode - standalone or integrated to ONAP (values - 'standalone' or 'onap'), label: Mode, type: string, default: "onap" }
marekpl03472762018-09-11 17:03:29 +020016 hvves_ip: { description: HV-VES IP, label: HV-VES IP, type: string, default: "" }
marekpl32037f72018-10-08 10:59:20 +020017 hvves_port: { description: HV-VES Port, label: HV-VES Port, type: string, default: "30222" }
18 nexus_port: { description: ONAP Nexus Port, label: ONAP Nexus Port, type: string, default: "10001" }
19 tls: { description: HV-VES TLS functionality, label: HV-VES TLS, type: string, default: "false" }
marekpl03472762018-09-11 17:03:29 +020020
21resources:
22 hvves-sim:
23 type: OS::Nova::Server
24 properties:
25 name: { get_param: name }
26 image: { get_param: image_name }
27 flavor: { get_param: flavor_name }
28 key_name: { get_param: key_pair }
29 networks:
30 - port: { get_resource: hvves-sim_port }
31 user_data_format: RAW
32 user_data:
33 str_replace:
34 template: |
35 #!/bin/bash
36
37 set_versions () {
38 DOCKER_VERSION=17.03
39 DOCKER_COMPOSE_VERSION=1.22.0
40 PROTOBUF_VERSION=3.6.1
41 }
42
43 enable_root_ssh () {
44 sed -i 's/PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
45 sed -i 's/PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
46 service sshd restart
47 echo -e "onap\nonap" | passwd root
48 }
49
50 update_os () {
51 rm -rf /var/lib/apt/lists/*
52 apt-get clean
53 apt-get update
54 }
55
56 docker_install_configure () {
57 curl "https://releases.rancher.com/install-docker/$DOCKER_VERSION.sh" | sh
58 mkdir -p /etc/systemd/system/docker.service.d/
59 cat > /etc/systemd/system/docker.service.d/docker.conf << EOF
60 [Service]
61 ExecStart=
62 ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry=nexus3.onap.org:$nexus_port
63 Environment="HTTP_PROXY=$proxy"
64 EOF
65 systemctl daemon-reload
66 systemctl restart docker
67 apt-mark hold docker-ce
68 docker login -u docker -p docker nexus3.onap.org:$nexus_port
69 }
70
71 docker_compose_install () {
72 curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
73 chmod +x /usr/local/bin/docker-compose
74 }
75
76 protobuf_install () {
77 apt-get install -y unzip
78 cd ~;curl -OL "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-x86_64.zip"
79 unzip ~/protoc-$PROTOBUF_VERSION-linux-x86_64.zip -d ~/protoc3
80 mv ~/protoc3/bin/* /usr/local/bin/
81 mv ~/protoc3/include/* /usr/local/include/
82 chown "$USER":"$USER" /usr/local/bin/protoc
83 chown -R "$USER":"$USER" /usr/local/include/google
84 rm -rf ~/protoc3
85 rm -f ~/protoc-$PROTOBUF_VERSION-linux-x86_64.zip
86 }
87
88 proto_files_checkout () {
89 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
90 }
91
92 kafkacat_install () {
93 apt-get -y install kafkacat
94 }
95
96 hvves_sim_yml_checkout () {
97 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
98 }
99
100 dcae_simulator_disable () {
101 cd ~/hv-ves_sim/;sed -i '/ dcae-app-simulator/,$d' docker-compose.yml
102 }
103
104 generate_certs () {
marekpl32037f72018-10-08 10:59:20 +0200105 apt-get -y install default-jre
marekpl03472762018-09-11 17:03:29 +0200106 mkdir ~/hv-ves_sim/ssl
marekpl32037f72018-10-08 10:59:20 +0200107 cd ~/hv-ves_sim/ssl;wget "https://gerrit.onap.org/r/gitweb?p=dcaegen2/collectors/hv-ves.git;a=blob_plain;f=ssl/gen-certs.sh;hb=HEAD" -O gen-certs.sh;chmod +x gen-certs.sh
108 cd ~/hv-ves_sim/ssl;/bin/bash gen-certs.sh
marekpl03472762018-09-11 17:03:29 +0200109 }
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
marekpl32037f72018-10-08 10:59:20 +0200126 elif [ "$mode" == "onap" ] && [ "$tls" == "true" ]
marekpl03472762018-09-11 17:03:29 +0200127 then
marekpl32037f72018-10-08 10:59:20 +0200128 cd ~/hv-ves_sim;nohup docker run -p "6062:6062" -v "$(pwd)/ssl/:/etc/ves-hv/" -i "nexus3.onap.org:$nexus_port/onap/org.onap.dcaegen2.collectors.hv-ves.hv-collector-xnf-simulator:latest" "--listen-port 6062 --ves-host $hvves_ip --ves-port $hvves_port --trust-store /etc/ves-hv/trust.p12 --trust-store-password onaponap --key-store /etc/ves-hv/client.p12 --key-store-password onaponap" &> ~/hv-ves_sim/docker.log &
129 echo -e "127.0.0.1\tmessage-router-kafka" >> /etc/hosts
130 elif [ "$mode" == "onap" ] && [ "$tls" == "false" ]
131 then
132 cd ~/hv-ves_sim;nohup docker run -p "6062:6062" -i "nexus3.onap.org:$nexus_port/onap/org.onap.dcaegen2.collectors.hv-ves.hv-collector-xnf-simulator:latest" "--listen-port 6062 --ves-host $hvves_ip --ves-port $hvves_port --ssl-disable" &> ~/hv-ves_sim/docker.log &
133 echo -e "127.0.0.1\tmessage-router-kafka" >> /etc/hosts
marekpl03472762018-09-11 17:03:29 +0200134 else
135 exit 1
136 fi
137 }
138
139 simulator_script_create () {
140 cat > ~/hv-ves_sim/simulator.sh << EOF
141 #!/bin/bash
142
143 input_parameters () {
144 option=\$1
145 file=\$2
146 }
147
148 help () {
149 echo -e "Usage: simulator.sh [send] [message]"
150 }
151
152 send_message () {
153 if [[ -z \$1 ]] || [[ -z \$2 ]]
154 then
155 echo "Input parameter(s) empty."
156 help
157 exit 1
158 elif [[ \$1 == "send" ]] && [[ -n \$2 ]]
159 then
160 curl -X POST -d @\$2 http://localhost:6062/simulator/async -H "Content-Type:application/json"
161 else
162 help
163 fi
164 }
165
166 main () {
167 input_parameters "\$1" "\$2"
168 send_message "\$option" "\$file"
169 }
170
171 main "\$1" "\$2"
172 EOF
173 chmod +x ~/hv-ves_sim/simulator.sh
174
175 }
176
177 message_samples_checkout () {
178 mkdir ~/hv-ves_sim/samples
179 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
180 }
181
182 set_versions
183 enable_root_ssh
184 update_os
185 docker_install_configure
186 docker_compose_install
187 protobuf_install
188 proto_files_checkout
189 kafkacat_install
190 hvves_sim_yml_checkout
191 dcae_simulator_disable
192 generate_certs
193 start_simulator_env
194 simulator_script_create
195 message_samples_checkout
196
197 params:
198 $proxy: { get_param: proxy }
199 $mode: { get_param: mode }
200 $hvves_ip: { get_param: hvves_ip }
201 $hvves_port: { get_param: hvves_port }
202 $nexus_port: { get_param: nexus_port }
marekpl32037f72018-10-08 10:59:20 +0200203 $tls: { get_param: tls }
marekpl03472762018-09-11 17:03:29 +0200204 hvves-sim_port:
205 type: OS::Neutron::Port
206 properties:
207 network_id: { get_param: private_net_id }
208 security_groups:
209 - { get_param: security_group }
210 fixed_ips:
211 - subnet_id: { get_param: private_subnet_id }
212 hvves-sim_public:
213 type: OS::Neutron::FloatingIP
214 properties:
215 floating_network_id: { get_param: public_net_id }
216 port_id: { get_resource: hvves-sim_port }
217
218outputs:
219 hvves-sim_private_ip:
220 description: HV-VES simulator private IP
221 value: { get_attr: [ hvves-sim, first_address ] }
222 hvves-sim_public_ip:
223 description: HV-VES simualtor floating IP
224 value: { get_attr: [ hvves-sim_public, floating_ip_address ] }
marekpl32037f72018-10-08 10:59:20 +0200225