Fix db in rule management problems
authoryoubowu <wu.youbo@zte.com.cn>
Wed, 1 Mar 2017 06:46:23 +0000 (14:46 +0800)
committer6092002067 <wu.youbo@zte.com.cn>
Wed, 1 Mar 2017 06:46:23 +0000 (14:46 +0800)
Issue-ID:HOLMES-50

Change-Id: Iea2cf3b49dd2019fccc7c0014c0c5a5597d7a9c7
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java

index b69e66b..beecdd3 100644 (file)
@@ -75,7 +75,7 @@ public class EngineWrapper {
         try {\r
             httpResponse = engineService.check(correlationCheckRule4Engine);\r
         } catch (Exception e) {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED,e);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED,e);\r
         }\r
         if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
             log.info("Call check rule rest interface in engine successfully.");\r
index a136d12..aa2cccc 100644 (file)
  */\r
 package org.openo.holmes.rulemgt.db;\r
 \r
+import java.util.List;\r
 import org.openo.holmes.common.api.entity.CorrelationRule;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
 import org.openo.holmes.rulemgt.db.mapper.CorrelationRuleMapper;\r
 import org.skife.jdbi.v2.sqlobject.Bind;\r
 import org.skife.jdbi.v2.sqlobject.BindBean;\r
@@ -24,10 +27,9 @@ import org.skife.jdbi.v2.sqlobject.SqlQuery;
 import org.skife.jdbi.v2.sqlobject.SqlUpdate;\r
 import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;\r
 \r
-import java.util.List;\r
-\r
 @RegisterMapper(CorrelationRuleMapper.class)\r
 public abstract class CorrelationRuleDao {\r
+\r
     @GetGeneratedKeys\r
     @SqlUpdate("INSERT INTO APLUS_RULE  (NAME,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,DOMAIN ,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,ISMANUAL,PACKAGE,RID) VALUES (:name,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:domain,:content,:vendor,:createTime,:updateTime,:engineId,:isManual,:packageName,:rid)")\r
     protected abstract int addRule(@BindBean CorrelationRule correlationRule);\r
@@ -45,10 +47,10 @@ public abstract class CorrelationRuleDao {
     protected abstract List<CorrelationRule> queryAllRules();\r
 \r
     @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")\r
-    public abstract CorrelationRule queryRuleByRid(@Bind("rid") String rid);\r
+    protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);\r
 \r
     @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")\r
-    public abstract CorrelationRule queryRuleByName(@Bind("name") String name);\r
+    protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);\r
 \r
     private void deleteRule2DbInner(CorrelationRule correlationRule) {\r
         String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";\r
@@ -60,26 +62,46 @@ public abstract class CorrelationRuleDao {
         }\r
     }\r
 \r
-    public CorrelationRule saveRule(CorrelationRule correlationRule) {\r
-        addRule(correlationRule);\r
-        return correlationRule;\r
+    public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {\r
+        try {\r
+            addRule(correlationRule);\r
+            return correlationRule;\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+        }\r
     }\r
 \r
-    public void updateRule(CorrelationRule correlationRule){\r
-        updateRuleByRid(correlationRule);\r
+    public void updateRule(CorrelationRule correlationRule) throws CorrelationException {\r
+        try {\r
+            updateRuleByRid(correlationRule);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+        }\r
     }\r
 \r
-    public void deleteRule(CorrelationRule correlationRule) {\r
-        deleteRule2DbInner(correlationRule);\r
+    public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {\r
+        try {\r
+            deleteRule2DbInner(correlationRule);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+        }\r
     }\r
 \r
 \r
-    public CorrelationRule getRuleByRid(String rid) {\r
-        return queryRuleByRid(rid);\r
+    public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {\r
+        try {\r
+            return queryRuleById(rid);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+        }\r
     }\r
 \r
-    public CorrelationRule queryRuleByRuleName(String name) {\r
-        return queryRuleByName(name);\r
+    public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {\r
+        try {\r
+            return queryRuleByName(name);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+        }\r
     }\r
 }\r
 \r
index 224f861..075da00 100644 (file)
@@ -78,7 +78,6 @@ public class CorrelationRuleQueryDao {
         correlationRule.setModifier((String) value.get("updator"));\r
         correlationRule.setUpdateTime((Date) value.get("updateTime"));\r
         correlationRule.setParams((Properties) value.get("params"));\r
-        correlationRule.setDomain((String) value.get("domain"));\r
         correlationRule.setContent((String) value.get("content"));\r
         correlationRule.setVendor((String) value.get("vendor"));\r
         correlationRule.setPackageName((String) value.get("package"));\r
index a8b114d..437e0dd 100644 (file)
@@ -39,7 +39,6 @@ public class CorrelationRuleMapper implements ResultSetMapper<CorrelationRule> {
         correlationRule.setModifier(resultSet.getString("updator"));\r
         correlationRule.setUpdateTime(resultSet.getDate("updateTime"));\r
         correlationRule.setParams((Properties)resultSet.getObject("params"));\r
-        correlationRule.setDomain(resultSet.getString("domain"));\r
         correlationRule.setContent(resultSet.getString("content"));\r
         correlationRule.setVendor(resultSet.getString("vendor"));\r
         correlationRule.setPackageName(resultSet.getString("package"));\r
index 24839e8..f672415 100644 (file)
@@ -167,7 +167,7 @@ public class EngineWrapperTest {
     @Test\r
     public void checkRuleFromEngine_invoke_rule_delete_exception() throws Exception {\r
         thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED);\r
 \r
         EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class))).andThrow(\r
                 new RuntimeException(""));\r
index 2a6b5f4..65a53dd 100644 (file)
@@ -42,7 +42,6 @@ public class CorrelationRuleMapperTest {
         expect(resultSet.getString("updator")).andReturn("");\r
         expect(resultSet.getDate("updateTime")).andReturn(new Date(System.currentTimeMillis()));\r
         expect(resultSet.getObject("params")).andReturn(new Properties());\r
-        expect(resultSet.getString("domain")).andReturn("");\r
         expect(resultSet.getString("content")).andReturn("");\r
         expect(resultSet.getString("vendor")).andReturn("");\r
         expect(resultSet.getString("package")).andReturn("");\r