Merge "[Tree-wide] Remove pnda charts from OOM"
[oom.git] / kubernetes / sdnc / resources / config / bin / startODL.sh
1 #!/bin/bash
2 {{/*
3
4 ###
5 # ============LICENSE_START=======================================================
6 # SDNC
7 # ================================================================================
8 # Copyright © 2020 Samsung Electronics
9 # Copyright (C) 2017 AT&T Intellectual Property. 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 # Append features to karaf boot feature configuration
26 # $1 additional feature to be added
27 # $2 repositories to be added (optional)
28 */}}
29 function addToFeatureBoot() {
30   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
31   ORIG=$CFG.orig
32   if [ -n "$2" ] ; then
33     echo "Add repository: $2"
34     mv $CFG $ORIG
35     cat $ORIG | sed -e "\|featuresRepositories|s|$|,$2|" > $CFG
36   fi
37   echo "Add boot feature: $1"
38   mv $CFG $ORIG
39   cat $ORIG | sed -e "\|featuresBoot *=|s|$|,$1|" > $CFG
40 }
41
42 # Append features to karaf boot feature configuration
43 # $1 search pattern
44 # $2 replacement
45 function replaceFeatureBoot() {
46   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
47   ORIG=$CFG.orig
48   echo "Replace boot feature $1 with: $2"
49   sed -i "/featuresBoot/ s/$1/$2/g" $CFG
50 }
51
52 function install_sdnrwt_features() {
53   addToFeatureBoot "$SDNRWT_BOOTFEATURES" $SDNRWT_REPOSITORY
54 }
55
56 function enable_odl_cluster(){
57   if [ -z $SDNC_REPLICAS ]; then
58      echo "SDNC_REPLICAS is not configured in Env field"
59      exit
60   fi
61
62   #Be sure to remove feature odl-netconf-connector-all from list
63   replaceFeatureBoot "odl-netconf-connector-all,"
64
65   echo "Installing Opendaylight cluster features"
66   replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
67   replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
68   addToFeatureBoot odl-jolokia
69   #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
70   #${ODL_HOME}/bin/client feature:install odl-jolokia
71
72
73   echo "Update cluster information statically"
74   hm=$(hostname)
75   echo "Get current Hostname ${hm}"
76
77   node=($(echo ${hm} | sed 's/-[0-9]*$//g'))
78   node_index=($(echo ${hm} | awk -F"-" '{print $NF}'))
79   member_offset=1
80
81   if $GEO_ENABLED; then
82     echo "This is a Geo cluster"
83
84     if [ -z $IS_PRIMARY_CLUSTER ] || [ -z $MY_ODL_CLUSTER ] || [ -z $PEER_ODL_CLUSTER ]; then
85      echo "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field"
86      return
87     fi
88
89     if $IS_PRIMARY_CLUSTER; then
90        PRIMARY_NODE=${MY_ODL_CLUSTER}
91        SECONDARY_NODE=${PEER_ODL_CLUSTER}
92     else
93        PRIMARY_NODE=${PEER_ODL_CLUSTER}
94        SECONDARY_NODE=${MY_ODL_CLUSTER}
95        member_offset=4
96     fi
97
98     node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
99
100     /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
101   else
102     echo "This is a local cluster"
103
104     node_list="${node}-0.{{.Values.service.name}}-cluster.{{.Release.Namespace}}";
105
106     for ((i=1;i<${SDNC_REPLICAS};i++));
107     do
108       node_list="${node_list} ${node}-$i.{{.Values.service.name}}-cluster.{{.Release.Namespace}}"
109     done
110
111     /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
112   fi
113 }
114
115
116 # Install SDN-C platform components if not already installed and start container
117
118 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
119 ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME}
120 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD}
121 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
122 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
123 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
124 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
125 GEO_ENABLED=${GEO_ENABLED:-false}
126 SDNC_AAF_ENABLED=${SDNC_AAF_ENABLED:-false}
127 SDNRWT=${SDNRWT:-false}
128 SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
129 export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
130
131 echo "Settings:"
132 echo "  ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
133 echo "  SDNC_REPLICAS=$SDNC_REPLICAS"
134 echo "  SDNRWT=$SDNRWT"
135 echo "  AAF_ENABLED=$SDNC_AAF_ENABLED"
136
137
138 if $SDNC_AAF_ENABLED; then
139         export SDNC_AAF_STORE_DIR=/opt/app/osaaf/local
140         export SDNC_AAF_CONFIG_DIR=/opt/app/osaaf/local
141         export SDNC_KEYPASS=`cat /opt/app/osaaf/local/.pass`
142         export SDNC_KEYSTORE=org.onap.sdnc.p12
143         sed -i '/cadi_prop_files/d' $ODL_HOME/etc/system.properties
144         echo "cadi_prop_files=$SDNC_AAF_CONFIG_DIR/org.onap.sdnc.props" >> $ODL_HOME/etc/system.properties
145
146         sed -i '/org.ops4j.pax.web.ssl.keystore/d' $ODL_HOME/etc/custom.properties
147         sed -i '/org.ops4j.pax.web.ssl.password/d' $ODL_HOME/etc/custom.properties
148         sed -i '/org.ops4j.pax.web.ssl.keypassword/d' $ODL_HOME/etc/custom.properties
149         echo org.ops4j.pax.web.ssl.keystore=$SDNC_AAF_STORE_DIR/$SDNC_KEYSTORE >> $ODL_HOME/etc/custom.properties
150         echo org.ops4j.pax.web.ssl.password=$SDNC_KEYPASS >> $ODL_HOME/etc/custom.properties
151         echo org.ops4j.pax.web.ssl.keypassword=$SDNC_KEYPASS >> $ODL_HOME/etc/custom.properties
152 fi
153
154 if [ ! -f ${SDNC_HOME}/.installed ]
155 then
156         echo "Installing SDN-C keyStore"
157         ${SDNC_HOME}/bin/addSdncKeyStore.sh
158
159         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
160
161         if $SDNRWT ; then install_sdnrwt_features ; fi
162
163         echo "Installed at `date`" > ${SDNC_HOME}/.installed
164 fi
165
166 cp /opt/opendaylight/current/certs/* /tmp
167 cp /var/custom-certs/* /tmp
168
169 nohup python ${SDNC_BIN}/installCerts.py &
170
171
172 exec ${ODL_HOME}/bin/karaf server