Fix aciton module code
authoryoubowu <wu.youbo@zte.com.cn>
Tue, 28 Feb 2017 08:42:10 +0000 (16:42 +0800)
committer6092002067 <wu.youbo@zte.com.cn>
Tue, 28 Feb 2017 08:56:32 +0000 (16:56 +0800)
Issue-ID:HOLMES-9

Change-Id: I4d95517f2c0fdf36ce001ffe5437f96335ffe2ac
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
holmes-actions/pom.xml
holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java
holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java
holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java
holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java
holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java
holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java
holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java
holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java
pom.xml

index 6d117f5..4fb2e3b 100644 (file)
             <groupId>org.openo.common-services.common-utilities</groupId>\r
             <artifactId>dropwizard-ioc-container</artifactId>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.easymock</groupId>\r
+            <artifactId>easymock</artifactId>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.powermock</groupId>\r
+            <artifactId>powermock-api-easymock</artifactId>\r
+            <scope>test</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.powermock</groupId>\r
+            <artifactId>powermock-module-junit4-rule</artifactId>\r
+            <scope>test</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.powermock</groupId>\r
+            <artifactId>powermock-classloading-xstream</artifactId>\r
+            <scope>test</scope>\r
+        </dependency>\r
     </dependencies>\r
     <build>\r
         <resources>\r
index 894886d..24f5bc9 100644 (file)
@@ -45,12 +45,8 @@ public class CorrelationRule {
     @JsonProperty\r
     private Properties params;\r
     @JsonProperty\r
-    private String domain;\r
-    @JsonProperty\r
     private String content;\r
     @JsonProperty\r
-    private int isManual;\r
-    @JsonProperty\r
     private String vendor;\r
     @JsonProperty(value = "createtime")\r
     private Date createTime;\r
index 3cd6093..e5eda70 100644 (file)
@@ -145,10 +145,6 @@ public class Alarm implements AplusData, Cloneable, Serializable {
         return 999;\r
     }\r
 \r
-    public Map<Integer, Integer> getLinkIdNodeIdx() {\r
-        return this.linkIdNodeIdxMap;\r
-    }\r
-\r
     public boolean containNode(int linkId, int index) {\r
         if (linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index) {\r
             return true;\r
index 6553998..3200ec0 100644 (file)
@@ -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;
-}
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.openo.holmes.common.config;\r
+\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import javax.validation.constraints.NotNull;\r
+\r
+public class MQConfig {\r
+\r
+    @JsonProperty\r
+    @NotNull\r
+    public String brokerIp;\r
+\r
+    @JsonProperty\r
+    @NotNull\r
+    public int brokerPort;\r
+\r
+    @JsonProperty\r
+    public String brokerUsername;\r
+\r
+    @JsonProperty\r
+    public String brokerPassword;\r
+}\r
index d941172..786deb3 100644 (file)
@@ -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";
-}
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.common.constant;\r
+\r
+public interface AlarmConst {\r
+\r
+    public static final String MQ_TOPIC_NAME_ALARMS_CORRELATION = "topic://voss/fm/alarms_correlation";\r
+\r
+    public static final String MQ_TOPIC_NAME_ALARM = "topic://voss/fm/alarm";\r
+\r
+    public static final String I18N_EN = "en";\r
+\r
+    public static final String I18N_ZH = "zh";\r
+\r
+    public static final String ZH_CN = "zh_CN";\r
+\r
+    public static final String ADMIN = "admin";\r
+}\r
index 826a565..e9c38b9 100644 (file)
-/**
- * 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);
-                }
-            }
-        }
-    }
-}
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.common.producer;\r
+\r
+import javax.inject.Inject;\r
+import javax.jms.Connection;\r
+import javax.jms.ConnectionFactory;\r
+import javax.jms.Destination;\r
+import javax.jms.JMSException;\r
+import javax.jms.MessageProducer;\r
+import javax.jms.ObjectMessage;\r
+import javax.jms.Session;\r
+import lombok.extern.slf4j.Slf4j;\r
+import org.glassfish.hk2.api.IterableProvider;\r
+import org.jvnet.hk2.annotations.Service;\r
+import org.openo.holmes.common.api.entity.CorrelationResult;\r
+import org.openo.holmes.common.api.stat.Alarm;\r
+import org.openo.holmes.common.api.stat.AplusResult;\r
+import org.openo.holmes.common.config.MQConfig;\r
+import org.openo.holmes.common.constant.AlarmConst;\r
+\r
+@Service\r
+@Slf4j\r
+public class MQProducer {\r
+\r
+    @Inject\r
+    private IterableProvider<MQConfig> mqConfigProvider;\r
+    private ConnectionFactory connectionFactory;\r
+\r
+    public void sendAlarmMQTopicMsg(Alarm alarm) {\r
+\r
+        Connection connection = null;\r
+        Session session;\r
+        Destination destination;\r
+        MessageProducer messageProducer;\r
+        try {\r
+            connection = connectionFactory.createConnection();\r
+            connection.start();\r
+            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);\r
+            destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM);\r
+            messageProducer = session.createProducer(destination);\r
+            ObjectMessage message = session.createObjectMessage(alarm);\r
+            messageProducer.send(message);\r
+            session.commit();\r
+        } catch (Exception e) {\r
+            log.error("Failed send alarm." + e.getMessage(), e);\r
+        } finally {\r
+            if (connection != null) {\r
+                try {\r
+                    connection.close();\r
+                } catch (JMSException e) {\r
+                    log.error("Failed close connection." + e.getMessage(), e);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    public void sendCorrelationMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm,\r
+            Alarm childAlarm) {\r
+\r
+        CorrelationResult correlationResult = new CorrelationResult();\r
+        correlationResult.setRuleId(ruleId);\r
+        correlationResult.setCreateTimeL(createTimeL);\r
+        correlationResult.setResultType(AplusResult.APLUS_CORRELATION);\r
+        correlationResult.setAffectedAlarms(new Alarm[]{parentAlarm, childAlarm});\r
+\r
+        Connection connection = null;\r
+        Session session;\r
+        Destination destination;\r
+        MessageProducer messageProducer;\r
+\r
+        try {\r
+            connection = connectionFactory.createConnection();\r
+            connection.start();\r
+            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);\r
+            destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION);\r
+            messageProducer = session.createProducer(destination);\r
+            ObjectMessage message = session.createObjectMessage(correlationResult);\r
+            messageProducer.send(message);\r
+            session.commit();\r
+        } catch (Exception e) {\r
+            log.error("Failed send correlation." + e.getMessage(), e);\r
+        } finally {\r
+            if (connection != null) {\r
+                try {\r
+                    connection.close();\r
+                } catch (JMSException e) {\r
+                    log.error("Failed close connection." + e.getMessage(), e);\r
+                }\r
+            }\r
+        }\r
+    }\r
+}\r
index b45fb4a..18890ce 100644 (file)
@@ -31,20 +31,20 @@ import org.skife.jdbi.v2.Handle;
 @Slf4j\r
 public class DbDaoUtil {\r
 \r
-    private static DBI jdbi;\r
+    private DBI jdbi;\r
     @Inject\r
     private Environment environmentProvider;\r
     @Inject\r
     private DataSourceFactory dataSourceFactoryProvider;\r
 \r
+    private DBIFactory factory = new DBIFactory();\r
+\r
     @PostConstruct\r
     public void init() {\r
         if (jdbi == null) {\r
             synchronized (DbDaoUtil.class) {\r
                 if (jdbi == null) {\r
-                    final DBIFactory factory = new DBIFactory();\r
-                    jdbi = factory\r
-                            .build(environmentProvider, dataSourceFactoryProvider, "mysql");\r
+                    jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "mysql");\r
                 }\r
             }\r
         }\r
index cc58446..1154f38 100644 (file)
@@ -15,7 +15,6 @@
  */\r
 package org.openo.holmes.common.utils;\r
 \r
-import java.util.Locale;\r
 import javax.ws.rs.WebApplicationException;\r
 import javax.ws.rs.core.MediaType;\r
 import javax.ws.rs.core.Response;\r
@@ -28,14 +27,6 @@ public class ExceptionUtil {
 \r
     }\r
 \r
-    public static String getExceptionMsg(Locale locale, Exception e) {\r
-        return I18nProxy.getInstance().getValue(locale, e.getMessage());\r
-    }\r
-\r
-    public static String getExceptionMsgByArgs(Locale locale, Exception e, String[] obj) {\r
-        return I18nProxy.getInstance().getValueByArgs(locale, e.getMessage(), obj);\r
-    }\r
-\r
     public static WebApplicationException buildExceptionResponse(String message) {\r
         Response response = Response.status(EXCEPTION_CODE).entity(message).type(MediaType.TEXT_PLAIN).build();\r
         return new WebApplicationException(response);\r
index 571ecee..1c8f72c 100644 (file)
@@ -40,7 +40,7 @@ public class LanguageUtil {
     public static Locale getLocale(HttpServletRequest servletRequest) {\r
         String language = (String) servletRequest.getHeader("language-option");\r
         if (JudgeNullUtil.isEmpty(language)) {\r
-            language = AlarmConst.ZH_CN;\r
+            language = AlarmConst.I18N_EN;\r
         }\r
         if (language.startsWith(AlarmConst.I18N_ZH)) {\r
             language = AlarmConst.I18N_ZH;\r
diff --git a/pom.xml b/pom.xml
index dab2867..28dbb33 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <dependency>\r
                 <groupId>org.powermock</groupId>\r
                 <artifactId>powermock-module-junit4</artifactId>\r
-                <version>1.6.4</version>\r
+                <version>1.6.5</version>\r
+                <scope>test</scope>\r
+            </dependency>\r
+            <dependency>\r
+                <groupId>org.easymock</groupId>\r
+                <artifactId>easymock</artifactId>\r
+                <version>3.0</version>\r
+                <scope>test</scope>\r
+            </dependency>\r
+            <dependency>\r
+                <groupId>org.powermock</groupId>\r
+                <artifactId>powermock-api-easymock</artifactId>\r
+                <version>1.6.5</version>\r
+                <scope>test</scope>\r
+            </dependency>\r
+            <dependency>\r
+                <groupId>org.powermock</groupId>\r
+                <artifactId>powermock-module-junit4-rule</artifactId>\r
+                <version>1.6.5</version>\r
+                <scope>test</scope>\r
+            </dependency>\r
+            <dependency>\r
+                <groupId>org.powermock</groupId>\r
+                <artifactId>powermock-classloading-xstream</artifactId>\r
+                <version>1.6.5</version>\r
                 <scope>test</scope>\r
             </dependency>\r
             <dependency>\r