summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/main
diff options
context:
space:
mode:
authorFengLiang <feng.liang1@zte.com.cn>2017-02-16 16:46:11 +0800
committerFengLiang <feng.liang1@zte.com.cn>2017-02-16 19:16:57 +0800
commit9b4711c706dde6caa4689e9317c906361627fc8b (patch)
tree9cddaf71b76edccbbaedf18a6f6ccebc1c8c0d0c /holmes-actions/src/main
parent95bf2aae433086e88bf996773a2ffed59d69c930 (diff)
Add mq
add mq function Change-Id: Ida02db81314d203f0e9b7b780f2848ac8dbdc4c8 Issue-ID:HOLMES-19 Signed-off-by: FengLiang <feng.liang1@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main')
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java3
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java3
-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.java148
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java122
5 files changed, 235 insertions, 119 deletions
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java
index da6924b..d78619d 100644
--- a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java
@@ -16,6 +16,7 @@
package org.openo.holmes.common.api.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.io.Serializable;
import org.openo.holmes.common.api.stat.Alarm;
import lombok.Getter;
@@ -27,7 +28,7 @@ import lombok.ToString;
@Getter
@NoArgsConstructor
@ToString
-public class CorrelationResult {
+public class CorrelationResult implements Serializable{
@JsonProperty
private String ruleId;
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 71a5d00..3cd6093 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
@@ -16,6 +16,7 @@
package org.openo.holmes.common.api.stat;
+import java.io.Serializable;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.util.Date;
@@ -34,7 +35,7 @@ import org.jdom.output.XMLOutputter;
@Getter
@Setter
-public class Alarm implements AplusData, Cloneable {
+public class Alarm implements AplusData, Cloneable, Serializable {
public static final byte EVENT_CLEARED_ALARM = 3;
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
new file mode 100644
index 0000000..d225dae
--- /dev/null
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java
@@ -0,0 +1,78 @@
+/**
+ * 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 = "localhost";
+
+ @JsonProperty
+ @NotNull
+ public int brokerPort = 5672;
+
+
+ @JsonProperty
+ public String brokerUsername;
+
+ @JsonProperty
+ public String brokerPassword;
+
+ @JsonProperty
+ public boolean autoDiscover = false;
+
+ @JsonProperty
+ public String mqServiceName = "mqService";
+
+ @JsonProperty
+ public String mqServiceVersion = "v1";
+
+
+ @JsonProperty
+ public long healthCheckMillisecondsToWait = 2000; // 2 seconds
+
+ @JsonProperty
+ public int shutdownWaitInSeconds = 20;
+
+ @JsonProperty
+ public int timeToLiveInSeconds = -1; // Default no TTL. Jackson does not support java.util.Optional yet.
+
+ @JsonProperty
+ public Map<String, String> extConsumerConfMap = new HashMap<>();
+
+ @JsonProperty
+ public Map<String, String> extProducerConfMap = new HashMap<>();
+
+
+ @Override
+ public String toString() {
+ return "MQConfig [brokerIp=" + brokerIp + ", brokerPort=" + brokerPort + ", brokerUsername="
+ + brokerUsername + ", brokerPassword=" + brokerPassword + ", autoDiscover="
+ + autoDiscover + ", mqServiceName=" + mqServiceName + ", mqServiceVersion="
+ + mqServiceVersion + ", healthCheckMillisecondsToWait=" + healthCheckMillisecondsToWait
+ + ", shutdownWaitInSeconds=" + shutdownWaitInSeconds + ", timeToLiveInSeconds="
+ + timeToLiveInSeconds + "]";
+ }
+
+
+}
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 b0d0b48..d941172 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,117 +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_QUEUE_NAME_EMF_UP = "queue://zenap/fm/emf_up";
-
- public static final String MQ_TOPIC_NAME_EMF_DOWN = "topic://zenap/fm/emf_down";
-
- public static final String MQ_TOPIC_NAME_NORTH_UP = "topic://zenap/fm/north_up";
-
- public static final String MQ_TOPIC_NAME_ALARM_RULE = "topic://zenap/fm/alarm_rule";
-
- public static final String INTERNAL_MQ_QUEUE_NAME_HISTORY_ALARM_2_DB = "queue://zenap/fm/historyalarm2DB";
-
- public static final String MQ_SELECTOR_KEY = "nf";
-
- public static final String MQ_EMF_DOWN_MSG_FILTER_KEY = "type";
-
- public static final String MQ_EMF_UP_MSG_FILTER_KEY = "type";
-
- public static final String INTERNAL_MQ_EMF_UP_ACKALARM_MSG_FILTER_VALUE = "ACK";
-
- public static final String MQ_EMF_DOWN_CLEARALARM_MSG_FILTER_VALUE = "CLEAR";
-
- public static final String MQ_EMF_UP_CLEARALARM_MSG_FILTER_VALUE = "CLEAR";
-
- public static final String MQ_EMF_UP_CHANGEALARM_MSG_FILTER_VALUE = "CHANGE";
-
- public static final String MQ_EMF_UP_RAISEALARM_MSG_FILTER_VALUE = "RAISE";
-
- public static final String INTERNAL_MQ_CLEARALARM_2_DB_FILTER_VALUE = "CLEAR";
-
- public static final String COMETD_MESSAGE_TOPIC = "cometd2Client";
-
- public static final String COMETD_MESSAGE_CHANEL = "/broadcast_channel/alarm_cometd_chanel";
-
- public static final String COMETD_NF_COUNTER_CHANEL = "/nf_counter_cometd_chanel";
-
- public static final String COMETD_PROMPTING_RULE_CHANEL = "/prompting_rule_cometd_chanel";
-
- public static final String COMETD_MASK_RULE_MESSAGE_FILTER_KEY = "mask_rule";
-
- public static final String COMETD_CLEAR_ALARM_MESSAGE_FILTER_KEY = "clear_alarm";
-
- public static final String COMETD_ACK_ALARM_MESSAGE_FILTER_KEY = "ack_alarm";
-
- public static final String COMETD_HISTORY_ALARM_ACK_STATE_MESSAGE_FILTER_KEY = "history_alarm_ack";
-
- public static final String CACHE_ACTIVE_ALARM_KEY = "TAG_ACTIVE_ALARM";
-
- public static final String CACHE_ALARM_CODE_KEY = "TAG_ALARM_CODE";
-
- public static final String CACHE_ALARM_RESTYPE_AND_RESVERSION_KEY = "TAG_ALARM_RESTYPE_AND_RESVERSION";
-
- public static final String CACHE_ALARM_REASON_KEY = "TAG_ALARM_REASON";
-
- public static final String CACHE_ALARM_MAIN_KEY = "TAG_ALARM_MAIN";
-
- public static final short STATUS_ENABLE = 0;
-
- public static final short STATUS_DISABLE = 1;
-
- public static final short STATUS_DELETED = 2;
-
- public static final short UNDEFINE_LEVEL = 0;
-
- public static final short CRITICA_LEVEL = 1;
-
- public static final short MAJOR_LEVEL = 2;
-
- public static final short MINOR_LEVEL = 3;
-
- public static final short WARNING_LEVEL = 4;
-
- 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 EN_US = "en_US";
-
- public static final String EXECUTE_TIMER = "0 0 0 */1 * ? ";
-
- public static final String COMMON_EM_RESTYPE = "common_em";
-
- public static final String EM_LOCATION = "em";
-
- public static final String BASE_MOC = "em";
-
- public static final String SYSTEM_ID = "SystemId";
-
- public static final String ADMIN = "admin";
-
- public static final long UNDEFINE_ALARM_CODE = -1;
-
- // for rule code
- public static final long FORWARD_FAILED_ALARM_CODE = 1028L;
-
- public static long ACTIVE_PERSISTING_RULE_CODE = 1017L;
- public static long UNACKNOWLEDGED_PERSISTING_RULE_CODE = 1018L;
-}
+/**
+ * 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
new file mode 100644
index 0000000..a9a869c
--- /dev/null
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java
@@ -0,0 +1,122 @@
+/**
+ * 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 static 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);
+ }
+ }
+ }
+ }
+}