From 7cbac177f8d733c8a2103b966f51a3afe4c2123c Mon Sep 17 00:00:00 2001 From: youbowu Date: Wed, 1 Mar 2017 14:46:23 +0800 Subject: Fix db in rule management problems Issue-ID:HOLMES-50 Change-Id: Iea2cf3b49dd2019fccc7c0014c0c5a5597d7a9c7 Signed-off-by: youbowu --- .../rulemgt/bolt/enginebolt/EngineWrapper.java | 2 +- .../holmes/rulemgt/db/CorrelationRuleDao.java | 52 +++++++++++++++------- .../holmes/rulemgt/db/CorrelationRuleQueryDao.java | 1 - .../rulemgt/db/mapper/CorrelationRuleMapper.java | 1 - .../rulemgt/bolt/enginebolt/EngineWrapperTest.java | 2 +- .../db/mapper/CorrelationRuleMapperTest.java | 1 - 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java index b69e66b..beecdd3 100644 --- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java @@ -75,7 +75,7 @@ public class EngineWrapper { try { httpResponse = engineService.check(correlationCheckRule4Engine); } catch (Exception e) { - throw new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED,e); + throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED,e); } if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) { log.info("Call check rule rest interface in engine successfully."); diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java index a136d12..aa2cccc 100644 --- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java @@ -15,7 +15,10 @@ */ package org.openo.holmes.rulemgt.db; +import java.util.List; import org.openo.holmes.common.api.entity.CorrelationRule; +import org.openo.holmes.common.exception.CorrelationException; +import org.openo.holmes.common.utils.I18nProxy; import org.openo.holmes.rulemgt.db.mapper.CorrelationRuleMapper; import org.skife.jdbi.v2.sqlobject.Bind; import org.skife.jdbi.v2.sqlobject.BindBean; @@ -24,10 +27,9 @@ import org.skife.jdbi.v2.sqlobject.SqlQuery; import org.skife.jdbi.v2.sqlobject.SqlUpdate; import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper; -import java.util.List; - @RegisterMapper(CorrelationRuleMapper.class) public abstract class CorrelationRuleDao { + @GetGeneratedKeys @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)") protected abstract int addRule(@BindBean CorrelationRule correlationRule); @@ -45,10 +47,10 @@ public abstract class CorrelationRuleDao { protected abstract List queryAllRules(); @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid") - public abstract CorrelationRule queryRuleByRid(@Bind("rid") String rid); + protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid); @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name") - public abstract CorrelationRule queryRuleByName(@Bind("name") String name); + protected abstract CorrelationRule queryRuleByName(@Bind("name") String name); private void deleteRule2DbInner(CorrelationRule correlationRule) { String name = correlationRule.getName() != null ? correlationRule.getName().trim() : ""; @@ -60,26 +62,46 @@ public abstract class CorrelationRuleDao { } } - public CorrelationRule saveRule(CorrelationRule correlationRule) { - addRule(correlationRule); - return correlationRule; + public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException { + try { + addRule(correlationRule); + return correlationRule; + } catch (Exception e) { + throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR); + } } - public void updateRule(CorrelationRule correlationRule){ - updateRuleByRid(correlationRule); + public void updateRule(CorrelationRule correlationRule) throws CorrelationException { + try { + updateRuleByRid(correlationRule); + } catch (Exception e) { + throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR); + } } - public void deleteRule(CorrelationRule correlationRule) { - deleteRule2DbInner(correlationRule); + public void deleteRule(CorrelationRule correlationRule) throws CorrelationException { + try { + deleteRule2DbInner(correlationRule); + } catch (Exception e) { + throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR); + } } - public CorrelationRule getRuleByRid(String rid) { - return queryRuleByRid(rid); + public CorrelationRule queryRuleByRid(String rid) throws CorrelationException { + try { + return queryRuleById(rid); + } catch (Exception e) { + throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR); + } } - public CorrelationRule queryRuleByRuleName(String name) { - return queryRuleByName(name); + public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException { + try { + return queryRuleByName(name); + } catch (Exception e) { + throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR); + } } } diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java index 224f861..075da00 100644 --- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java @@ -78,7 +78,6 @@ public class CorrelationRuleQueryDao { correlationRule.setModifier((String) value.get("updator")); correlationRule.setUpdateTime((Date) value.get("updateTime")); correlationRule.setParams((Properties) value.get("params")); - correlationRule.setDomain((String) value.get("domain")); correlationRule.setContent((String) value.get("content")); correlationRule.setVendor((String) value.get("vendor")); correlationRule.setPackageName((String) value.get("package")); diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java index a8b114d..437e0dd 100644 --- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java @@ -39,7 +39,6 @@ public class CorrelationRuleMapper implements ResultSetMapper { correlationRule.setModifier(resultSet.getString("updator")); correlationRule.setUpdateTime(resultSet.getDate("updateTime")); correlationRule.setParams((Properties)resultSet.getObject("params")); - correlationRule.setDomain(resultSet.getString("domain")); correlationRule.setContent(resultSet.getString("content")); correlationRule.setVendor(resultSet.getString("vendor")); correlationRule.setPackageName(resultSet.getString("package")); diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java index 24839e8..f672415 100644 --- a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java +++ b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java @@ -167,7 +167,7 @@ public class EngineWrapperTest { @Test public void checkRuleFromEngine_invoke_rule_delete_exception() throws Exception { thrown.expect(CorrelationException.class); - thrown.expectMessage(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED); + thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED); EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class))).andThrow( new RuntimeException("")); diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java index 2a6b5f4..65a53dd 100644 --- a/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java +++ b/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java @@ -42,7 +42,6 @@ public class CorrelationRuleMapperTest { expect(resultSet.getString("updator")).andReturn(""); expect(resultSet.getDate("updateTime")).andReturn(new Date(System.currentTimeMillis())); expect(resultSet.getObject("params")).andReturn(new Properties()); - expect(resultSet.getString("domain")).andReturn(""); expect(resultSet.getString("content")).andReturn(""); expect(resultSet.getString("vendor")).andReturn(""); expect(resultSet.getString("package")).andReturn(""); -- cgit 1.2.3-korg