summaryrefslogtreecommitdiffstats
path: root/aai-schema-service/src/main/scripts/common_functions.sh
blob: dd235c2c01b1a7f0444d001caf9337e09112c206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/ksh
#
# ============LICENSE_START=======================================================
# org.onap.aai
# ================================================================================
# Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
#


# Common functions that can be used throughout multiple scripts
# In order to call these functions, this file needs to be sourced

# Checks if the user that is currently running is aaiadmin
check_user(){

    userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )

    if [ "${userid}" != "aaiadmin" ]; then
        echo "You must be aaiadmin to run $0. The id used $userid."
        exit 1
    fi
}

# Sources the profile and sets the project home
source_profile(){
    PROJECT_HOME=/opt/app/aai-schema-service
}

# Runs the spring boot jar based on which main class
# to execute and which logback file to use for that class
execute_spring_jar(){

    className=$1;
    logbackFile=$2;

    shift 2;

    EXECUTABLE_JAR=$(ls ${PROJECT_HOME}/lib/*.jar);

    JAVA_OPTS="${JAVA_PRE_OPTS} -DAJSC_HOME=$PROJECT_HOME";
    JAVA_OPTS="$JAVA_OPTS -DBUNDLECONFIG_DIR=resources";
    JAVA_OPTS="$JAVA_OPTS -Daai.home=$PROJECT_HOME ";
    JAVA_OPTS="$JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2";
    JAVA_OPTS="$JAVA_OPTS -Dloader.main=${className}";
    JAVA_OPTS="$JAVA_OPTS -Dloader.path=${PROJECT_HOME}/resources";
    JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=${logbackFile}";

    export SOURCE_NAME=$(grep '^schema.source.name=' ${PROJECT_HOME}/resources/application.properties | cut -d"=" -f2-);
    # Needed for the schema ingest library beans
    eval $(grep '^schema\.' ${PROJECT_HOME}/resources/application.properties | \
     sed 's/^\(.*\)$/JAVA_OPTS="$JAVA_OPTS -D\1"/g' | \
     sed 's/${server.local.startpath}/${PROJECT_HOME}\/resources/g'| \
     sed 's/${schema.source.name}/'${SOURCE_NAME}'/g'\
    )

    JAVA_OPTS="${JAVA_OPTS} ${JAVA_POST_OPTS}";

    ${JAVA_HOME}/bin/java ${JVM_OPTS} ${JAVA_OPTS} -jar ${EXECUTABLE_JAR} "$@"
}

# Prints the start date and the script that the user called
start_date(){
    echo
    echo `date` "   Starting $0"
}

# Prints the end date and the script that the user called
end_date(){
    echo
    echo `date` "   Done $0"
}

# Inserts GEN_DB_WITH_NO_SCHEMA as a paranmter if it isn't there already
force_GEN_DB_WITH_NO_SCHEMA () {
  for p in "$@"
    do
    if [ "$p" == "GEN_DB_WITH_NO_SCHEMA" ]
    then
      echo "$@"
      return
    fi
    done
    echo "GEN_DB_WITH_NO_SCHEMA $@"
    return
}