Merge "adapt sdnc-image to latest baseimage"
[sdnc/oam.git] / installation / sdnc / src / main / scripts / startODL.sh
1 #!/bin/sh
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 install_sdnr_northbound_features() {
55   addToFeatureBoot "$SDNR_NORTHBOUND_BOOTFEATURES" $SDNR_NORTHBOUND_REPOSITORY
56 }
57
58 function enable_odl_cluster(){
59   if [ -z $SDNC_REPLICAS ]; then
60      echo "SDNC_REPLICAS is not configured in Env field"
61      exit
62   fi
63
64   echo "Installing Opendaylight cluster features"
65   replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
66   replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
67   addToFeatureBoot odl-jolokia
68   #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
69   #${ODL_HOME}/bin/client feature:install odl-jolokia
70
71   echo "Update cluster information statically"
72   hm=$(hostname)
73   echo "Get current Hostname ${hm}"
74
75   node=($(echo ${hm} | tr '-' '\n'))
76   node_name=${node[0]}
77   node_index=${node[1]}
78
79   if [ -z $PEER_ODL_CLUSTER ]; then
80     echo "This is a local cluster"
81     node_list="${node_name}-0.sdnhost-cluster.onap.svc.cluster.local";
82
83     for ((i=1;i<${SDNC_REPLICAS};i++));
84     do
85       node_list="${node_list} ${node_name}-$i.sdnhost-cluster.onap.svc.cluster.local"
86     done
87     /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
88   else
89     echo "This is a Geo cluster"
90
91     if $IS_PRIMARY_CLUSTER; then
92        PRIMARY_NODE=${MY_ODL_CLUSTER}
93        SECONDARY_NODE=${PEER_ODL_CLUSTER}
94     else
95        PRIMARY_NODE=${PEER_ODL_CLUSTER}
96        SECONDARY_NODE=${MY_ODL_CLUSTER}
97        member_offset=4
98     fi
99
100     node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
101     /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
102   fi
103 }
104
105
106 # Install SDN-C platform components if not already installed and start container
107
108 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
109 ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME:-admin}
110 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
111 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
112 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
113 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
114 SLEEP_TIME=${SLEEP_TIME:-120}
115 MYSQL_PASSWD=${MYSQL_PASSWD:-openECOMP1.0}
116 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
117 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
118 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
119 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
120 SDNRWT=${SDNRWT:-false}
121 SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
122 SDNR_NORTHBOUND=${SDNR_NORTHBOUND:-false}
123 SDNR_NORTHBOUND_BOOTFEATURES=${SDNR_NORTHBOUND_BOOTFEATURES:-sdnr-northbound-all}
124 export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
125
126 echo "Settings:"
127 echo "  ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
128 echo "  SDNC_REPLICAS=$SDNC_REPLICAS"
129 echo "  SDNRWT=$SDNRWT"
130 echo "  SDNR_NORTHBOUND=$SDNR_NORTHBOUND"
131
132
133 #
134 # Wait for database
135 #
136 echo "Waiting for mysql"
137 until mysql -h dbhost -u root -p${MYSQL_PASSWD} mysql &> /dev/null
138 do
139   printf "."
140   sleep 1
141 done
142 echo -e "\nmysql ready"
143
144 if [ ! -d ${INSTALLED_DIR} ]
145 then
146     mkdir -p ${INSTALLED_DIR}
147 fi
148
149 if [ ! -f ${INSTALLED_DIR}/.installed ]
150 then
151         echo "Installing SDN-C database"
152         ${SDNC_HOME}/bin/installSdncDb.sh
153         echo "Installing SDN-C keyStore"
154         ${SDNC_HOME}/bin/addSdncKeyStore.sh
155         echo "Installing A1-adapter trustStore"
156         ${SDNC_HOME}/bin/addA1TrustStore.sh
157
158         #${CCSDK_HOME}/bin/installOdlHostKey.sh
159
160         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
161         then
162                 echo "Installing directed graphs"
163                 ${SDNC_HOME}/svclogic/bin/install.sh
164         fi
165
166     if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
167
168         if $SDNRWT ; then install_sdnrwt_features ; fi
169
170   if $SDNR_NORTHBOUND ; then install_sdnr_northbound_features ; fi
171
172         echo "Installed at `date`" > ${INSTALLED_DIR}/.installed
173 fi
174
175 cp /opt/opendaylight/current/certs/* /tmp
176 cp /var/custom-certs/* /tmp
177
178 # Create ODL data log directory (it nornally is created after karaf
179 # is started, but needs to exist before installCerts.py runs)
180 mkdir -p /opt/opendaylight/data/log
181 nohup python3 ${SDNC_BIN}/installCerts.py &
182
183 exec ${ODL_HOME}/bin/karaf server