Move to new xml dg loader
[appc/deployment.git] / installation / appc / src / main / scripts / startODL.sh
1 #!/bin/bash
2
3 ###
4 # ============LICENSE_START=======================================================
5 # APPC
6 # ================================================================================
7 # Copyright (C) 2017-2018 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 ###
22
23 #
24 # This script takes care of installing the SDNC & APPC platform components 
25 #  if not already installed, and starts the APPC Docker Container
26 #
27
28 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
29 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
30 SDNC_HOME=${SDNC_HOME:-/opt/onap/ccsdk}
31 APPC_HOME=${APPC_HOME:-/opt/onap/appc}
32 SLEEP_TIME=${SLEEP_TIME:-120}
33 MYSQL_PASSWD=${MYSQL_PASSWD:-openECOMP1.0}
34
35 appcInstallStartTime=$(date +%s)
36
37 #
38 # Adding the DMAAP_TOPIC_ENV variable into APPC-ASDC-LISTENER properties
39 #
40 DMAAP_TOPIC_ENV=${DMAAP_TOPIC_ENV}
41
42 if [ -z "$DMAAP_TOPIC_ENV" ]
43         then
44         echo "DMAAP_TOPIC_ENV shell variable is empty. Adding default value OS-ETE-DFW"
45                 DMAAP_TOPIC_ENV="OS-ETE-DFW"
46         else
47                 echo "DMAAP_TOPIC_ENV shell variable exists and it's $DMAAP_TOPIC_ENV"
48 fi
49
50 echo "Adding a value to property appc.asdc.env in appc.properties for appc-asdc-listener feature"
51 echo "" >> $APPC_HOME/data/properties/appc.properties
52 echo "appc.asdc.env=$DMAAP_TOPIC_ENV" >> $APPC_HOME/data/properties/appc.properties
53 echo "" >> $APPC_HOME/data/properties/appc.properties
54
55 #
56 # Wait for database to init properly
57 #
58 echo "Waiting for mysql"
59 until mysql -h dbhost -u root -p${MYSQL_PASSWD} mysql &> /dev/null
60 do
61   printf "."
62   sleep 1
63 done
64 echo -e "\nmysql ready"
65
66 if [ ! -f ${SDNC_HOME}/.installed ]
67 then
68         echo "Installing SDNC database"
69         ${SDNC_HOME}/bin/installSdncDb.sh
70         echo "Installing APPC database"
71         ${APPC_HOME}/bin/installAppcDb.sh
72         echo "Installing ODL Host Key"
73         ${SDNC_HOME}/bin/installOdlHostKey.sh
74         echo "Starting OpenDaylight"
75         ${ODL_HOME}/bin/start
76         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
77         sleep ${SLEEP_TIME}
78         echo "Copying a working version of the logging configuration into the opendaylight etc folder"
79         cp ${APPC_HOME}/data/org.ops4j.pax.logging.cfg ${ODL_HOME}/etc/org.ops4j.pax.logging.cfg
80         echo "Copying a new version of aaf cadi shiro into the opendaylight deploy folder"
81         cp ${APPC_HOME}/data/aaf-shiro-aafrealm-osgi-bundle.jar ${ODL_HOME}/deploy/aaf-shiro-aafrealm-osgi-bundle.jar
82         echo "Installing SDNC platform features"
83         ${SDNC_HOME}/bin/installFeatures.sh
84         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
85         then
86                 echo "Installing directed graphs"
87                 ${SDNC_HOME}/svclogic/bin/install.sh
88         fi
89         
90         echo "Installing APPC platform features"
91         ${APPC_HOME}/bin/installFeatures.sh
92         
93         
94
95         if [ -x ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh ]
96         then
97                 echo "Installing APPC JSON DGs converted to XML using dg-loader"
98                 ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh
99         fi
100         
101         echo "Adding a property system.properties for AAF cadi.properties location"
102         echo "" >> ${ODL_HOME}/etc/system.properties
103         echo "cadi_prop_files=${APPC_HOME}/data/properties/cadi.properties" >> ${ODL_HOME}/etc/system.properties
104         echo "" >> ${ODL_HOME}/etc/system.properties
105         
106         echo "Copying the aaa shiro configuration into opendaylight"
107     cp ${APPC_HOME}/data/aaa-app-config.xml ${ODL_HOME}/etc/opendaylight/datastore/initial/config/aaa-app-config.xml
108
109     echo "Restarting OpenDaylight"
110     ${ODL_HOME}/bin/stop
111         checkRun () {
112                 running=0
113                 while read a b c d e f g h
114                 do
115                 if [ "$h" == "/bin/sh /opt/opendaylight/current/bin/karaf server" ]
116                 then
117                         running=1
118                 fi
119                 done < <(ps -eaf)
120                 echo $running
121         }
122         
123         while [ $( checkRun ) == 1 ]
124         do
125                 echo "Karaf is still running, waiting..."
126                 sleep 5s
127         done
128         echo "Karaf process has stopped"
129         sleep 10s
130         echo "Installed at `date`" > ${SDNC_HOME}/.installed
131 fi
132
133         appcInstallEndTime=$(date +%s)
134         echo "Total Appc install took $(expr $appcInstallEndTime - $appcInstallStartTime) seconds"
135
136 exec ${ODL_HOME}/bin/karaf