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 * ====================================================================
22 package org.onap.music.main;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Properties;
31 import javax.servlet.ServletContextEvent;
32 import javax.servlet.ServletContextListener;
33 import javax.servlet.annotation.WebListener;
34 import org.onap.music.eelf.logging.EELFLoggerDelegate;
37 public class PropertiesListener implements ServletContextListener {
38 private Properties prop;
40 private static EELFLoggerDelegate logger =
41 EELFLoggerDelegate.getLogger(PropertiesListener.class);
44 public void contextInitialized(ServletContextEvent servletContextEvent) {
45 prop = new Properties();
46 Properties projectProp = new Properties();
47 URL resource = getClass().getResource("/");
48 String musicPropertiesFilePath = resource.getPath().replace("WEB-INF/classes/",
49 "WEB-INF/classes/project.properties");
53 InputStream musicProps = null;
54 projectProp.load(new FileInputStream(musicPropertiesFilePath));
55 if (projectProp.containsKey("music.properties")) {
56 musicProps = new FileInputStream(projectProp.getProperty("music.properties"));
58 musicProps = new FileInputStream(MusicUtil.getMusicPropertiesFilePath());
60 prop.load(musicProps);
62 prop.putAll(projectProp);
63 String[] propKeys = MusicUtil.getPropkeys();
64 for (int k = 0; k < propKeys.length; k++) {
65 String key = propKeys[k];
66 if (prop.containsKey(key) && prop.get(key) != null) {
67 logger.info(key + " : " + prop.getProperty(key));
69 case "zookeeper.host":
70 MusicUtil.setMyZkHost(prop.getProperty(key));
72 case "cassandra.host":
73 MusicUtil.setMyCassaHost(prop.getProperty(key));
76 MusicUtil.setDefaultMusicIp(prop.getProperty(key));
79 MusicUtil.setDebug(Boolean
80 .getBoolean(prop.getProperty(key).toLowerCase()));
83 MusicUtil.setVersion(prop.getProperty(key));
86 MusicUtil.setMusicRestIp(prop.getProperty(key));
88 case "music.properties":
89 MusicUtil.setMusicPropertiesFilePath(prop.getProperty(key));
91 case "lock.lease.period":
92 MusicUtil.setDefaultLockLeasePeriod(
93 Long.parseLong(prop.getProperty(key)));
96 MusicUtil.setMyId(Integer.parseInt(prop.getProperty(key)));
99 String[] ids = prop.getProperty(key).split(":");
100 MusicUtil.setAllIds(new ArrayList<String>(Arrays.asList(ids)));
103 MusicUtil.setPublicIp(prop.getProperty(key));
105 case "all.public.ips":
106 String[] ips = prop.getProperty(key).split(":");
107 if (ips.length == 1) {
109 } else if (ips.length > 1) {
110 MusicUtil.setAllPublicIps(
111 new ArrayList<String>(Arrays.asList(ips)));
114 case "cassandra.user":
115 MusicUtil.setCassName(prop.getProperty(key));
117 case "cassandra.password":
118 MusicUtil.setCassPwd(prop.getProperty(key));
120 case "aaf.endpoint.url":
121 MusicUtil.setAafEndpointUrl(prop.getProperty(key));
124 logger.error(EELFLoggerDelegate.errorLogger,
125 "No case found for " + key);
129 } catch (IOException e) {
130 logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
133 logger.info(EELFLoggerDelegate.applicationLogger,
134 "Starting MUSIC " + MusicUtil.getVersion() + " on node with id "
135 + MusicUtil.getMyId() + " and public ip "
136 + MusicUtil.getPublicIp() + "...");
137 logger.info(EELFLoggerDelegate.applicationLogger,
138 "List of all MUSIC ids:" + MusicUtil.getAllIds().toString());
139 logger.info(EELFLoggerDelegate.applicationLogger,
140 "List of all MUSIC public ips:" + MusicUtil.getAllPublicIps().toString());
144 public void contextDestroyed(ServletContextEvent servletContextEvent) {