From 0d2f003049e562354fda88729dbab70f46daa25f Mon Sep 17 00:00:00 2001 From: "Nelson, Thomas (tn1381)" Date: Mon, 20 Aug 2018 04:45:13 +0000 Subject: Update swagger.json and other updates. Change-Id: I84753300e64ba82072e65ef1bde2cb76771ee046 Issue-ID: MUSIC-97 Signed-off-by: Nelson, Thomas (tn1381) --- src/main/java/org/onap/music/main/CachingUtil.java | 39 +++++++--- .../java/org/onap/music/main/CronJobManager.java | 87 ++++++++-------------- src/main/java/org/onap/music/main/MusicCore.java | 16 ++++ src/main/java/org/onap/music/main/MusicUtil.java | 21 +++++- 4 files changed, 95 insertions(+), 68 deletions(-) (limited to 'src/main/java/org/onap/music/main') diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java index d3654118..83b5158f 100755 --- a/src/main/java/org/onap/music/main/CachingUtil.java +++ b/src/main/java/org/onap/music/main/CachingUtil.java @@ -41,7 +41,8 @@ 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.MusicServiceException; - +import org.onap.music.datastore.jsonobjects.JsonNotification; +import org.onap.music.datastore.jsonobjects.JsonCallback; import com.att.eelf.configuration.EELFLogger; import com.datastax.driver.core.DataType; import com.datastax.driver.core.ResultSet; @@ -65,6 +66,7 @@ public class CachingUtil implements Runnable { private static CacheAccess> aafCache = JCS.getInstance("aafCache"); private static CacheAccess appNameCache = JCS.getInstance("appNameCache"); private static CacheAccess> musicValidateCache = JCS.getInstance("musicValidateCache"); + private static CacheAccess callBackCache = JCS.getInstance("callBackCache"); private static Map userAttempts = new HashMap<>(); private static Map lastFailedTime = new HashMap<>(); @@ -73,6 +75,14 @@ public class CachingUtil implements Runnable { return true; return false; } + + public static void updateCallBackCache(String appName, JsonCallback jsonCallBack) { + callBackCache.put(appName, jsonCallBack); + } + + public static JsonCallback getCallBackCache(String appName) { + return callBackCache.get(appName); + } public void initializeMusicCache() { logger.info(EELFLoggerDelegate.applicationLogger,"Initializing Music Cache..."); @@ -102,8 +112,8 @@ public class CachingUtil implements Runnable { String keySpace = row.getString("application_name"); try { userAttempts.put(nameSpace, 0); - AAFResponse responseObj = triggerAAF(nameSpace, userId, password); - if (responseObj.getNs().size() > 0) { + boolean responseObj = triggerAAF(nameSpace, userId, password); + if (responseObj) { map = new HashMap<>(); map.put(userId, password); aafCache.put(nameSpace, map); @@ -164,8 +174,8 @@ public class CachingUtil implements Runnable { } } - AAFResponse responseObj = triggerAAF(nameSpace, userId, password); - if (responseObj.getNs().size() > 0) { + boolean responseObj = triggerAAF(nameSpace, userId, password); + if (responseObj) { //if (responseObj.getNs().get(0).getAdmin().contains(userId)) { //Map map = new HashMap<>(); //map.put(userId, password); @@ -177,7 +187,7 @@ public class CachingUtil implements Runnable { return false; } - private static AAFResponse triggerAAF(String nameSpace, String userId, String password) + private static boolean triggerAAF(String nameSpace, String userId, String password) throws Exception { if (MusicUtil.getAafEndpointUrl() == null) { logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR); @@ -210,14 +220,14 @@ public class CachingUtil implements Runnable { // TODO Allow for 2-3 times and forbid any attempt to trigger AAF with invalid values // for specific time. } - response.getHeaders().put(HttpHeaders.CONTENT_TYPE, + /*response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON)); // AAFResponse output = response.getEntity(AAFResponse.class); response.bufferEntity(); String x = response.getEntity(String.class); - AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class); + AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class);*/ - return responseObj; + return true; } public static void updateMusicCache(String keyspace, String nameSpace) { @@ -417,4 +427,15 @@ public class CachingUtil implements Runnable { CachingUtil.updateMusicValidateCache(nameSpace, userId, pwd); return resultMap; } + + public static void deleteKeysFromDB(String deleteKeys) { + PreparedQueryObject pQuery = new PreparedQueryObject(); + pQuery.appendQueryString( + "DELETE FROM admin.locks WHERE lock_id IN ("+deleteKeys+")"); + try { + MusicCore.nonKeyRelatedPut(pQuery, "eventual"); + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/org/onap/music/main/CronJobManager.java b/src/main/java/org/onap/music/main/CronJobManager.java index 5b7a8de4..0344c4a1 100644 --- a/src/main/java/org/onap/music/main/CronJobManager.java +++ b/src/main/java/org/onap/music/main/CronJobManager.java @@ -32,16 +32,18 @@ import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.exceptions.MusicLockingException; import org.onap.music.exceptions.MusicServiceException; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; -@WebListener +//@WebListener public class CronJobManager implements ServletContextListener { private ScheduledExecutorService scheduler; + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CronJobManager.class); @Override public void contextInitialized(ServletContextEvent event) { @@ -55,8 +57,23 @@ public class CronJobManager implements ServletContextListener { } catch (MusicServiceException e1) { e1.printStackTrace(); } - - pQuery = new PreparedQueryObject(); + + //Zookeeper cleanup + scheduler.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + deleteLocksFromDB(); + } + } , 0, 24, TimeUnit.HOURS); + } + + @Override + public void contextDestroyed(ServletContextEvent event) { + scheduler.shutdownNow(); + } + + public void deleteLocksFromDB() { + PreparedQueryObject pQuery = new PreparedQueryObject(); pQuery.appendQueryString( "select * from admin.locks"); try { @@ -71,68 +88,22 @@ public class CronJobManager implements ServletContextListener { if(System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) { expiredKeys = true; String new_id = id.substring(1); - MusicCore.deleteLock(new_id); - deleteKeys.append(id).append(","); + try { + MusicCore.deleteLock(new_id); + } catch (MusicLockingException e) { + logger.info(EELFLoggerDelegate.applicationLogger, + e.getMessage()); + } + deleteKeys.append("'").append(id).append("'").append(","); } - else { - MusicUtil.zkNodeMap.put(id, ctime); - } - }; + } if(expiredKeys) { deleteKeys.deleteCharAt(deleteKeys.length()-1); - deleteKeysFromDB(deleteKeys); + CachingUtil.deleteKeysFromDB(deleteKeys.toString()); } } catch (MusicServiceException e) { e.printStackTrace(); - } catch (MusicLockingException e) { - e.printStackTrace(); - } - - //Zookeeper cleanup - scheduler.scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - Iterator> it = MusicUtil.zkNodeMap.entrySet().iterator(); - StringBuilder deleteKeys = new StringBuilder(); - Boolean expiredKeys = false; - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - long ctime = pair.getValue(); - if (System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) { - try { - expiredKeys = true; - String id = pair.getKey(); - deleteKeys.append("'").append(id).append("'").append(","); - MusicCore.deleteLock(id.substring(1)); - MusicUtil.zkNodeMap.remove(id); - - } catch (MusicLockingException e) { - e.printStackTrace(); - } - } - } - if(expiredKeys) { - deleteKeys.deleteCharAt(deleteKeys.length()-1); - deleteKeysFromDB(deleteKeys); - } } - } , 0, 24, TimeUnit.HOURS); - } - - @Override - public void contextDestroyed(ServletContextEvent event) { - scheduler.shutdownNow(); - } - - public void deleteKeysFromDB(StringBuilder deleteKeys) { - PreparedQueryObject pQuery = new PreparedQueryObject(); - pQuery.appendQueryString( - "DELETE FROM admin.locks WHERE lock_id IN ("+deleteKeys+")"); - try { - MusicCore.nonKeyRelatedPut(pQuery, "eventual"); - } catch (Exception e) { - e.printStackTrace(); - } } } diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java index dfc93ccc..b729ba74 100644 --- a/src/main/java/org/onap/music/main/MusicCore.java +++ b/src/main/java/org/onap/music/main/MusicCore.java @@ -708,6 +708,22 @@ public class MusicCore { } return results; } + + public static String getMyHostId() { + PreparedQueryObject pQuery = new PreparedQueryObject(); + pQuery.appendQueryString("SELECT HOST_ID FROM SYSTEM.LOCAL"); + ResultSet rs = null; + try { + rs = getDSHandle().executeEventualGet(pQuery); + Row row = rs.one(); + return (row == null) ? "UNKNOWN" : row.getUUID("HOST_ID").toString(); + } catch (Exception e) { + e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger,e.getMessage()); + } + logger.error(EELFLoggerDelegate.errorLogger, "Some issue during MusicCore.getMyHostId"); + return "UNKNOW"; + } /** * This method performs DDL operations on cassandra, if the the resource is available. Lock ID diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java index 2dd2f231..40d19766 100755 --- a/src/main/java/org/onap/music/main/MusicUtil.java +++ b/src/main/java/org/onap/music/main/MusicUtil.java @@ -86,6 +86,8 @@ public class MusicUtil { private static String myCassaHost = LOCALHOST; private static String defaultMusicIp = LOCALHOST; private static int cassandraPort = 9042; + private static int notifytimeout = 30000; + private static int notifyinterval = 5000; private static boolean debug = true; private static String version = "2.3.0"; @@ -94,7 +96,7 @@ public class MusicUtil { private static long defaultLockLeasePeriod = 6000; private static final String[] propKeys = new String[] { "zookeeper.host", "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","cassandra.port" }; + "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url","cassandra.port", "notify.timeout", "notify.interval" }; private static String cassName = "cassandra"; private static String cassPwd; @@ -608,7 +610,24 @@ public class MusicUtil { MusicUtil.setCassName(prop.getProperty("cassandra.user")); MusicUtil.setCassPwd(prop.getProperty("cassandra.password")); MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port"))); + MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty("notify.timeout"))); + MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty("notify.interval"))); } + + private static void setNotifyInterval(int notifyinterval) { + MusicUtil.notifyinterval = notifyinterval; + } + private static void setNotifyTimeOut(int notifytimeout) { + MusicUtil.notifytimeout = notifytimeout; + } + public static int getNotifyInterval() { + return MusicUtil.notifyinterval; + } + + public static int getNotifyTimeout() { + return MusicUtil.notifytimeout; + + } } -- cgit 1.2.3-korg