summaryrefslogtreecommitdiffstats
path: root/holmes-actions
diff options
context:
space:
mode:
authoryoubowu <wu.youbo@zte.com.cn>2017-02-28 16:42:10 +0800
committer6092002067 <wu.youbo@zte.com.cn>2017-02-28 16:56:32 +0800
commit189aa621be296963eb0b8b8891d4cea44cf4ede5 (patch)
tree6071ceab474ebab0a3018db88c5f127a2b3f3eee /holmes-actions
parent677b825b6d3228d4593a1e7313e7c45705af65a9 (diff)
Fix aciton module code
Issue-ID:HOLMES-9 Change-Id: I4d95517f2c0fdf36ce001ffe5437f96335ffe2ac Signed-off-by: youbowu <wu.youbo@zte.com.cn>
Diffstat (limited to 'holmes-actions')
-rw-r--r--holmes-actions/pom.xml19
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java4
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java4
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java78
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java62
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java228
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java8
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java9
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java2
9 files changed, 200 insertions, 214 deletions
diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml
index 6d117f5..4fb2e3b 100644
--- a/holmes-actions/pom.xml
+++ b/holmes-actions/pom.xml
@@ -94,6 +94,25 @@
<groupId>org.openo.common-services.common-utilities</groupId>
<artifactId>dropwizard-ioc-container</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4-rule</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-classloading-xstream</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<resources>
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java
index 894886d..24f5bc9 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java
@@ -45,12 +45,8 @@ public class CorrelationRule {
@JsonProperty
private Properties params;
@JsonProperty
- private String domain;
- @JsonProperty
private String content;
@JsonProperty
- private int isManual;
- @JsonProperty
private String vendor;
@JsonProperty(value = "createtime")
private Date createTime;
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java
index 3cd6093..e5eda70 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java
@@ -145,10 +145,6 @@ public class Alarm implements AplusData, Cloneable, Serializable {
return 999;
}
- public Map<Integer, Integer> getLinkIdNodeIdx() {
- return this.linkIdNodeIdxMap;
- }
-
public boolean containNode(int linkId, int index) {
if (linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index) {
return true;
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java b/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java
index 6553998..3200ec0 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java
@@ -1,39 +1,39 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * 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.openo.holmes.common.config;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.HashMap;
-import java.util.Map;
-import javax.validation.constraints.NotNull;
-
-public class MQConfig {
-
- @JsonProperty
- @NotNull
- public String brokerIp;
-
- @JsonProperty
- @NotNull
- public int brokerPort;
-
- @JsonProperty
- public String brokerUsername;
-
- @JsonProperty
- public String brokerPassword;
-}
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.openo.holmes.common.config;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.HashMap;
+import java.util.Map;
+import javax.validation.constraints.NotNull;
+
+public class MQConfig {
+
+ @JsonProperty
+ @NotNull
+ public String brokerIp;
+
+ @JsonProperty
+ @NotNull
+ public int brokerPort;
+
+ @JsonProperty
+ public String brokerUsername;
+
+ @JsonProperty
+ public String brokerPassword;
+}
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java b/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java
index d941172..786deb3 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java
@@ -1,31 +1,31 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * 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.openo.holmes.common.constant;
-
-public interface AlarmConst {
-
- public static final String MQ_TOPIC_NAME_ALARMS_CORRELATION = "topic://voss/fm/alarms_correlation";
-
- public static final String MQ_TOPIC_NAME_ALARM = "topic://voss/fm/alarm";
-
- public static final String I18N_EN = "en";
-
- public static final String I18N_ZH = "zh";
-
- public static final String ZH_CN = "zh_CN";
-
- public static final String ADMIN = "admin";
-}
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.openo.holmes.common.constant;
+
+public interface AlarmConst {
+
+ public static final String MQ_TOPIC_NAME_ALARMS_CORRELATION = "topic://voss/fm/alarms_correlation";
+
+ public static final String MQ_TOPIC_NAME_ALARM = "topic://voss/fm/alarm";
+
+ public static final String I18N_EN = "en";
+
+ public static final String I18N_ZH = "zh";
+
+ public static final String ZH_CN = "zh_CN";
+
+ public static final String ADMIN = "admin";
+}
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java b/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java
index 826a565..e9c38b9 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java
@@ -1,122 +1,106 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * 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.openo.holmes.common.producer;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.glassfish.hk2.api.IterableProvider;
-import org.jvnet.hk2.annotations.Service;
-import org.openo.holmes.common.api.entity.CorrelationResult;
-import org.openo.holmes.common.api.stat.Alarm;
-import org.openo.holmes.common.api.stat.AplusResult;
-import org.openo.holmes.common.config.MQConfig;
-import org.openo.holmes.common.constant.AlarmConst;
-
-@Service
-@Slf4j
-public class MQProducer {
-
- @Inject
- private IterableProvider<MQConfig> mqConfigProvider;
- private ConnectionFactory connectionFactory;
-
- @PostConstruct
- public void init() {
-
- String brokerURL =
- "tcp://" + mqConfigProvider.get().brokerIp + ":" + mqConfigProvider.get().brokerPort;
- connectionFactory = new ActiveMQConnectionFactory(mqConfigProvider.get().brokerUsername,
- mqConfigProvider.get().brokerPassword, brokerURL);
- }
-
- public void sendAlarmMQTopicMsg(Alarm alarm) {
-
- Connection connection = null;
- Session session;
- Destination destination;
- MessageProducer messageProducer;
-
- try {
-
- connection = connectionFactory.createConnection();
- connection.start();
- session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM);
- messageProducer = session.createProducer(destination);
- ObjectMessage message = session.createObjectMessage(alarm);
- messageProducer.send(message);
- session.commit();
-
- } catch (Exception e) {
- log.error("Failed send alarm." + e.getMessage(), e);
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (JMSException e) {
- log.error("Failed close connection." + e.getMessage(), e);
- }
- }
- }
- }
-
- public void sendCorrelationMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm,
- Alarm childAlarm) {
-
- CorrelationResult correlationResult = new CorrelationResult();
- correlationResult.setRuleId(ruleId);
- correlationResult.setCreateTimeL(createTimeL);
- correlationResult.setResultType(AplusResult.APLUS_CORRELATION);
- correlationResult.setAffectedAlarms(new Alarm[]{parentAlarm, childAlarm});
-
- Connection connection = null;
- Session session;
- Destination destination;
- MessageProducer messageProducer;
-
- try {
-
- connection = connectionFactory.createConnection();
- connection.start();
- session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION);
- messageProducer = session.createProducer(destination);
- ObjectMessage message = session.createObjectMessage(correlationResult);
- messageProducer.send(message);
- session.commit();
-
- } catch (Exception e) {
- log.error("Failed send correlation." + e.getMessage(), e);
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (JMSException e) {
- log.error("Failed close connection." + e.getMessage(), e);
- }
- }
- }
- }
-}
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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.openo.holmes.common.producer;
+
+import javax.inject.Inject;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import lombok.extern.slf4j.Slf4j;
+import org.glassfish.hk2.api.IterableProvider;
+import org.jvnet.hk2.annotations.Service;
+import org.openo.holmes.common.api.entity.CorrelationResult;
+import org.openo.holmes.common.api.stat.Alarm;
+import org.openo.holmes.common.api.stat.AplusResult;
+import org.openo.holmes.common.config.MQConfig;
+import org.openo.holmes.common.constant.AlarmConst;
+
+@Service
+@Slf4j
+public class MQProducer {
+
+ @Inject
+ private IterableProvider<MQConfig> mqConfigProvider;
+ private ConnectionFactory connectionFactory;
+
+ public void sendAlarmMQTopicMsg(Alarm alarm) {
+
+ Connection connection = null;
+ Session session;
+ Destination destination;
+ MessageProducer messageProducer;
+ try {
+ connection = connectionFactory.createConnection();
+ connection.start();
+ session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM);
+ messageProducer = session.createProducer(destination);
+ ObjectMessage message = session.createObjectMessage(alarm);
+ messageProducer.send(message);
+ session.commit();
+ } catch (Exception e) {
+ log.error("Failed send alarm." + e.getMessage(), e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ log.error("Failed close connection." + e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ public void sendCorrelationMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm,
+ Alarm childAlarm) {
+
+ CorrelationResult correlationResult = new CorrelationResult();
+ correlationResult.setRuleId(ruleId);
+ correlationResult.setCreateTimeL(createTimeL);
+ correlationResult.setResultType(AplusResult.APLUS_CORRELATION);
+ correlationResult.setAffectedAlarms(new Alarm[]{parentAlarm, childAlarm});
+
+ Connection connection = null;
+ Session session;
+ Destination destination;
+ MessageProducer messageProducer;
+
+ try {
+ connection = connectionFactory.createConnection();
+ connection.start();
+ session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION);
+ messageProducer = session.createProducer(destination);
+ ObjectMessage message = session.createObjectMessage(correlationResult);
+ messageProducer.send(message);
+ session.commit();
+ } catch (Exception e) {
+ log.error("Failed send correlation." + e.getMessage(), e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ log.error("Failed close connection." + e.getMessage(), e);
+ }
+ }
+ }
+ }
+}
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java
index b45fb4a..18890ce 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java
@@ -31,20 +31,20 @@ import org.skife.jdbi.v2.Handle;
@Slf4j
public class DbDaoUtil {
- private static DBI jdbi;
+ private DBI jdbi;
@Inject
private Environment environmentProvider;
@Inject
private DataSourceFactory dataSourceFactoryProvider;
+ private DBIFactory factory = new DBIFactory();
+
@PostConstruct
public void init() {
if (jdbi == null) {
synchronized (DbDaoUtil.class) {
if (jdbi == null) {
- final DBIFactory factory = new DBIFactory();
- jdbi = factory
- .build(environmentProvider, dataSourceFactoryProvider, "mysql");
+ jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "mysql");
}
}
}
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java
index cc58446..1154f38 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java
@@ -15,7 +15,6 @@
*/
package org.openo.holmes.common.utils;
-import java.util.Locale;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -28,14 +27,6 @@ public class ExceptionUtil {
}
- public static String getExceptionMsg(Locale locale, Exception e) {
- return I18nProxy.getInstance().getValue(locale, e.getMessage());
- }
-
- public static String getExceptionMsgByArgs(Locale locale, Exception e, String[] obj) {
- return I18nProxy.getInstance().getValueByArgs(locale, e.getMessage(), obj);
- }
-
public static WebApplicationException buildExceptionResponse(String message) {
Response response = Response.status(EXCEPTION_CODE).entity(message).type(MediaType.TEXT_PLAIN).build();
return new WebApplicationException(response);
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java
index 571ecee..1c8f72c 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java
@@ -40,7 +40,7 @@ public class LanguageUtil {
public static Locale getLocale(HttpServletRequest servletRequest) {
String language = (String) servletRequest.getHeader("language-option");
if (JudgeNullUtil.isEmpty(language)) {
- language = AlarmConst.ZH_CN;
+ language = AlarmConst.I18N_EN;
}
if (language.startsWith(AlarmConst.I18N_ZH)) {
language = AlarmConst.I18N_ZH;