summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java15
-rw-r--r--engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java6
-rw-r--r--engine-d/src/test/java/org/openo/holmes/engine/wrapper/RuleMgtWrapperTest.java17
3 files changed, 18 insertions, 20 deletions
diff --git a/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java b/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java
index b6d867f..9b83002 100644
--- a/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java
+++ b/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java
@@ -49,9 +49,6 @@ import org.openo.holmes.common.api.stat.Alarm;
import org.openo.holmes.common.config.MQConfig;
import org.openo.holmes.common.constant.AlarmConst;
import org.openo.holmes.common.exception.CorrelationException;
-import org.openo.holmes.common.exception.DbException;
-import org.openo.holmes.common.exception.EngineException;
-import org.openo.holmes.common.exception.RuleIllegalityException;
import org.openo.holmes.common.utils.ExceptionUtil;
import org.openo.holmes.common.utils.I18nProxy;
import org.openo.holmes.engine.request.DeployRuleRequest;
@@ -107,7 +104,7 @@ public class DroolsEngine {
}
- private void start() throws EngineException, RuleIllegalityException, DbException {
+ private void start() throws CorrelationException {
log.info("Drools Engine Initialize Beginning...");
initEngineParameter();
@@ -120,7 +117,7 @@ public class DroolsEngine {
this.ksession.dispose();
}
- private void initEngineParameter() throws EngineException {
+ private void initEngineParameter(){
this.kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
this.kconf.setOption(EventProcessingOption.STREAM);
@@ -134,19 +131,19 @@ public class DroolsEngine {
this.ksession = kbase.newStatefulKnowledgeSession();
}
- private void initDeployRule() throws RuleIllegalityException, EngineException, DbException {
+ private void initDeployRule() throws CorrelationException {
List<CorrelationRule> rules = ruleMgtWrapper.queryRuleByEnable(ENABLE);
if (!rules.isEmpty()) {
for (CorrelationRule rule : rules) {
if (rule.getContent() != null) {
- deployRuleFromCache(rule.getContent());
+ deployRuleFromDB(rule.getContent());
}
}
}
}
- private void deployRuleFromCache(String ruleContent) throws EngineException {
+ private void deployRuleFromDB(String ruleContent) throws CorrelationException {
StringReader reader = new StringReader(ruleContent);
Resource res = ResourceFactory.newReaderResource(reader);
@@ -160,7 +157,7 @@ public class DroolsEngine {
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
} catch (Exception e) {
- throw new EngineException(e);
+ throw new CorrelationException(e.getMessage(), e);
}
ksession.fireAllRules();
diff --git a/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java b/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java
index 59110d8..7df791d 100644
--- a/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java
+++ b/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java
@@ -21,7 +21,7 @@ import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
import org.openo.holmes.common.api.entity.CorrelationRule;
-import org.openo.holmes.common.exception.DbException;
+import org.openo.holmes.common.exception.CorrelationException;
import org.openo.holmes.common.utils.DbDaoUtil;
import org.openo.holmes.common.utils.I18nProxy;
import org.openo.holmes.engine.db.CorrelationRuleDao;
@@ -35,12 +35,12 @@ public class RuleMgtWrapper {
@Inject
private DbDaoUtil daoUtil;
- public List<CorrelationRule> queryRuleByEnable(int enable) throws DbException {
+ public List<CorrelationRule> queryRuleByEnable(int enable) throws CorrelationException {
List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
.queryRuleByRuleEnable(enable);
if (ruleTemp == null) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);
}
return ruleTemp;
}
diff --git a/engine-d/src/test/java/org/openo/holmes/engine/wrapper/RuleMgtWrapperTest.java b/engine-d/src/test/java/org/openo/holmes/engine/wrapper/RuleMgtWrapperTest.java
index 75c4a20..593b1ce 100644
--- a/engine-d/src/test/java/org/openo/holmes/engine/wrapper/RuleMgtWrapperTest.java
+++ b/engine-d/src/test/java/org/openo/holmes/engine/wrapper/RuleMgtWrapperTest.java
@@ -16,21 +16,22 @@
package org.openo.holmes.engine.wrapper;
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
+
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.openo.holmes.common.api.entity.CorrelationRule;
-import org.openo.holmes.common.exception.DbException;
+import org.openo.holmes.common.exception.CorrelationException;
import org.openo.holmes.common.utils.DbDaoUtil;
import org.openo.holmes.engine.db.CorrelationRuleDao;
import org.powermock.api.easymock.PowerMock;
import org.powermock.reflect.Whitebox;
-import java.util.ArrayList;
-
-import static org.easymock.EasyMock.*;
-
public class RuleMgtWrapperTest {
@Rule
@@ -48,10 +49,10 @@ public class RuleMgtWrapperTest {
}
@Test
- public void queryRuleByEnable_ruletemp_is_null() throws DbException {
+ public void queryRuleByEnable_ruletemp_is_null() throws CorrelationException {
int enable = 3;
- thrown.expect(DbException.class);
+ thrown.expect(CorrelationException.class);
CorrelationRuleDao correlationRuleDao = PowerMock.createMock(CorrelationRuleDao.class);
expect(daoUtil.getJdbiDaoByOnDemand(anyObject(Class.class))).andReturn(correlationRuleDao);
@@ -62,7 +63,7 @@ public class RuleMgtWrapperTest {
}
@Test
- public void queryRuleByEnable_normal() throws DbException {
+ public void queryRuleByEnable_normal() throws CorrelationException {
int enable = 3;
CorrelationRuleDao correlationRuleDao = PowerMock.createMock(CorrelationRuleDao.class);