Merge "Fix bbs dgs bug for edge"
[sdnc/oam.git] / installation / sdnc / src / main / scripts / startODL.sh
1 #!/bin/bash
2
3 ###
4 # ============LICENSE_START=======================================================
5 # openECOMP : SDN-C
6 # ================================================================================
7 # Copyright (C) 2017 AT&T Intellectual Property. All rights
8 #                                                       reserved.
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
13 #
14 #      http://www.apache.org/licenses/LICENSE-2.0
15 #
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=========================================================
22 ###
23
24 # Append features to karaf boot feature configuration
25 # $1 additional feature to be added
26 # $2 repositories to be added (optional)
27 function addToFeatureBoot() {
28   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
29   ORIG=$CFG.orig
30   if [ -n "$2" ] ; then
31     echo "Add repository: $2"
32     mv $CFG $ORIG
33     cat $ORIG | sed -e "\|featuresRepositories|s|$|,$2|" > $CFG
34   fi
35   echo "Add boot feature: $1"
36   mv $CFG $ORIG
37   cat $ORIG | sed -e "\|featuresBoot *=|s|$|,$1|" > $CFG
38 }
39
40 # Append features to karaf boot feature configuration
41 # $1 search pattern
42 # $2 replacement
43 function replaceFeatureBoot() {
44   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
45   ORIG=$CFG.orig
46   echo "Replace boot feature $1 with: $2"
47   sed -i "/featuresBoot/ s/$1/$2/g" $CFG
48 }
49
50 function install_sdnrwt_features() {
51   addToFeatureBoot "$SDNRWT_BOOTFEATURES" $SDNRWT_REPOSITORY
52 }
53
54 function enable_odl_cluster(){
55   if [ -z $SDNC_REPLICAS ]; then
56      echo "SDNC_REPLICAS is not configured in Env field"
57      exit
58   fi
59
60   echo "Installing Opendaylight cluster features"
61   replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
62   replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
63   addToFeatureBoot odl-jolokia
64   #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
65   #${ODL_HOME}/bin/client feature:install odl-jolokia
66
67   echo "Update cluster information statically"
68   hm=$(hostname)
69   echo "Get current Hostname ${hm}"
70
71   node=($(echo ${hm} | tr '-' '\n'))
72   node_name=${node[0]}
73   node_index=${node[1]}
74
75   if [ -z $PEER_ODL_CLUSTER ]; then
76     echo "This is a local cluster"
77     node_list="${node_name}-0.sdnhost-cluster.onap.svc.cluster.local";
78
79     for ((i=1;i<${SDNC_REPLICAS};i++));
80     do
81       node_list="${node_list} ${node_name}-$i.sdnhost-cluster.onap.svc.cluster.local"
82     done
83     /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
84   else
85     echo "This is a Geo cluster"
86
87     if $IS_PRIMARY_CLUSTER; then
88        PRIMARY_NODE=${MY_ODL_CLUSTER}
89        SECONDARY_NODE=${PEER_ODL_CLUSTER}
90     else
91        PRIMARY_NODE=${PEER_ODL_CLUSTER}
92        SECONDARY_NODE=${MY_ODL_CLUSTER}
93        member_offset=4
94     fi
95
96     node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
97     /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
98   fi
99 }
100
101
102 # Install SDN-C platform components if not already installed and start container
103
104 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
105 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
106 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
107 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
108 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
109 SLEEP_TIME=${SLEEP_TIME:-120}
110 MYSQL_PASSWD=${MYSQL_PASSWD:-openECOMP1.0}
111 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
112 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
113 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
114 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
115 SDNRWT=${SDNRWT:-false}
116 SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
117
118
119 echo "Settings:"
120 echo "  ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
121 echo "  SDNC_REPLICAS=$SDNC_REPLICAS"
122 echo "  SDNRWT=$SDNRWT"
123
124 #
125 # Wait for database
126 #
127 echo "Waiting for mysql"
128 until mysql -h dbhost -u root -p${MYSQL_PASSWD} mysql &> /dev/null
129 do
130   printf "."
131   sleep 1
132 done
133 echo -e "\nmysql ready"
134
135 if [ ! -d ${INSTALLED_DIR} ]
136 then
137     mkdir -p ${INSTALLED_DIR}
138 fi
139
140 if [ ! -f ${INSTALLED_DIR}/.installed ]
141 then
142         echo "Installing SDN-C database"
143         ${SDNC_HOME}/bin/installSdncDb.sh
144         echo "Installing SDN-C keyStore"
145         ${SDNC_HOME}/bin/addSdncKeyStore.sh
146
147         #${CCSDK_HOME}/bin/installOdlHostKey.sh
148
149         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
150         then
151                 echo "Installing directed graphs"
152                 ${SDNC_HOME}/svclogic/bin/install.sh
153         fi
154
155     if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
156
157         if $SDNRWT ; then install_sdnrwt_features ; fi
158
159         echo "Installed at `date`" > ${INSTALLED_DIR}/.installed
160 fi
161
162 cp /opt/opendaylight/current/certs/* /tmp
163
164 nohup python ${SDNC_BIN}/installCerts.py &
165
166 exec ${ODL_HOME}/bin/karaf server