Modify updateQueryData to support debugging mode
[aai/traversal.git] / aai-traversal / src / main / scripts / install / updateQueryData.sh
1 #!/bin/ksh
2 #
3 # ============LICENSE_START=======================================================
4 # org.onap.aai
5 # ================================================================================
6 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #    http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END=========================================================
20 #
21 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 #
23
24 PROGNAME=$(basename $0)
25 PROJECT_HOME=/opt/app/aai-traversal
26 OUTFILE=$PROJECT_HOME/logs/misc/${PROGNAME}.log.$(date +\%Y-\%m-\%d)
27
28 if [ "$1" = "--debug" ]; then
29     set -x;
30 fi;
31
32 TS=$(date "+%Y-%m-%d %H:%M:%S")
33
34 CHECK_USER="aaiadmin"
35 userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )
36 if [ "${userid}" != $CHECK_USER ]; then
37     echo "You must be  $CHECK_USER to run $0. The id used $userid."
38     exit 1
39 fi 
40
41 error_exit () {
42         echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2" 1>&2
43         echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2" >> $OUTFILE
44 #       exit ${2:-"1"}
45 }
46
47 j=0
48 for filepath in `ls $PROJECT_HOME/resources/etc/scriptdata/widget-model-json/*.json|sort -f`
49 do
50 j=$(expr "$j" + 1)
51 filename=$(basename $filepath)
52 echo "Begin putTool for widget $filename" | tee -a $OUTFILE
53 vers=`grep model-invariant-id $filepath|cut -d':' -f2|cut -d'"' -f2`
54 # last parameter will skip put if it exists
55 resource=service-design-and-creation/models/model/$vers
56 if [ "$1" = "--debug" ]; then
57   bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
58 else 
59   $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
60 fi;
61 echo "End putTool for widget $filename" | tee -a $OUTFILE
62 done
63
64 j=0
65 for filepath in `ls $PROJECT_HOME/resources/etc/scriptdata/named-query-json/*.json|sort -f`
66 do
67 j=$(expr "$j" + 1)
68 filename=$(basename $filepath)
69 echo "Begin putTool for named-query $filename" | tee -a $OUTFILE
70 vers=`grep named-query-uuid $filepath|cut -d':' -f2|cut -d'"' -f2`
71 # last parameter will skip put if it exists
72 resource=service-design-and-creation/named-queries/named-query/$vers
73 if [ "$1" = "--debug" ]; then
74   bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
75 else
76   $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
77 fi;
78 echo "End putTool for named-query $filename" | tee -a $OUTFILE
79 done
80
81 j=0
82 for filepath in `ls $PROJECT_HOME/resources/etc/scriptdata/resource-model-json/*.json|sort -f`
83 do
84 j=$(expr "$j" + 1)
85 filename=$(basename $filepath)
86 echo "Begin putTool for resource model $filename" | tee -a $OUTFILE
87 vers=`grep model-invariant-id $filepath|cut -d':' -f2|cut -d'"' -f2`
88 # last parameter will skip put if it exists
89 resource=service-design-and-creation/models/model/$vers
90 if [ "$1" = "--debug" ]; then
91   bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
92 else
93   $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
94 fi;
95 echo "End putTool for resource model $filename" | tee -a $OUTFILE
96 done
97
98 j=0
99 for filepath in `ls $PROJECT_HOME/resources/etc/scriptdata/service-model-json/*.json|sort -f`
100 do
101 j=$(expr "$j" + 1)
102 filename=$(basename $filepath)
103 echo "Begin putTool for service model $filename" | tee -a $OUTFILE
104 vers=`grep model-invariant-id $filepath|cut -d':' -f2|cut -d'"' -f2`
105 # last parameter will skip put if it exists
106 resource=service-design-and-creation/models/model/$vers
107 if [ "$1" = "--debug" ]; then
108   bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
109 else
110   $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j
111 fi;
112 echo "End putTool for service model $filename" | tee -a $OUTFILE
113 done
114
115 echo "$PROGNAME completed ${TS}" | tee -a $OUTFILE
116 echo "See output and error file: $OUTFILE"
117
118 exit 0