diff options
author | Nelson, Thomas (tn1381) <tn1381@att.com> | 2019-06-25 19:48:27 -0400 |
---|---|---|
committer | Nelson, Thomas (tn1381) <tn1381@att.com> | 2019-06-26 11:18:47 -0400 |
commit | 7a8411afab33104f8bea2048411bb9da5e7b0f68 (patch) | |
tree | 677a1cac68bc8f25ad5d14412ae7d92fec1c0282 | |
parent | fcca903302375403ff16216ce9b4b3cca2d1362c (diff) |
Sonar fixes for MusicApplication
and util files.
Fixed Testing issuse
Update Gitignore to include vscode.
Issue-ID: MUSIC-419
Signed-off-by: Nelson, Thomas (tn1381) <tn1381@att.com>
Change-Id: I202613f905e2ef0cde338e7c98074faf68bc649a
Signed-off-by: Nelson, Thomas (tn1381) <tn1381@att.com>
-rw-r--r-- | .gitignore | 8 | ||||
-rwxr-xr-x | src/main/java/org/onap/music/MusicApplication.java | 40 | ||||
-rw-r--r-- | src/main/java/org/onap/music/main/MusicCore.java | 14 | ||||
-rw-r--r-- | src/main/java/org/onap/music/service/impl/MusicCassaCore.java | 26 | ||||
-rw-r--r-- | src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java | 2 | ||||
-rw-r--r-- | src/test/java/org/onap/music/unittests/TestsUsingCassandra.java | 2 |
6 files changed, 55 insertions, 37 deletions
@@ -33,3 +33,11 @@ debug-logs/ docs/Makefile docs/_build docs/conf.py + +#VSCODE +.VSCODE +.attach_pid* + + +#jmeter +jmeter.log diff --git a/src/main/java/org/onap/music/MusicApplication.java b/src/main/java/org/onap/music/MusicApplication.java index 9b831e37..aa4de01e 100755 --- a/src/main/java/org/onap/music/MusicApplication.java +++ b/src/main/java/org/onap/music/MusicApplication.java @@ -33,7 +33,6 @@ import org.onap.music.authentication.CadiAuthFilter; import org.onap.music.authentication.MusicAuthorizationFilter; import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.eelf.logging.MusicLoggingServletFilter; -import org.onap.music.main.CipherUtil; import org.onap.music.main.MusicUtil; import org.onap.music.main.PropertiesLoader; import org.springframework.beans.factory.annotation.Autowired; @@ -44,7 +43,6 @@ import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoCo import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.DependsOn; @@ -57,10 +55,15 @@ import org.springframework.web.context.request.RequestContextListener; @EnableScheduling public class MusicApplication extends SpringBootServletInitializer { + private final String KEYSPACE_PATTERN = "/v2/keyspaces/*"; + private final String LOCKS_PATTERN = "/v2/locks/*"; + private final String Q_PATTERN = "/v2/priorityq/*"; + @Autowired private PropertiesLoader propertyLoader; private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicApplication.class); + public static void main(String[] args) { new MusicApplication().configure(new SpringApplicationBuilder(MusicApplication.class)).run(args); } @@ -76,8 +79,6 @@ public class MusicApplication extends SpringBootServletInitializer { propertyLoader.loadProperties(); } - @Autowired - private ApplicationContext appContext; @Bean @DependsOn("loadProperties") @@ -96,9 +97,7 @@ public class MusicApplication extends SpringBootServletInitializer { propertyLoader.loadProperties(); if (MusicUtil.getIsCadi()) { PropAccess propAccess = propAccess(); - CadiAuthFilter cadiFilter = new CadiAuthFilter(propAccess); - - return cadiFilter; + return new CadiAuthFilter(propAccess); } else { return (ServletRequest request, ServletResponse response, FilterChain chain) -> { // do nothing for now. @@ -124,15 +123,14 @@ public class MusicApplication extends SpringBootServletInitializer { FilterRegistrationBean<Filter> frb = new FilterRegistrationBean<>(); frb.setFilter(new MusicLoggingServletFilter()); frb.addUrlPatterns( - "/v2/keyspaces/*", - "/v2/locks/*", - "/v2/priorityq/*" + KEYSPACE_PATTERN, + LOCKS_PATTERN, + Q_PATTERN ); frb.setName("logFilter"); frb.setOrder(1); return frb; } - @Bean @DependsOn("loadProperties") @@ -140,14 +138,11 @@ public class MusicApplication extends SpringBootServletInitializer { logger.info("cadiFilterRegistration called for cadi filter.."); FilterRegistrationBean<Filter> frb = new FilterRegistrationBean<>(); frb.setFilter(cadiFilter()); - - // The Following Patterns are used to control what APIs will be secure - // TODO: Make this a configurable item. Build this from an array? if (MusicUtil.getIsCadi()) { frb.addUrlPatterns( - "/v2/keyspaces/*", - "/v2/locks/*", - "/v2/priorityq/*" + KEYSPACE_PATTERN, + LOCKS_PATTERN, + Q_PATTERN ); } else { frb.addUrlPatterns("/v0/test"); @@ -175,10 +170,10 @@ public class MusicApplication extends SpringBootServletInitializer { if (MusicUtil.getIsCadi()) { frb.addUrlPatterns( - "/v2/keyspaces/*", - "/v2/locks/*", - "/v2/priorityq/*" - ); + KEYSPACE_PATTERN, + LOCKS_PATTERN, + Q_PATTERN + ); } else { frb.addUrlPatterns("/v0/test"); } @@ -192,8 +187,7 @@ public class MusicApplication extends SpringBootServletInitializer { public Filter cadiMusicAuthFilter() throws ServletException { propertyLoader.loadProperties(); if (MusicUtil.getIsCadi()) { - MusicAuthorizationFilter authFilter = new MusicAuthorizationFilter(); - return authFilter; + return new MusicAuthorizationFilter(); } else { return (ServletRequest request, ServletResponse response, FilterChain chain) -> { // do nothing for now. diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java index 6a0d2471..1f1d6a16 100644 --- a/src/main/java/org/onap/music/main/MusicCore.java +++ b/src/main/java/org/onap/music/main/MusicCore.java @@ -34,17 +34,21 @@ import org.onap.music.lockingservice.cassandra.CassaLockStore; import org.onap.music.lockingservice.cassandra.LockType; import org.onap.music.lockingservice.cassandra.MusicLockState; import org.onap.music.service.MusicCoreService; -import org.onap.music.service.impl.MusicCassaCore; import com.datastax.driver.core.ResultSet; public class MusicCore { private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class); - private static boolean unitTestRun = true; - private static MusicCoreService musicCore = MusicUtil.getMusicCoreService(); - public static CassaLockStore mLockHandle; + private static CassaLockStore mLockHandle; + + public static CassaLockStore getmLockHandle() { + return mLockHandle; + } + public static void setmLockHandle(CassaLockStore mLockHandleIn) { + mLockHandle = mLockHandleIn; + } /** * Acquire lock @@ -178,4 +182,6 @@ public class MusicCore { return musicCore.releaseLock(lockId, voluntaryRelease); } + + } diff --git a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java index 253081e0..07864576 100644 --- a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java +++ b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java @@ -29,7 +29,6 @@ import java.io.StringWriter; import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import java.util.concurrent.TimeUnit; import org.onap.music.datastore.MusicDataStore; import org.onap.music.datastore.MusicDataStoreHandle; @@ -51,7 +50,6 @@ import org.onap.music.main.ResultType; import org.onap.music.main.ReturnType; import org.onap.music.service.MusicCoreService; -import com.att.eelf.configuration.EELFLogger; import com.datastax.driver.core.DataType; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; @@ -61,14 +59,22 @@ import org.onap.music.datastore.*; public class MusicCassaCore implements MusicCoreService { - public static CassaLockStore mLockHandle = null;; + private static CassaLockStore mLockHandle = null; private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCassaCore.class); - private static boolean unitTestRun=true; private static MusicCassaCore musicCassaCoreInstance = null; private MusicCassaCore() { + // not going to happen + } + + public static CassaLockStore getmLockHandle() { + return mLockHandle; + } + public static void setmLockHandle(CassaLockStore mLockHandle) { + MusicCassaCore.mLockHandle = mLockHandle; } + public static MusicCassaCore getInstance() { if(musicCassaCoreInstance == null) { @@ -77,6 +83,9 @@ public class MusicCassaCore implements MusicCoreService { return musicCassaCoreInstance; } + + + public static CassaLockStore getLockingServiceHandle() throws MusicLockingException { logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring lock store handle"); long start = System.currentTimeMillis(); @@ -95,7 +104,7 @@ public class MusicCassaCore implements MusicCoreService { } public String createLockReference(String fullyQualifiedKey) throws MusicLockingException { - return createLockReference(fullyQualifiedKey, LockType.WRITE); + return createLockReference(fullyQualifiedKey, LockType.WRITE); } public String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException { @@ -125,8 +134,8 @@ public class MusicCassaCore implements MusicCoreService { public ReturnType acquireLockWithLease(String fullyQualifiedKey, String lockReference, long leasePeriod) throws MusicLockingException, MusicQueryException, MusicServiceException { - evictExpiredLockHolder(fullyQualifiedKey,leasePeriod); - return acquireLock(fullyQualifiedKey, lockReference); + evictExpiredLockHolder(fullyQualifiedKey,leasePeriod); + return acquireLock(fullyQualifiedKey, lockReference); } private void evictExpiredLockHolder(String fullyQualifiedKey, long leasePeriod) @@ -167,7 +176,7 @@ public class MusicCassaCore implements MusicCoreService { if (!lockInfo.getIsLockOwner()) { return new ReturnType(ResultType.FAILURE, lockId + " is not a lock holder");//not top of the lock store q } - + //check to see if the value of the key has to be synced in case there was a forceful release String syncTable = keyspace+".unsyncedKeys_"+table; String query = "select * from "+syncTable+" where key='"+localFullyQualifiedKey+"';"; @@ -805,4 +814,5 @@ public class MusicCassaCore implements MusicCoreService { return null; } + } diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java index a9e6e4b6..385a4698 100644 --- a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java +++ b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java @@ -132,7 +132,7 @@ public class TestRestMusicQAPI { try { ReflectionTestUtils.setField(MusicDataStoreHandle.class, "mDstoreHandle", CassandraCQL.connectToEmbeddedCassandra()); - MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.getDSHandle()); + MusicCore.setmLockHandle(new CassaLockStore(MusicDataStoreHandle.getDSHandle())); // System.out.println("before class keysp"); //resp=data.createKeySpace(majorV,minorV,patchV,aid,appName,userId,password,kspObject,keyspaceName); diff --git a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java index e2c65447..cc7c5146 100644 --- a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java +++ b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java @@ -66,7 +66,7 @@ public class TestsUsingCassandra { public static void beforeClass() throws Exception { ReflectionTestUtils.setField(MusicDataStoreHandle.class, "mDstoreHandle", CassandraCQL.connectToEmbeddedCassandra()); - MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.getDSHandle()); + MusicCore.setmLockHandle(new CassaLockStore(MusicDataStoreHandle.getDSHandle())); createAdminTable(); } |