Merge " Fix logging format"
[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 "Installing Opendaylight cluster features"
36   ${ODL_HOME}/bin/client -u karaf feature:install odl-mdsal-clustering
37   ${ODL_HOME}/bin/client -u karaf feature:install odl-jolokia
38
39   echo "Update cluster information statically"
40   hm=$(hostname)
41   echo "Get current Hostname ${hm}"
42
43   node=($(echo ${hm} | sed 's/-[0-9]*$//g'))
44   node_index=($(echo ${hm} | awk -F"-" '{print $NF}'))
45   node_list="${node}-0.{{ .Values.service.name }}-cluster.{{.Release.Namespace}}";
46
47   for ((i=1;i<${APPC_REPLICAS};i++));
48   do
49     node_list="${node_list} ${node}-$i.{{ .Values.service.name }}-cluster.{{.Release.Namespace}}"
50   done
51
52   /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
53 }
54
55 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
56 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
57 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
58 APPC_HOME=${APPC_HOME:-/opt/onap/appc}
59 SLEEP_TIME=${SLEEP_TIME:-120}
60 MYSQL_PASSWD=${MYSQL_PASSWD:-{{.Values.config.dbRootPassword}}}
61 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
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 mysql"
85 until mysql -h {{.Values.mysql.service.name}}.{{.Release.Namespace}} -u root -p{{.Values.config.dbRootPassword}} mysql &> /dev/null
86 do
87   printf "."
88   sleep 1
89 done
90 echo -e "\nmysql ready"
91
92 if [ ! -f ${SDNC_HOME}/.installed ]
93 then
94         echo "Installing SDNC database"
95         ${SDNC_HOME}/bin/installSdncDb.sh
96         echo "Installing APPC database"
97         ${APPC_HOME}/bin/installAppcDb.sh
98         echo "Starting OpenDaylight"
99         ${ODL_HOME}/bin/start
100         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
101         sleep ${SLEEP_TIME}
102         echo "Inserting modified installFeatures.sh for sdnc"
103         rm ${SDNC_HOME}/bin/installFeatures.sh
104         cp ${APPC_HOME}/data/sdncInstallFeatures.sh ${SDNC_HOME}/bin/installFeatures.sh
105         echo "Installing SDNC platform features"
106         ${SDNC_HOME}/bin/installFeatures.sh
107         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
108         then
109                 echo "Installing directed graphs"
110                 ${SDNC_HOME}/svclogic/bin/install.sh
111         fi
112
113         echo "Installing APPC platform features"
114         ${APPC_HOME}/bin/installFeatures.sh
115         if [ -x ${APPC_HOME}/svclogic/bin/install.sh ]
116         then
117                 echo "Installing APPC DGs using platform-logic"
118                 ${APPC_HOME}/svclogic/bin/install.sh
119         fi
120
121         if [ -x ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh ]
122         then
123                 echo "Installing APPC JSON DGs converted to XML using dg-loader"
124                 ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh
125         fi
126
127         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
128
129         echo "Restarting OpenDaylight"
130         ${ODL_HOME}/bin/stop
131         echo "Installed at `date`" > ${SDNC_HOME}/.installed
132 fi
133
134 exec ${ODL_HOME}/bin/karaf
135