summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2020-06-13 16:51:20 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2020-06-13 16:51:20 +0800
commitb6bcfbcc8b7445a953b4d5963dc4ff93028362c5 (patch)
treee850fe74efb0f180b65b1cf087736f89660c3407
parentaa96befb67370641ba50b745ce3408dedaee90c8 (diff)
Fixed Bugs Detected by SonarCloud
Change-Id: Iaa0a6ce8c8aa4b88d59aad882f31135acf89cc26 Issue-ID: HOLMES-316 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java24
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java25
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java19
3 files changed, 14 insertions, 54 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java
index b6cfc06..6d9d602 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,28 +78,6 @@ public class Alarm implements AplusData, Cloneable, Serializable {
linkIdNodeIdxMap.put(linkId, index);
}
- /**
- * Comparison of the location of different links: 999 the same link: the location of the node
- * number less than otherIdIdx in the location of the number (in the otherIdIdx upstream):-1,
- * the same link: the node position number is equal to the number of position in the otherIdIdx
- * (in the same site otherIdIdx):0, the same link: the node location number is greater than the
- * number of locations in otherIdIdx (otherIdIdx) with the site):1,
- */
- public int CompareLinkPosition(Map<Integer, Integer> otherIdIdx) {
- Set<Integer> myIdSet = new HashSet<>();
- myIdSet.addAll(this.linkIdNodeIdxMap.keySet());
- myIdSet.retainAll(otherIdIdx.keySet());
-
- if (myIdSet.isEmpty()) {
- return 999;
- }
-
- for (int tempLinkId : myIdSet) {
- return this.linkIdNodeIdxMap.get(tempLinkId) - otherIdIdx.get(tempLinkId);
- }
- return 999;
- }
-
public boolean containNode(int linkId, int index) {
return linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
index 76e11ba..a88519a 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
@@ -1,12 +1,12 @@
/**
- * Copyright 2017 ZTE Corporation.
- *
+ * Copyright 2017-2020 ZTE Corporation.
+ * <p>
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -18,14 +18,15 @@ package org.onap.holmes.common.utils;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.setup.Environment;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Handle;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
@Singleton
@Service
@Slf4j
@@ -40,13 +41,9 @@ public class DbDaoUtil {
private DBIFactory factory = new DBIFactory();
@PostConstruct
- public void init() {
+ public synchronized void init() {
if (jdbi == null) {
- synchronized (DbDaoUtil.class) {
- if (jdbi == null) {
- jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "mysql");
- }
- }
+ jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "postgres");
}
}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
index d701f3d..6cf62d6 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +19,7 @@ package org.onap.holmes.common.api.stat;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
+
import java.util.Date;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertFalse;
@@ -53,20 +52,6 @@ public class AlarmTest {
}
@Test
- public void testCompareLinkPosition_isEmpty() throws Exception {
- final Map<Integer, Integer> otherIdIdx = new HashMap<>();
- assertThat(999, equalTo(alarm.CompareLinkPosition(otherIdIdx)));
- }
-
- @Test
- public void testCompareLinkPosition_TempLinkId() throws Exception {
- final Map<Integer, Integer> otherIdIdx = new HashMap<>();
- otherIdIdx.put(1, 2);
- alarm.addLinkIdNodeIdx(1, 3);
- assertThat(1, equalTo(alarm.CompareLinkPosition(otherIdIdx)));
- }
-
- @Test
public void testContainNode_NoContainLink() throws Exception {
alarm.addLinkIdNodeIdx(1, 2);
assertThat(false, equalTo(alarm.containNode(2, 2)));