blob: 721f3407d561b0e22e2a451caa2c9a845ee513ba [file] [log] [blame]
Alexander Dehn5c1105e2020-09-14 20:55:56 +00001#!/bin/bash
2
3###
4# ============LICENSE_START=======================================================
5# SDNC
6# ================================================================================
7# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
8# ================================================================================
9# Update by Copyright (C) 2020 highstreet technologies GmbH. All rights reserved.
10# ================================================================================
11# Licensed under the Apache License, Version 2.0 (the "License");
12# you may not use this file except in compliance with the License.
13# You may obtain a copy of the License at
14#
15# http://www.apache.org/licenses/LICENSE-2.0
16#
17# Unless required by applicable law or agreed to in writing, software
18# distributed under the License is distributed on an "AS IS" BASIS,
19# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20# See the License for the specific language governing permissions and
21# limitations under the License.
22# ============LICENSE_END=========================================================
23###
24
25# Install SDN-C platform components if not already installed and start container
26
27# List of used constants, that are provided during container initialization
28
29ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
30ODL_FEATURES_BOOT_FILE=$ODL_HOME/etc/org.apache.karaf.features.cfg
31#
32ODL_REMOVEIDMDB=${ODL_REMOVEIDMDB:-false}
33
34#ODL_CERT_DIR
35ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME:-admin}
36if $ODL_REMOVEIDMDB ; then
37 echo "Remove odl idmdb"
38 rm $ODL_HOME/data/idmlight.db.mv.db
39 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-admin}
40else
41 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
42fi
43
44export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
45
46SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
47SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
48CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
49
50#- ODL Cluster
51ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
52#SDNC_REPLICAS
53
54#- ODL GEO cluster
55GEO_ENABLED=${GEO_ENABLED:-false}
56#IS_PRIMARY_CLUSTER
57#MY_ODL_CLUSTER
58#PEER_ODL_CLUSTER
59
60#- AAF
61SDNC_AAF_ENABLED=${SDNC_AAF_ENABLED:-false}
62
63#- SDN-R
64SDNRWT=${SDNRWT:-false}
65SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
66SDNRDM=${SDNRDM:-false}
67# Add devicemanager base and specific repositories
68SDNRDM_BASE_REPO=${SDNRDM_BASE_REPO:-mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-feature-aggregator-devicemanager-base/$CCSDKFEATUREVERSION/xml/features}
69SDNRDM_ONF_REPO=${SDNRDM_ONF_REPO:-mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-onf-feature/$CCSDKFEATUREVERSION/xml/features}
70SDNRDM_ORAN_REPO=${SDNRDM_ORAN_REPO:-mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-oran-feature/$CCSDKFEATUREVERSION/xml/features}
71SDNRDM_GRAN_REPO=${SDNRDM_GRAN_REPO:-mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-gran-feature/$CCSDKFEATUREVERSION/xml/features}
72# Add devicemanager features
73SDNRDM_SDM_LIST=${SDNRDM_SDM_LIST:-sdnr-wt-devicemanager-onf-feature, sdnr-wt-devicemanager-oran-feature, sdnr-wt-devicemanager-gran-feature}
74SDNRDM_BOOTFEATURES=${SDNRDM_BOOTFEATURES:-sdnr-wt-feature-aggregator-devicemanager-base, ${SDNRDM_SDM_LIST}}
75SDNRINIT=${SDNRINIT:-false}
76SDNRONLY=${SDNRONLY:-false}
77SDNRDBURL=${SDNRDBURL:-http://sdnrdb:9200}
78#SDNRDBUSERNAME
79#SDNRDBPASSWORD
80#SDNRDBPARAMETER
81SDNRDBCOMMAND=${SDNRDBCOMMAND:--c init -db $SDNRDBURL -dbu $SDNRDBUSERNAME -dbp $SDNRDBPASSWORD $SDNRDBPARAMETER}
82
83SDNR_NORTHBOUND=${SDNR_NORTHBOUND:-false}
84SDNR_NORTHBOUND_BOOTFEATURES=${SDNR_NORTHBOUND_BOOTFEATURES:-sdnr-northbound-all}
85
86# Functions
87
88# Test if repository exists, like this mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-oran-feature/0.7.2/xml/features
89# $1 repository
90function isRepoExisting() {
91 REPO=$(echo $1 | sed -E "s#mvn:(.*)/xml/features\$#\1#")
92 OIFS="$IFS"
93 IFS='/' parts=($REPO)
94 IFS="$OIFS"
95 path="$ODL_HOME/system/"${parts[0]//./\/}"/"${parts[1]}"/"${parts[2]}
96 [ -d "$path" ]
97}
98
99# Add features repository to karaf featuresRepositories configuration
100# $1 repositories to be added
101function addRepository() {
102 CFG=$ODL_FEATURES_BOOT_FILE
103 ORIG=$CFG.orig
104 if isRepoExisting "$1" ; then
105 echo "Add repository: $1"
106 sed -i "\|featuresRepositories|s|$|, $1|" $CFG
107 else
108 echo "Repo does not exist: $1"
109 fi
110}
111
112# Append features to karaf boot feature configuration
113# $1 additional feature to be added
114# $2 repositories to be added (optional)
115function addToFeatureBoot() {
116 CFG=$ODL_FEATURES_BOOT_FILE
117 ORIG=$CFG.orig
118 if [ -n "$2" ] ; then
119 addRepository $2
120 fi
121 echo "Add boot feature: $1"
122 sed -i "\|featuresBoot *=|s|$|,$1|" $CFG
123}
124
125# Append features to karaf boot feature configuration
126# $1 search pattern
127# $2 replacement
128function replaceFeatureBoot() {
129 CFG=$ODL_FEATURES_BOOT_FILE
130 echo "Replace boot feature $1 with: $2"
131 sed -i "/featuresBoot/ s/$1/$2/g" $CFG
132}
133
134# Remove all sdnc specific features
135function cleanupFeatureBoot() {
136 echo "Remove northbound bootfeatures "
137 sed -i "/featuresBoot/ s/,ccsdk-sli-core-all.*$//g" $ODL_FEATURES_BOOT_FILE
138}
139
140function initialize_sdnr() {
141 echo "SDN-R Database Initialization"
142 INITCMD="$JAVA_HOME/bin/java -jar "
143 INITCMD+="$ODL_HOME/system/org/onap/ccsdk/features/sdnr/wt/sdnr-wt-data-provider-setup/$CCSDKFEATUREVERSION/sdnr-dmt.jar "
144 INITCMD+="$SDNRDBCOMMAND"
145 echo "Execute: $INITCMD"
146 n=0
147 until [ $n -ge 5 ] ; do
148 $INITCMD && break
149 n=$[$n+1]
150 sleep 15
151 done
152 return $?
153}
154
155function install_sdnrwt_features() {
156 # Repository setup provided via sdnc dockerfile
157 if $SDNRWT; then
158 addRepository $SDNRDM_BASE_REPO
159 addRepository $SDNRDM_ONF_REPO
160 addRepository $SDNRDM_ORAN_REPO
161 addRepository $SDNRDM_GRAN_REPO
162
163 if $SDNRONLY; then
164 cleanupFeatureBoot
165 fi
166 if $SDNRDM; then
167 addToFeatureBoot "$SDNRDM_BOOTFEATURES"
168 else
169 addToFeatureBoot "$SDNRWT_BOOTFEATURES"
170 fi
171 fi
172}
173
174
175function install_sdnr_northbound_features() {
176 # Repository setup provided via sdnc dockerfile
177 addToFeatureBoot "$SDNR_NORTHBOUND_BOOTFEATURES"
178}
179
180# Reconfigure ODL from default single node configuration to cluster
181
182function enable_odl_cluster(){
183 if [ -z $SDNC_REPLICAS ]; then
184 echo "SDNC_REPLICAS is not configured in Env field"
185 exit
186 fi
187
188 # ODL NETCONF setup
189 echo "Installing Opendaylight cluster features for mdsal and netconf"
190
191 #Be sure to remove feature odl-netconf-connector-all from list
192 replaceFeatureBoot "odl-netconf-connector-all,"
193 #Activate cluster
194 replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
195 replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
196 addToFeatureBoot odl-jolokia
197
198 # ODL Cluster or Geo cluster configuration
199
200 echo "Update cluster information statically"
201 fqdn=$(hostname -f)
202 echo "Get current fqdn ${fqdn}"
203
204 # Extract node index using first digit after "-"
205 # Example 2 from "sdnr-2.logo.ost.das.r32.com"
206 node_index=($(echo ${fqdn} | sed -r 's/.*-([0-9]).*/\1/g'))
207
208 if $GEO_ENABLED; then
209 echo "This is a Geo cluster"
210
211 if [ -z $IS_PRIMARY_CLUSTER ] || [ -z $MY_ODL_CLUSTER ] || [ -z $PEER_ODL_CLUSTER ]; then
212 echo "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field"
213 return
214 fi
215
216 member_offset=1
217 if $IS_PRIMARY_CLUSTER; then
218 PRIMARY_NODE=${MY_ODL_CLUSTER}
219 SECONDARY_NODE=${PEER_ODL_CLUSTER}
220 else
221 PRIMARY_NODE=${PEER_ODL_CLUSTER}
222 SECONDARY_NODE=${MY_ODL_CLUSTER}
223 member_offset=4
224 fi
225
226 node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
227 $SDNC_BIN/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
228 else
229 echo "This is a local cluster"
230 for ((i=0;i<${SDNC_REPLICAS};i++)); do
231 #assemble node list by replaceing node-index in hostname with "i"
232 node_name=$(echo ${fqdn} | sed -r "s/-[0-9]/-$i/g")
233 node_list="${node_list} $node_name"
234 done
235 echo "Node index: $((node_index+1)) list: ${node_list[@]}"
236 $ODL_HOME/bin/configure_cluster.sh $((node_index+1)) ${node_list}
237 fi
238}
239
240# -----------------------
241# Main script starts here
242
243echo "Image path=${IMAGEPATH}"
244echo "Image names=${IMAGENAMES}"
245echo "Settings:"
246echo " USER=$(whoami)"
247echo " SDNC_BIN=$SDNC_BIN"
248echo " SDNC_HOME=$SDNC_HOME"
249echo " ODL_CERT_DIR=$ODL_CERT_DIR"
250echo " CCSDKFEATUREVERSION=$CCSDKFEATUREVERSION"
251echo " ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
252echo " ODL_REMOVEIDMDB=$ODL_REMOVEIDMDB"
253echo " SDNC_REPLICAS=$SDNC_REPLICAS"
254echo " SDNRWT=$SDNRWT"
255echo " SDNRDM=$SDNRDM"
256echo " SDNRONLY=$SDNRONLY"
257echo " SDNRINIT=$SDNRINIT"
258echo " SDNRDBURL=$SDNRDBURL"
259echo " SDNRDBUSERNAME=$SDNRDBUSERNAME"
260echo " SDNRDBPASSWORD=$SDNRDBPASSWORD"
261echo " GEO_ENABLED=$GEO_ENABLED"
262echo " IS_PRIMARY_CLUSTER=$IS_PRIMARY_CLUSTER"
263echo " MY_ODL_CLUSTER=$MY_ODL_CLUSTER"
264echo " PEER_ODL_CLUSTER=$PEER_ODL_CLUSTER"
265echo " AAF_ENABLED=$SDNC_AAF_ENABLED"
266
267if $SDNC_AAF_ENABLED; then
268 export SDNC_AAF_STORE_DIR=/opt/app/osaaf/local
269 export SDNC_AAF_CONFIG_DIR=/opt/app/osaaf/local
270 export SDNC_KEYPASS=`cat /opt/app/osaaf/local/.pass`
271 export SDNC_KEYSTORE=org.onap.sdnc.p12
272 sed -i '/cadi_prop_files/d' $ODL_HOME/etc/system.properties
273 echo "cadi_prop_files=$SDNC_AAF_CONFIG_DIR/org.onap.sdnc.props" >> $ODL_HOME/etc/system.properties
274
275 sed -i '/org.ops4j.pax.web.ssl.keystore/d' $ODL_HOME/etc/custom.properties
276 sed -i '/org.ops4j.pax.web.ssl.password/d' $ODL_HOME/etc/custom.properties
277 sed -i '/org.ops4j.pax.web.ssl.keypassword/d' $ODL_HOME/etc/custom.properties
278 echo org.ops4j.pax.web.ssl.keystore=$SDNC_AAF_STORE_DIR/$SDNC_KEYSTORE >> $ODL_HOME/etc/custom.properties
279 echo org.ops4j.pax.web.ssl.password=$SDNC_KEYPASS >> $ODL_HOME/etc/custom.properties
280 echo org.ops4j.pax.web.ssl.keypassword=$SDNC_KEYPASS >> $ODL_HOME/etc/custom.properties
281fi
282
283if $SDNRINIT ; then
284 #One time intialization action
285 initialize_sdnr
286 init_result=$?
287 echo "Result of init script: $init_result"
288 if $SDNRWT ; then
289 echo "Proceed to initialize sdnr"
290 else
291 exit $init_result
292 fi
293fi
294
295if [ ! -f ${SDNC_HOME}/.installed ]
296then
297 echo "Installing SDN-C keyStore"
298 /bin/bash ${SDNC_HOME}/bin/addSdncKeyStore.sh
299
300 if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
301
302 if $SDNRWT ; then install_sdnrwt_features ; fi
303
304 if $SDNR_NORTHBOUND ; then install_sdnr_northbound_features ; fi
305
306 echo "Installed at `date`" > ${SDNC_HOME}/.installed
307fi
308
309# Odl configuration done
310ODL_FEATURES_BOOT=$(sed -n "/featuresBoot =/p" $ODL_FEATURES_BOOT_FILE)
311export ODL_FEATURES_BOOT
312
313if [ -z "$ODL_CERT_DIR" ] ; then
314 echo "No certs provided. Skip installation."
315else
316 echo "Start background cert installer"
317 nohup python ${SDNC_BIN}/installCerts.oom.py &
318fi
319
320echo "Startup opendaylight"
321echo $ODL_FEATURES_BOOT
322exec ${ODL_HOME}/bin/karaf server