c6aa5ed1ac2fff7b731d3b4830de48227342dd55
[dmaap/messagerouter/msgrtr.git] / src / main / swm / common / localize.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 FINAL_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi.properties
24 TEMPLATE_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi_template.properties
25 BACKUP1_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi.properties.bk.1
26 BACKUP2_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi.properties.bk.2
27
28 echo "Localizing the Cambria API Server configuration"
29
30 if [ -z "${ELASTICSEARCH_NODES}" ]; then
31         echo "ERROR: ELASTICSEARCH_NODES must be set"; exit 1
32 fi
33
34 if [ -z "${ZOOKEEPER_ENSEMBLE}" ]; then
35         echo "ERROR: ZOOKEEPER_ENSEMBLE must be set"; exit 2
36 fi
37
38 if [ -z "${ZOOKEEPER_CLIENT_PORT}" ]; then
39         ZOOKEEPER_CLIENT_PORT=2181
40 fi
41
42 if [ -z "${CAMBRIA_SERVICE_PORT}" ]; then
43         CAMBRIA_SERVICE_PORT=3904
44 fi
45
46 if [ -z "${CAMBRIA_BROKER_TYPE}" ]; then
47         CAMBRIA_BROKER_TYPE=kafka
48 fi
49
50 if [ -z "${KAFKA_PORT}" ]; then
51         KAFKA_PORT=9092
52 fi
53
54 if [ -z "${KAFKA_BROKER_LIST}" ]; then
55         KAFKA_BROKER_LIST=localhost:${KAFKA_PORT}
56 fi
57
58 #------------------------------------------------------------------------
59 #- MAKE A BACKUP OF PREVIOUS BACKUP FILE, IF EXISTS
60 #------------------------------------------------------------------------
61 if [ -f ${BACKUP1_CONFIG_FILE} ]; then
62     cp -f ${BACKUP1_CONFIG_FILE} ${BACKUP2_CONFIG_FILE} || {
63         echo "ERROR: Could not copy ${BACKUP1_CONFIG_FILE} to ${BACKUP2_CONFIG_FILE}"
64         exit 5
65     }
66 fi
67  
68 #------------------------------------------------------------------------
69 #- MAKE A BACKUP OF CURRENT FILE, IF EXISTS
70 #------------------------------------------------------------------------
71 if [ -f ${FINAL_CONFIG_FILE} ]; then
72     cp -f ${FINAL_CONFIG_FILE} ${BACKUP1_CONFIG_FILE} || {
73         echo "ERROR: Could not copy ${FINAL_CONFIG_FILE} to ${BACKUP1_CONFIG_FILE}"
74         exit 6
75     }
76 fi
77
78 CAMBRIA_ZOOKEEPER_NODES=`echo ${ZOOKEEPER_ENSEMBLE} | sed -e "s/ /:${ZOOKEEPER_CLIENT_PORT},/g" | sed -e "s/$/:${ZOOKEEPER_CLIENT_PORT}/g"`
79
80 #------------------------------------------------------------------------
81 #- PROCESS THE TEMPLATE
82 #------------------------------------------------------------------------
83 sed -e 's/${CAMBRIA_SERVICE_PORT}/'${CAMBRIA_SERVICE_PORT}'/g' \
84     -e 's/${CAMBRIA_BROKER_TYPE}/'${CAMBRIA_BROKER_TYPE}'/g' \
85     -e 's/${KAFKA_BROKER_LIST}/'${KAFKA_BROKER_LIST}'/g' \
86     -e 's/${CAMBRIA_ZOOKEEPER_NODES}/'${CAMBRIA_ZOOKEEPER_NODES}'/g' ${TEMPLATE_CONFIG_FILE} > ${FINAL_CONFIG_FILE} || {
87             echo "ERROR: Could not process template file ${TEMPLATE_CONFIG_FILE} into ${FINAL_CONFIG_FILE}"
88             exit 7
89         }
90
91 FINAL_LOG4J_FILE=${ROOT_DIR}/etc/log4j.xml
92 TEMPLATE_LOG4J_FILE=${ROOT_DIR}/etc/log4j_template.xml
93 BACKUP1_LOG4J_FILE=${ROOT_DIR}/etc/log4j.xml.bk.1
94 BACKUP2_LOG4J_FILE=${ROOT_DIR}/etc/log4j.xml.bk.2
95
96 if [ -z "${CAMBRIA_LOG_DIR}" ]; then
97         CAMBRIA_LOG_DIR=${ROOT_DIR}/logs
98 fi
99
100 if [ -z "${CAMBRIA_LOG_THRESHOLD}" ]; then
101         CAMBRIA_LOG_THRESHOLD="INFO"
102 fi
103
104 #------------------------------------------------------------------------
105 #- MAKE A BACKUP OF PREVIOUS BACKUP FILE, IF EXISTS
106 #------------------------------------------------------------------------
107 if [ -f ${BACKUP1_LOG4J_FILE} ]; then
108     cp -f ${BACKUP1_LOG4J_FILE} ${BACKUP2_LOG4J_FILE} || {
109         echo "ERROR: Could not copy ${BACKUP1_LOG4J_FILE} to ${BACKUP2_LOG4J_FILE}"
110         exit 8
111     }
112 fi
113  
114 #------------------------------------------------------------------------
115 #- MAKE A BACKUP OF CURRENT FILE, IF EXISTS
116 #------------------------------------------------------------------------
117 if [ -f ${FINAL_LOG4J_FILE} ]; then
118     cp -f ${FINAL_LOG4J_FILE} ${BACKUP1_LOG4J_FILE} || {
119         echo "ERROR: Could not copy ${FINAL_LOG4J_FILE} to ${BACKUP1_LOG4J_FILE}"
120         exit 9
121     }
122 fi
123
124 #------------------------------------------------------------------------
125 #- PROCESS THE TEMPLATE
126 #------------------------------------------------------------------------
127 sed -e 's/${CAMBRIA_LOG_THRESHOLD}/'${CAMBRIA_LOG_THRESHOLD}'/g' \
128     -e 's,${CAMBRIA_LOG_DIR},'${CAMBRIA_LOG_DIR}',g' ${TEMPLATE_LOG4J_FILE} > ${FINAL_LOG4J_FILE} || {
129             echo "ERROR: Could not process template file ${TEMPLATE_LOG4J_FILE} into ${FINAL_LOG4J_FILE}"
130             exit 10
131         }
132
133 FINAL_LOGSTASH_FILE=${ROOT_DIR}/etc/messages.conf
134 TEMPLATE_LOGSTASH_FILE=${ROOT_DIR}/etc/logstash_cambria_template.conf
135 BACKUP1_LOGSTASH_FILE=${ROOT_DIR}/etc/messages.conf.bk.1
136 BACKUP2_LOGSTASH_FILE=${ROOT_DIR}/etc/messages.conf.bk.2
137 #------------------------------------------------------------------------
138 #- MAKE A BACKUP OF PREVIOUS BACKUP FILE, IF EXISTS
139 #------------------------------------------------------------------------
140 if [ -f ${BACKUP1_LOGSTASH_FILE} ]; then
141     cp -f ${BACKUP1_LOGSTASH_FILE} ${BACKUP2_LOGSTASH_FILE} || {
142         echo "ERROR: Could not copy ${BACKUP1_LOGSTASH_FILE} to ${BACKUP2_LOGSTASH_FILE}"
143         exit 11
144     }
145 fi
146  
147 #------------------------------------------------------------------------
148 #- MAKE A BACKUP OF CURRENT FILE, IF EXISTS
149 #------------------------------------------------------------------------
150 if [ -f ${FINAL_LOGSTASH_FILE} ]; then
151     cp -f ${FINAL_LOGSTASH_FILE} ${BACKUP1_LOGSTASH_FILE} || {
152         echo "ERROR: Could not copy ${FINAL_LOGSTASH_FILE} to ${BACKUP1_LOGSTASH_FILE}"
153         exit 12
154     }
155 fi
156
157 #------------------------------------------------------------------------
158 #- PROCESS THE TEMPLATE
159 #------------------------------------------------------------------------
160 sed -e 's,${CAMBRIA_SERVER_LOG},'${CAMBRIA_LOG_DIR}/cambria.log',g' \
161     -e 's/${ELASTICSEARCH_NODES}/'${ELASTICSEARCH_NODES}'/g' ${TEMPLATE_LOGSTASH_FILE} > ${FINAL_LOGSTASH_FILE} || {
162             echo "ERROR: Could not process template file ${TEMPLATE_LOGSTASH_FILE} into ${FINAL_LOGSTASH_FILE}"
163             exit 13
164         }
165
166 #------------------------------------------------------------------------
167 #- CLEAN EXIT
168 #------------------------------------------------------------------------
169 echo "Localized Successfully."
170 exit 0