Improve emsdriver code 91/36491/1
authoryangyan <yangyanyj@chinamobile.com>
Mon, 19 Mar 2018 10:08:44 +0000 (18:08 +0800)
committeryangyan <yangyanyj@chinamobile.com>
Mon, 19 Mar 2018 10:09:09 +0000 (18:09 +0800)
Issue-ID: VFC-826
Change-Id: I9017cd912cd7869d3f6a3ea302e259aa17ed3ba6
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
15 files changed:
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadService.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtil.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/Msg.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThread.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Gunzip.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java
ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java
ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/AlarmManagerTest.java [new file with mode: 0644]
ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java

index 55d8d72..da48829 100644 (file)
@@ -43,7 +43,7 @@ import java.util.regex.Pattern;
 public class TaskThread implements Runnable {
 
        private static final Log log = LogFactory.getLog(TaskThread.class);
-       public MessageChannel pmResultChannel; //This should also be private. Need to change in TastThreadTest 
+       private MessageChannel pmResultChannel; //This should also be private. Need to change in TastThreadTest 
        private MessageChannel cmResultChannel;
        private CollectMsg data;
 
@@ -924,5 +924,12 @@ public class TaskThread implements Runnable {
                }
                return regularList;
        }
+       
+       public MessageChannel getPmResultChannel() {
+               return pmResultChannel;
+       }
 
+       public void setPmResultChannel(MessageChannel pmResultChannel) {
+               this.pmResultChannel = pmResultChannel;
+       }
 }
index b0dca40..2a7bac4 100644 (file)
@@ -25,7 +25,6 @@ import java.util.concurrent.*;
 
 
 public class TaskThreadService extends Thread {
-
     private final ExecutorService pool;
     private static final Log log = LogFactory.getLog(TaskThreadService.class);
     private BlockingQueue<CollectMsg> queue = new LinkedBlockingQueue<>();
index 8672bca..eede19b 100644 (file)
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.onap.vfc.nfvo.emsdriver.collector.alarm;
 
 import java.io.*;
index 5cfd0cb..3245625 100644 (file)
@@ -21,7 +21,6 @@ import java.io.UnsupportedEncodingException;
 
 
 public class Msg {
-
     public final static String reqLoginAlarm = "reqLoginAlarm;user=%s;key=%s;type=%s";
     public final static String reqHeartBeat = "reqHeartBeat;reqId=%s";
     public final static String disconnectMsg = "closeConnAlarm";
index 2613759..6b4037a 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Date;
 
 public class DateUtil {
 
-
     public static long[] getScanScope(Date fireTime, long collectPeriod) {
         Calendar fire = Calendar.getInstance();
         long start = 0L;
index d17bccb..64b518b 100644 (file)
@@ -60,7 +60,6 @@ public abstract class DriverThread implements Runnable {
     }
 
     public boolean stop() {
-
         this.setRun(false);
         while (!isEnd()) {
             try {
index 89aa731..e6ed9d5 100644 (file)
@@ -20,9 +20,6 @@ import java.util.zip.GZIPInputStream;
 
 public class Gunzip {
 
-       /**
-        *
-        */
        public void unCompress(String gzFileName, String toFile) throws IOException {
                try (   FileInputStream gzInput = new FileInputStream(gzFileName);
                        GZIPInputStream gzIn = new GZIPInputStream(gzInput)){
index 1b9606b..e09ff8d 100644 (file)
@@ -21,7 +21,6 @@ import java.io.StringWriter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-
 public class StringUtil {
 
     private static final Log log = LogFactory.getLog(StringUtil.class);
@@ -47,7 +46,6 @@ public class StringUtil {
     }
 
     public static boolean isBank(String str) {
-
         if (str == null || str.trim().length() == 0) {
 
             return true;
index bc70907..504a47b 100644 (file)
@@ -29,9 +29,6 @@ public class UnZip {
     protected String deCompressPath = null;
     protected String zipFilePath = null;
 
-    /**
-     *
-     */
     public UnZip(String zipFilePath, String toPath) throws IOException {
         File zipFile = new File(
                 new File(zipFilePath).getAbsolutePath());
@@ -48,9 +45,6 @@ public class UnZip {
             deCompressPath = deCompressPath + File.separator;
     }
 
-    /**
-     *
-     */
     public void deCompress() throws IOException {
         try(ZipFile zipFile = new ZipFile(zipFilePath)){
             Enumeration<ZipEntry> e = zipFile.getEntries();
@@ -68,9 +62,6 @@ public class UnZip {
         }  
    }
 
-    /**
-     *
-     */
     protected void deCompressFile(InputStream input, String toPath)
             throws IOException {
         byte byteBuf[] = new byte[2048];
index 354a344..0e3f27c 100644 (file)
@@ -34,7 +34,7 @@ final public class VarExprParser {
         if (str.indexOf("${") == -1)
             return str;
 
-        // 支持原系统变量
+        // support original system variable
         str = str.replace("${s_year}", "${SCAN_START_TIME,yyyy}");
         str = str.replace("${s_mon}", "${SCAN_START_TIME,MM}");
         str = str.replace("${s_day}", "${SCAN_START_TIME,dd}");
@@ -109,16 +109,13 @@ final public class VarExprParser {
     }
 
     /**
-     * 仅支持该两个变量替换  省得正则匹配慢
-     *
+     * Support two variable substitutions
      * @param result
      * @param scan_start_time
      * @param scan_stop_time
      * @return
      */
-    public static String replaceTimeVar(String result,
-                                        String scan_start_time, String scan_stop_time) {
-
+    public static String replaceTimeVar(String result,String scan_start_time, String scan_stop_time) {
         boolean isReplace = false;
         if (result.indexOf("${SCAN_ST") != -1) {
             isReplace = true;
index 92345bf..19483ca 100644 (file)
@@ -27,7 +27,6 @@ import java.io.InputStream;
 public class XmlUtil {
 
     public static Document getDocument(InputStream is) throws XMLStreamException, JDOMException, IOException {
-
         SAXBuilder builder = new SAXBuilder();
         Document doc = builder.build(is);
         return doc;
index 1d757a3..d79e89d 100644 (file)
@@ -26,22 +26,16 @@ import java.util.zip.ZipOutputStream;
 public class Zip {
     protected int compressDirectoryCount = 0;
     protected int compressFileCount = 0;
-
     protected int relativeAddrIdx = 0;
     protected int compressLevel = 6;
     protected String zipFilePath = null;
     protected String compressPath = null;
-
     protected ZipOutputStream zipOutput = null;
 
-    /**
-     *
-     */
     public Zip(String compressPath, String zipFilePath) throws IOException {
         File compressFile = new File(compressPath);
         if (!compressFile.exists())
             throw new IOException("the file or directory '" + compressPath + "' not found!");
-
         this.zipFilePath = zipFilePath;
         this.compressPath = compressFile.getAbsolutePath();
 
@@ -55,12 +49,8 @@ public class Zip {
         relativeAddrIdx = this.compressPath.lastIndexOf(File.separator) + 1;
     }
 
-    /**
-     *
-     */
     public void compress() throws IOException {
         File theFile = new File(zipFilePath);
-
         if (!theFile.exists()) {
             String parentPath = theFile.getParent();
             if (parentPath != null)
@@ -87,8 +77,6 @@ public class Zip {
                     compressDirectory(listFiles[i]);
                 }
         }
-
-
     }
 
     protected void compressFile(String absolutePath) throws IOException {
index d6365b6..767aac3 100644 (file)
@@ -21,6 +21,7 @@ import org.junit.Test;
 import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
 import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
 import org.onap.vfc.nfvo.emsdriver.commons.utils.Gzip;
+import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannel;
 import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannelFactory;
 
 import java.io.File;
@@ -39,7 +40,8 @@ public class TaskThreadTest {
     @Before
     public void setUp() throws IOException {
         taskThread = new TaskThread();
-        taskThread.pmResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_PM_CHANNEL_KEY);
+        MessageChannel pmResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_PM_CHANNEL_KEY);
+        taskThread.setPmResultChannel(pmResultChannel);
         Gzip gzip = new Gzip();
         gzip.compress(csvPath, gzPath);
     }
@@ -65,7 +67,12 @@ public class TaskThreadTest {
         File file = new File(xmlPath);
         boolean re = taskThread.processPMXml(file);
         assertTrue(re);
-        System.out.println(taskThread.pmResultChannel.size());
+        MessageChannel pmResultChannel = taskThread.getPmResultChannel();
+        if(null!=pmResultChannel){
+            System.out.println(pmResultChannel.size());
+        }else{
+               System.out.println("pmResultChannel is null");
+        }
     }
 
     @Test
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/AlarmManagerTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/AlarmManagerTest.java
new file mode 100644 (file)
index 0000000..60ddc82
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
+ *
+ * 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
+ *
+ * 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.
+ */
+package org.onap.vfc.nfvo.emsdriver.taskscheduler;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.vfc.nfvo.emsdriver.collector.alarm.AlarmManager;
+import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationImp;
+import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface;
+
+public class AlarmManagerTest {
+
+       private AlarmManager alarmManager;
+       private ConfigurationInterface configurationInterface;
+       
+       
+       @Before
+       public void setUp() throws Exception {
+               configurationInterface = new ConfigurationImp();
+               
+               alarmManager = new AlarmManager();
+               alarmManager.setConfigurationInterface(configurationInterface);
+               alarmManager.dispose();
+       }
+
+       @Test
+       public void test() {
+               Thread t = new Thread(alarmManager);
+               t.start();
+       }
+
+       @Test
+       public void testGetConfigurationInteface(){
+               ConfigurationInterface confInteface = alarmManager.getConfigurationInterface();
+               assertEquals(configurationInterface,confInteface);
+       }
+}
index 1ebacc2..fb420ca 100644 (file)
@@ -31,7 +31,6 @@ public class CollectManagerTest {
        @Before
        public void setUp() throws Exception {
                configurationInterface = new ConfigurationImp();
-               
                collectManager = new CollectManager();
                collectManager.setConfigurationInterface(configurationInterface);
                collectManager.dispose();
@@ -43,4 +42,9 @@ public class CollectManagerTest {
                t.start();
        }
 
+       @Test
+       public void testGetConfigurationInteface(){
+               ConfigurationInterface confInteface = collectManager.getConfigurationInterface();
+               assertEquals(configurationInterface,confInteface);
+       }
 }