Refactoring the sdc-BE-init python scripts
[sdc.git] / catalog-be / sdc-backend-init / chef-repo / cookbooks / sdc-catalog-be-setup / recipes / 3_import_Normatives.rb
1 be_ip=node['Nodes'][:BE]
2
3 if node['disableHttp']
4   protocol = "https"
5   be_port = node['BE']['https_port']
6   param="-i #{be_ip} -p #{be_port} --https"
7 else
8   protocol = "http"
9   be_port = node['BE']['http_port']
10   param="-i #{be_ip} -p #{be_port}"
11 end
12
13 cookbook_file "/var/tmp/normatives.tar.gz" do
14   source "normatives.tar.gz"
15 end
16
17 bash "executing-import_Normatives" do
18   code <<-EOH
19     set -ex
20
21     cd /var/tmp/
22     tar -xvf normatives.tar.gz
23     
24     # executing the normatives
25     # add --debug to the importNormativeAll.py arguments to enable debug
26     
27     check_normative="/tmp/check_normative.out"
28     status_code=$(curl -k -s -o ${check_normative} -w "%{http_code}\\n" -X GET -H 'Content-Type: application/json;charset=UTF-8' -H 'USER_ID: jh0003' -H 'X-ECOMP-RequestID: cbe744a0-037b-458f-aab5-df6e543c4090' "#{protocol}://#{be_ip}:#{be_port}/sdc2/rest/v1/screen")
29     if [ "$status_code" != 200 ] ; then
30       exit "$status_code"
31     fi
32     
33     #curl -s -X GET -H "Content-Type: application/json;charset=UTF-8" -H "USER_ID: jh0003" -H "X-ECOMP-RequestID: cbe744a0-037b-458f-aab5-df6e543c4090" "#{protocol}://#{be_ip}:#{be_port}/sdc2/rest/v1/screen" > ${check_normative}
34     
35     resources_len=`cat ${check_normative}| jq '.["resources"]|length'`
36     mkdir -p /var/lib/jetty/logs
37
38     cd /var/tmp/normatives/import/tosca/
39     if [ $resources_len -eq 0 ] ; then
40       sdcimportall #{param} > /var/lib/jetty/logs/importNormativeAll.log
41       rc=$?
42       if [[ $rc != 0 ]]; then exit $rc; fi
43     else
44       sdcupgradeall #{param} > /var/lib/jetty/logs/upgradeNormative.log
45       rc=$?
46       if [[ $rc != 0 ]]; then exit $rc; fi
47     fi
48   EOH
49 end