X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=music-rest%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fmusic%2Fmain%2FPropertiesLoader.java;h=11dc51dd3e8620f1c75ff3ad8682a5f266298cb8;hb=0c173cdf44af313e376f1e8ae4fd6e6973c6c20b;hp=7ef36f23243f37bf44727c432d73e2151a86fe7c;hpb=021bf79c3a37acc0121b4b18b63f572d8ac9dd7e;p=music.git diff --git a/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java b/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java index 7ef36f23..11dc51dd 100644 --- a/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java +++ b/music-rest/src/main/java/org/onap/music/main/PropertiesLoader.java @@ -22,6 +22,7 @@ package org.onap.music.main; +import java.util.HashSet; import java.util.Properties; import org.onap.music.eelf.logging.EELFLoggerDelegate; @@ -32,7 +33,8 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.stereotype.Component; -@PropertySource(value = {"file:/opt/app/music/etc/music.properties", "classpath:/project.properties","file:/opt/app/music/etc/key.properties"}) +@PropertySource(value = {"file:/opt/app/music/etc/music.properties", "classpath:/project.properties"}) +//"file:/opt/app/music/etc/key.properties" @Component public class PropertiesLoader implements InitializingBean { @@ -41,37 +43,55 @@ public class PropertiesLoader implements InitializingBean { @Value("${debug}") public String debug; - + @Value("${version}") public String version; @Value("${build}") public String build; - + @Value("${music.properties}") public String musicProperties; - + @Value("${lock.lease.period}") public String lockLeasePeriod; - + @Value("${cassandra.user}") public String cassandraUser; - + @Value("${cassandra.password}") public String cassandraPassword; - + @Value("${cassandra.port}") public String cassandraPort; - + + @Value("${cassandra.connecttimeoutms}") + public String cassandraConnectTimeOutMS; + + @Value("${cassandra.readtimeoutms}") + public String cassandraReadTimeOutMS; + @Value("${cadi}") public String isCadi; - + @Value("${keyspace.active}") public String isKeyspaceActive; @Value("${retry.count}") public String rertryCount; + @Value("${lock.daemon.sleeptime.ms}") + public String lockDaemonSleeptimems; + + @Value("${keyspaces.for.lock.cleanup}") + public String keyspacesForLockCleanup; + + @Value("${create.lock.wait.period.ms}") + private long createLockWaitPeriod; + + @Value("${create.lock.wait.increment.ms}") + private int createLockWaitIncrement; + @Value("${transId.header.prefix}") private String transIdPrefix; @@ -83,7 +103,7 @@ public class PropertiesLoader implements InitializingBean { @Value("${messageId.header.prefix}") private String messageIdPrefix; - + @Value("${transId.header.required}") private Boolean transIdRequired; @@ -99,21 +119,21 @@ public class PropertiesLoader implements InitializingBean { @Value("${music.aaf.ns}") private String musicAafNs; - @Value("${cipher.enc.key}") + @Value("${cipher.enc.key:}") private String cipherEncKey; - + @SuppressWarnings("unused") - private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class); - + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class); + @Bean public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() { - + PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); pspc.setIgnoreResourceNotFound(true); pspc.setIgnoreUnresolvablePlaceholders(true); return pspc; } - + /** * . */ @@ -133,6 +153,12 @@ public class PropertiesLoader implements InitializingBean { if (cassandraPassword != null && !cassandraPassword.equals("${cassandra.password}")) { MusicUtil.setCassPwd(cassandraPassword); } + if (cassandraConnectTimeOutMS != null && !cassandraConnectTimeOutMS.equals("${cassandra.connecttimeoutms}")) { + MusicUtil.setCassandraConnectTimeOutMS(Integer.parseInt(cassandraConnectTimeOutMS)); + } + if (cassandraReadTimeOutMS != null && !cassandraReadTimeOutMS.equals("${cassandra.readtimeoutms}")) { + MusicUtil.setCassandraReadTimeOutMS(Integer.parseInt(cassandraReadTimeOutMS)); + } if (debug != null && !debug.equals("${debug}")) { MusicUtil.setDebug(Boolean.parseBoolean(debug)); } @@ -160,6 +186,16 @@ public class PropertiesLoader implements InitializingBean { if (isKeyspaceActive != null && !isKeyspaceActive.equals("${keyspace.active}")) { MusicUtil.setKeyspaceActive(Boolean.parseBoolean(isKeyspaceActive)); } + if (lockDaemonSleeptimems != null && !lockDaemonSleeptimems.equals("${lock.daemon.sleeptime.ms}")) { + MusicUtil.setLockDaemonSleepTimeMs(Long.parseLong(lockDaemonSleeptimems)); + } + if (keyspacesForLockCleanup !=null && !keyspacesForLockCleanup.equals("${keyspaces.for.lock.cleanup}")) { + HashSet keyspaces = new HashSet<>(); + for (String keyspace: keyspacesForLockCleanup.split(",")) { + keyspaces.add(keyspace); + } + MusicUtil.setKeyspacesToCleanLocks(keyspaces); + } if(transIdPrefix!=null) { MusicUtil.setTransIdPrefix(transIdPrefix); } @@ -191,6 +227,14 @@ public class PropertiesLoader implements InitializingBean { if(messageIdRequired!=null) { MusicUtil.setMessageIdRequired(messageIdRequired); } + + if(createLockWaitPeriod!=0) { + MusicUtil.setCreateLockWaitPeriod(createLockWaitPeriod); + } + + if(createLockWaitIncrement!=0) { + MusicUtil.setCreateLockWaitIncrement(createLockWaitIncrement); + } } public static void loadProperties(Properties properties) { @@ -209,7 +253,15 @@ public class PropertiesLoader implements InitializingBean { if (properties.getProperty("cassandra.password")!=null) { MusicUtil.setCassPwd(properties.getProperty("cassandra.password")); } - + + if(properties.getProperty("cassandra.connectTimeOutMS")!=null) { + MusicUtil.setCassandraConnectTimeOutMS(Integer.parseInt(properties.getProperty("cassandra.connecttimeoutms"))); + } + + if(properties.getProperty("cassandra.readTimeOutMS")!=null) { + MusicUtil.setCassandraReadTimeOutMS(Integer.parseInt(properties.getProperty("cassandra.readtimeoutms"))); + } + if (properties.getProperty("music.properties")!=null) { MusicUtil.setMusicPropertiesFilePath(properties.getProperty("music.properties")); } @@ -283,11 +335,39 @@ public class PropertiesLoader implements InitializingBean { } } - + @Override public void afterPropertiesSet() throws Exception { // TODO Auto-generated method stub - + + } + + /* For unit testing purpose only*/ + protected void setProperties() { + cassandraHost = "127.0.0.1"; + debug = "true"; + version = "x.x.x"; + build = "y.y"; + musicProperties = "property"; + lockLeasePeriod = "5000"; + cassandraUser = "user"; + cassandraPassword = "password"; + cassandraPort = "8007"; + cassandraConnectTimeOutMS = "1000"; + cassandraReadTimeOutMS = "1000"; + isCadi = "true"; + isKeyspaceActive = "true"; + rertryCount = "20"; + transIdPrefix = "transId-"; + conversationIdPrefix = "conversation-"; + clientIdPrefix = "clientId-"; + messageIdPrefix = "messageId-"; + transIdRequired = true; + conversationIdRequired = true; + clientIdRequired = true; + messageIdRequired = true; + musicAafNs = "ns"; + cipherEncKey = "key"; } }