update link to upper-constraints.txt
[dmaap/messagerouter/messageservice.git] / src / main / swm / common / install_postproc.sh
1 #!/bin/sh
2 #*******************************************************************************
3 #  ============LICENSE_START=======================================================
4 #  org.onap.dmaap
5 #  ================================================================================
6 #  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
7 #  ================================================================================
8 #  Licensed under the Apache License, Version 2.0 (the "License");
9 #  you may not use this file except in compliance with the License.
10 #  You may obtain a copy of the License at
11 #        http://www.apache.org/licenses/LICENSE-2.0
12 #  
13 #  Unless required by applicable law or agreed to in writing, software
14 #  distributed under the License is distributed on an "AS IS" BASIS,
15 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #  See the License for the specific language governing permissions and
17 #  limitations under the License.
18 #  ============LICENSE_END=========================================================
19 #
20 #  ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 #  
22 #*******************************************************************************
23
24 if [ -f "/tmp/exitdmaapMRpostproc" ]; then
25 echo "file /tmp/exitdmaapMRpostproc found .exiting..........."
26 exit 0;
27 fi
28 . `dirname $0`/install.env
29
30 mkdir -p ${ROOT_DIR}/conf || fail 100 "Error on creating the conf directory."
31 mkdir -p ${ROOT_DIR}/docs || fail 100 "Error on creating the docs directory."
32 mkdir -p ${ROOT_DIR}/lib  || fail 100 "Error on creating the lib directory."
33 mkdir -p ${ROOT_DIR}/log || fail 100 "Error on creating the logs directory."
34
35 ##############################################################################
36 # REMOVING THE DATA DIRECTORY
37 # The following if statement is checking to see if a new version is being installed
38 # on top of another version. If a new version is installed on top of the current
39 # version WITHOUT a proper deinstall, this will remove the data directory which
40 # is necessary to cleanup old AJSC route metadata. If CSTEM chooses to re-run
41 # the install_postproc.sh to update swm node variables, this if statement will NOT
42 # remove the data directory which is necessary for the SAME version to utilize the
43 # correct data directory route metadata.
44 ##############################################################################
45 if [ "${AFTSWM_ACTION_NEW_VERSION}" != "${AFTSWM_ACTION_PREVIOUS_VERSION}" ]
46 then
47 rm -rf ${ROOT_DIR}/data
48 fi
49
50 # Cleaning the jetty directory which contains the AJSC exploded war as well as
51 # any other apps running under jetty directory
52 rm -rf ${ROOT_DIR}/jetty
53
54 # A simple override for the SOA Cloud platform value.  Normally this is not
55 # needed outside of SOA Cloud development sandboxes
56 # this is used in the template.lrm.xml file during startup of the service
57 if [ ! -z "${SCLD_PLATFORM}" ]; then
58         SCLD_OPTIONAL_PLATFORM_FLAG="-Dplatform=${SCLD_PLATFORM}"; export SCLD_OPTIONAL_PLATFORM_FLAG
59 fi
60
61 ##############################################################################
62 # PROCESS TEMPLATE FILES FROM ENVIRONMENT
63 # pattern: looks for all files starting with "template.", processes them using the
64 # current environment, then renames them by removing the "template." in the same
65 # directory
66 ##############################################################################
67 utilpath=`dirname $0`/utils 
68 for tfile in `ls ${ROOT_DIR}/bundleconfig/etc/sysprops/template.* ${ROOT_DIR}/bundleconfig/etc/appprops/template.* ${ROOT_DIR}/bin/template.* ${ROOT_DIR}/etc/template.* 2>/dev/null`; do
69     dfile=`echo ${tfile} | sed -e 's@/template\.@/@g'`
70     sh ${utilpath}/findreplace.sh ${tfile} ${dfile} || exit 200
71 done
72
73 runningCount=`${LRMCLI} -running | grep -w ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} | wc -l` || fail 300 "Unable to determine how many instances are running prior to notifying LRM of the upgrade"
74
75 ##############################################################################
76 # DEPLOY CONTAINER TO LRM
77 ##############################################################################
78
79 if [ -z "${RESOURCE_MANAGER_WAIT_TIME_IN_SECONDS}" ]
80 then
81   RESOURCE_MANAGER_WAIT_TIME_IN_SECONDS=180
82   export RESOURCE_MANAGER_WAIT_TIME_IN_SECONDS
83 fi
84
85
86
87 DTE_TME_STAMP=`date +%Y%m%d_%H%M%S`
88
89 LRM_ADD_LOG=/tmp/${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME}_ADD_${DTE_TME_STAMP}.out 
90         echo "Adding resource to lrm" 
91         echo "${LRMCLI} -add -file ${ROOT_DIR}/etc/lrm.xml -ttw ${RESOURCE_MANAGER_WAIT_TIME_IN_SECONDS}" 
92         ${LRMCLI} -add -file ${ROOT_DIR}/etc/lrm.xml -ttw ${RESOURCE_MANAGER_WAIT_TIME_IN_SECONDS} > ${LRM_ADD_LOG}
93         LRM_ADD_RC=$?
94         echo "LRMCLI ADD RC : ${LRM_ADD_RC}"
95         if [ "${LRM_ADD_RC}" -ne "0" ]; then
96         
97                 RSRC_EXIST=`cat ${LRM_ADD_LOG} | grep SCLD-LRM-1024` # resource is already added 
98             if [ "${RSRC_EXIST:-}x" = "x" ]; then 
99                 echo "LRM add for Resource ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} failed..." 
100                 cat ${LRM_ADD_LOG} 
101                 rm -f ${LRM_ADD_LOG} 
102                 exit 1 
103             fi 
104             echo "LRM Resource for ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} already exists. Proceeding with either addOrUpgrade or modify" 
105             echo "Get the number of configured ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} instance" 
106             versionCtr=`${LRMCLI} -configured | grep ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} | awk {'print $3'} | wc -l`
107             if [ ${versionCtr} -eq 1 ]; then
108                 echo "Updating lrm resource"
109                 echo "${LRMCLI} -addOrUpgrade -file ${ROOT_DIR}/etc/lrm.xml -ttw ${RESOURCE_MANAGER_WAIT_TIME_IN_SECONDS}"
110                 ${LRMCLI} -addOrUpgrade -file ${ROOT_DIR}/etc/lrm.xml -ttw ${RESOURCE_MANAGER_WAIT_TIME_IN_SECONDS} || abort "lrmcli addOrUpgrade failed"
111             else
112                 echo "Modifying lrm resource"
113                 echo "${LRMCLI} -modify -file ${ROOT_DIR}/etc/lrm.xml"
114                 ${LRMCLI} -modify -file ${ROOT_DIR}/etc/lrm.xml || abort "lrmcli modify failed"
115             fi
116         fi
117                 
118                 echo "LRMCLI execution on ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} executed succesfully!"
119
120 ls ${ROOT_DIR}/bundleconfig/etc/appprops/MsgRtrApi.properties
121
122 if  [ ! -z $CONFIG_ZK_SERVERS ]; then
123 sed -i '/config.zk.servers=/c\config.zk.servers='$CONFIG_ZK_SERVERS ${ROOT_DIR}/bundleconfig/etc/appprops/MsgRtrApi.properties
124 fi
125
126 if  [ ! -z $TRANSID_REQD ]; then
127 sed -i '/transidUEBtopicreqd=/c\transidUEBtopicreqd='$TRANSID_REQD ${ROOT_DIR}/bundleconfig/etc/appprops/MsgRtrApi.properties
128 fi
129
130 if [ ! -z $MR_TOPICFACTOTRYCLASS ]; then
131 sed -i '/msgRtr.topicfactory.aaf=/c\msgRtr.topicfactory.aaf='$MR_TOPICFACTOTRYCLASS ${ROOT_DIR}/bundleconfig/etc/appprops/MsgRtrApi.properties
132 fi
133
134 if [ ! -z $MR_NAMESPACE ]; then
135 sed -i '/msgRtr.namespace.aaf=/c\msgRtr.namespace.aaf='$MR_NAMESPACE ${ROOT_DIR}/bundleconfig/etc/appprops/MsgRtrApi.properties
136 fi
137
138
139 if [ ! -z $CADI_KEYFILE ]; then
140 sed -i '/cadi_keyfile=/c\cadi_keyfile='$CADI_KEYFILE ${ROOT_DIR}/etc/cadi.properties
141 fi
142
143 if [ ! -z $AAF_URL ]; then
144 sed -i '/aaf_url=/c\aaf_url='$AAF_URL ${ROOT_DIR}/etc/cadi.properties
145 fi
146
147 if [ ! -z $AAF_ID ]; then
148 sed -i '/aaf_id=/c\aaf_id='$AAF_ID ${ROOT_DIR}/etc/cadi.properties
149 fi
150
151 if [ ! -z $AAF_PWD ]; then
152 sed -i '/aaf_password=/c\aaf_password='$AAF_PWD ${ROOT_DIR}/etc/cadi.properties
153 fi
154
155 if [ ! -z $MR_LOGLOC ]; then
156 sed -i '/<property name="logDirectory" value=/c\<property name="logDirectory" value="'$MR_LOGLOC'"/>' ${ROOT_DIR}/bundleconfig/etc/logback.xml
157 fi
158
159 if [ ! -z $MR_KSPATH ]; then
160 sed -i '/<Set name="KeyStorePath">/c\<Set name="KeyStorePath">'$MR_KSPATH'</Set>' ${ROOT_DIR}/etc/ajsc-jetty.xml
161 fi
162
163 if [ ! -z $MR_KSPWD ]; then
164 sed -i '/<Set name="KeyStorePassword">/c\<Set name="KeyStorePassword">'$MR_KSPWD'</Set>' ${ROOT_DIR}/etc/ajsc-jetty.xml
165 fi
166
167
168 if [ ! -z $MR_KMPWD ]; then
169 sed -i '/<Set name="KeyManagerPassword">/c\<Set name="KeyManagerPassword">'$MR_KMPWD'</Set>' ${ROOT_DIR}/etc/ajsc-jetty.xml
170 fi
171
172  
173
174 if [ "${runningCount}" -eq 0 ]; then
175     if [ "${LRM_START_SVC}" = "true" ]; then
176         echo "${LRMCLI} -start -name ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} -version ${AFTSWM_ACTION_NEW_VERSION} -routeoffer ${AFT_SERVICE_ENV} | egrep SUCCESS\|SCLD-LRM-1041"
177        ${LRMCLI} -start -name ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} -version ${AFTSWM_ACTION_NEW_VERSION} -routeoffer ${AFT_SERVICE_ENV} | egrep SUCCESS\|SCLD-LRM-1041 
178         if [ $? -ne 0 ]; then 
179             fail 500 "Start of ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME} with routeOffer ${AFT_SERVICE_ENV} failed" 
180             fi
181             echo "${LRMCLI} -running | grep -w ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME}"
182         ${LRMCLI} -running | grep -w ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME}
183     else
184         echo "PROC_USER_MSG: LRM_START_SVC is set to false and no running instances were found prior to upgrading so ending install with no running service instances."
185     fi 
186 else
187     ${LRMCLI} -running | grep -w ${SOA_CLOUD_NAMESPACE}.${AFTSWM_ACTION_ARTIFACT_NAME}
188 fi
189
190     
191 exit 0