summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main/java
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2017-02-18 14:33:57 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2017-02-18 15:52:31 +0800
commit5947322b7253ba4eff59ee38951114e77050c8c7 (patch)
tree730de9b7cc1ee3820d3cf96a44204db86955fbd8 /rulemgt/src/main/java
parentcbe87c3d24a9a3fdb3843e44cd686dd78de1debf (diff)
Modify the UT Due to the Code Modification
Change-Id: I5b787bb2f64d05050921ded375438d507efbfd61 Issue-ID:HOLMES-12 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'rulemgt/src/main/java')
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java1
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java8
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java5
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java4
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java60
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java90
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java117
7 files changed, 124 insertions, 161 deletions
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
index 5c5a30c..3433678 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
@@ -22,7 +22,6 @@ import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
-import lombok.Getter;
public class RuleAppConfig extends Configuration {
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 e2f4fdd..329b9c9 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
@@ -17,7 +17,7 @@ package org.openo.holmes.rulemgt.bolt.enginebolt;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
-import org.openo.holmes.common.exception.CallException;
+import org.openo.holmes.common.exception.CorrelationException;
import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
@@ -26,16 +26,16 @@ import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
public class EngineWrapper {
- public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CallException {
+ public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {
return "";
}
- public boolean deleteRuleFromEngine(String packageName) throws CallException {
+ public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {
return true;
}
public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)
- throws CallException {
+ throws CorrelationException {
return true;
}
}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java
index 55c3cd8..e086829 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java
@@ -16,8 +16,13 @@
package org.openo.holmes.rulemgt.constant;
public class RuleMgtConstant {
+
public static final int STATUS_RULE_OPEN = 1;
public static final int STATUS_RULE_CLOSE = 0;
public static final int STATUS_RULE_ALL = 2;
public static final String PACKAGE_NAME = "packagename";
+
+ private RuleMgtConstant() {
+
+ }
}
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 7a7a0eb..a136d12 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
@@ -53,9 +53,9 @@ public abstract class CorrelationRuleDao {
private void deleteRule2DbInner(CorrelationRule correlationRule) {
String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
- if (!name.equals("") && !rid.equals("")) {
+ if (!"".equals(name) && !"".equals(rid)) {
deleteRuleByRidAndName(rid, name);
- } else if (!rid.equals("")) {
+ } else if (!"".equals(rid)) {
deleteRuleByRid(rid);
}
}
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 9b66ae5..62f8bad 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
@@ -15,19 +15,6 @@
*/
package org.openo.holmes.rulemgt.db;
-import org.openo.holmes.common.api.entity.CorrelationRule;
-import org.openo.holmes.common.exception.DataFormatException;
-import org.openo.holmes.common.exception.DbException;
-import org.openo.holmes.common.utils.DbDaoUtil;
-import org.openo.holmes.common.utils.I18nProxy;
-import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.openo.holmes.rulemgt.constant.RuleMgtConstant;
-import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
-
-import javax.inject.Inject;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -36,14 +23,27 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import javax.inject.Inject;
+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.CorrelationException;
+import org.openo.holmes.common.utils.DbDaoUtil;
+import org.openo.holmes.common.utils.I18nProxy;
+import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.Query;
@Service
@Slf4j
public class CorrelationRuleQueryDao {
+
@Inject
private DbDaoUtil dbDaoUtil;
- public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {
+ public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)
+ throws CorrelationException {
List<CorrelationRule> correlationRules = new ArrayList<CorrelationRule>();
Handle handle = null;
String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);
@@ -58,7 +58,7 @@ public class CorrelationRuleQueryDao {
return correlationRules;
} catch (Exception e) {
log.warn("Query rule: rule id =" + ruleQueryCondition.getRid() + " failed");
- throw new DbException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED, e);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED, e);
} finally {
dbDaoUtil.close(handle);
}
@@ -86,7 +86,7 @@ public class CorrelationRuleQueryDao {
return correlationRule;
}
- private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws DataFormatException {
+ private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws CorrelationException {
try {
Class clazz = ruleQueryCondition.getClass();
Field[] fields = clazz.getDeclaredFields();
@@ -95,23 +95,17 @@ public class CorrelationRuleQueryDao {
for (Field field : fields) {
PropertyDescriptor pd = new PropertyDescriptor(field.getName(),
clazz);
- Method getMethod = pd.getReadMethod();//获得get方法
- Object o = getMethod.invoke(ruleQueryCondition);//执行get方法返回一个Object
+ Method getMethod = pd.getReadMethod();
+ Object o = getMethod.invoke(ruleQueryCondition);
if (o != null) {
- if (field.getName().equals("enabled")) {
- int enabled = (int) o;
- if (enabled != RuleMgtConstant.STATUS_RULE_ALL) {
- whereSql = whereSql + "enable =" + enabled;
- whereSql += " AND ";
- }
- } else if (field.getName().equals("name")) {
- if (!"".equals(o.toString().trim())) {
- whereSql = whereSql + field.getName() + " like '%" + o + "%' AND ";
- }
- } else {
- if (!"".equals(o.toString().trim())) {
- whereSql = whereSql + field.getName() + "='" + o + "' AND ";
- }
+ String tempName = field.getName();
+ if ("enabled".equals(tempName) && (int) o != RuleMgtConstant.STATUS_RULE_ALL) {
+ whereSql = whereSql + "enable =" + (int) o;
+ whereSql += " AND ";
+ } else if ("name".equals(tempName) && !"".equals(o.toString().trim())) {
+ whereSql = whereSql + field.getName() + " like '%" + o + "%' AND ";
+ } else if (!"".equals(o.toString().trim())) {
+ whereSql = whereSql + field.getName() + "='" + o + "' AND ";
}
}
}
@@ -121,7 +115,7 @@ public class CorrelationRuleQueryDao {
}
return "";
} catch (Exception e) {
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);
}
}
}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
index 8395df7..c2d95f9 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
@@ -35,9 +35,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
-import org.openo.holmes.common.exception.CallException;
-import org.openo.holmes.common.exception.DataFormatException;
-import org.openo.holmes.common.exception.DbException;
+import org.openo.holmes.common.exception.CorrelationException;
import org.openo.holmes.common.utils.ExceptionUtil;
import org.openo.holmes.common.utils.I18nProxy;
import org.openo.holmes.common.utils.JacksonUtil;
@@ -67,30 +65,18 @@ public class RuleMgtResources {
@ApiOperation(value = "Save the alarm+ rule to the database, and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)
@Timed
public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value = "alarm+ rule create request.<br>[rulename]:<font color=\"red\">required</font><br>[content]:<font color=\"red\">required</font><br>[enabled]:<font color=\"red\">required</font>", required = true) RuleCreateRequest ruleCreateRequest) {
+ @ApiParam(value = "alarm+ rule create request.<br>[rulename]:<font color=\"red\">required</font><br>[content]:<font color=\"red\">required</font><br>[enabled]:<font color=\"red\">required</font>", required = true) RuleCreateRequest ruleCreateRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
- .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);
+ .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);
log.info("create rule:" + ruleCreateRequest.getRuleName() + " success.");
return ruleChangeResponse;
- } catch (CallException e) {
+ } catch (CorrelationException e) {
log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (DbException e) {
- log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (DataFormatException e) {
- log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (Exception e) {
- log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));
+ e.getMessage()));
}
}
@@ -99,29 +85,17 @@ public class RuleMgtResources {
@ApiOperation(value = "Update the alarm+ rule and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)
@Timed
public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {
+ @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
- .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);
+ .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);
return ruleChangeResponse;
- } catch (CallException e) {
+ } catch (CorrelationException e) {
log.error("create rule:" + ruleUpdateRequest.getContent() + " failed", e);
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (DataFormatException e) {
- log.error("update alarm plus rule:" + ruleUpdateRequest.getContent() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (DbException e) {
- log.error("update rule:" + ruleUpdateRequest.getContent() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (Exception e) {
- log.error("update rule:" + ruleUpdateRequest.getRuleId() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));
+ e.getMessage()));
}
}
@@ -130,28 +104,16 @@ public class RuleMgtResources {
@ApiOperation(value = "Delete the alarm+ rule,and when the enable is open also removed from the engine.")
@Timed
public boolean deleteCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {
+ @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {
Locale locale = LanguageUtil.getLocale(request);
try {
ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
log.info("delete rule:" + ruleDeleteRequest.getRuleId() + " successful");
return true;
- } catch (DataFormatException e) {
+ } catch (CorrelationException e) {
log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (DbException e) {
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (CallException e) {
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (Exception e) {
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));
+ e.getMessage()));
}
}
@@ -160,38 +122,30 @@ public class RuleMgtResources {
@ApiOperation(value = "According to the conditions query the alarm + rules", response = RuleQueryListResponse.class)
@Timed
public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,
- @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"
- + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"
- + "<b>[modifier]</b>:modifier of the rule;<br>"
- + "<b>[enabled]</b>: 0 is Enabled,1 is disabled;<br><font color=\"red\">for example:</font><br>{\"ruleid\":\"rule_1484727187317\"}", required = false) @QueryParam("queryrequest") String ruleQueryRequest) {
+ @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"
+ + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"
+ + "<b>[modifier]</b>:modifier of the rule;<br>"
+ + "<b>[enabled]</b>: 0 is Enabled,1 is disabled;<br><font color=\"red\">for example:</font><br>{\"ruleid\":\"rule_1484727187317\"}", required = false) @QueryParam("queryrequest") String ruleQueryRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleQueryListResponse ruleQueryListResponse;
RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);
try {
ruleQueryListResponse = ruleMgtWrapper
- .getCorrelationRuleByCondition(ruleQueryCondition);
+ .getCorrelationRuleByCondition(ruleQueryCondition);
return ruleQueryListResponse;
- } catch (DataFormatException e) {
+ } catch (CorrelationException e) {
log.error("query rule failed,cause query condition conversion failure", e);
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (DbException e) {
- log.error("query rule failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- } catch (Exception e) {
- log.error("query rule failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));
+ e.getMessage()));
}
}
private RuleQueryCondition getRuleQueryCondition(String queryRequest,
- HttpServletRequest request) {
+ HttpServletRequest request) {
Locale locale = LanguageUtil.getLocale(request);
try {
RuleQueryCondition ruleQueryCondition = JacksonUtil
- .jsonToBean(queryRequest, RuleQueryCondition.class);
+ .jsonToBean(queryRequest, RuleQueryCondition.class);
if (queryRequest == null) {
ruleQueryCondition.setEnabled(2);
} else if (queryRequest.indexOf("enabled") == -1) {
@@ -201,7 +155,7 @@ public class RuleMgtResources {
} catch (IOException e) {
log.warn("queryRequest convert to json failed", e);
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));
+ I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));
}
}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java
index 60bce08..67183b7 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java
@@ -23,9 +23,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.CallException;
-import org.openo.holmes.common.exception.DataFormatException;
-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.rulemgt.bean.request.CorrelationCheckRule4Engine;
@@ -56,24 +54,29 @@ public class RuleMgtWrapper {
private DbDaoUtil daoUtil;
public RuleAddAndUpdateResponse addCorrelationRule(String creator,
- RuleCreateRequest ruleCreateRequest)
- throws DataFormatException, CallException, DbException {
+ RuleCreateRequest ruleCreateRequest)
+ throws CorrelationException {
CorrelationRule correlationRule = convertRuleCreateRequest2CorrelationRule(creator,
- ruleCreateRequest);
+ ruleCreateRequest);
if (correlationRule.getName() == null || "".equals(correlationRule.getName().trim())) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);
+ }
+ CorrelationRule ruleTemp;
+ try {
+ ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
+ .queryRuleByRuleName(correlationRule.getName());
+ } catch (Exception e) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR, e);
}
- CorrelationRule ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .queryRuleByRuleName(correlationRule.getName());
if (ruleTemp != null) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);
}
correlationRule.setPackageName(deployRule2Engine(correlationRule));
try {
correlationRule = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .saveRule(correlationRule);
- } catch (RuntimeException e) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED, e);
+ .saveRule(correlationRule);
+ } catch (Exception e) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED, e);
}
RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();
ruleAddAndUpdateResponse.setRuleId(correlationRule.getRid());
@@ -81,17 +84,22 @@ public class RuleMgtWrapper {
}
public RuleAddAndUpdateResponse updateCorrelationRule(String modifier,
- RuleUpdateRequest ruleUpdateRequest)
- throws DataFormatException, DbException, CallException {
+ RuleUpdateRequest ruleUpdateRequest)
+ throws CorrelationException {
if (ruleUpdateRequest != null) {
- CorrelationRule oldCorrelationRule = daoUtil
- .getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .getRuleByRid(ruleUpdateRequest.getRuleId());
+ CorrelationRule oldCorrelationRule;
+ try {
+ oldCorrelationRule = daoUtil
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)
+ .getRuleByRid(ruleUpdateRequest.getRuleId());
+ } catch (Exception e) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR, e);
+ }
if (oldCorrelationRule == null) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);
}
CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,
- ruleUpdateRequest);
+ ruleUpdateRequest);
checkCorrelation(newCorrelationRule, oldCorrelationRule);
RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();
try {
@@ -99,65 +107,68 @@ public class RuleMgtWrapper {
engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName());
}
daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .updateRule(newCorrelationRule);
- } catch (RuntimeException e) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED, e);
+ .updateRule(newCorrelationRule);
+ } catch (Exception e) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED, e);
}
ruleChangeResponse.setRuleId(newCorrelationRule.getRid());
deployRule2Engine(newCorrelationRule);
return ruleChangeResponse;
} else {
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
}
}
public void checkCorrelation(CorrelationRule newCorrelationRule,
- CorrelationRule oldCorrelationRule) throws DataFormatException {
+ CorrelationRule oldCorrelationRule) throws CorrelationException {
int newEnabled = newCorrelationRule.getEnabled();
if (newCorrelationRule.getContent() == null) {
newCorrelationRule.setContent(oldCorrelationRule.getContent());
}
if (newEnabled != RuleMgtConstant.STATUS_RULE_CLOSE
- && newEnabled != RuleMgtConstant.STATUS_RULE_OPEN) {
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);
+ && newEnabled != RuleMgtConstant.STATUS_RULE_OPEN) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);
}
}
public void deleteCorrelationRule(RuleDeleteRequest ruleDeleteRequest)
- throws DbException, DataFormatException, CallException {
+ throws CorrelationException {
if (ruleDeleteRequest != null) {
- CorrelationRule correlationRule = daoUtil
- .getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .getRuleByRid(ruleDeleteRequest.getRuleId());
+ CorrelationRule correlationRule;
+ try {
+ correlationRule = daoUtil
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)
+ .getRuleByRid(ruleDeleteRequest.getRuleId());
+ } catch (Exception e) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);
+ }
if (correlationRule == null) {
log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId()
- + " does not exist the database.");
- throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);
+ + " does not exist the database.");
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);
}
try {
if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {
engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName());
}
daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .deleteRule(correlationRule);
- } catch (RuntimeException e) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED, e);
+ .deleteRule(correlationRule);
+ } catch (Exception e) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED, e);
}
- } else
-
- {
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ } else {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
}
}
public CorrelationRule convertRuleCreateRequest2CorrelationRule(String userName,
- RuleCreateRequest ruleCreateRequest) throws DataFormatException {
+ RuleCreateRequest ruleCreateRequest) throws CorrelationException {
if (ruleCreateRequest != null) {
if (ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_OPEN
- && ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_CLOSE) {
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ && ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_CLOSE) {
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
}
CorrelationRule correlationRule = new CorrelationRule();
String ruleId = "rule_" + System.currentTimeMillis();
@@ -177,13 +188,13 @@ public class RuleMgtWrapper {
correlationRule.setEnabled(ruleCreateRequest.getEnabled());
return correlationRule;
} else {
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
}
}
private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,
- RuleUpdateRequest ruleUpdateRequest) throws DataFormatException {
+ RuleUpdateRequest ruleUpdateRequest) throws CorrelationException {
if (ruleUpdateRequest != null) {
CorrelationRule correlationRule = new CorrelationRule();
correlationRule.setRid(ruleUpdateRequest.getRuleId());
@@ -194,12 +205,12 @@ public class RuleMgtWrapper {
correlationRule.setModifier(modifier);
return correlationRule;
} else {
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
}
}
- private String deployRule2Engine(CorrelationRule correlationRule) throws CallException {
+ private String deployRule2Engine(CorrelationRule correlationRule) throws CorrelationException {
if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule))) {
if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {
return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule));
@@ -209,18 +220,18 @@ public class RuleMgtWrapper {
}
public RuleQueryListResponse getCorrelationRuleByCondition(
- RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {
+ RuleQueryCondition ruleQueryCondition) throws CorrelationException {
List<CorrelationRule> correlationRule = correlationRuleQueryDao
- .getCorrelationRulesByCondition(ruleQueryCondition);
+ .getCorrelationRulesByCondition(ruleQueryCondition);
RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
ruleQueryListResponse.setTotalCount(correlationRule.size());
ruleQueryListResponse
- .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));
+ .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));
return ruleQueryListResponse;
}
private List<RuleResult4API> correlationRules2RuleResult4APIs(
- List<CorrelationRule> correlationRules) {
+ List<CorrelationRule> correlationRules) {
List<RuleResult4API> ruleResult4APIs = new ArrayList<RuleResult4API>();
for (CorrelationRule correlationRule : correlationRules) {
RuleResult4API ruleResult4API = new RuleResult4API();
@@ -239,7 +250,7 @@ public class RuleMgtWrapper {
}
private CorrelationDeployRule4Engine correlationRules2DeployRule(
- CorrelationRule correlationRule) {
+ CorrelationRule correlationRule) {
CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
correlationDeployRule4Engine.setContent(correlationRule.getContent());
correlationDeployRule4Engine.setEngineId(correlationRule.getEngineId());
@@ -247,7 +258,7 @@ public class RuleMgtWrapper {
}
private CorrelationCheckRule4Engine correlationRules2CheckRule(
- CorrelationRule correlationRule) {
+ CorrelationRule correlationRule) {
CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();
correlationCheckRule4Engine.setContent(correlationRule.getContent());
return correlationCheckRule4Engine;