Merge "Update CLAMP deployment for Frankfurt release (RC0)"
[oom.git] / kubernetes / sdnc / resources / config / bin / startODL.sh
1 #!/bin/bash
2
3 ###
4 # ============LICENSE_START=======================================================
5 # SDNC
6 # ================================================================================
7 # Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END=========================================================
21 ###
22
23 # Append features to karaf boot feature configuration
24 # $1 additional feature to be added
25 # $2 repositories to be added (optional)
26 function addToFeatureBoot() {
27   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
28   ORIG=$CFG.orig
29   if [ -n "$2" ] ; then
30     echo "Add repository: $2"
31     mv $CFG $ORIG
32     cat $ORIG | sed -e "\|featuresRepositories|s|$|,$2|" > $CFG
33   fi
34   echo "Add boot feature: $1"
35   mv $CFG $ORIG
36   cat $ORIG | sed -e "\|featuresBoot *=|s|$|,$1|" > $CFG
37 }
38
39 # Append features to karaf boot feature configuration
40 # $1 search pattern
41 # $2 replacement
42 function replaceFeatureBoot() {
43   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
44   ORIG=$CFG.orig
45   echo "Replace boot feature $1 with: $2"
46   sed -i "/featuresBoot/ s/$1/$2/g" $CFG
47 }
48
49 function install_sdnrwt_features() {
50   addToFeatureBoot "$SDNRWT_BOOTFEATURES" $SDNRWT_REPOSITORY
51 }
52
53 function enable_odl_cluster(){
54   if [ -z $SDNC_REPLICAS ]; then
55      echo "SDNC_REPLICAS is not configured in Env field"
56      exit
57   fi
58
59   #Be sure to remove feature odl-netconf-connector-all from list
60   replaceFeatureBoot "odl-netconf-connector-all,"
61
62   echo "Installing Opendaylight cluster features"
63   replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
64   replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
65   addToFeatureBoot odl-jolokia
66   #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
67   #${ODL_HOME}/bin/client feature:install odl-jolokia
68
69
70   echo "Update cluster information statically"
71   hm=$(hostname)
72   echo "Get current Hostname ${hm}"
73
74   node=($(echo ${hm} | sed 's/-[0-9]*$//g'))
75   node_index=($(echo ${hm} | awk -F"-" '{print $NF}'))
76   member_offset=1
77
78   if $GEO_ENABLED; then
79     echo "This is a Geo cluster"
80
81     if [ -z $IS_PRIMARY_CLUSTER ] || [ -z $MY_ODL_CLUSTER ] || [ -z $PEER_ODL_CLUSTER ]; then
82      echo "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field"
83      return
84     fi
85
86     if $IS_PRIMARY_CLUSTER; then
87        PRIMARY_NODE=${MY_ODL_CLUSTER}
88        SECONDARY_NODE=${PEER_ODL_CLUSTER}
89     else
90        PRIMARY_NODE=${PEER_ODL_CLUSTER}
91        SECONDARY_NODE=${MY_ODL_CLUSTER}
92        member_offset=4
93     fi
94
95     node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
96
97     /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
98   else
99     echo "This is a local cluster"
100
101     node_list="${node}-0.{{.Values.service.name}}-cluster.{{.Release.Namespace}}";
102
103     for ((i=1;i<${SDNC_REPLICAS};i++));
104     do
105       node_list="${node_list} ${node}-$i.{{.Values.service.name}}-cluster.{{.Release.Namespace}}"
106     done
107
108     /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
109   fi
110 }
111
112
113 # Install SDN-C platform components if not already installed and start container
114
115 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
116 ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME}
117 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD}
118 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
119 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
120 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
121 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
122 GEO_ENABLED=${GEO_ENABLED:-false}
123 SDNC_AAF_ENABLED=${SDNC_AAF_ENABLED:-false}
124 SDNRWT=${SDNRWT:-false}
125 SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
126 export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
127
128 echo "Settings:"
129 echo "  ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
130 echo "  SDNC_REPLICAS=$SDNC_REPLICAS"
131 echo "  SDNRWT=$SDNRWT"
132 echo "  AAF_ENABLED=$SDNC_AAF_ENABLED"
133
134
135 if $SDNC_AAF_ENABLED; then
136         export SDNC_STORE_DIR=/opt/app/osaaf/local
137         export SDNC_CONFIG_DIR=/opt/app/osaaf/local
138         export SDNC_KEYPASS=`cat /opt/app/osaaf/local/.pass`
139         export SDNC_KEYSTORE=org.onap.sdnc.p12
140         sed -i '/cadi_prop_files/d' $ODL_HOME/etc/system.properties
141         echo "cadi_prop_files=$SDNC_CONFIG_DIR/org.onap.sdnc.props" >> $ODL_HOME/etc/system.properties
142
143         sed -i '/org.ops4j.pax.web.ssl.keystore/d' $ODL_HOME/etc/custom.properties
144         sed -i '/org.ops4j.pax.web.ssl.password/d' $ODL_HOME/etc/custom.properties
145         sed -i '/org.ops4j.pax.web.ssl.keypassword/d' $ODL_HOME/etc/custom.properties
146         echo org.ops4j.pax.web.ssl.keystore=$SDNC_STORE_DIR/$SDNC_KEYSTORE >> $ODL_HOME/etc/custom.properties
147         echo org.ops4j.pax.web.ssl.password=$SDNC_KEYPASS >> $ODL_HOME/etc/custom.properties
148         echo org.ops4j.pax.web.ssl.keypassword=$SDNC_KEYPASS >> $ODL_HOME/etc/custom.properties
149 fi
150
151 if [ ! -f ${SDNC_HOME}/.installed ]
152 then
153         echo "Installing SDN-C keyStore"
154         ${SDNC_HOME}/bin/addSdncKeyStore.sh
155
156         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
157
158         if $SDNRWT ; then install_sdnrwt_features ; fi
159
160         echo "Installed at `date`" > ${SDNC_HOME}/.installed
161 fi
162
163 cp /opt/opendaylight/current/certs/* /tmp
164
165 nohup python ${SDNC_BIN}/installCerts.py &
166
167
168 exec ${ODL_HOME}/bin/karaf server