summaryrefslogtreecommitdiffstats
path: root/src/main/swm/common/localize.sh
blob: c6aa5ed1ac2fff7b731d3b4830de48227342dd55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh
#*******************************************************************************
#  ============LICENSE_START=======================================================
#  org.onap.dmaap
#  ================================================================================
#  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
#  ================================================================================
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#        http://www.apache.org/licenses/LICENSE-2.0
#  
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#  ============LICENSE_END=========================================================
#
#  ECOMP is a trademark and service mark of AT&T Intellectual Property.
#  
#*******************************************************************************
FINAL_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi.properties
TEMPLATE_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi_template.properties
BACKUP1_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi.properties.bk.1
BACKUP2_CONFIG_FILE=${ROOT_DIR}/etc/cambriaApi.properties.bk.2

echo "Localizing the Cambria API Server configuration"

if [ -z "${ELASTICSEARCH_NODES}" ]; then
	echo "ERROR: ELASTICSEARCH_NODES must be set"; exit 1
fi

if [ -z "${ZOOKEEPER_ENSEMBLE}" ]; then
	echo "ERROR: ZOOKEEPER_ENSEMBLE must be set"; exit 2
fi

if [ -z "${ZOOKEEPER_CLIENT_PORT}" ]; then
	ZOOKEEPER_CLIENT_PORT=2181
fi

if [ -z "${CAMBRIA_SERVICE_PORT}" ]; then
	CAMBRIA_SERVICE_PORT=3904
fi

if [ -z "${CAMBRIA_BROKER_TYPE}" ]; then
	CAMBRIA_BROKER_TYPE=kafka
fi

if [ -z "${KAFKA_PORT}" ]; then
	KAFKA_PORT=9092
fi

if [ -z "${KAFKA_BROKER_LIST}" ]; then
	KAFKA_BROKER_LIST=localhost:${KAFKA_PORT}
fi

#------------------------------------------------------------------------
#- MAKE A BACKUP OF PREVIOUS BACKUP FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${BACKUP1_CONFIG_FILE} ]; then
    cp -f ${BACKUP1_CONFIG_FILE} ${BACKUP2_CONFIG_FILE} || {
        echo "ERROR: Could not copy ${BACKUP1_CONFIG_FILE} to ${BACKUP2_CONFIG_FILE}"
        exit 5
    }
fi
 
#------------------------------------------------------------------------
#- MAKE A BACKUP OF CURRENT FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${FINAL_CONFIG_FILE} ]; then
    cp -f ${FINAL_CONFIG_FILE} ${BACKUP1_CONFIG_FILE} || {
        echo "ERROR: Could not copy ${FINAL_CONFIG_FILE} to ${BACKUP1_CONFIG_FILE}"
        exit 6
    }
fi

CAMBRIA_ZOOKEEPER_NODES=`echo ${ZOOKEEPER_ENSEMBLE} | sed -e "s/ /:${ZOOKEEPER_CLIENT_PORT},/g" | sed -e "s/$/:${ZOOKEEPER_CLIENT_PORT}/g"`

#------------------------------------------------------------------------
#- PROCESS THE TEMPLATE
#------------------------------------------------------------------------
sed -e 's/${CAMBRIA_SERVICE_PORT}/'${CAMBRIA_SERVICE_PORT}'/g' \
    -e 's/${CAMBRIA_BROKER_TYPE}/'${CAMBRIA_BROKER_TYPE}'/g' \
    -e 's/${KAFKA_BROKER_LIST}/'${KAFKA_BROKER_LIST}'/g' \
    -e 's/${CAMBRIA_ZOOKEEPER_NODES}/'${CAMBRIA_ZOOKEEPER_NODES}'/g' ${TEMPLATE_CONFIG_FILE} > ${FINAL_CONFIG_FILE} || {
	    echo "ERROR: Could not process template file ${TEMPLATE_CONFIG_FILE} into ${FINAL_CONFIG_FILE}"
	    exit 7
	}

FINAL_LOG4J_FILE=${ROOT_DIR}/etc/log4j.xml
TEMPLATE_LOG4J_FILE=${ROOT_DIR}/etc/log4j_template.xml
BACKUP1_LOG4J_FILE=${ROOT_DIR}/etc/log4j.xml.bk.1
BACKUP2_LOG4J_FILE=${ROOT_DIR}/etc/log4j.xml.bk.2

if [ -z "${CAMBRIA_LOG_DIR}" ]; then
	CAMBRIA_LOG_DIR=${ROOT_DIR}/logs
fi

if [ -z "${CAMBRIA_LOG_THRESHOLD}" ]; then
	CAMBRIA_LOG_THRESHOLD="INFO"
fi

#------------------------------------------------------------------------
#- MAKE A BACKUP OF PREVIOUS BACKUP FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${BACKUP1_LOG4J_FILE} ]; then
    cp -f ${BACKUP1_LOG4J_FILE} ${BACKUP2_LOG4J_FILE} || {
        echo "ERROR: Could not copy ${BACKUP1_LOG4J_FILE} to ${BACKUP2_LOG4J_FILE}"
        exit 8
    }
fi
 
#------------------------------------------------------------------------
#- MAKE A BACKUP OF CURRENT FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${FINAL_LOG4J_FILE} ]; then
    cp -f ${FINAL_LOG4J_FILE} ${BACKUP1_LOG4J_FILE} || {
        echo "ERROR: Could not copy ${FINAL_LOG4J_FILE} to ${BACKUP1_LOG4J_FILE}"
        exit 9
    }
fi

#------------------------------------------------------------------------
#- PROCESS THE TEMPLATE
#------------------------------------------------------------------------
sed -e 's/${CAMBRIA_LOG_THRESHOLD}/'${CAMBRIA_LOG_THRESHOLD}'/g' \
    -e 's,${CAMBRIA_LOG_DIR},'${CAMBRIA_LOG_DIR}',g' ${TEMPLATE_LOG4J_FILE} > ${FINAL_LOG4J_FILE} || {
	    echo "ERROR: Could not process template file ${TEMPLATE_LOG4J_FILE} into ${FINAL_LOG4J_FILE}"
	    exit 10
	}

FINAL_LOGSTASH_FILE=${ROOT_DIR}/etc/messages.conf
TEMPLATE_LOGSTASH_FILE=${ROOT_DIR}/etc/logstash_cambria_template.conf
BACKUP1_LOGSTASH_FILE=${ROOT_DIR}/etc/messages.conf.bk.1
BACKUP2_LOGSTASH_FILE=${ROOT_DIR}/etc/messages.conf.bk.2
#------------------------------------------------------------------------
#- MAKE A BACKUP OF PREVIOUS BACKUP FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${BACKUP1_LOGSTASH_FILE} ]; then
    cp -f ${BACKUP1_LOGSTASH_FILE} ${BACKUP2_LOGSTASH_FILE} || {
        echo "ERROR: Could not copy ${BACKUP1_LOGSTASH_FILE} to ${BACKUP2_LOGSTASH_FILE}"
        exit 11
    }
fi
 
#------------------------------------------------------------------------
#- MAKE A BACKUP OF CURRENT FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${FINAL_LOGSTASH_FILE} ]; then
    cp -f ${FINAL_LOGSTASH_FILE} ${BACKUP1_LOGSTASH_FILE} || {
        echo "ERROR: Could not copy ${FINAL_LOGSTASH_FILE} to ${BACKUP1_LOGSTASH_FILE}"
        exit 12
    }
fi

#------------------------------------------------------------------------
#- PROCESS THE TEMPLATE
#------------------------------------------------------------------------
sed -e 's,${CAMBRIA_SERVER_LOG},'${CAMBRIA_LOG_DIR}/cambria.log',g' \
    -e 's/${ELASTICSEARCH_NODES}/'${ELASTICSEARCH_NODES}'/g' ${TEMPLATE_LOGSTASH_FILE} > ${FINAL_LOGSTASH_FILE} || {
	    echo "ERROR: Could not process template file ${TEMPLATE_LOGSTASH_FILE} into ${FINAL_LOGSTASH_FILE}"
	    exit 13
	}

#------------------------------------------------------------------------
#- CLEAN EXIT
#------------------------------------------------------------------------
echo "Localized Successfully."
exit 0