e13193f364d68cfd0128b0b5e9d2b39f7d8ce677
[oom.git] / kubernetes / appc / resources / config / appc / opt / onap / appc / bin / startODL.sh
1 #!/bin/bash -x
2
3 ###
4 # ============LICENSE_START=======================================================
5 # APPC
6 # ================================================================================
7 # Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END=========================================================
21 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ###
23
24 #
25 # This script takes care of installing the SDNC & APPC platform components
26 #  if not already installed, and starts the APPC Docker Container
27 #
28
29 function enable_odl_cluster(){
30   if [ -z $APPC_REPLICAS ]; then
31      echo "APPC_REPLICAS is not configured in Env field"
32      exit
33   fi
34
35   echo "Update cluster information statically"
36   hm=$(hostname)
37   echo "Get current Hostname ${hm}"
38
39   node=($(echo ${hm} | sed 's/-[0-9]*$//g'))
40   node_index=($(echo ${hm} | awk -F"-" '{print $NF}'))
41   node_list="${node}-0.{{ .Values.service.name }}-cluster.{{.Release.Namespace}}";
42
43   for ((i=1;i<${APPC_REPLICAS};i++));
44   do
45     node_list="${node_list} ${node}-$i.{{ .Values.service.name }}-cluster.{{.Release.Namespace}}"
46   done
47
48   /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
49 }
50
51 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
52 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-admin}
53 SDNC_HOME=${SDNC_HOME:-/opt/onap/ccsdk}
54 APPC_HOME=${APPC_HOME:-/opt/onap/appc}
55 SLEEP_TIME=${SLEEP_TIME:-120}
56 MYSQL_PASSWD=${MYSQL_PASSWD:-{{.Values.config.dbRootPassword}}}
57 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
58
59 appcInstallStartTime=$(date +%s)
60
61 #
62 # Adding the DMAAP_TOPIC_ENV variable into APPC-ASDC-LISTENER properties
63 #
64 DMAAP_TOPIC_ENV=${DMAAP_TOPIC_ENV}
65
66 if [ -z "$DMAAP_TOPIC_ENV" ]
67         then
68         echo "DMAAP_TOPIC_ENV shell variable is empty. Adding default value OS-ETE-DFW"
69                 DMAAP_TOPIC_ENV="OS-ETE-DFW"
70         else
71                 echo "DMAAP_TOPIC_ENV shell variable exists and it's $DMAAP_TOPIC_ENV"
72 fi
73
74 echo "Adding a value to property appc.asdc.env in appc.properties for appc-asdc-listener feature"
75 echo "" >> $APPC_HOME/data/properties/appc.properties
76 echo "appc.asdc.env=$DMAAP_TOPIC_ENV" >> $APPC_HOME/data/properties/appc.properties
77 echo "" >> $APPC_HOME/data/properties/appc.properties
78
79 #
80 # Wait for database to init properly
81 #
82 echo "Waiting for mysql"
83 until mysql -h {{.Values.mysql.service.name}}.{{.Release.Namespace}} -u root -p{{.Values.config.dbRootPassword}} mysql &> /dev/null
84 do
85   printf "."
86   sleep 1
87 done
88 echo -e "\nmysql ready"
89
90 if [ ! -f ${SDNC_HOME}/.installed ]
91 then
92         echo "Installing SDNC database"
93         ${SDNC_HOME}/bin/installSdncDb.sh
94
95         echo "Installing APPC database"
96         ${APPC_HOME}/bin/installAppcDb.sh
97
98         echo "Installing ODL Host Key"
99         ${SDNC_HOME}/bin/installOdlHostKey.sh
100
101         echo "Starting OpenDaylight"
102         ${ODL_HOME}/bin/start
103
104         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
105         sleep ${SLEEP_TIME}
106
107         echo "Copying a working version of the logging configuration into the opendaylight etc folder"
108         cp ${APPC_HOME}/data/org.ops4j.pax.logging.cfg ${ODL_HOME}/etc/org.ops4j.pax.logging.cfg
109         echo "Copying a new version of aaf cadi shiro into the opendaylight deploy folder"
110         cp ${APPC_HOME}/data/aaf-shiro-aafrealm-osgi-bundle.jar ${ODL_HOME}/deploy/aaf-shiro-aafrealm-osgi-bundle.jar
111
112         echo "Installing SDNC platform features"
113         ${SDNC_HOME}/bin/installFeatures.sh
114
115         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
116         then
117                 echo "Installing directed graphs"
118                 ${SDNC_HOME}/svclogic/bin/install.sh
119         fi
120
121         if $ENABLE_ODL_CLUSTER ; then echo "Installing Opendaylight cluster features" ; ${ODL_HOME}/bin/client feature:install odl-mdsal-clustering ; ${ODL_HOME}/bin/client feature:install odl-jolokia ; fi
122
123         echo "Installing APPC platform features"
124         ${APPC_HOME}/bin/installFeatures.sh
125
126         if [ -x ${APPC_HOME}/svclogic/bin/install.sh ]
127         then
128                 echo "Installing APPC DGs using platform-logic"
129                 ${APPC_HOME}/svclogic/bin/install.sh
130         fi
131
132         if [ -x ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh ]
133         then
134                 echo "Installing APPC JSON DGs converted to XML using dg-loader"
135                 ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh
136         fi
137
138         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
139
140         echo "Adding a property system.properties for AAF cadi.properties location"
141         echo "" >> ${ODL_HOME}/etc/system.properties
142         echo "cadi_prop_files=${APPC_HOME}/data/properties/cadi.properties" >> ${ODL_HOME}/etc/system.properties
143         echo "" >> ${ODL_HOME}/etc/system.properties
144
145         echo "Copying the aaa shiro configuration into opendaylight"
146         cp ${APPC_HOME}/data/aaa-app-config.xml ${ODL_HOME}/etc/opendaylight/datastore/initial/config/aaa-app-config.xml
147
148
149         echo "Restarting OpenDaylight"
150         ${ODL_HOME}/bin/stop
151         checkRun () {
152                 running=0
153                 while read a b c d e f g h
154                 do
155                 if [ "$h" == "/bin/sh /opt/opendaylight/current/bin/karaf server" ]
156                 then
157                      running=1
158                 fi
159                 done < <(ps -eaf)
160                 echo $running
161         }
162
163         while [ $( checkRun ) == 1 ]
164         do
165                 echo "Karaf is still running, waiting..."
166                 sleep 5s
167         done
168         echo "Karaf process has stopped"
169         sleep 10s
170         echo "Installed at `date`" > ${SDNC_HOME}/.installed
171 fi
172
173         appcInstallEndTime=$(date +%s)
174         echo "Total Appc install took $(expr $appcInstallEndTime - $appcInstallStartTime) seconds"
175
176 exec ${ODL_HOME}/bin/karaf
177