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;
}
- private void start() throws EngineException, RuleIllegalityException, DbException {
+ private void start() throws CorrelationException {
log.info("Drools Engine Initialize Beginning...");
initEngineParameter();
this.ksession.dispose();
}
- private void initEngineParameter() throws EngineException {
+ private void initEngineParameter(){
this.kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
this.kconf.setOption(EventProcessingOption.STREAM);
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);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
} catch (Exception e) {
- throw new EngineException(e);
+ throw new CorrelationException(e.getMessage(), e);
}
ksession.fireAllRules();
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;
@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;
}
\r
package org.openo.holmes.engine.wrapper;\r
\r
+import static org.easymock.EasyMock.anyInt;\r
+import static org.easymock.EasyMock.anyObject;\r
+import static org.easymock.EasyMock.expect;\r
+\r
+import java.util.ArrayList;\r
import org.junit.Before;\r
import org.junit.Rule;\r
import org.junit.Test;\r
import org.junit.rules.ExpectedException;\r
import org.openo.holmes.common.api.entity.CorrelationRule;\r
-import org.openo.holmes.common.exception.DbException;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
import org.openo.holmes.common.utils.DbDaoUtil;\r
import org.openo.holmes.engine.db.CorrelationRuleDao;\r
import org.powermock.api.easymock.PowerMock;\r
import org.powermock.reflect.Whitebox;\r
\r
-import java.util.ArrayList;\r
-\r
-import static org.easymock.EasyMock.*;\r
-\r
public class RuleMgtWrapperTest {\r
\r
@Rule\r
}\r
\r
@Test\r
- public void queryRuleByEnable_ruletemp_is_null() throws DbException {\r
+ public void queryRuleByEnable_ruletemp_is_null() throws CorrelationException {\r
int enable = 3;\r
\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
\r
CorrelationRuleDao correlationRuleDao = PowerMock.createMock(CorrelationRuleDao.class);\r
expect(daoUtil.getJdbiDaoByOnDemand(anyObject(Class.class))).andReturn(correlationRuleDao);\r
}\r
\r
@Test\r
- public void queryRuleByEnable_normal() throws DbException {\r
+ public void queryRuleByEnable_normal() throws CorrelationException {\r
int enable = 3;\r
\r
CorrelationRuleDao correlationRuleDao = PowerMock.createMock(CorrelationRuleDao.class);\r