Add additional logging statements
[aai/schema-service.git] / aai-schema-service / src / main / scripts / common_functions.sh
1 #!/bin/ksh
2 #
3 # ============LICENSE_START=======================================================
4 # org.onap.aai
5 # ================================================================================
6 # Copyright © 2017-2018 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
22
23 # Common functions that can be used throughout multiple scripts
24 # In order to call these functions, this file needs to be sourced
25
26 # Checks if the user that is currently running is aaiadmin
27 check_user(){
28
29     userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )
30
31     if [ "${userid}" != "aaiadmin" ]; then
32         echo "You must be aaiadmin to run $0. The id used $userid."
33         exit 1
34     fi
35 }
36
37 # Sources the profile and sets the project home
38 source_profile(){
39     . /etc/profile.d/aai.sh
40     PROJECT_HOME=/opt/app/aai-schema-service
41 }
42
43 # Runs the spring boot jar based on which main class
44 # to execute and which logback file to use for that class
45 execute_spring_jar(){
46
47     className=$1;
48     logbackFile=$2;
49
50     shift 2;
51
52     EXECUTABLE_JAR=$(ls ${PROJECT_HOME}/lib/*.jar);
53
54     JAVA_OPTS="${JAVA_PRE_OPTS} -DAJSC_HOME=$PROJECT_HOME";
55     JAVA_OPTS="$JAVA_OPTS -DBUNDLECONFIG_DIR=resources";
56     JAVA_OPTS="$JAVA_OPTS -Daai.home=$PROJECT_HOME ";
57     JAVA_OPTS="$JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2";
58     JAVA_OPTS="$JAVA_OPTS -Dloader.main=${className}";
59     JAVA_OPTS="$JAVA_OPTS -Dloader.path=${PROJECT_HOME}/resources";
60     JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=${logbackFile}";
61
62     export SOURCE_NAME=$(grep '^schema.source.name=' ${PROJECT_HOME}/resources/application.properties | cut -d"=" -f2-);
63     # Needed for the schema ingest library beans
64     eval $(grep '^schema\.' ${PROJECT_HOME}/resources/application.properties | \
65      sed 's/^\(.*\)$/JAVA_OPTS="$JAVA_OPTS -D\1"/g' | \
66      sed 's/${server.local.startpath}/${PROJECT_HOME}\/resources/g'| \
67      sed 's/${schema.source.name}/'${SOURCE_NAME}'/g'\
68     )
69
70     JAVA_OPTS="${JAVA_OPTS} ${JAVA_POST_OPTS}";
71
72     ${JAVA_HOME}/bin/java ${JVM_OPTS} ${JAVA_OPTS} -jar ${EXECUTABLE_JAR} "$@"
73 }
74
75 # Prints the start date and the script that the user called
76 start_date(){
77     echo
78     echo `date` "   Starting $0"
79 }
80
81 # Prints the end date and the script that the user called
82 end_date(){
83     echo
84     echo `date` "   Done $0"
85 }
86
87 # Inserts GEN_DB_WITH_NO_SCHEMA as a paranmter if it isn't there already
88 force_GEN_DB_WITH_NO_SCHEMA () {
89   for p in "$@"
90     do
91     if [ "$p" == "GEN_DB_WITH_NO_SCHEMA" ]
92     then
93       echo "$@"
94       return
95     fi
96     done
97     echo "GEN_DB_WITH_NO_SCHEMA $@"
98     return
99 }
100