Sonar Fixes - MusicDataStoreHandle.java
[music.git] / src / main / java / org / onap / music / rest / RestMusicBmAPI.java
index 8f62f9c..f2946c1 100644 (file)
@@ -1,20 +1,25 @@
 /*
- * ============LICENSE_START========================================== org.onap.music
- * =================================================================== Copyright (c) 2017 AT&T
- * Intellectual Property ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ *  Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
  * 
- * http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  * 
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
  * 
  * ============LICENSE_END=============================================
  * ====================================================================
  */
+
 package org.onap.music.rest;
 
 import java.util.List;
@@ -31,25 +36,18 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
-import org.apache.log4j.Logger;
 import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
 import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.CachingUtil;
 import org.onap.music.main.MusicCore;
 import org.onap.music.main.MusicUtil;
 import org.onap.music.main.ResultType;
 import org.onap.music.main.ReturnType;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
+import org.onap.music.service.impl.MusicZKCore;
+import org.onap.music.datastore.MusicDataStoreHandle;
 import org.onap.music.datastore.PreparedQueryObject;
 import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.TableMetadata;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
 
 /*
  * These are functions created purely for benchmarking purposes. Commented out Swagger - This should
@@ -61,7 +59,7 @@ import io.swagger.annotations.ApiParam;
 public class RestMusicBmAPI {
 
     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicBmAPI.class);
-
+    public static final String UPDATE_CONST=" update-";
     // pure zk calls...
 
     /**
@@ -73,7 +71,7 @@ public class RestMusicBmAPI {
     @Path("/purezk/{name}")
     @Consumes(MediaType.APPLICATION_JSON)
     public void pureZkCreate(@PathParam("name") String nodeName) throws Exception {
-        MusicCore.pureZkCreate("/" + nodeName);
+        MusicZKCore.pureZkCreate("/" + nodeName);
     }
 
 
@@ -90,7 +88,7 @@ public class RestMusicBmAPI {
                     throws Exception {
         logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zk normal update-------------------------");
         long start = System.currentTimeMillis();
-        MusicCore.pureZkWrite(nodeName, insObj.serialize());
+        MusicZKCore.pureZkWrite(nodeName, insObj.serialize());
         long end = System.currentTimeMillis();
         logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk normal update:" + (end - start) + " ms");
     }
@@ -105,7 +103,7 @@ public class RestMusicBmAPI {
     @Path("/purezk/{name}")
     @Consumes(MediaType.TEXT_PLAIN)
     public byte[] pureZkGet(@PathParam("name") String nodeName) throws Exception {
-        return MusicCore.pureZkRead(nodeName);
+        return MusicZKCore.pureZkRead(nodeName);
     }
 
     /**
@@ -124,7 +122,7 @@ public class RestMusicBmAPI {
         String operationId = UUID.randomUUID().toString();// just for debugging purposes.
         String consistency = updateObj.getConsistencyInfo().get("type");
 
-        logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zookeeper " + consistency + " update-" + operationId
+        logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zookeeper " + consistency + UPDATE_CONST + operationId
                         + "-------------------------");
 
         byte[] data = updateObj.serialize();
@@ -137,13 +135,20 @@ public class RestMusicBmAPI {
         long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
         ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockname, lockId, leasePeriod);
         long lockAcqTime = System.currentTimeMillis();
-        long zkPutTime = 0, lockReleaseTime = 0;
+        long zkPutTime = 0;
+        long lockReleaseTime = 0;
 
         if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
             logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
-            MusicCore.pureZkWrite(lockname, data);
+            MusicZKCore.pureZkWrite(lockname, data);
             zkPutTime = System.currentTimeMillis();
             boolean voluntaryRelease = true;
+/*<<<<<<< HEAD
+            if (("atomic").equals(consistency))
+                MusicCore.releaseLock(lockId, voluntaryRelease);
+            else if (("atomic_delete_lock").equals(consistency))
+                MusicCore.deleteLock(lockname);
+=======*/
             if (consistency.equals("atomic"))
                 MusicCore.releaseLock(lockId, voluntaryRelease);
             else if (consistency.equals("atomic_delete_lock"))
@@ -162,12 +167,12 @@ public class RestMusicBmAPI {
                         + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
                         + "|zk put time:" + (zkPutTime - lockAcqTime);
 
-        if (consistency.equals("atomic"))
+        if ("atomic".equals(consistency))
             lockingInfo = lockingInfo + "|lock release time:" + (lockReleaseTime - zkPutTime) + "|";
-        else if (consistency.equals("atomic_delete_lock"))
+        else if ("atomic_delete_lock".equals(consistency))
             lockingInfo = lockingInfo + "|lock delete time:" + (lockReleaseTime - zkPutTime) + "|";
 
-        String timingString = "Time taken in ms for Zookeeper " + consistency + " update-"
+        String timingString = "Time taken in ms for Zookeeper " + consistency + UPDATE_CONST
                         + operationId + ":" + "|total operation time:" + (endTime - startTime)
                         + "|json parsing time:" + (jsonParseCompletionTime - startTime)
                         + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
@@ -195,7 +200,7 @@ public class RestMusicBmAPI {
         ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockName, lockId, leasePeriod);
         if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
             logger.info("acquired lock with id " + lockId);
-            MusicCore.pureZkRead(nodeName);
+            MusicZKCore.pureZkRead(nodeName);
             boolean voluntaryRelease = true;
             MusicCore.releaseLock(lockId, voluntaryRelease);
         } else {
@@ -227,11 +232,11 @@ public class RestMusicBmAPI {
         long startTime = System.currentTimeMillis();
         String operationId = UUID.randomUUID().toString();// just for debugging purposes.
         String consistency = insObj.getConsistencyInfo().get("type");
-        logger.info(EELFLoggerDelegate.applicationLogger,"--------------Cassandra " + consistency + " update-" + operationId
+        logger.info(EELFLoggerDelegate.applicationLogger,"--------------Cassandra " + consistency + UPDATE_CONST + operationId
                         + "-------------------------");
         PreparedQueryObject queryObject = new PreparedQueryObject();
         Map<String, Object> valuesMap = insObj.getValues();
-        TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+        TableMetadata tableInfo = MusicDataStoreHandle.returnColumnMetadata(keyspace, tablename);
         String vectorTs = "'" + Thread.currentThread().getId() + System.currentTimeMillis() + "'";
         String fieldValueString = "vector_ts= ? ,";
         queryObject.addValue(vectorTs);
@@ -296,13 +301,13 @@ public class RestMusicBmAPI {
         long jsonParseCompletionTime = System.currentTimeMillis();
 
         boolean operationResult = true;
-        MusicCore.getDSHandle().executePut(queryObject, insObj.getConsistencyInfo().get("type"));
+        MusicDataStoreHandle.getDSHandle().executePut(queryObject, insObj.getConsistencyInfo().get("type"));
 
         long actualUpdateCompletionTime = System.currentTimeMillis();
 
         long endTime = System.currentTimeMillis();
 
-        String timingString = "Time taken in ms for Cassandra " + consistency + " update-"
+        String timingString = "Time taken in ms for Cassandra " + consistency + UPDATE_CONST
                         + operationId + ":" + "|total operation time:" + (endTime - startTime)
                         + "|json parsing time:" + (jsonParseCompletionTime - startTime)
                         + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)