Merge "Add Common Helm Chart "mariadb-galera""
[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 feature:install odl-mdsal-clustering
37   ${ODL_HOME}/bin/client 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:-admin}
57 SDNC_HOME=${SDNC_HOME:-/opt/onap/ccsdk}
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 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 mysql"
87 until mysql -h {{.Values.mysql.service.name}}.{{.Release.Namespace}} -u root -p{{.Values.config.dbRootPassword}} mysql &> /dev/null
88 do
89   printf "."
90   sleep 1
91 done
92 echo -e "\nmysql 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 "Starting OpenDaylight"
103         ${ODL_HOME}/bin/start
104
105         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
106         sleep ${SLEEP_TIME}
107
108         echo "Copying a working version of the logging configuration into the opendaylight etc folder"
109         cp ${APPC_HOME}/data/org.ops4j.pax.logging.cfg ${ODL_HOME}/etc/org.ops4j.pax.logging.cfg
110         echo "Copying a new version of aaf cadi shiro into the opendaylight deploy folder"
111         cp ${APPC_HOME}/data/aaf-cadi-shiro.jar ${ODL_HOME}/deploy/aaf-cadi-shiro.jar
112
113         echo "Installing SDNC platform features"
114         ${SDNC_HOME}/bin/installFeatures.sh
115
116         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
117         then
118                 echo "Installing directed graphs"
119                 ${SDNC_HOME}/svclogic/bin/install.sh
120         fi
121
122         echo "Installing APPC platform features"
123         ${APPC_HOME}/bin/installFeatures.sh
124
125         if [ -x ${APPC_HOME}/svclogic/bin/install.sh ]
126         then
127                 echo "Installing APPC DGs using platform-logic"
128                 ${APPC_HOME}/svclogic/bin/install.sh
129         fi
130
131         if [ -x ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh ]
132         then
133                 echo "Installing APPC JSON DGs converted to XML using dg-loader"
134                 ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh
135         fi
136
137         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
138
139         echo "Adding a property system.properties for AAF cadi.properties location"
140         echo "" >> ${ODL_HOME}/etc/system.properties
141         echo "cadi_prop_files=${APPC_HOME}/data/properties/cadi.properties" >> ${ODL_HOME}/etc/system.properties
142         echo "" >> ${ODL_HOME}/etc/system.properties
143
144         echo "Copying a working version of the shiro configuration into the opendaylight etc folder"
145         cp ${APPC_HOME}/data/shiro.ini ${ODL_HOME}/etc/shiro.ini
146
147         echo "Restarting OpenDaylight"
148         ${ODL_HOME}/bin/stop
149         echo "Waiting 60 seconds for OpenDaylight stop to complete"
150         sleep 60
151         echo "Installed at `date`" > ${SDNC_HOME}/.installed
152 fi
153
154         appcInstallEndTime=$(date +%s)
155         echo "Total Appc install took $(expr $appcInstallEndTime - $appcInstallStartTime) seconds"
156
157 exec ${ODL_HOME}/bin/karaf
158