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