Sonar fixes for MusicApplication 89/90489/2
authorNelson, Thomas (tn1381) <tn1381@att.com>
Tue, 25 Jun 2019 23:48:27 +0000 (19:48 -0400)
committerNelson, Thomas (tn1381) <tn1381@att.com>
Wed, 26 Jun 2019 15:18:47 +0000 (11:18 -0400)
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>
.gitignore
src/main/java/org/onap/music/MusicApplication.java
src/main/java/org/onap/music/main/MusicCore.java
src/main/java/org/onap/music/service/impl/MusicCassaCore.java
src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
src/test/java/org/onap/music/unittests/TestsUsingCassandra.java

index 3af6f43..62501cf 100644 (file)
@@ -33,3 +33,11 @@ debug-logs/
 docs/Makefile
 docs/_build
 docs/conf.py
+
+#VSCODE
+.VSCODE
+.attach_pid*
+
+
+#jmeter
+jmeter.log
index 9b831e3..aa4de01 100755 (executable)
@@ -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.
index 6a0d247..1f1d6a1 100644 (file)
@@ -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);
     }
 
+
+
 }
index 253081e..0786457 100644 (file)
@@ -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;
     }
 
+
 }
index a9e6e4b..385a469 100644 (file)
@@ -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);
index e2c6544..cc7c514 100644 (file)
@@ -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();
     }