Update OOM APPC chart to enhance AAF support
[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 ENABLE_AAF=${ENABLE_AAF:-false}
59 AAF_EXT_IP=${AAF_EXT_IP:-{{.Values.config.aafExtIP}}}
60 AAF_EXT_FQDN=${AAF_EXT_FQDN:-{{.Values.config.aafExtFQDN}}}
61
62 appcInstallStartTime=$(date +%s)
63
64 #
65 # Adding the DMAAP_TOPIC_ENV variable into APPC-ASDC-LISTENER properties
66 #
67 DMAAP_TOPIC_ENV=${DMAAP_TOPIC_ENV}
68
69 if [ -z "$DMAAP_TOPIC_ENV" ]
70         then
71         echo "DMAAP_TOPIC_ENV shell variable is empty. Adding default value OS-ETE-DFW"
72                 DMAAP_TOPIC_ENV="OS-ETE-DFW"
73         else
74                 echo "DMAAP_TOPIC_ENV shell variable exists and it's $DMAAP_TOPIC_ENV"
75 fi
76
77 echo "Adding a value to property appc.asdc.env in appc.properties for appc-asdc-listener feature"
78 echo "" >> $APPC_HOME/data/properties/appc.properties
79 echo "appc.asdc.env=$DMAAP_TOPIC_ENV" >> $APPC_HOME/data/properties/appc.properties
80 echo "" >> $APPC_HOME/data/properties/appc.properties
81
82 #
83 # Wait for database to init properly
84 #
85 echo "Waiting for mysql"
86 until mysql -h {{.Values.mysql.service.name}}.{{.Release.Namespace}} -u root -p{{.Values.config.dbRootPassword}} mysql &> /dev/null
87 do
88   printf "."
89   sleep 1
90 done
91 echo -e "\nmysql ready"
92
93 if [ ! -f ${SDNC_HOME}/.installed ]
94 then
95         echo "Installing SDNC database"
96         ${SDNC_HOME}/bin/installSdncDb.sh
97
98         echo "Installing APPC database"
99         ${APPC_HOME}/bin/installAppcDb.sh
100
101         echo "Installing ODL Host Key"
102         ${SDNC_HOME}/bin/installOdlHostKey.sh
103
104         echo "Starting OpenDaylight"
105         ${ODL_HOME}/bin/start
106
107         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
108         sleep ${SLEEP_TIME}
109
110         echo "Copying a working version of the logging configuration into the opendaylight etc folder"
111         cp ${APPC_HOME}/data/org.ops4j.pax.logging.cfg ${ODL_HOME}/etc/org.ops4j.pax.logging.cfg
112         echo "Copying a new version of aaf cadi shiro into the opendaylight deploy folder"
113         cp ${APPC_HOME}/data/aaf-shiro-aafrealm-osgi-bundle.jar ${ODL_HOME}/deploy/aaf-shiro-aafrealm-osgi-bundle.jar
114
115         echo "Installing SDNC platform features"
116         ${SDNC_HOME}/bin/installFeatures.sh
117
118         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
119         then
120                 echo "Installing directed graphs"
121                 ${SDNC_HOME}/svclogic/bin/install.sh
122         fi
123
124         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
125
126         echo "Installing APPC platform features"
127         ${APPC_HOME}/bin/installFeatures.sh
128
129         if [ -x ${APPC_HOME}/svclogic/bin/install.sh ]
130         then
131                 echo "Installing APPC DGs using platform-logic"
132                 ${APPC_HOME}/svclogic/bin/install.sh
133         fi
134
135         if [ -x ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh ]
136         then
137                 echo "Installing APPC JSON DGs converted to XML using dg-loader"
138                 ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh
139         fi
140
141         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
142
143         echo "Adding a property system.properties for AAF cadi.properties location"
144         echo "" >> ${ODL_HOME}/etc/system.properties
145         echo "cadi_prop_files=${APPC_HOME}/data/properties/cadi.properties" >> ${ODL_HOME}/etc/system.properties
146         echo "" >> ${ODL_HOME}/etc/system.properties
147
148         echo "Copying the aaa shiro configuration into opendaylight"
149         if $ENABLE_AAF
150         then
151              echo "${AAF_EXT_IP} ${AAF_EXT_FQDN}" >> /etc/hosts
152              cp ${APPC_HOME}/data/properties/aaa-app-config.xml ${ODL_HOME}/etc/opendaylight/datastore/initial/config/aaa-app-config.xml
153         else
154              cp ${APPC_HOME}/data/aaa-app-config.xml ${ODL_HOME}/etc/opendaylight/datastore/initial/config/aaa-app-config.xml
155         fi
156
157         echo "Restarting OpenDaylight"
158         ${ODL_HOME}/bin/stop
159         checkRun () {
160                 running=0
161                 while read a b c d e f g h
162                 do
163                 if [ "$h" == "/bin/sh /opt/opendaylight/current/bin/karaf server" ]
164                 then
165                      running=1
166                 fi
167                 done < <(ps -eaf)
168                 echo $running
169         }
170
171         while [ $( checkRun ) == 1 ]
172         do
173                 echo "Karaf is still running, waiting..."
174                 sleep 5s
175         done
176         echo "Karaf process has stopped"
177         sleep 10s
178         echo "Installed at `date`" > ${SDNC_HOME}/.installed
179 fi
180
181         appcInstallEndTime=$(date +%s)
182         echo "Total Appc install took $(expr $appcInstallEndTime - $appcInstallStartTime) seconds"
183
184 echo "Starting cdt-proxy-service jar, logging to ${APPC_HOME}/cdt-proxy-service/jar.log"
185 java -jar ${APPC_HOME}/cdt-proxy-service/cdt-proxy-service.jar > ${APPC_HOME}/cdt-proxy-service/jar.log &
186
187 exec ${ODL_HOME}/bin/karaf
188