[AAI] Release docker artifact 1.12.4
[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     PROJECT_HOME=/opt/app/aai-schema-service
40 }
41
42 # Runs the spring boot jar based on which main class
43 # to execute and which logback file to use for that class
44 execute_spring_jar(){
45
46     className=$1;
47     logbackFile=$2;
48
49     shift 2;
50
51     EXECUTABLE_JAR=$(ls ${PROJECT_HOME}/lib/*.jar);
52
53     JAVA_OPTS="${JAVA_PRE_OPTS} -DAJSC_HOME=$PROJECT_HOME";
54     JAVA_OPTS="$JAVA_OPTS -DBUNDLECONFIG_DIR=resources";
55     JAVA_OPTS="$JAVA_OPTS -Daai.home=$PROJECT_HOME ";
56     JAVA_OPTS="$JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2";
57     JAVA_OPTS="$JAVA_OPTS -Dloader.main=${className}";
58     JAVA_OPTS="$JAVA_OPTS -Dloader.path=${PROJECT_HOME}/resources";
59     JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=${logbackFile}";
60
61     export SOURCE_NAME=$(grep '^schema.source.name=' ${PROJECT_HOME}/resources/application.properties | cut -d"=" -f2-);
62     # Needed for the schema ingest library beans
63     eval $(grep '^schema\.' ${PROJECT_HOME}/resources/application.properties | \
64      sed 's/^\(.*\)$/JAVA_OPTS="$JAVA_OPTS -D\1"/g' | \
65      sed 's/${server.local.startpath}/${PROJECT_HOME}\/resources/g'| \
66      sed 's/${schema.source.name}/'${SOURCE_NAME}'/g'\
67     )
68
69     JAVA_OPTS="${JAVA_OPTS} ${JAVA_POST_OPTS}";
70
71     ${JAVA_HOME}/bin/java ${JVM_OPTS} ${JAVA_OPTS} -jar ${EXECUTABLE_JAR} "$@"
72 }
73
74 # Prints the start date and the script that the user called
75 start_date(){
76     echo
77     echo `date` "   Starting $0"
78 }
79
80 # Prints the end date and the script that the user called
81 end_date(){
82     echo
83     echo `date` "   Done $0"
84 }
85
86 # Inserts GEN_DB_WITH_NO_SCHEMA as a paranmter if it isn't there already
87 force_GEN_DB_WITH_NO_SCHEMA () {
88   for p in "$@"
89     do
90     if [ "$p" == "GEN_DB_WITH_NO_SCHEMA" ]
91     then
92       echo "$@"
93       return
94     fi
95     done
96     echo "GEN_DB_WITH_NO_SCHEMA $@"
97     return
98 }
99