[CONSUL] Add limits to consul chart.
[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-2019 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 #set -x
30
31 function enable_odl_cluster(){
32   if [ -z $APPC_REPLICAS ]; then
33      echo "APPC_REPLICAS is not configured in Env field"
34      exit
35   fi
36
37   echo "Update cluster information statically"
38   hm=$(hostname)
39   echo "Get current Hostname ${hm}"
40
41   node=($(echo ${hm} | sed 's/-[0-9]*$//g'))
42   node_index=($(echo ${hm} | awk -F"-" '{print $NF}'))
43   node_list="${node}-0.{{ .Values.service.name }}-cluster.{{.Release.Namespace}}";
44
45   for ((i=1;i<${APPC_REPLICAS};i++));
46   do
47     node_list="${node_list} ${node}-$i.{{ .Values.service.name }}-cluster.{{.Release.Namespace}}"
48   done
49
50   /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
51 }
52
53 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
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_ROOT_PASSWORD}
58 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
59 ENABLE_AAF=${ENABLE_AAF:-true}
60 DBINIT_DIR=${DBINIT_DIR:-/opt/opendaylight/current/daexim}
61
62 #
63 # Wait for database to init properly
64 #
65 echo "Waiting for mariadbgalera"
66 until mysql -h {{.Values.config.mariadbGaleraSVCName}}.{{.Release.Namespace}} -u root -p${MYSQL_PASSWD}  mysql &> /dev/null
67 do
68   printf "."
69   sleep 1
70 done
71 echo -e "\nmariadbgalera ready"
72
73 if [ ! -d ${DBINIT_DIR} ]
74 then
75     mkdir -p ${DBINIT_DIR}
76 fi
77
78 if [ ! -f ${DBINIT_DIR}/.installed ]
79 then
80         sdnc_db_exists=$(mysql -h {{.Values.config.mariadbGaleraSVCName}}.{{.Release.Namespace}} -u root -p${MYSQL_PASSWD} mysql <<-END
81 show databases like 'sdnctl';
82 END
83 )
84         if [ "x${sdnc_db_exists}" == "x" ]
85         then
86             echo "Installing SDNC database"
87             ${SDNC_HOME}/bin/installSdncDb.sh
88
89             appc_db_exists=$(mysql -h {{.Values.config.mariadbGaleraSVCName}}.{{.Release.Namespace}} -u root -p${MYSQL_PASSWD} mysql <<-END
90 show databases like 'appcctl';
91 END
92 )
93             if [ "x${appc_db_exists}" == "x" ]
94             then
95               echo "Installing APPC database"
96               ${APPC_HOME}/bin/installAppcDb.sh
97             fi
98         else
99             sleep 30
100         fi
101
102         echo "Installed at `date`" > ${DBINIT_DIR}/.installed
103 fi
104
105
106 if [ ! -f ${SDNC_HOME}/.installed ]
107 then
108         echo "Installing ODL Host Key"
109         ${SDNC_HOME}/bin/installOdlHostKey.sh
110
111 #        echo "Copying a working version of the logging configuration into the opendaylight etc folder"
112 #        cp ${APPC_HOME}/data/org.ops4j.pax.logging.cfg ${ODL_HOME}/etc/org.ops4j.pax.logging.cfg
113
114
115         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
116         sleep ${SLEEP_TIME}
117
118
119         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
120         then
121                 echo "Installing directed graphs"
122                 ${SDNC_HOME}/svclogic/bin/install.sh
123         fi
124
125         if [ -x ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh ]
126         then
127                 echo "Installing APPC JSON DGs converted to XML using dg-loader"
128                 ${APPC_HOME}/svclogic/bin/install-converted-dgs.sh
129         fi
130
131         if $ENABLE_ODL_CLUSTER
132         then
133                 echo "Enabling Opendaylight cluster features"
134                 enable_odl_cluster
135         fi
136
137         echo "Copying the aaa shiro configuration into opendaylight"
138         mkdir -p ${ODL_HOME}/etc/opendaylight/datastore/initial/config
139         if $ENABLE_AAF
140         then
141              cp ${APPC_HOME}/data/properties/aaa-app-config.xml ${ODL_HOME}/etc/opendaylight/datastore/initial/config/aaa-app-config.xml
142         fi
143
144 fi
145
146 # Move journal and snapshots directory to persistent storage
147
148 hostdir=${ODL_HOME}/daexim/$(hostname -s)
149 if [ ! -d $hostdir ]
150 then
151     mkdir -p $hostdir
152     if [ -d ${ODL_HOME}/journal ]
153     then
154         mv ${ODL_HOME}/journal ${hostdir}
155     else
156         mkdir ${hostdir}/journal
157     fi
158     if [ -d ${ODL_HOME}/snapshots ]
159     then
160         mv ${ODL_HOME}/snapshots ${hostdir}
161     else
162         mkdir ${hostdir}/snapshots
163     fi
164 fi
165
166 ln -s ${hostdir}/journal ${ODL_HOME}/journal
167 ln -s ${hostdir}/snapshots ${ODL_HOME}/snapshots
168
169 echo "Starting cdt-proxy-service jar, logging to ${APPC_HOME}/cdt-proxy-service/jar.log"
170 java -jar ${APPC_HOME}/cdt-proxy-service/cdt-proxy-service.jar > ${APPC_HOME}/cdt-proxy-service/jar.log &
171
172 echo "Starting dmaap-event-service jar, logging to ${APPC_HOME}/dmaap-event-service/jar.log"
173 java -jar -Dorg_onap_appc_bootstrap_path=/opt/onap/appc/data/properties -Dorg_onap_appc_bootstrap_file=appc.properties ${APPC_HOME}/dmaap-event-service/dmaap-event-service.jar > ${APPC_HOME}/dmaap-event-service/jar.log &
174
175 echo "Adding a property system.properties for AAF cadi.properties location"
176 echo "" >> ${ODL_HOME}/etc/system.properties
177 echo "cadi_prop_files=${APPC_HOME}/data/properties/cadi.properties" >> ${ODL_HOME}/etc/system.properties
178 echo "" >> ${ODL_HOME}/etc/system.properties
179
180 echo "Adding a value to property appc.asdc.env in appc.properties for appc-asdc-listener feature"
181 echo "" >> $APPC_HOME/data/properties/appc.properties
182 echo "appc.asdc.env=$DMAAP_TOPIC_ENV" >> $APPC_HOME/data/properties/appc.properties
183 echo "" >> $APPC_HOME/data/properties/appc.properties
184
185 echo "Copying jetty, keystore for https into opendalight"
186 cp ${APPC_HOME}/data/jetty.xml ${ODL_HOME}/etc/jetty.xml
187 cp ${APPC_HOME}/data/keystore ${ODL_HOME}/etc/keystore
188 cp ${APPC_HOME}/data/custom.properties ${ODL_HOME}/etc/custom.properties
189
190 echo "Copying a working version of the logging configuration into the opendaylight etc folder"
191 cp ${APPC_HOME}/data/org.ops4j.pax.logging.cfg ${ODL_HOME}/etc/org.ops4j.pax.logging.cfg
192
193 ODL_BOOT_FEATURES_EXTRA="odl-netconf-connector,odl-restconf-noauth,odl-netconf-clustered-topology,odl-mdsal-clustering"
194 sed -i -e "\|featuresBoot[^a-zA-Z]|s|$|,${ODL_BOOT_FEATURES_EXTRA}|"  $ODL_HOME/etc/org.apache.karaf.features.cfg
195
196 exec ${APPC_HOME}/bin/dockerInstall.sh &
197 echo "Starting OpenDaylight"
198 exec ${ODL_HOME}/bin/karaf server