3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright (C) 2020 Samsung Electronics
7 # Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
8 # Copyright (C) 2020 Highstreet Technologies
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
14 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 # A single entry point script that can be used in Kubernetes based deployments (via OOM) and standalone docker deployments.
24 # Please see https://wiki.onap.org/display/DW/startODL.sh+-+Important+Environment+variables+and+their+description for more details
28 # Test if repository exists, like this mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-oran-feature/0.7.2/xml/features
31 REPO=$(echo "$1" | sed -E "s#mvn:(.*)/xml/features\$#\1#")
36 path="$ODL_HOME/system/$(echo "$2" | tr '.' '/')/$3/$4"
40 # Add features repository to karaf featuresRepositories configuration
41 # $1 repositories to be added
43 CFG=$ODL_FEATURES_BOOT_FILE
45 if isRepoExisting "$1" ; then
46 printf "%s\n" "Add repository: $1"
47 sed -i "\|featuresRepositories|s|$|, $1|" "$CFG"
49 printf "%s\n" "Repo does not exist: $1"
53 # Append features to karaf boot feature configuration
54 # $1 additional feature to be added
55 # $2 repositories to be added (optional)
57 CFG=$ODL_FEATURES_BOOT_FILE
60 printf "%s\n" "Add repository: $2"
62 sed -e "\|featuresRepositories|s|$|,$2|" "$ORIG" > "$CFG"
64 printf "%s\n" "Add boot feature: $1"
66 sed -e "\|featuresBoot *=|s|$|,$1|" "$ORIG" > "$CFG"
69 # Append features to karaf boot feature configuration
72 replaceFeatureBoot() {
73 CFG="$ODL_HOME"/etc/org.apache.karaf.features.cfg
75 printf "%s %s\n" "Replace boot feature $1 with: $2"
76 sed -i "/featuresBoot/ s/$1/$2/g" "$CFG"
79 # Remove all sdnc specific features
80 cleanupFeatureBoot() {
81 printf "Remove northbound bootfeatures \n"
82 sed -i "/featuresBoot/ s/,ccsdk-sli-core-all.*$//g" "$ODL_FEATURES_BOOT_FILE"
86 printf "SDN-R Database Initialization"
87 INITCMD="$JAVA_HOME/bin/java -jar "
88 INITCMD="${INITCMD} $ODL_HOME/system/org/onap/ccsdk/features/sdnr/wt/sdnr-wt-data-provider-setup/$CCSDKFEATUREVERSION/sdnr-dmt.jar "
89 INITCMD="${INITCMD} $SDNRDBCOMMAND"
90 printf "%s\n" "Execute: $INITCMD"
92 until [ $n -ge 5 ] ; do
100 install_sdnrwt_features() {
101 # Repository setup provided via sdnc dockerfile
107 addToFeatureBoot "$SDNRDM_BOOTFEATURES"
109 addToFeatureBoot "$SDNRODLUX_BOOTFEATURES"
113 install_sdnr_oauth_features() {
114 addToFeatureBoot "$SDNROAUTH_BOOTFEATURES"
116 install_sdnr_northbound_features() {
117 addToFeatureBoot "$SDNR_NORTHBOUND_BOOTFEATURES"
120 # Reconfigure ODL from default single node configuration to cluster
122 enable_odl_cluster() {
123 if [ -z "$SDNC_REPLICAS" ]; then
124 printf "SDNC_REPLICAS is not configured in Env field"
129 printf "Installing Opendaylight cluster features for mdsal and netconf\n"
131 #Be sure to remove feature odl-netconf-connector-all from list
132 replaceFeatureBoot "odl-netconf-connector-all,"
134 printf "Installing Opendaylight cluster features\n"
135 replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
136 replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
137 addToFeatureBoot odl-jolokia
138 #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
139 #${ODL_HOME}/bin/client feature:install odl-jolokia
141 # ODL Cluster or Geo cluster configuration
143 printf "Update cluster information statically\n"
145 printf "%s\n" "Get current fqdn ${fqdn}"
147 # Extract node index using first digit after "-"
148 # Example 2 from "sdnr-2.logo.ost.das.r32.com"
149 node_index=$(echo "${fqdn}" | sed -r 's/.*-([0-9]).*/\1/g')
152 if $GEO_ENABLED; then
153 printf "This is a Geo cluster\n"
155 if [ -z "$IS_PRIMARY_CLUSTER" ] || [ -z "$MY_ODL_CLUSTER" ] || [ -z "$PEER_ODL_CLUSTER" ]; then
156 printf "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field\n"
160 if $IS_PRIMARY_CLUSTER; then
161 PRIMARY_NODE=${MY_ODL_CLUSTER}
162 SECONDARY_NODE=${PEER_ODL_CLUSTER}
164 PRIMARY_NODE=${PEER_ODL_CLUSTER}
165 SECONDARY_NODE=${MY_ODL_CLUSTER}
169 node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
171 "${SDNC_BIN}"/configure_geo_cluster.sh $((node_index+member_offset)) "${node_list}"
173 printf "This is a local cluster\n"
176 # SERVICE_NAME and NAMESPACE are used to create cluster node names and are provided via Helm charts in OOM environment
177 if [ ! -z "$SERVICE_NAME" ] && [ ! -z "$NAMESPACE" ]; then
178 # Extract node name minus the index
179 # Example sdnr from "sdnr-2.logo.ost.das.r32.com"
180 node_name=$(echo "${fqdn}" | sed 's/-[0-9].*$//g')
181 while [ $i -lt "$SDNC_REPLICAS" ]; do
182 node_list="${node_list} ${node_name}-$i.${SERVICE_NAME}-cluster.${NAMESPACE}"
185 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
186 elif [ -z "$SERVICE_NAME" ] && [ -z "$NAMESPACE" ]; then
187 # Hostname is used in Standalone environment to create cluster node names
188 while [ $i -lt "$SDNC_REPLICAS" ]; do
189 #assemble node list by replacing node-index in hostname with "i"
190 node_name=$(echo "${fqdn}" | sed -r "s/-[0-9]/-$i/g")
191 node_list="${node_list} ${node_name}"
194 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
196 printf "Unhandled cluster scenario. Terminating the container\n"
197 printf "Any one of the below 2 conditions should be satisfied for successfully enabling cluster mode : \n"
198 printf "1. OOM Environment - Both SERVICE_NAME and NAMESPACE environment variables have to be set.\n"
199 printf "2. Docker (standalone) Environment - Neither of SERVICE_NAME and NAMESPACE have to be set.\n"
200 printf "Current configuration - SERVICE_NAME = $SERVICE_NAME NAMESPACE = $NAMESPACE\n"
207 # Install SDN-C platform components if not already installed and start container
209 # -----------------------
210 # Main script starts here
211 printf "Installing SDNC/R from startODL.sh script\n"
212 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
213 ODL_FEATURES_BOOT_FILE=$ODL_HOME/etc/org.apache.karaf.features.cfg
215 ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME:-admin}
216 ODL_REMOVEIDMDB=${ODL_REMOVEIDMDB:-true}
218 if $ODL_REMOVEIDMDB ; then
219 if [ -f $ODL_HOME/data/idmlight.db.mv.db ]; then
220 rm $ODL_HOME/data/idmlight.db.mv.db
224 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
225 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
226 # Whether to intialize MYSql DB or not. Default is to initialize
227 SDNC_DB_INIT=${SDNC_DB_INIT:-false}
228 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
229 JDEBUG=${JDEBUG:-false}
230 MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-openECOMP1.0}
231 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
232 ENABLE_OAUTH=${ENABLE_OAUTH:-false}
233 ENABLE_ODLUX_RBAC=${ENABLE_ODLUX_RBAC:-false}
234 GEO_ENABLED=${GEO_ENABLED:-false}
235 SDNC_AAF_ENABLED=${SDNC_AAF_ENABLED:-false}
236 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
237 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
238 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
239 SDNRWT=${SDNRWT:-false}
240 SDNRODLUX_BOOTFEATURES=${SDNRODLUX_BOOTFEATURES:-sdnr-wt-helpserver-feature,sdnr-wt-odlux-core-feature,sdnr-wt-odlux-apps-feature}
241 SDNROAUTH_BOOTFEATURES=${SDNROAUTH_BOOTFEATURES:-sdnr-wt-feature-aggregator-oauth}
242 SDNRDM=${SDNRDM:-false}
243 # Add devicemanager features
244 SDNRDM_SDM_LIST=${SDNRDM_SDM_LIST:-sdnr-wt-feature-aggregator-devicemanager}
245 SDNRDM_BOOTFEATURES=${SDNRDM_BOOTFEATURES:-sdnr-wt-feature-aggregator-devicemanager-base,${SDNRDM_SDM_LIST}}
246 # Whether to Initialize the ElasticSearch DB.
247 SDNRINIT=${SDNRINIT:-false}
248 SDNRONLY=${SDNRONLY:-false}
249 SDNRDBURL=${SDNRDBURL:-http://sdnrdb:9200}
250 SDNRDBCOMMAND=${SDNRDBCOMMAND:--c init -db $SDNRDBURL -dbu $SDNRDBUSERNAME -dbp $SDNRDBPASSWORD $SDNRDBPARAMETER}
252 SDNR_NORTHBOUND=${SDNR_NORTHBOUND:-false}
253 SDNR_NORTHBOUND_BOOTFEATURES=${SDNR_NORTHBOUND_BOOTFEATURES:-sdnr-northbound-all}
255 #export for installCerts.py
256 export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
259 printf "Activate remote debugging\n"
260 #JSTADTPOLICYFILE="$ODL_HOME/etc/tools.policy"
261 #echo -e "grant codebase \"file:${JAVA_HOME}/lib/tools.jar\" {\n permission java.security.AllPermission;\n };" > $JSTADTPOLICYFILE
263 #$JAVA_HOME/bin/jstatd -p 1089 -J-Djava.security.policy=$JSTADTPOLICYFILE &
264 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.port=1090"
265 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.rmi.port=1090"
266 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Djava.rmi.server.hostname=$(hostname) "
267 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.local.only=false"
268 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
269 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
270 export EXTRA_JAVA_OPTS
275 printf "%s\n" " SDNC_BIN=$SDNC_BIN"
276 printf "%s\n" " SDNC_HOME=$SDNC_HOME"
277 printf "%s\n" " SDNC_DB_INIT=$SDNC_DB_INIT"
278 printf "%s\n" " ODL_CERT_DIR=$ODL_CERT_DIR"
279 printf "%s\n" " CCSDKFEATUREVERSION=$CCSDKFEATUREVERSION"
280 printf "%s\n" " ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
281 printf "%s\n" " ODL_REMOVEIDMDB=$ODL_REMOVEIDMDB"
282 printf "%s\n" " SDNC_REPLICAS=$SDNC_REPLICAS"
283 printf "%s\n" " ENABLE_OAUTH=$ENABLE_OAUTH"
284 printf "%s\n" " ENABLE_ODLUX_RBAC=$ENABLE_ODLUX_RBAC"
285 printf "%s\n" " SDNRWT=$SDNRWT"
286 printf "%s\n" " SDNRDM=$SDNRDM"
287 printf "%s\n" " SDNRONLY=$SDNRONLY"
288 printf "%s\n" " SDNRINIT=$SDNRINIT"
289 printf "%s\n" " SDNRDBURL=$SDNRDBURL"
290 printf "%s\n" " SDNRDBUSERNAME=$SDNRDBUSERNAME"
291 printf "%s\n" " GEO_ENABLED=$GEO_ENABLED"
292 printf "%s\n" " IS_PRIMARY_CLUSTER=$IS_PRIMARY_CLUSTER"
293 printf "%s\n" " MY_ODL_CLUSTER=$MY_ODL_CLUSTER"
294 printf "%s\n" " PEER_ODL_CLUSTER=$PEER_ODL_CLUSTER"
295 printf "%s\n" " SDNR_NORTHBOUND=$SDNR_NORTHBOUND"
296 printf "%s\n" " AAF_ENABLED=$SDNC_AAF_ENABLED"
297 printf "%s\n" " SERVICE_NAME=$SERVICE_NAME"
298 printf "%s\n" " NAMESPACE=$NAMESPACE"
300 if "$SDNC_AAF_ENABLED"; then
301 export SDNC_AAF_STORE_DIR=/opt/app/osaaf/local
302 export SDNC_AAF_CONFIG_DIR=/opt/app/osaaf/local
303 export SDNC_KEYPASS=$(cat /opt/app/osaaf/local/.pass)
304 export SDNC_KEYSTORE=org.onap.sdnc.p12
305 sed -i '/cadi_prop_files/d' "$ODL_HOME"/etc/system.properties
306 echo "cadi_prop_files=$SDNC_AAF_CONFIG_DIR/org.onap.sdnc.props" >> "$ODL_HOME"/etc/system.properties
308 sed -i '/org.ops4j.pax.web.ssl.keystore/d' "$ODL_HOME"/etc/custom.properties
309 sed -i '/org.ops4j.pax.web.ssl.password/d' "$ODL_HOME"/etc/custom.properties
310 sed -i '/org.ops4j.pax.web.ssl.keypassword/d' "$ODL_HOME"/etc/custom.properties
311 echo "org.ops4j.pax.web.ssl.keystore=$SDNC_AAF_STORE_DIR/$SDNC_KEYSTORE" >> "$ODL_HOME"/etc/custom.properties
312 echo "org.ops4j.pax.web.ssl.password=$SDNC_KEYPASS" >> "$ODL_HOME"/etc/custom.properties
313 echo "org.ops4j.pax.web.ssl.keypassword=$SDNC_KEYPASS" >> "$ODL_HOME"/etc/custom.properties
317 #One time intialization action
320 printf "%s\n" "Result of init script: $init_result"
322 printf "Proceed to initialize sdnr\n"
328 # do not start container if ADMIN_PASSWORD is not set
329 if [ -z "$ODL_ADMIN_PASSWORD" ]; then
330 echo "ODL_ADMIN_PASSWORD is not set"
334 # Check for MySQL DB connectivity only if SDNC_DB_INIT is set to "true"
335 if $SDNC_DB_INIT; then
339 printf "Waiting for mysql"
340 until mysql -h dbhost -u root -p"${MYSQL_ROOT_PASSWORD}" -e "select 1" > /dev/null 2>&1
345 printf "\nmysql ready"
349 if [ ! -d "${INSTALLED_DIR}" ]
351 mkdir -p "${INSTALLED_DIR}"
354 if [ ! -f "${SDNC_HOME}"/.installed ]
356 # for integration testing. In OOM, a separate job takes care of installing it.
357 if $SDNC_DB_INIT; then
358 printf "Installing SDN-C database\n"
359 "${SDNC_HOME}"/bin/installSdncDb.sh
361 printf "Installing SDN-C keyStore\n"
362 "${SDNC_HOME}"/bin/addSdncKeyStore.sh
363 printf "Installing A1-adapter trustStore\n"
364 "${SDNC_HOME}"/bin/addA1TrustStore.sh
366 if [ -x "${SDNC_HOME}"/svclogic/bin/install.sh ]
368 printf "Installing directed graphs\n"
369 "${SDNC_HOME}"/svclogic/bin/install.sh
372 if $SDNRWT ; then install_sdnrwt_features ; fi
373 if $ENABLE_OAUTH ; then
374 cp $SDNC_HOME/data/oauth-aaa-app-config.xml $ODL_HOME/system/org/opendaylight/aaa/aaa-shiro/0.12.1/aaa-shiro-0.12.1-aaa-app-config.xml
375 install_sdnr_oauth_features
378 # The enable_odl_cluster call should not be moved above this line as the cleanFeatureBoot will overwrite entries. Ex: odl-jolokia
379 if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
381 if $SDNR_NORTHBOUND ; then install_sdnr_northbound_features ; fi
382 printf "%s" "Installed at $(date)" > "${SDNC_HOME}"/.installed
385 #cp /opt/opendaylight/current/certs/* /tmp
386 #cp /var/custom-certs/* /tmp
388 if [ -n "$OVERRIDE_FEATURES_BOOT" ] ; then
389 printf "%s\n" "Override features boot: $OVERRIDE_FEATURES_BOOT"
390 sed -i "/$FEATURESBOOTMARKER/c\featuresBoot = $OVERRIDE_FEATURES_BOOT" "$ODL_FEATURES_BOOT_FILE"
393 # Odl configuration done
394 ODL_REPOSITORIES_BOOT=$(sed -n "/$REPOSITORIESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
395 ODL_FEATURES_BOOT=$(sed -n "/$FEATURESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
396 export ODL_FEATURES_BOOT
398 # Create ODL data log directory (it nornally is created after karaf
399 # is started, but needs to exist before installCerts.py runs)
400 if [ -z "$ODL_CERT_DIR" ] ; then
401 printf "No certs provided. Skip installation.\n"
403 printf "Start background cert installer\n"
404 mkdir -p /opt/opendaylight/data/log
405 nohup python3 "${SDNC_BIN}"/installCerts.py &
406 printf "Start monitoring certificate installation. \n"
407 nohup sh "${SDNC_BIN}"/monitorCertsInstall.sh &
410 printf "Startup opendaylight\n"
411 printf "%s\n" "$ODL_REPOSITORIES_BOOT"
412 printf "%s\n" "$ODL_FEATURES_BOOT"
413 exec "${ODL_HOME}"/bin/karaf server