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;
}
return regularList;
}
+
+ public MessageChannel getPmResultChannel() {
+ return pmResultChannel;
+ }
+ public void setPmResultChannel(MessageChannel pmResultChannel) {
+ this.pmResultChannel = pmResultChannel;
+ }
}
public class TaskThreadService extends Thread {
-
private final ExecutorService pool;
private static final Log log = LogFactory.getLog(TaskThreadService.class);
private BlockingQueue<CollectMsg> queue = new LinkedBlockingQueue<>();
* 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.*;
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";
public class DateUtil {
-
public static long[] getScanScope(Date fireTime, long collectPeriod) {
Calendar fire = Calendar.getInstance();
long start = 0L;
}
public boolean stop() {
-
this.setRun(false);
while (!isEnd()) {
try {
public class Gunzip {
- /**
- *
- */
public void unCompress(String gzFileName, String toFile) throws IOException {
try ( FileInputStream gzInput = new FileInputStream(gzFileName);
GZIPInputStream gzIn = new GZIPInputStream(gzInput)){
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
public class StringUtil {
private static final Log log = LogFactory.getLog(StringUtil.class);
}
public static boolean isBank(String str) {
-
if (str == null || str.trim().length() == 0) {
return true;
protected String deCompressPath = null;
protected String zipFilePath = null;
- /**
- *
- */
public UnZip(String zipFilePath, String toPath) throws IOException {
File zipFile = new File(
new File(zipFilePath).getAbsolutePath());
deCompressPath = deCompressPath + File.separator;
}
- /**
- *
- */
public void deCompress() throws IOException {
try(ZipFile zipFile = new ZipFile(zipFilePath)){
Enumeration<ZipEntry> e = zipFile.getEntries();
}
}
- /**
- *
- */
protected void deCompressFile(InputStream input, String toPath)
throws IOException {
byte byteBuf[] = new byte[2048];
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}");
}
/**
- * 仅支持该两个变量替换 省得正则匹配慢
- *
+ * 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;
public class XmlUtil {
public static Document getDocument(InputStream is) throws XMLStreamException, JDOMException, IOException {
-
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(is);
return doc;
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();
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)
compressDirectory(listFiles[i]);
}
}
-
-
}
protected void compressFile(String absolutePath) throws IOException {
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;
@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);
}
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
--- /dev/null
+/*
+ * 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);
+ }
+}
@Before
public void setUp() throws Exception {
configurationInterface = new ConfigurationImp();
-
collectManager = new CollectManager();
collectManager.setConfigurationInterface(configurationInterface);
collectManager.dispose();
t.start();
}
+ @Test
+ public void testGetConfigurationInteface(){
+ ConfigurationInterface confInteface = collectManager.getConfigurationInterface();
+ assertEquals(configurationInterface,confInteface);
+ }
}