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