diff options
Diffstat (limited to 'src/main/java/org/onap/music/main')
-rwxr-xr-x | src/main/java/org/onap/music/main/MusicUtil.java | 23 | ||||
-rwxr-xr-x | src/main/java/org/onap/music/main/PropertiesListener.java | 257 | ||||
-rw-r--r-- | src/main/java/org/onap/music/main/PropertiesLoader.java | 5 |
3 files changed, 1 insertions, 284 deletions
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java index aa82ea97..b737377d 100755 --- a/src/main/java/org/onap/music/main/MusicUtil.java +++ b/src/main/java/org/onap/music/main/MusicUtil.java @@ -118,7 +118,7 @@ public class MusicUtil { private static String musicRestIp = LOCALHOST; private static String musicPropertiesFilePath = PROPERTIES_FILE; private static long defaultLockLeasePeriod = 6000; - private static final String[] propKeys = new String[] { "zookeeper.host", "cassandra.host", "music.ip", "debug", + private static final String[] propKeys = new String[] { "cassandra.host", "music.ip", "debug", "version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", "public.ip", "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url","admin.username","admin.password","aaf.admin.url", "music.namespace","admin.aaf.role","cassandra.port","lock.using"}; @@ -428,25 +428,6 @@ public class MusicUtil { } /** - * Get MyZkHost - Zookeeper Hostname - Default = localhost property file - * value - zookeeper.host - * - * @return - */ - public static String getMyZkHost() { - return myZkHost; - } - - /** - * Set MyZkHost - Zookeeper Hostname - * - * @param myZkHost - */ - public static void setMyZkHost(String myZkHost) { - MusicUtil.myZkHost = myZkHost; - } - - /** * Get MyCassHost - Cassandra Hostname - Default = localhost property file * value - cassandra.host * @@ -734,8 +715,6 @@ public class MusicUtil { } // get the property value and return it MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host")); - String zkHosts = prop.getProperty("zookeeper.host"); - MusicUtil.setMyZkHost(zkHosts); MusicUtil.setCassName(prop.getProperty("cassandra.user")); MusicUtil.setCassPwd(prop.getProperty("cassandra.password")); MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port"))); diff --git a/src/main/java/org/onap/music/main/PropertiesListener.java b/src/main/java/org/onap/music/main/PropertiesListener.java deleted file mode 100755 index c5e8c37c..00000000 --- a/src/main/java/org/onap/music/main/PropertiesListener.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * Modifications Copyright (C) 2018 IBM. - * =================================================================== - * 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============================================= - * ==================================================================== - */ - -package org.onap.music.main; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Properties; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.onap.music.datastore.PreparedQueryObject; -import org.onap.music.eelf.logging.EELFLoggerDelegate; -import org.onap.music.eelf.logging.format.AppMessages; -import org.onap.music.eelf.logging.format.ErrorSeverity; -import org.onap.music.eelf.logging.format.ErrorTypes; - -import org.onap.music.exceptions.MusicLockingException; -import org.onap.music.exceptions.MusicServiceException; - -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.Row; - -public class PropertiesListener { // implements ServletContextListener { - private Properties prop; - private static final String MUSIC_PROPERTIES="music.properties"; -/* private Properties prop; - ->>>>>>> c8db07f77a945bc22046ef50d773c3c3608b014a - private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesListener.class); - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - prop = new Properties(); - Properties projectProp = new Properties(); - URL resource = getClass().getResource("/"); - String musicPropertiesFilePath = resource.getPath().replace("WEB-INF/classes/","WEB-INF/classes/project.properties"); - - // Open the file - try { - InputStream musicProps = null; - projectProp.load(new FileInputStream(musicPropertiesFilePath)); - if (projectProp.containsKey(MUSIC_PROPERTIES)) { - musicProps = new FileInputStream(projectProp.getProperty(MUSIC_PROPERTIES)); - } else { - musicProps = new FileInputStream(MusicUtil.getMusicPropertiesFilePath()); - } - prop.load(musicProps); - musicProps.close(); - prop.putAll(projectProp); - String[] propKeys = MusicUtil.getPropkeys(); - for (int k = 0; k < propKeys.length; k++) { - String key = propKeys[k]; - if (prop.containsKey(key) && prop.get(key) != null) { - logger.info(key + " : " + prop.getProperty(key)); - switch (key) { - case "zookeeper.host": - MusicUtil.setMyZkHost(prop.getProperty(key)); - break; - case "cassandra.host": - MusicUtil.setMyCassaHost(prop.getProperty(key)); - break; - case "music.ip": - MusicUtil.setDefaultMusicIp(prop.getProperty(key)); - break; - case "debug": - MusicUtil.setDebug(Boolean - .getBoolean(prop.getProperty(key).toLowerCase())); - break; - case "version": - MusicUtil.setVersion(prop.getProperty(key)); - break; - case "music.rest.ip": - MusicUtil.setMusicRestIp(prop.getProperty(key)); - break; - case MUSIC_PROPERTIES: - MusicUtil.setMusicPropertiesFilePath(prop.getProperty(key)); - break; - case "lock.lease.period": - MusicUtil.setDefaultLockLeasePeriod( - Long.parseLong(prop.getProperty(key))); - break; - case "my.id": - MusicUtil.setMyId(Integer.parseInt(prop.getProperty(key))); - break; - case "all.ids": - String[] ids = prop.getProperty(key).split(":"); - MusicUtil.setAllIds(new ArrayList<String>(Arrays.asList(ids))); - break; - case "public.ip": - MusicUtil.setPublicIp(prop.getProperty(key)); - break; - case "all.public.ips": - String[] ips = prop.getProperty(key).split(":"); - if (ips.length == 1) { - // Future use - } else if (ips.length > 1) { - MusicUtil.setAllPublicIps( - new ArrayList<String>(Arrays.asList(ips))); - } - break; - case "cassandra.user": - MusicUtil.setCassName(prop.getProperty(key)); - break; - case "cassandra.password": - MusicUtil.setCassPwd(prop.getProperty(key)); - break; - case "aaf.endpoint.url": - MusicUtil.setAafEndpointUrl(prop.getProperty(key)); - break; - case "admin.username": - MusicUtil.setAdminId(prop.getProperty(key)); - break; - case "admin.password": - MusicUtil.setAdminPass(prop.getProperty(key)); - break; - case "cassandra.port": - MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty(key))); - break; - case "aaf.admin.url": - MusicUtil.setAafAdminUrl(prop.getProperty(key)); - break; - case "music.namespace": - MusicUtil.setMusicNamespace(prop.getProperty(key)); - break; - case "admin.aaf.role": - MusicUtil.setAdminAafRole(prop.getProperty(key)); - break; - case "notify.interval": - MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty(key))); - break; - case "notify.timeout": - MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty(key))); - break; - case "lock.using": - MusicUtil.setLockUsing(prop.getProperty(key)); - break; - case "cacheobject.maxlife": - MusicUtil.setCacheObjectMaxLife(Integer.parseInt(prop.getProperty(key))); - CachingUtil.setCacheEternalProps(); - break; - default: - logger.error(EELFLoggerDelegate.errorLogger, - "No case found for " + key); - } - } - } - } catch (IOException e) { - logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.IOERROR ,ErrorSeverity.CRITICAL, ErrorTypes.CONNECTIONERROR); - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); - } - - logger.info(EELFLoggerDelegate.applicationLogger, - "Starting MUSIC " + MusicUtil.getVersion() + " on node with id " - + MusicUtil.getMyId() + " and public ip " - + MusicUtil.getPublicIp() + "..."); - logger.info(EELFLoggerDelegate.applicationLogger, - "List of all MUSIC ids:" + MusicUtil.getAllIds().toString()); - logger.info(EELFLoggerDelegate.applicationLogger, - "List of all MUSIC public ips:" + MusicUtil.getAllPublicIps().toString()); - - scheduleCronJobForZKCleanup(); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - prop = null; - } - - - private ScheduledExecutorService scheduler; - public void scheduleCronJobForZKCleanup() { - scheduler = Executors.newSingleThreadScheduledExecutor(); - scheduler.scheduleAtFixedRate(new CachingUtil(), 0, 24, TimeUnit.HOURS); - PreparedQueryObject pQuery = new PreparedQueryObject(); - String consistency = MusicUtil.EVENTUAL; - pQuery.appendQueryString("CREATE TABLE IF NOT EXISTS admin.locks ( lock_id text PRIMARY KEY, ctime text)"); - try { - ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency); - } catch (MusicServiceException e1) { - logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),ErrorSeverity.ERROR); - } - - //Zookeeper cleanup - scheduler.scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - deleteLocksFromDB(); - } - } , 0, 24, TimeUnit.HOURS); - } - - - public void deleteLocksFromDB() { - PreparedQueryObject pQuery = new PreparedQueryObject(); - pQuery.appendQueryString( - "select * from admin.locks"); - try { - ResultSet rs = MusicCore.get(pQuery); - Iterator<Row> it = rs.iterator(); - StringBuilder deleteKeys = new StringBuilder(); - Boolean expiredKeys = false; - while (it.hasNext()) { - Row row = (Row) it.next(); - String id = row.getString("lock_id"); - long ctime = Long.parseLong(row.getString("ctime")); - if(System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) { - expiredKeys = true; - String new_id = id.substring(1); - try { - MusicCore.deleteLock(new_id); - } catch (MusicLockingException e) { - logger.info(EELFLoggerDelegate.applicationLogger, - e.getMessage()); - } - deleteKeys.append("'").append(id).append("'").append(","); - } - } - if(expiredKeys) { - deleteKeys.deleteCharAt(deleteKeys.length()-1); - CachingUtil.deleteKeysFromDB(deleteKeys.toString()); - } - } catch (MusicServiceException e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),ErrorSeverity.ERROR); - } - } -*/ -} diff --git a/src/main/java/org/onap/music/main/PropertiesLoader.java b/src/main/java/org/onap/music/main/PropertiesLoader.java index ee10db42..db04ff4b 100644 --- a/src/main/java/org/onap/music/main/PropertiesLoader.java +++ b/src/main/java/org/onap/music/main/PropertiesLoader.java @@ -37,9 +37,6 @@ import org.springframework.stereotype.Component; @Component public class PropertiesLoader implements InitializingBean { - @Value("${zookeeper.host}") - private String zookeeperHost; - @Value("${cassandra.host}") public String cassandraHost; @@ -168,8 +165,6 @@ public class PropertiesLoader implements InitializingBean { logger.info("#### Cassandra Host: " + MusicUtil.getMyCassaHost()); if(myId != null && !myId.equals("${my.id}")) MusicUtil.setMyId(Integer.parseInt(myId)); - if(zookeeperHost != null && !zookeeperHost.equals("${zookeeper.host}")) - MusicUtil.setMyZkHost(zookeeperHost); if(notifyInterval != null && !notifyInterval.equals("${notify.interval}")) MusicUtil.setNotifyInterval(Integer.parseInt(notifyInterval)); if(notifyTimeout != null && !notifyTimeout.equals("${notify.timeout}")) |