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;
43 public String musicIp;
49 public String version;
54 @Value("${music.properties}")
55 public String musicProperties;
57 @Value("${lock.lease.period}")
58 public String lockLeasePeriod;
60 @Value("${cassandra.user}")
61 public String cassandraUser;
63 @Value("${cassandra.password}")
64 public String cassandraPassword;
66 @Value("${cassandra.port}")
67 public String cassandraPort;
72 @Value("${keyspace.active}")
73 public String isKeyspaceActive;
75 @Value("${retry.count}")
76 public String rertryCount;
78 @Value("${transId.header.prefix}")
79 private String transIdPrefix;
81 @Value("${conversation.header.prefix}")
82 private String conversationIdPrefix;
84 @Value("${clientId.header.prefix}")
85 private String clientIdPrefix;
87 @Value("${messageId.header.prefix}")
88 private String messageIdPrefix;
90 @Value("${transId.header.required}")
91 private Boolean transIdRequired;
93 @Value("${conversation.header.required}")
94 private Boolean conversationIdRequired;
96 @Value("${clientId.header.required}")
97 private Boolean clientIdRequired;
99 @Value("${messageId.header.required}")
100 private Boolean messageIdRequired;
102 @Value("${music.aaf.ns}")
103 private String musicAafNs;
105 @Value("${cipher.enc.key}")
106 private String cipherEncKey;
108 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class);
111 public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
112 //return new PropertySourcesPlaceholderConfigurer();
113 PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
114 pspc.setIgnoreResourceNotFound(true);
115 pspc.setIgnoreUnresolvablePlaceholders(true);
122 public void loadProperties() {
123 if(cipherEncKey != null) {
124 MusicUtil.setCipherEncKey(cipherEncKey);
126 if (musicAafNs != null) {
127 MusicUtil.setMusicAafNs(musicAafNs);
129 if (cassandraPort != null && !cassandraPort.equals("${cassandra.port}")) {
130 MusicUtil.setCassandraPort(Integer.parseInt(cassandraPort));
132 if (cassandraUser != null && !cassandraUser.equals("${cassandra.user}")) {
133 MusicUtil.setCassName(cassandraUser);
135 if (cassandraPassword != null && !cassandraPassword.equals("${cassandra.password}")) {
136 MusicUtil.setCassPwd(cassandraPassword);
138 if (debug != null && !debug.equals("${debug}")) {
139 MusicUtil.setDebug(Boolean.parseBoolean(debug));
141 if (lockLeasePeriod != null && !lockLeasePeriod.equals("${lock.lease.period}")) {
142 MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(lockLeasePeriod));
144 if (musicProperties != null && !musicProperties.equals("${music.properties}")) {
145 MusicUtil.setMusicPropertiesFilePath(musicProperties);
147 if (cassandraHost != null && !cassandraHost.equals("${cassandra.host}")) {
148 MusicUtil.setMyCassaHost(cassandraHost);
150 if (version != null && !version.equals("${version}")) {
151 MusicUtil.setVersion(version);
153 if (build != null && !version.equals("${build}")) {
154 MusicUtil.setBuild(build);
156 if (isCadi != null && !isCadi.equals("${cadi}")) {
157 MusicUtil.setIsCadi(Boolean.parseBoolean(isCadi));
159 if (rertryCount != null && !rertryCount.equals("${retry.count}")) {
160 MusicUtil.setRetryCount(Integer.parseInt(rertryCount));
162 if (isKeyspaceActive != null && !isKeyspaceActive.equals("${keyspace.active}")) {
163 MusicUtil.setKeyspaceActive(Boolean.parseBoolean(isKeyspaceActive));
165 if(transIdPrefix!=null) {
166 MusicUtil.setTransIdPrefix(transIdPrefix);
169 if(conversationIdPrefix!=null) {
170 MusicUtil.setConversationIdPrefix(conversationIdPrefix);
173 if(clientIdPrefix!=null) {
174 MusicUtil.setClientIdPrefix(clientIdPrefix);
177 if(messageIdPrefix!=null) {
178 MusicUtil.setMessageIdPrefix(messageIdPrefix);
181 if(transIdRequired!=null) {
182 MusicUtil.setTransIdRequired(transIdRequired);
185 if(conversationIdRequired!=null) {
186 MusicUtil.setConversationIdRequired(conversationIdRequired);
189 if(clientIdRequired!=null) {
190 MusicUtil.setClientIdRequired(clientIdRequired);
193 if(messageIdRequired!=null) {
194 MusicUtil.setMessageIdRequired(messageIdRequired);
198 public static void loadProperties(Properties properties) {
199 if (properties.getProperty("cassandra.host")!=null) {
200 MusicUtil.setMyCassaHost(properties.getProperty("cassandra.host"));
203 if (properties.getProperty("cassandra.port")!=null) {
204 MusicUtil.setCassandraPort(Integer.parseInt(properties.getProperty("cassandra.port")));
207 if (properties.getProperty("cassandra.user")!=null) {
208 MusicUtil.setCassName(properties.getProperty("cassandra.user"));
211 if (properties.getProperty("cassandra.password")!=null) {
212 MusicUtil.setCassPwd(properties.getProperty("cassandra.password"));
215 if (properties.getProperty("music.properties")!=null) {
216 MusicUtil.setMusicPropertiesFilePath(properties.getProperty("music.properties"));
219 if (properties.getProperty("debug")!=null) {
220 MusicUtil.setDebug(Boolean.parseBoolean(properties.getProperty("debug")));
223 if (properties.getProperty("version")!=null) {
224 MusicUtil.setVersion(properties.getProperty("version"));
227 if (properties.getProperty("build")!=null) {
228 MusicUtil.setBuild(properties.getProperty("build"));
231 if (properties.getProperty("lock.lease.period")!=null) {
232 MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(properties.getProperty("lock.lease.period")));
235 if (properties.getProperty("cadi")!=null) {
236 MusicUtil.setIsCadi(Boolean.parseBoolean(properties.getProperty("cadi")));
239 if (properties.getProperty("keyspace.active")!=null) {
240 MusicUtil.setKeyspaceActive(Boolean.parseBoolean(properties.getProperty("keyspace.active")));
243 if (properties.getProperty("retry.count")!=null) {
244 MusicUtil.setRetryCount(Integer.parseInt(properties.getProperty("retry.count")));
247 if (properties.getProperty("transId.header.prefix")!=null) {
248 MusicUtil.setTransIdPrefix(properties.getProperty("transId.header.prefix"));
251 if (properties.getProperty("conversation.header.prefix")!=null) {
252 MusicUtil.setConversationIdPrefix(properties.getProperty("conversation.header.prefix"));
255 if (properties.getProperty("clientId.header.prefix")!=null) {
256 MusicUtil.setClientIdPrefix(properties.getProperty("clientId.header.prefix"));
259 if (properties.getProperty("messageId.header.prefix")!=null) {
260 MusicUtil.setMessageIdPrefix(properties.getProperty("messageId.header.prefix"));
263 if (properties.getProperty("transId.header.required")!=null) {
264 MusicUtil.setTransIdRequired(Boolean.parseBoolean(properties.getProperty("transId.header.required")));
267 if (properties.getProperty("conversation.header.required")!=null) {
268 MusicUtil.setConversationIdRequired(Boolean.parseBoolean(properties.getProperty("conversation.header.required")));
271 if (properties.getProperty("clientId.header.required")!=null) {
272 MusicUtil.setClientIdRequired(Boolean.parseBoolean(properties.getProperty("clientId.header.required")));
275 if (properties.getProperty("messageId.header.required")!=null) {
276 MusicUtil.setMessageIdRequired(Boolean.parseBoolean(properties.getProperty("messageId.header.required")));
279 if (properties.getProperty("music.aaf.ns")!=null) {
280 MusicUtil.setMusicAafNs(properties.getProperty("music.aaf.ns"));
283 if (properties.getProperty("cipher.enc.key")!=null) {
284 MusicUtil.setCipherEncKey(properties.getProperty("cipher.enc.key"));
290 public void afterPropertiesSet() throws Exception {
291 // TODO Auto-generated method stub