From c2efe177fb1f418734e7d3d7ece32e7ddd97a640 Mon Sep 17 00:00:00 2001 From: "Gadicherla, Shiva" Date: Thu, 26 Dec 2019 16:33:20 +0000 Subject: [PATCH] Added properties for cassandra connect and read time outs with Junit cases. Issue-ID: MUSIC-521 Signed-off-by: Gadicherla, Shiva Change-Id: I15b09521f87161189f56701b7021f58276c875dc --- WebContent/WEB-INF/music.properties.sample | 2 + .../org/onap/music/datastore/MusicDataStore.java | 123 ++++++++++---------- .../main/java/org/onap/music/main/MusicUtil.java | 124 ++++++++++++--------- .../org/onap/music/cassandra/MusicUtilTest.java | 49 +++++--- .../java/org/onap/music/main/PropertiesLoader.java | 56 +++++++--- 5 files changed, 207 insertions(+), 147 deletions(-) diff --git a/WebContent/WEB-INF/music.properties.sample b/WebContent/WEB-INF/music.properties.sample index 871b0c3f..41b919fe 100644 --- a/WebContent/WEB-INF/music.properties.sample +++ b/WebContent/WEB-INF/music.properties.sample @@ -14,5 +14,7 @@ all.public.ips=12.13.14.45:12.13.14.46:12.13.14.47 # Cassandra Username and password cassandra.user=cassandra cassandra.password=cassandra +cassandra.connecttimeoutms=5000 +cassandra.readtimeoutms=5000 # AAF Endpoint aaf.endpoint.url=http://aafendpoint/proxy/authz/nss/ \ No newline at end of file diff --git a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java index dd911491..7f6c42ca 100755 --- a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java +++ b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java @@ -51,6 +51,7 @@ import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.SocketOptions; import com.datastax.driver.core.TableMetadata; import com.datastax.driver.core.exceptions.AlreadyExistsException; import com.datastax.driver.core.exceptions.InvalidQueryException; @@ -90,7 +91,7 @@ public class MusicDataStore { setCluster(cluster); } - + /** * @param session */ @@ -111,10 +112,10 @@ public class MusicDataStore { public void setCluster(Cluster cluster) { EnumNameCodec lockTypeCodec = new EnumNameCodec(LockType.class); cluster.getConfiguration().getCodecRegistry().register(lockTypeCodec); - + this.cluster = cluster; } - + public Cluster getCluster() { return this.cluster; } @@ -122,7 +123,7 @@ public class MusicDataStore { private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStore.class); - + /** * * @param remoteIp @@ -155,38 +156,44 @@ public class MusicDataStore { poolingOptions .setConnectionsPerHost(HostDistance.LOCAL, 4, 10) .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); - + Cluster cluster; if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) { String cassPwd = CipherUtil.decryptPKC(MusicUtil.getCassPwd()); logger.info(EELFLoggerDelegate.applicationLogger, "Building with credentials "+MusicUtil.getCassName()+" & "+ MusicUtil.getCassPwd()); cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) - .withCredentials(MusicUtil.getCassName(), cassPwd) - //.withLoadBalancingPolicy(new RoundRobinPolicy()) - .withoutJMXReporting() - .withPoolingOptions(poolingOptions) - .addContactPoints(addresses).build(); + .withCredentials(MusicUtil.getCassName(), cassPwd) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .withoutJMXReporting() + .withPoolingOptions(poolingOptions) + .withSocketOptions( + new SocketOptions().setConnectTimeoutMillis(MusicUtil.getCassandraConnectTimeOutMS()) + .setReadTimeoutMillis(MusicUtil.getCassandraReadTimeOutMS())) + .addContactPoints(addresses).build(); } else { cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) - .withoutJMXReporting() - .withPoolingOptions(poolingOptions) - .addContactPoints(addresses) - .build(); + .withoutJMXReporting() + .withPoolingOptions(poolingOptions) + .withSocketOptions(new SocketOptions() + .setConnectTimeoutMillis(MusicUtil.getCassandraConnectTimeOutMS()) + .setReadTimeoutMillis(MusicUtil.getCassandraReadTimeOutMS())) + .addContactPoints(addresses) + .build(); } - + this.setCluster(cluster); Metadata metadata = this.cluster.getMetadata(); logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster " - + metadata.getClusterName() + " at " + address); + + metadata.getClusterName() + " at " + address); try { session = this.cluster.connect(); } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.CASSANDRACONNECTIVITY, - ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE, ex); + ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE, ex); throw new MusicServiceException( - "Error while connecting to Cassandra cluster.. " + ex.getMessage()); + "Error while connecting to Cassandra cluster.. " + ex.getMessage()); } } @@ -214,16 +221,16 @@ public class MusicDataStore { KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(keyspace); return ks.getTable(tableName); } - + /** - * - * @param keyspace - * @param tableName - * @return TableMetadata - */ - public KeyspaceMetadata returnKeyspaceMetadata(String keyspace) { - return cluster.getMetadata().getKeyspace(keyspace); - } + * + * @param keyspace + * @param tableName + * @return TableMetadata + */ + public KeyspaceMetadata returnKeyspaceMetadata(String keyspace) { + return cluster.getMetadata().getKeyspace(keyspace); + } /** @@ -289,7 +296,7 @@ public class MusicDataStore { */ public Map> marshalData(ResultSet results) { Map> resultMap = - new HashMap<>(); + new HashMap<>(); int counter = 0; for (Row row : results) { ColumnDefinitions colInfo = row.getColumnDefinitions(); @@ -301,7 +308,7 @@ public class MusicDataStore { getBlobValue(row, definition.getName(), definition.getType())); } else { resultOutput.put(definition.getName(), - getColValue(row, definition.getName(), definition.getType())); + getColValue(row, definition.getName(), definition.getType())); } } } @@ -313,7 +320,7 @@ public class MusicDataStore { // Prepared Statements 1802 additions - + public boolean executePut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException, MusicQueryException { return executePut(queryObject, consistency, 0); @@ -329,19 +336,19 @@ public class MusicDataStore { * @throws MusicQueryException */ public boolean executePut(PreparedQueryObject queryObject, String consistency,long timeSlot) - throws MusicServiceException, MusicQueryException { + throws MusicServiceException, MusicQueryException { boolean result = false; long timeOfWrite = System.currentTimeMillis(); if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) { logger.error(EELFLoggerDelegate.errorLogger, queryObject.getQuery(),AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR); throw new MusicQueryException("Ill formed queryObject for the request = " + "[" - + queryObject.getQuery() + "]"); + + queryObject.getQuery() + "]"); } logger.debug(EELFLoggerDelegate.applicationLogger, - "In preprared Execute Put: the actual insert query:" - + queryObject.getQuery() + "; the values" - + queryObject.getValues()); + "In preprared Execute Put: the actual insert query:" + + queryObject.getQuery() + "; the values" + + queryObject.getValues()); SimpleStatement preparedInsert = null; try { @@ -381,12 +388,12 @@ public class MusicDataStore { // logger.error(EELFLoggerDelegate.errorLogger,e.getClass().toString() + ":" + e.getMessage(),AppMessages.SESSIONFAILED + " [" // + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, e); throw new MusicServiceException("Executing Session Failure for Request = " + "[" - + queryObject.getQuery() + "]" + " Reason = " + e.getMessage(),e); + + queryObject.getQuery() + "]" + " Reason = " + e.getMessage(),e); } return result; } - /* *//** + /* *//** * This method performs DDL operations on Cassandra using consistency level ONE. * * @param queryObject Object containing cassandra prepared query and values. @@ -429,15 +436,15 @@ public class MusicDataStore { return results; } - *//** - * - * This method performs DDL operation on Cassandra using consistency level QUORUM. - * - * @param queryObject Object containing cassandra prepared query and values. - * @return ResultSet - * @throws MusicServiceException - * @throws MusicQueryException - *//* + *//** + * + * This method performs DDL operation on Cassandra using consistency level QUORUM. + * + * @param queryObject Object containing cassandra prepared query and values. + * @return ResultSet + * @throws MusicServiceException + * @throws MusicQueryException + *//* public ResultSet executeCriticalGet(PreparedQueryObject queryObject) throws MusicServiceException, MusicQueryException { if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) { @@ -460,12 +467,12 @@ public class MusicDataStore { return results; } - */ + */ public ResultSet executeGet(PreparedQueryObject queryObject,String consistencyLevel) throws MusicQueryException, MusicServiceException { if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) { logger.error(EELFLoggerDelegate.errorLogger, "",AppMessages.QUERYERROR+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR); throw new MusicQueryException("Error processing Prepared Query Object for the request = " + "[" - + queryObject.getQuery() + "]"); + + queryObject.getQuery() + "]"); } ResultSet results = null; try { @@ -482,24 +489,24 @@ public class MusicDataStore { } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, "Execute Get Error" + ex.getMessage(),AppMessages.UNKNOWNERROR+ "[" + queryObject - .getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, ex); + .getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, ex); throw new MusicServiceException("Execute Get Error" + ex.getMessage()); } - + return results; - + } - + /** * This method performs DDL operations on Cassandra using consistency level ONE. * * @param queryObject Object containing cassandra prepared query and values. */ public ResultSet executeOneConsistencyGet(PreparedQueryObject queryObject) - throws MusicServiceException, MusicQueryException { + throws MusicServiceException, MusicQueryException { return executeGet(queryObject, CONSISTENCY_LEVEL_ONE); } - + /** * * This method performs DDL operation on Cassandra using consistency level LOCAL_QUORUM. @@ -507,10 +514,10 @@ public class MusicDataStore { * @param queryObject Object containing cassandra prepared query and values. */ public ResultSet executeLocalQuorumConsistencyGet(PreparedQueryObject queryObject) - throws MusicServiceException, MusicQueryException { + throws MusicServiceException, MusicQueryException { return executeGet(queryObject, CONSISTENCY_LEVEL_LOCAL_QUORUM); } - + /** * * This method performs DDL operation on Cassandra using consistency level QUORUM. @@ -518,8 +525,8 @@ public class MusicDataStore { * @param queryObject Object containing cassandra prepared query and values. */ public ResultSet executeQuorumConsistencyGet(PreparedQueryObject queryObject) - throws MusicServiceException, MusicQueryException { + throws MusicServiceException, MusicQueryException { return executeGet(queryObject, CONSISTENCY_LEVEL_QUORUM); } - + } diff --git a/music-core/src/main/java/org/onap/music/main/MusicUtil.java b/music-core/src/main/java/org/onap/music/main/MusicUtil.java index db51322d..78d17c60 100644 --- a/music-core/src/main/java/org/onap/music/main/MusicUtil.java +++ b/music-core/src/main/java/org/onap/music/main/MusicUtil.java @@ -118,8 +118,8 @@ public class MusicUtil { // "clientId.header.prefix","messageId.header.prefix"}; // Consistency Constants and variables. private static final String[] cosistencyLevel = new String[] { - "ALL","EACH_QUORUM","QUORUM","LOCAL_QUORUM","ONE","TWO", - "THREE","LOCAL_ONE","ANY","SERIAL","LOCAL_SERIAL"}; + "ALL","EACH_QUORUM","QUORUM","LOCAL_QUORUM","ONE","TWO", + "THREE","LOCAL_ONE","ANY","SERIAL","LOCAL_SERIAL"}; private static final Map consistencyName = new HashMap<>(); static { consistencyName.put("ONE",ConsistencyLevel.ONE); @@ -139,6 +139,8 @@ public class MusicUtil { private static String cassPwd; private static String myCassaHost = LOCALHOST; private static int cassandraPort = 9042; + private static int cassandraConnectTimeOutMS; + private static int cassandraReadTimeOutMS; // AAF private static String musicAafNs = "org.onap.music.cadi"; @@ -150,11 +152,11 @@ public class MusicUtil { // Response/Request tracking headers private static String transIdPrefix = "false"; - private static String conversationIdPrefix = "false"; + private static String conversationIdPrefix = "false"; private static String clientIdPrefix = "false"; private static String messageIdPrefix = "false"; - private static Boolean transIdRequired = false; - private static Boolean conversationIdRequired = false; + private static Boolean transIdRequired = false; + private static Boolean conversationIdRequired = false; private static Boolean clientIdRequired = false; private static Boolean messageIdRequired = false; private static String cipherEncKey = ""; @@ -162,7 +164,7 @@ public class MusicUtil { public MusicUtil() { throw new IllegalStateException("Utility Class"); } - + public static String getLockUsing() { return lockUsing; } @@ -200,15 +202,31 @@ public class MusicUtil { return cassPwd; } + public static int getCassandraConnectTimeOutMS() { + return cassandraConnectTimeOutMS; + } + + public static void setCassandraConnectTimeOutMS(int cassandraConnectTimeOutMS) { + MusicUtil.cassandraConnectTimeOutMS = cassandraConnectTimeOutMS; + } + + public static int getCassandraReadTimeOutMS() { + return cassandraReadTimeOutMS; + } + + public static void setCassandraReadTimeOutMS(int cassandraReadTimeOutMS) { + MusicUtil.cassandraReadTimeOutMS = cassandraReadTimeOutMS; + } + /** * Returns An array of property names that should be in the Properties * files. * // * @return // */ -// public static String[] getPropkeys() { -// return propKeys.clone(); -// } + // public static String[] getPropkeys() { + // return propKeys.clone(); + // } /** * Get MusicPropertiesFilePath - Default = /opt/music/music.properties @@ -319,7 +337,7 @@ public class MusicUtil { public static void setMyCassaHost(String myCassaHost) { MusicUtil.myCassaHost = myCassaHost; } - + /** * Gey default retry count * @return @@ -425,23 +443,23 @@ public class MusicUtil { String value = ""; switch (type.getName()) { - case UUID: - value = valueObj + ""; - break; - case TEXT: - case VARCHAR: - String valueString = valueObj + ""; - valueString = valueString.replace("'", "''"); - value = "'" + valueString + "'"; - break; - case MAP: { - Map otMap = (Map) valueObj; - value = "{" + jsonMaptoSqlString(otMap, ",") + "}"; - break; - } - default: - value = valueObj + ""; - break; + case UUID: + value = valueObj + ""; + break; + case TEXT: + case VARCHAR: + String valueString = valueObj + ""; + valueString = valueString.replace("'", "''"); + value = "'" + valueString + "'"; + break; + case MAP: { + Map otMap = (Map) valueObj; + value = "{" + jsonMaptoSqlString(otMap, ",") + "}"; + break; + } + default: + value = valueObj + ""; + break; } return value; } @@ -585,14 +603,14 @@ public class MusicUtil { return ts; } - + public static MusicCoreService getMusicCoreService() { if(getLockUsing().equals(MusicUtil.CASSANDRA)) return MusicCassaCore.getInstance(); else return MusicCassaCore.getInstance(); } - + /** * @param lockName * @return @@ -617,9 +635,9 @@ public class MusicUtil { } public static void writeBackToQuorum(PreparedQueryObject selectQuery, String primaryKeyName, - PreparedQueryObject updateQuery, String keyspace, String table, - Object cqlFormattedPrimaryKeyValue) - throws Exception { + PreparedQueryObject updateQuery, String keyspace, String table, + Object cqlFormattedPrimaryKeyValue) + throws Exception { try { ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery); // write it back to a quorum @@ -642,16 +660,16 @@ public class MusicUtil { counter = counter + 1; } updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET " - + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";"); + + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";"); updateQuery.addValue(cqlFormattedPrimaryKeyValue); MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical"); } catch (MusicServiceException | MusicQueryException e) { logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery , - ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR, e); + ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR, e); } } - + public static boolean getIsCadi() { return MusicUtil.isCadi; } @@ -730,64 +748,64 @@ public class MusicUtil { MusicUtil.messageIdPrefix = checkPrefix(messageIdPrefix); } - /** - * @return the transIdRequired - */ + /** + * @return the transIdRequired + */ public static Boolean getTransIdRequired() { return transIdRequired; } /** - * @param transIdRequired the transIdRequired to set - */ + * @param transIdRequired the transIdRequired to set + */ public static void setTransIdRequired(Boolean transIdRequired) { MusicUtil.transIdRequired = transIdRequired; } /** - * @return the conversationIdRequired - */ + * @return the conversationIdRequired + */ public static Boolean getConversationIdRequired() { return conversationIdRequired; } /** - * @param conversationIdRequired the conversationIdRequired to set - */ + * @param conversationIdRequired the conversationIdRequired to set + */ public static void setConversationIdRequired(Boolean conversationIdRequired) { MusicUtil.conversationIdRequired = conversationIdRequired; } /** - * @return the clientIdRequired - */ + * @return the clientIdRequired + */ public static Boolean getClientIdRequired() { return clientIdRequired; } /** - * @param clientIdRequired the clientIdRequired to set - */ + * @param clientIdRequired the clientIdRequired to set + */ public static void setClientIdRequired(Boolean clientIdRequired) { MusicUtil.clientIdRequired = clientIdRequired; } /** - * @return the messageIdRequired - */ + * @return the messageIdRequired + */ public static Boolean getMessageIdRequired() { return messageIdRequired; } /** - * @param messageIdRequired the messageIdRequired to set - */ + * @param messageIdRequired the messageIdRequired to set + */ public static void setMessageIdRequired(Boolean messageIdRequired) { MusicUtil.messageIdRequired = messageIdRequired; } @@ -801,7 +819,7 @@ public class MusicUtil { public static void setCipherEncKey(String cipherEncKey) { MusicUtil.cipherEncKey = cipherEncKey; if ( null == cipherEncKey || cipherEncKey.equals("") || - cipherEncKey.equals("nothing to see here")) { + cipherEncKey.equals("nothing to see here")) { logger.error(EELFLoggerDelegate.errorLogger, "Missing Cipher Encryption Key."); } } diff --git a/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java b/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java index 90cd68e2..b7245d78 100644 --- a/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java +++ b/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java @@ -75,7 +75,7 @@ public class MusicUtilTest { mc = null; mc = MusicUtil.getMusicCoreService(); assertTrue(mc != null); - + } @Test @@ -123,7 +123,7 @@ public class MusicUtilTest { assertEquals(MusicUtil.buildVersion("1","2",null),"1.2"); } -/* + /* @Test public void testBuileVersionResponse() { assertTrue(MusicUtil.buildVersionResponse("1","2","3").getClass().getSimpleName().equals("Builder")); @@ -131,7 +131,7 @@ public class MusicUtilTest { assertTrue(MusicUtil.buildVersionResponse("1","2",null).getClass().getSimpleName().equals("Builder")); assertTrue(MusicUtil.buildVersionResponse(null,null,null).getClass().getSimpleName().equals("Builder")); } -*/ + */ @Test public void testGetConsistency() { assertTrue(ConsistencyLevel.ONE.equals(MusicUtil.getConsistencyLevel("one"))); @@ -174,7 +174,7 @@ public class MusicUtilTest { System.out.println("#######" + myQueryObject.getQuery().isEmpty()); assertFalse(MusicUtil.isValidQueryObject(false,myQueryObject)); - + } @@ -233,7 +233,7 @@ public class MusicUtilTest { assertTrue(result.contains("name")); assertTrue(result.contains("value")); } - + @Test public void test_generateUUID() { //this function shouldn't be in cachingUtil @@ -255,62 +255,62 @@ public class MusicUtilTest { MusicUtil.setLockUsing("testlock"); assertEquals("testlock", MusicUtil.getLockUsing()); } - + @Test public void testCassaPort() { MusicUtil.setCassandraPort(1234); assertEquals(1234, MusicUtil.getCassandraPort()); } - + @Test public void testBuild() { MusicUtil.setBuild("testbuild"); assertEquals("testbuild", MusicUtil.getBuild()); } - + @Test public void testTransId() { MusicUtil.setTransIdPrefix("prefix"); assertEquals("prefix-", MusicUtil.getTransIdPrefix()); } - - + + @Test public void testConversationIdPrefix() { MusicUtil.setConversationIdPrefix("prefix-"); assertEquals("prefix-", MusicUtil.getConversationIdPrefix()); } - + @Test public void testClientIdPrefix() { MusicUtil.setClientIdPrefix("clientIdPrefix"); assertEquals("clientIdPrefix-", MusicUtil.getClientIdPrefix()); } - + @Test public void testMessageIdPrefix() { MusicUtil.setMessageIdPrefix("clientIdPrefix"); assertEquals("clientIdPrefix-", MusicUtil.getMessageIdPrefix()); } - + @Test public void testTransIdPrefix() { MusicUtil.setTransIdPrefix("transIdPrefix"); assertEquals("transIdPrefix-", MusicUtil.getTransIdPrefix()); } - + @Test public void testConvIdReq() { MusicUtil.setConversationIdRequired(true); assertEquals(true, MusicUtil.getConversationIdRequired()); } - + @Test public void testClientIdRequired() { MusicUtil.setClientIdRequired(true); assertEquals(true, MusicUtil.getClientIdRequired()); } - + @Test public void testMessageIdRequired() { MusicUtil.setMessageIdRequired(true); @@ -322,11 +322,24 @@ public class MusicUtilTest { MusicUtil.setTransIdRequired(true); assertEquals(true,MusicUtil.getTransIdRequired()); } -/* + + @Test + public void testGetCassandraConnectTimeOutMS() { + MusicUtil.setCassandraConnectTimeOutMS(2000); + assertEquals(2000,MusicUtil.getCassandraConnectTimeOutMS()); + } + + @Test + public void testGetCassandraReadTimeOutMS() { + MusicUtil.setCassandraReadTimeOutMS(2000); + assertEquals(2000,MusicUtil.getCassandraReadTimeOutMS()); + } + + /* @Test public void testLoadProperties() { PropertiesLoader pl = new PropertiesLoader(); pl.loadProperties(); } -*/ + */ } 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..6fbc76a7 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 @@ -41,37 +41,43 @@ 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("${transId.header.prefix}") private String transIdPrefix; @@ -83,7 +89,7 @@ public class PropertiesLoader implements InitializingBean { @Value("${messageId.header.prefix}") private String messageIdPrefix; - + @Value("${transId.header.required}") private Boolean transIdRequired; @@ -101,19 +107,19 @@ public class PropertiesLoader implements InitializingBean { @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 +139,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)); } @@ -209,7 +221,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 +303,11 @@ public class PropertiesLoader implements InitializingBean { } } - + @Override public void afterPropertiesSet() throws Exception { // TODO Auto-generated method stub - + } } -- 2.16.6