2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * ===================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.main;
25 import java.util.Properties;
27 import org.onap.music.eelf.logging.EELFLoggerDelegate;
28 import org.springframework.beans.factory.InitializingBean;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.PropertySource;
32 import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
33 import org.springframework.stereotype.Component;
35 @PropertySource(value = {"file:/opt/app/music/etc/music.properties", "classpath:/project.properties","file:/opt/app/music/etc/key.properties"})
37 public class PropertiesLoader implements InitializingBean {
39 @Value("${cassandra.host}")
40 public String cassandraHost;
46 public String version;
51 @Value("${music.properties}")
52 public String musicProperties;
54 @Value("${lock.lease.period}")
55 public String lockLeasePeriod;
57 @Value("${cassandra.user}")
58 public String cassandraUser;
60 @Value("${cassandra.password}")
61 public String cassandraPassword;
63 @Value("${cassandra.port}")
64 public String cassandraPort;
66 @Value("${cassandra.connecttimeoutms}")
67 public String cassandraConnectTimeOutMS;
69 @Value("${cassandra.readtimeoutms}")
70 public String cassandraReadTimeOutMS;
75 @Value("${keyspace.active}")
76 public String isKeyspaceActive;
78 @Value("${retry.count}")
79 public String rertryCount;
81 @Value("${transId.header.prefix}")
82 private String transIdPrefix;
84 @Value("${conversation.header.prefix}")
85 private String conversationIdPrefix;
87 @Value("${clientId.header.prefix}")
88 private String clientIdPrefix;
90 @Value("${messageId.header.prefix}")
91 private String messageIdPrefix;
93 @Value("${transId.header.required}")
94 private Boolean transIdRequired;
96 @Value("${conversation.header.required}")
97 private Boolean conversationIdRequired;
99 @Value("${clientId.header.required}")
100 private Boolean clientIdRequired;
102 @Value("${messageId.header.required}")
103 private Boolean messageIdRequired;
105 @Value("${music.aaf.ns}")
106 private String musicAafNs;
108 @Value("${cipher.enc.key}")
109 private String cipherEncKey;
111 @SuppressWarnings("unused")
112 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class);
115 public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
117 PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
118 pspc.setIgnoreResourceNotFound(true);
119 pspc.setIgnoreUnresolvablePlaceholders(true);
126 public void loadProperties() {
127 if(cipherEncKey != null) {
128 MusicUtil.setCipherEncKey(cipherEncKey);
130 if (musicAafNs != null) {
131 MusicUtil.setMusicAafNs(musicAafNs);
133 if (cassandraPort != null && !cassandraPort.equals("${cassandra.port}")) {
134 MusicUtil.setCassandraPort(Integer.parseInt(cassandraPort));
136 if (cassandraUser != null && !cassandraUser.equals("${cassandra.user}")) {
137 MusicUtil.setCassName(cassandraUser);
139 if (cassandraPassword != null && !cassandraPassword.equals("${cassandra.password}")) {
140 MusicUtil.setCassPwd(cassandraPassword);
142 if (cassandraConnectTimeOutMS != null && !cassandraConnectTimeOutMS.equals("${cassandra.connecttimeoutms}")) {
143 MusicUtil.setCassandraConnectTimeOutMS(Integer.parseInt(cassandraConnectTimeOutMS));
145 if (cassandraReadTimeOutMS != null && !cassandraReadTimeOutMS.equals("${cassandra.readtimeoutms}")) {
146 MusicUtil.setCassandraReadTimeOutMS(Integer.parseInt(cassandraReadTimeOutMS));
148 if (debug != null && !debug.equals("${debug}")) {
149 MusicUtil.setDebug(Boolean.parseBoolean(debug));
151 if (lockLeasePeriod != null && !lockLeasePeriod.equals("${lock.lease.period}")) {
152 MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(lockLeasePeriod));
154 if (musicProperties != null && !musicProperties.equals("${music.properties}")) {
155 MusicUtil.setMusicPropertiesFilePath(musicProperties);
157 if (cassandraHost != null && !cassandraHost.equals("${cassandra.host}")) {
158 MusicUtil.setMyCassaHost(cassandraHost);
160 if (version != null && !version.equals("${version}")) {
161 MusicUtil.setVersion(version);
163 if (build != null && !version.equals("${build}")) {
164 MusicUtil.setBuild(build);
166 if (isCadi != null && !isCadi.equals("${cadi}")) {
167 MusicUtil.setIsCadi(Boolean.parseBoolean(isCadi));
169 if (rertryCount != null && !rertryCount.equals("${retry.count}")) {
170 MusicUtil.setRetryCount(Integer.parseInt(rertryCount));
172 if (isKeyspaceActive != null && !isKeyspaceActive.equals("${keyspace.active}")) {
173 MusicUtil.setKeyspaceActive(Boolean.parseBoolean(isKeyspaceActive));
175 if(transIdPrefix!=null) {
176 MusicUtil.setTransIdPrefix(transIdPrefix);
179 if(conversationIdPrefix!=null) {
180 MusicUtil.setConversationIdPrefix(conversationIdPrefix);
183 if(clientIdPrefix!=null) {
184 MusicUtil.setClientIdPrefix(clientIdPrefix);
187 if(messageIdPrefix!=null) {
188 MusicUtil.setMessageIdPrefix(messageIdPrefix);
191 if(transIdRequired!=null) {
192 MusicUtil.setTransIdRequired(transIdRequired);
195 if(conversationIdRequired!=null) {
196 MusicUtil.setConversationIdRequired(conversationIdRequired);
199 if(clientIdRequired!=null) {
200 MusicUtil.setClientIdRequired(clientIdRequired);
203 if(messageIdRequired!=null) {
204 MusicUtil.setMessageIdRequired(messageIdRequired);
208 public static void loadProperties(Properties properties) {
209 if (properties.getProperty("cassandra.host")!=null) {
210 MusicUtil.setMyCassaHost(properties.getProperty("cassandra.host"));
213 if (properties.getProperty("cassandra.port")!=null) {
214 MusicUtil.setCassandraPort(Integer.parseInt(properties.getProperty("cassandra.port")));
217 if (properties.getProperty("cassandra.user")!=null) {
218 MusicUtil.setCassName(properties.getProperty("cassandra.user"));
221 if (properties.getProperty("cassandra.password")!=null) {
222 MusicUtil.setCassPwd(properties.getProperty("cassandra.password"));
225 if(properties.getProperty("cassandra.connectTimeOutMS")!=null) {
226 MusicUtil.setCassandraConnectTimeOutMS(Integer.parseInt(properties.getProperty("cassandra.connecttimeoutms")));
229 if(properties.getProperty("cassandra.readTimeOutMS")!=null) {
230 MusicUtil.setCassandraReadTimeOutMS(Integer.parseInt(properties.getProperty("cassandra.readtimeoutms")));
233 if (properties.getProperty("music.properties")!=null) {
234 MusicUtil.setMusicPropertiesFilePath(properties.getProperty("music.properties"));
237 if (properties.getProperty("debug")!=null) {
238 MusicUtil.setDebug(Boolean.parseBoolean(properties.getProperty("debug")));
241 if (properties.getProperty("version")!=null) {
242 MusicUtil.setVersion(properties.getProperty("version"));
245 if (properties.getProperty("build")!=null) {
246 MusicUtil.setBuild(properties.getProperty("build"));
249 if (properties.getProperty("lock.lease.period")!=null) {
250 MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(properties.getProperty("lock.lease.period")));
253 if (properties.getProperty("cadi")!=null) {
254 MusicUtil.setIsCadi(Boolean.parseBoolean(properties.getProperty("cadi")));
257 if (properties.getProperty("keyspace.active")!=null) {
258 MusicUtil.setKeyspaceActive(Boolean.parseBoolean(properties.getProperty("keyspace.active")));
261 if (properties.getProperty("retry.count")!=null) {
262 MusicUtil.setRetryCount(Integer.parseInt(properties.getProperty("retry.count")));
265 if (properties.getProperty("transId.header.prefix")!=null) {
266 MusicUtil.setTransIdPrefix(properties.getProperty("transId.header.prefix"));
269 if (properties.getProperty("conversation.header.prefix")!=null) {
270 MusicUtil.setConversationIdPrefix(properties.getProperty("conversation.header.prefix"));
273 if (properties.getProperty("clientId.header.prefix")!=null) {
274 MusicUtil.setClientIdPrefix(properties.getProperty("clientId.header.prefix"));
277 if (properties.getProperty("messageId.header.prefix")!=null) {
278 MusicUtil.setMessageIdPrefix(properties.getProperty("messageId.header.prefix"));
281 if (properties.getProperty("transId.header.required")!=null) {
282 MusicUtil.setTransIdRequired(Boolean.parseBoolean(properties.getProperty("transId.header.required")));
285 if (properties.getProperty("conversation.header.required")!=null) {
286 MusicUtil.setConversationIdRequired(Boolean.parseBoolean(properties.getProperty("conversation.header.required")));
289 if (properties.getProperty("clientId.header.required")!=null) {
290 MusicUtil.setClientIdRequired(Boolean.parseBoolean(properties.getProperty("clientId.header.required")));
293 if (properties.getProperty("messageId.header.required")!=null) {
294 MusicUtil.setMessageIdRequired(Boolean.parseBoolean(properties.getProperty("messageId.header.required")));
297 if (properties.getProperty("music.aaf.ns")!=null) {
298 MusicUtil.setMusicAafNs(properties.getProperty("music.aaf.ns"));
301 if (properties.getProperty("cipher.enc.key")!=null) {
302 MusicUtil.setCipherEncKey(properties.getProperty("cipher.enc.key"));
308 public void afterPropertiesSet() throws Exception {
309 // TODO Auto-generated method stub