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
103 addRepository "$SDNRDM_BASE_REPO"
104 addRepository "$SDNRDM_ONF_REPO"
110 addToFeatureBoot "$SDNRDM_BOOTFEATURES"
112 addToFeatureBoot "$SDNRWT_BOOTFEATURES"
117 install_sdnr_northbound_features() {
118 addToFeatureBoot "$SDNR_NORTHBOUND_BOOTFEATURES"
121 # Reconfigure ODL from default single node configuration to cluster
123 enable_odl_cluster() {
124 if [ -z "$SDNC_REPLICAS" ]; then
125 printf "SDNC_REPLICAS is not configured in Env field"
130 printf "Installing Opendaylight cluster features for mdsal and netconf\n"
132 #Be sure to remove feature odl-netconf-connector-all from list
133 replaceFeatureBoot "odl-netconf-connector-all,"
135 printf "Installing Opendaylight cluster features\n"
136 replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
137 replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
138 addToFeatureBoot odl-jolokia
139 #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
140 #${ODL_HOME}/bin/client feature:install odl-jolokia
142 # ODL Cluster or Geo cluster configuration
144 printf "Update cluster information statically\n"
146 printf "%s\n" "Get current fqdn ${fqdn}"
148 # Extract node index using first digit after "-"
149 # Example 2 from "sdnr-2.logo.ost.das.r32.com"
150 node_index=$(echo "${fqdn}" | sed -r 's/.*-([0-9]).*/\1/g')
153 if $GEO_ENABLED; then
154 printf "This is a Geo cluster\n"
156 if [ -z "$IS_PRIMARY_CLUSTER" ] || [ -z "$MY_ODL_CLUSTER" ] || [ -z "$PEER_ODL_CLUSTER" ]; then
157 printf "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field\n"
161 if $IS_PRIMARY_CLUSTER; then
162 PRIMARY_NODE=${MY_ODL_CLUSTER}
163 SECONDARY_NODE=${PEER_ODL_CLUSTER}
165 PRIMARY_NODE=${PEER_ODL_CLUSTER}
166 SECONDARY_NODE=${MY_ODL_CLUSTER}
170 node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
172 "${SDNC_BIN}"/configure_geo_cluster.sh $((node_index+member_offset)) "${node_list}"
174 printf "This is a local cluster\n"
177 # SERVICE_NAME and NAMESPACE are used to create cluster node names and are provided via Helm charts in OOM environment
178 if [ ! -z "$SERVICE_NAME" ] && [ ! -z "$NAMESPACE" ]; then
179 # Extract node name minus the index
180 # Example sdnr from "sdnr-2.logo.ost.das.r32.com"
181 node_name=$(echo "${fqdn}" | sed 's/-[0-9].*$//g')
182 while [ $i -lt "$SDNC_REPLICAS" ]; do
183 node_list="${node_list} ${node_name}-$i.${SERVICE_NAME}-cluster.${NAMESPACE}"
186 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
187 elif [ -z "$SERVICE_NAME" ] && [ -z "$NAMESPACE" ]; then
188 # Hostname is used in Standalone environment to create cluster node names
189 while [ $i -lt "$SDNC_REPLICAS" ]; do
190 #assemble node list by replacing node-index in hostname with "i"
191 node_name=$(echo "${fqdn}" | sed -r "s/-[0-9]/-$i/g")
192 node_list="${node_list} ${node_name}"
195 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
197 printf "Unhandled cluster scenario. Terminating the container\n"
198 printf "Any one of the below 2 conditions should be satisfied for successfully enabling cluster mode : \n"
199 printf "1. OOM Environment - Both SERVICE_NAME and NAMESPACE environment variables have to be set.\n"
200 printf "2. Docker (standalone) Environment - Neither of SERVICE_NAME and NAMESPACE have to be set.\n"
201 printf "Current configuration - SERVICE_NAME = $SERVICE_NAME NAMESPACE = $NAMESPACE\n"
208 # Install SDN-C platform components if not already installed and start container
210 # -----------------------
211 # Main script starts here
212 printf "Installing SDNC/R from startODL.sh script\n"
213 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
214 ODL_FEATURES_BOOT_FILE=$ODL_HOME/etc/org.apache.karaf.features.cfg
216 ODL_REMOVEIDMDB=${ODL_REMOVEIDMDB:-false}
218 ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME:-admin}
219 if $ODL_REMOVEIDMDB ; then
220 printf "Remove odl idmdb"
221 rm "$ODL_HOME"/data/idmlight.db.mv.db
222 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-admin}
224 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
226 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
227 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
228 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
229 # Whether to intialize MYSql DB or not. Default is to initialize
230 SDNC_DB_INIT=${SDNC_DB_INIT:-false}
231 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
232 JDEBUG=${JDEBUG:-false}
233 MYSQL_PASSWD=${MYSQL_PASSWD:-openECOMP1.0}
234 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
235 GEO_ENABLED=${GEO_ENABLED:-false}
236 SDNC_AAF_ENABLED=${SDNC_AAF_ENABLED:-false}
237 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
238 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
239 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
240 SDNRWT=${SDNRWT:-false}
241 SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
242 SDNRDM=${SDNRDM:-false}
243 # Add devicemanager base and specific repositories
244 SDNRDM_BASE_REPO=${SDNRDM_BASE_REPO:-mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-feature-aggregator-devicemanager-base/$CCSDKFEATUREVERSION/xml/features}
245 SDNRDM_ONF_REPO=${SDNRDM_ONF_REPO:-mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-onf-feature/$CCSDKFEATUREVERSION/xml/features}
246 # Add devicemanager features
247 SDNRDM_SDM_LIST=${SDNRDM_SDM_LIST:-sdnr-wt-devicemanager-onf-feature}
248 SDNRDM_BOOTFEATURES=${SDNRDM_BOOTFEATURES:-sdnr-wt-feature-aggregator-devicemanager-base, ${SDNRDM_SDM_LIST}}
249 # Whether to Initialize the ElasticSearch DB.
250 SDNRINIT=${SDNRINIT:-false}
251 SDNRONLY=${SDNRONLY:-false}
252 SDNRDBURL=${SDNRDBURL:-http://sdnrdb:9200}
253 SDNRDBCOMMAND=${SDNRDBCOMMAND:--c init -db $SDNRDBURL -dbu $SDNRDBUSERNAME -dbp $SDNRDBPASSWORD $SDNRDBPARAMETER}
255 SDNR_NORTHBOUND=${SDNR_NORTHBOUND:-false}
256 SDNR_NORTHBOUND_BOOTFEATURES=${SDNR_NORTHBOUND_BOOTFEATURES:-sdnr-northbound-all}
258 export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
261 printf "Activate remote debugging\n"
262 #JSTADTPOLICYFILE="$ODL_HOME/etc/tools.policy"
263 #echo -e "grant codebase \"file:${JAVA_HOME}/lib/tools.jar\" {\n permission java.security.AllPermission;\n };" > $JSTADTPOLICYFILE
265 #$JAVA_HOME/bin/jstatd -p 1089 -J-Djava.security.policy=$JSTADTPOLICYFILE &
266 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.port=1090"
267 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.rmi.port=1090"
268 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Djava.rmi.server.hostname=$(hostname) "
269 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.local.only=false"
270 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
271 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
272 export EXTRA_JAVA_OPTS
277 printf "%s\n" " SDNC_BIN=$SDNC_BIN"
278 printf "%s\n" " SDNC_HOME=$SDNC_HOME"
279 printf "%s\n" " SDNC_DB_INIT=$SDNC_DB_INIT"
280 printf "%s\n" " ODL_CERT_DIR=$ODL_CERT_DIR"
281 printf "%s\n" " CCSDKFEATUREVERSION=$CCSDKFEATUREVERSION"
282 printf "%s\n" " ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
283 printf "%s\n" " ODL_REMOVEIDMDB=$ODL_REMOVEIDMDB"
284 printf "%s\n" " SDNC_REPLICAS=$SDNC_REPLICAS"
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 # Check for MySQL DB connectivity only if SDNC_DB_INIT is set to "true"
329 if $SDNC_DB_INIT; then
333 printf "Waiting for mysql"
334 until mysql -h dbhost -u root -p"${MYSQL_PASSWD}" mysql > /dev/null 2>&1
339 printf "\nmysql ready"
342 if [ ! -d "${INSTALLED_DIR}" ]
344 mkdir -p "${INSTALLED_DIR}"
347 if [ ! -f "${SDNC_HOME}"/.installed ]
349 # for integration testing. In OOM, a separate job takes care of installing it.
350 if $SDNC_DB_INIT; then
351 printf "Installing SDN-C database\n"
352 "${SDNC_HOME}"/bin/installSdncDb.sh
354 printf "Installing SDN-C keyStore\n"
355 "${SDNC_HOME}"/bin/addSdncKeyStore.sh
356 printf "Installing A1-adapter trustStore\n"
357 "${SDNC_HOME}"/bin/addA1TrustStore.sh
359 if [ -x "${SDNC_HOME}"/svclogic/bin/install.sh ]
361 printf "Installing directed graphs\n"
362 "${SDNC_HOME}"/svclogic/bin/install.sh
365 if $SDNRWT ; then install_sdnrwt_features ; fi
366 # The enable_odl_cluster call should not be moved above this line as the cleanFeatureBoot will overwrite entries. Ex: odl-jolokia
367 if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
369 if $SDNR_NORTHBOUND ; then install_sdnr_northbound_features ; fi
370 printf "%s" "Installed at $(date)" > "${SDNC_HOME}"/.installed
373 #cp /opt/opendaylight/current/certs/* /tmp
374 #cp /var/custom-certs/* /tmp
376 if [ -n "$OVERRIDE_FEATURES_BOOT" ] ; then
377 printf "%s\n" "Override features boot: $OVERRIDE_FEATURES_BOOT"
378 sed -i "/$FEATURESBOOTMARKER/c\featuresBoot = $OVERRIDE_FEATURES_BOOT" "$ODL_FEATURES_BOOT_FILE"
381 # Odl configuration done
382 ODL_REPOSITORIES_BOOT=$(sed -n "/$REPOSITORIESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
383 ODL_FEATURES_BOOT=$(sed -n "/$FEATURESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
384 export ODL_FEATURES_BOOT
386 # Create ODL data log directory (it nornally is created after karaf
387 # is started, but needs to exist before installCerts.py runs)
388 if [ -z "$ODL_CERT_DIR" ] ; then
389 printf "No certs provided. Skip installation.\n"
391 printf "Start background cert installer\n"
392 mkdir -p /opt/opendaylight/data/log
393 nohup python3 "${SDNC_BIN}"/installCerts.py &
396 printf "Startup opendaylight\n"
397 printf "%s\n" "$ODL_REPOSITORIES_BOOT"
398 printf "%s\n" "$ODL_FEATURES_BOOT"
399 exec "${ODL_HOME}"/bin/karaf server