import org.hibernate.validator.constraints.NotEmpty;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
-import lombok.Getter;
public class RuleAppConfig extends Configuration {
\r
import lombok.extern.slf4j.Slf4j;\r
import org.jvnet.hk2.annotations.Service;\r
-import org.openo.holmes.common.exception.CallException;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
\r
public class EngineWrapper {\r
\r
\r
- public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CallException {\r
+ public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {\r
return "";\r
}\r
\r
- public boolean deleteRuleFromEngine(String packageName) throws CallException {\r
+ public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {\r
return true;\r
}\r
\r
public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
- throws CallException {\r
+ throws CorrelationException {\r
return true;\r
}\r
}\r
package org.openo.holmes.rulemgt.constant;\r
\r
public class RuleMgtConstant {\r
+\r
public static final int STATUS_RULE_OPEN = 1;\r
public static final int STATUS_RULE_CLOSE = 0;\r
public static final int STATUS_RULE_ALL = 2;\r
public static final String PACKAGE_NAME = "packagename";\r
+\r
+ private RuleMgtConstant() {\r
+\r
+ }\r
}\r
private void deleteRule2DbInner(CorrelationRule correlationRule) {\r
String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";\r
String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";\r
- if (!name.equals("") && !rid.equals("")) {\r
+ if (!"".equals(name) && !"".equals(rid)) {\r
deleteRuleByRidAndName(rid, name);\r
- } else if (!rid.equals("")) {\r
+ } else if (!"".equals(rid)) {\r
deleteRuleByRid(rid);\r
}\r
}\r
*/\r
package org.openo.holmes.rulemgt.db;\r
\r
-import org.openo.holmes.common.api.entity.CorrelationRule;\r
-import org.openo.holmes.common.exception.DataFormatException;\r
-import org.openo.holmes.common.exception.DbException;\r
-import org.openo.holmes.common.utils.DbDaoUtil;\r
-import org.openo.holmes.common.utils.I18nProxy;\r
-import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;\r
-import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
-import lombok.extern.slf4j.Slf4j;\r
-import org.jvnet.hk2.annotations.Service;\r
-import org.skife.jdbi.v2.Handle;\r
-import org.skife.jdbi.v2.Query;\r
-\r
-import javax.inject.Inject;\r
import java.beans.PropertyDescriptor;\r
import java.lang.reflect.Field;\r
import java.lang.reflect.Method;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Properties;\r
+import javax.inject.Inject;\r
+import lombok.extern.slf4j.Slf4j;\r
+import org.jvnet.hk2.annotations.Service;\r
+import org.openo.holmes.common.api.entity.CorrelationRule;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
+import org.openo.holmes.common.utils.DbDaoUtil;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
+import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;\r
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
+import org.skife.jdbi.v2.Handle;\r
+import org.skife.jdbi.v2.Query;\r
\r
@Service\r
@Slf4j\r
public class CorrelationRuleQueryDao {\r
+\r
@Inject\r
private DbDaoUtil dbDaoUtil;\r
\r
- public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {\r
+ public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)\r
+ throws CorrelationException {\r
List<CorrelationRule> correlationRules = new ArrayList<CorrelationRule>();\r
Handle handle = null;\r
String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);\r
return correlationRules;\r
} catch (Exception e) {\r
log.warn("Query rule: rule id =" + ruleQueryCondition.getRid() + " failed");\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED, e);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED, e);\r
} finally {\r
dbDaoUtil.close(handle);\r
}\r
return correlationRule;\r
}\r
\r
- private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws DataFormatException {\r
+ private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws CorrelationException {\r
try {\r
Class clazz = ruleQueryCondition.getClass();\r
Field[] fields = clazz.getDeclaredFields();\r
for (Field field : fields) {\r
PropertyDescriptor pd = new PropertyDescriptor(field.getName(),\r
clazz);\r
- Method getMethod = pd.getReadMethod();//获得get方法\r
- Object o = getMethod.invoke(ruleQueryCondition);//执行get方法返回一个Object\r
+ Method getMethod = pd.getReadMethod();\r
+ Object o = getMethod.invoke(ruleQueryCondition);\r
if (o != null) {\r
- if (field.getName().equals("enabled")) {\r
- int enabled = (int) o;\r
- if (enabled != RuleMgtConstant.STATUS_RULE_ALL) {\r
- whereSql = whereSql + "enable =" + enabled;\r
- whereSql += " AND ";\r
- }\r
- } else if (field.getName().equals("name")) {\r
- if (!"".equals(o.toString().trim())) {\r
- whereSql = whereSql + field.getName() + " like '%" + o + "%' AND ";\r
- }\r
- } else {\r
- if (!"".equals(o.toString().trim())) {\r
- whereSql = whereSql + field.getName() + "='" + o + "' AND ";\r
- }\r
+ String tempName = field.getName();\r
+ if ("enabled".equals(tempName) && (int) o != RuleMgtConstant.STATUS_RULE_ALL) {\r
+ whereSql = whereSql + "enable =" + (int) o;\r
+ whereSql += " AND ";\r
+ } else if ("name".equals(tempName) && !"".equals(o.toString().trim())) {\r
+ whereSql = whereSql + field.getName() + " like '%" + o + "%' AND ";\r
+ } else if (!"".equals(o.toString().trim())) {\r
+ whereSql = whereSql + field.getName() + "='" + o + "' AND ";\r
}\r
}\r
}\r
}\r
return "";\r
} catch (Exception e) {\r
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);\r
}\r
}\r
}\r
import javax.ws.rs.core.MediaType;\r
import lombok.extern.slf4j.Slf4j;\r
import org.jvnet.hk2.annotations.Service;\r
-import org.openo.holmes.common.exception.CallException;\r
-import org.openo.holmes.common.exception.DataFormatException;\r
-import org.openo.holmes.common.exception.DbException;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
import org.openo.holmes.common.utils.ExceptionUtil;\r
import org.openo.holmes.common.utils.I18nProxy;\r
import org.openo.holmes.common.utils.JacksonUtil;\r
@ApiOperation(value = "Save the alarm+ rule to the database, and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)\r
@Timed\r
public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,\r
- @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) {\r
+ @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) {\r
Locale locale = LanguageUtil.getLocale(request);\r
RuleAddAndUpdateResponse ruleChangeResponse;\r
try {\r
ruleChangeResponse = ruleMgtWrapper\r
- .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);\r
+ .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);\r
log.info("create rule:" + ruleCreateRequest.getRuleName() + " success.");\r
return ruleChangeResponse;\r
- } catch (CallException e) {\r
+ } catch (CorrelationException e) {\r
log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (DbException e) {\r
- log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (DataFormatException e) {\r
- log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (Exception e) {\r
- log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+ e.getMessage()));\r
}\r
}\r
\r
@ApiOperation(value = "Update the alarm+ rule and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)\r
@Timed\r
public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,\r
- @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {\r
+ @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {\r
Locale locale = LanguageUtil.getLocale(request);\r
RuleAddAndUpdateResponse ruleChangeResponse;\r
try {\r
ruleChangeResponse = ruleMgtWrapper\r
- .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
+ .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
return ruleChangeResponse;\r
- } catch (CallException e) {\r
+ } catch (CorrelationException e) {\r
log.error("create rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (DataFormatException e) {\r
- log.error("update alarm plus rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (DbException e) {\r
- log.error("update rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (Exception e) {\r
- log.error("update rule:" + ruleUpdateRequest.getRuleId() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+ e.getMessage()));\r
}\r
}\r
\r
@ApiOperation(value = "Delete the alarm+ rule,and when the enable is open also removed from the engine.")\r
@Timed\r
public boolean deleteCorrelationRule(@Context HttpServletRequest request,\r
- @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {\r
+ @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {\r
Locale locale = LanguageUtil.getLocale(request);\r
try {\r
ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
log.info("delete rule:" + ruleDeleteRequest.getRuleId() + " successful");\r
return true;\r
- } catch (DataFormatException e) {\r
+ } catch (CorrelationException e) {\r
log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (DbException e) {\r
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (CallException e) {\r
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (Exception e) {\r
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+ e.getMessage()));\r
}\r
}\r
\r
@ApiOperation(value = "According to the conditions query the alarm + rules", response = RuleQueryListResponse.class)\r
@Timed\r
public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,\r
- @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"\r
- + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"\r
- + "<b>[modifier]</b>:modifier of the rule;<br>"\r
- + "<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) {\r
+ @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"\r
+ + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"\r
+ + "<b>[modifier]</b>:modifier of the rule;<br>"\r
+ + "<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) {\r
Locale locale = LanguageUtil.getLocale(request);\r
RuleQueryListResponse ruleQueryListResponse;\r
RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);\r
try {\r
ruleQueryListResponse = ruleMgtWrapper\r
- .getCorrelationRuleByCondition(ruleQueryCondition);\r
+ .getCorrelationRuleByCondition(ruleQueryCondition);\r
return ruleQueryListResponse;\r
- } catch (DataFormatException e) {\r
+ } catch (CorrelationException e) {\r
log.error("query rule failed,cause query condition conversion failure", e);\r
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (DbException e) {\r
- log.error("query rule failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- e.getMessage()));\r
- } catch (Exception e) {\r
- log.error("query rule failed", e);\r
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+ e.getMessage()));\r
}\r
}\r
\r
private RuleQueryCondition getRuleQueryCondition(String queryRequest,\r
- HttpServletRequest request) {\r
+ HttpServletRequest request) {\r
Locale locale = LanguageUtil.getLocale(request);\r
try {\r
RuleQueryCondition ruleQueryCondition = JacksonUtil\r
- .jsonToBean(queryRequest, RuleQueryCondition.class);\r
+ .jsonToBean(queryRequest, RuleQueryCondition.class);\r
if (queryRequest == null) {\r
ruleQueryCondition.setEnabled(2);\r
} else if (queryRequest.indexOf("enabled") == -1) {\r
} catch (IOException e) {\r
log.warn("queryRequest convert to json failed", e);\r
throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
- I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));\r
+ I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));\r
}\r
}\r
\r
import lombok.extern.slf4j.Slf4j;\r
import org.jvnet.hk2.annotations.Service;\r
import org.openo.holmes.common.api.entity.CorrelationRule;\r
-import org.openo.holmes.common.exception.CallException;\r
-import org.openo.holmes.common.exception.DataFormatException;\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.common.utils.I18nProxy;\r
import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
private DbDaoUtil daoUtil;\r
\r
public RuleAddAndUpdateResponse addCorrelationRule(String creator,\r
- RuleCreateRequest ruleCreateRequest)\r
- throws DataFormatException, CallException, DbException {\r
+ RuleCreateRequest ruleCreateRequest)\r
+ throws CorrelationException {\r
CorrelationRule correlationRule = convertRuleCreateRequest2CorrelationRule(creator,\r
- ruleCreateRequest);\r
+ ruleCreateRequest);\r
if (correlationRule.getName() == null || "".equals(correlationRule.getName().trim())) {\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
+ }\r
+ CorrelationRule ruleTemp;\r
+ try {\r
+ ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+ .queryRuleByRuleName(correlationRule.getName());\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR, e);\r
}\r
- CorrelationRule ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
- .queryRuleByRuleName(correlationRule.getName());\r
if (ruleTemp != null) {\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
}\r
correlationRule.setPackageName(deployRule2Engine(correlationRule));\r
try {\r
correlationRule = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
- .saveRule(correlationRule);\r
- } catch (RuntimeException e) {\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED, e);\r
+ .saveRule(correlationRule);\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED, e);\r
}\r
RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();\r
ruleAddAndUpdateResponse.setRuleId(correlationRule.getRid());\r
}\r
\r
public RuleAddAndUpdateResponse updateCorrelationRule(String modifier,\r
- RuleUpdateRequest ruleUpdateRequest)\r
- throws DataFormatException, DbException, CallException {\r
+ RuleUpdateRequest ruleUpdateRequest)\r
+ throws CorrelationException {\r
if (ruleUpdateRequest != null) {\r
- CorrelationRule oldCorrelationRule = daoUtil\r
- .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
- .getRuleByRid(ruleUpdateRequest.getRuleId());\r
+ CorrelationRule oldCorrelationRule;\r
+ try {\r
+ oldCorrelationRule = daoUtil\r
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+ .getRuleByRid(ruleUpdateRequest.getRuleId());\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR, e);\r
+ }\r
if (oldCorrelationRule == null) {\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
}\r
CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,\r
- ruleUpdateRequest);\r
+ ruleUpdateRequest);\r
checkCorrelation(newCorrelationRule, oldCorrelationRule);\r
RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();\r
try {\r
engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName());\r
}\r
daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
- .updateRule(newCorrelationRule);\r
- } catch (RuntimeException e) {\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED, e);\r
+ .updateRule(newCorrelationRule);\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED, e);\r
}\r
ruleChangeResponse.setRuleId(newCorrelationRule.getRid());\r
deployRule2Engine(newCorrelationRule);\r
return ruleChangeResponse;\r
} else {\r
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
}\r
\r
}\r
\r
public void checkCorrelation(CorrelationRule newCorrelationRule,\r
- CorrelationRule oldCorrelationRule) throws DataFormatException {\r
+ CorrelationRule oldCorrelationRule) throws CorrelationException {\r
int newEnabled = newCorrelationRule.getEnabled();\r
if (newCorrelationRule.getContent() == null) {\r
newCorrelationRule.setContent(oldCorrelationRule.getContent());\r
}\r
if (newEnabled != RuleMgtConstant.STATUS_RULE_CLOSE\r
- && newEnabled != RuleMgtConstant.STATUS_RULE_OPEN) {\r
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
+ && newEnabled != RuleMgtConstant.STATUS_RULE_OPEN) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
}\r
}\r
\r
public void deleteCorrelationRule(RuleDeleteRequest ruleDeleteRequest)\r
- throws DbException, DataFormatException, CallException {\r
+ throws CorrelationException {\r
if (ruleDeleteRequest != null) {\r
- CorrelationRule correlationRule = daoUtil\r
- .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
- .getRuleByRid(ruleDeleteRequest.getRuleId());\r
+ CorrelationRule correlationRule;\r
+ try {\r
+ correlationRule = daoUtil\r
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+ .getRuleByRid(ruleDeleteRequest.getRuleId());\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+ }\r
if (correlationRule == null) {\r
log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId()\r
- + " does not exist the database.");\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
+ + " does not exist the database.");\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
}\r
try {\r
if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName());\r
}\r
daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
- .deleteRule(correlationRule);\r
- } catch (RuntimeException e) {\r
- throw new DbException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED, e);\r
+ .deleteRule(correlationRule);\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED, e);\r
}\r
- } else\r
-\r
- {\r
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ } else {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
}\r
\r
}\r
\r
public CorrelationRule convertRuleCreateRequest2CorrelationRule(String userName,\r
- RuleCreateRequest ruleCreateRequest) throws DataFormatException {\r
+ RuleCreateRequest ruleCreateRequest) throws CorrelationException {\r
if (ruleCreateRequest != null) {\r
if (ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_OPEN\r
- && ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_CLOSE) {\r
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ && ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_CLOSE) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
}\r
CorrelationRule correlationRule = new CorrelationRule();\r
String ruleId = "rule_" + System.currentTimeMillis();\r
correlationRule.setEnabled(ruleCreateRequest.getEnabled());\r
return correlationRule;\r
} else {\r
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
}\r
\r
}\r
\r
private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,\r
- RuleUpdateRequest ruleUpdateRequest) throws DataFormatException {\r
+ RuleUpdateRequest ruleUpdateRequest) throws CorrelationException {\r
if (ruleUpdateRequest != null) {\r
CorrelationRule correlationRule = new CorrelationRule();\r
correlationRule.setRid(ruleUpdateRequest.getRuleId());\r
correlationRule.setModifier(modifier);\r
return correlationRule;\r
} else {\r
- throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
}\r
\r
}\r
\r
- private String deployRule2Engine(CorrelationRule correlationRule) throws CallException {\r
+ private String deployRule2Engine(CorrelationRule correlationRule) throws CorrelationException {\r
if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule))) {\r
if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule));\r
}\r
\r
public RuleQueryListResponse getCorrelationRuleByCondition(\r
- RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {\r
+ RuleQueryCondition ruleQueryCondition) throws CorrelationException {\r
List<CorrelationRule> correlationRule = correlationRuleQueryDao\r
- .getCorrelationRulesByCondition(ruleQueryCondition);\r
+ .getCorrelationRulesByCondition(ruleQueryCondition);\r
RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();\r
ruleQueryListResponse.setTotalCount(correlationRule.size());\r
ruleQueryListResponse\r
- .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));\r
+ .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));\r
return ruleQueryListResponse;\r
}\r
\r
private List<RuleResult4API> correlationRules2RuleResult4APIs(\r
- List<CorrelationRule> correlationRules) {\r
+ List<CorrelationRule> correlationRules) {\r
List<RuleResult4API> ruleResult4APIs = new ArrayList<RuleResult4API>();\r
for (CorrelationRule correlationRule : correlationRules) {\r
RuleResult4API ruleResult4API = new RuleResult4API();\r
}\r
\r
private CorrelationDeployRule4Engine correlationRules2DeployRule(\r
- CorrelationRule correlationRule) {\r
+ CorrelationRule correlationRule) {\r
CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
correlationDeployRule4Engine.setContent(correlationRule.getContent());\r
correlationDeployRule4Engine.setEngineId(correlationRule.getEngineId());\r
}\r
\r
private CorrelationCheckRule4Engine correlationRules2CheckRule(\r
- CorrelationRule correlationRule) {\r
+ CorrelationRule correlationRule) {\r
CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();\r
correlationCheckRule4Engine.setContent(correlationRule.getContent());\r
return correlationCheckRule4Engine;\r
import org.junit.rules.ExpectedException;\r
import org.junit.runner.RunWith;\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.common.utils.I18nProxy;\r
import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;\r
@Test\r
public void getCorrelationRulesByCondition_db_exception() throws Exception {\r
\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED);\r
\r
EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);\r
import org.junit.Rule;\r
import org.junit.Test;\r
import org.junit.rules.ExpectedException;\r
-import org.openo.holmes.common.exception.CallException;\r
-import org.openo.holmes.common.exception.DataFormatException;\r
-import org.openo.holmes.common.exception.DbException;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
import org.openo.holmes.rulemgt.bean.request.RuleCreateRequest;\r
import org.openo.holmes.rulemgt.bean.request.RuleDeleteRequest;\r
import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;\r
}\r
\r
@Test\r
- public void addCorrelationRule_call_exception() throws Exception {\r
+ public void addCorrelationRule_correlation_exception() throws Exception {\r
thrown.expect(WebApplicationException.class);\r
\r
final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))\r
- .andThrow(new CallException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
- PowerMock.replayAll();\r
- ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void addCorrelationRule_db_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
- EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest)).andThrow(new DbException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
- PowerMock.replayAll();\r
- ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void addCorrelationRule_data_format_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
- EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))\r
- .andThrow(new DataFormatException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
- PowerMock.replayAll();\r
- ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void addCorrelationRule_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
- EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))\r
- .andThrow(new RuntimeException(""));\r
+ .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
PowerMock.replayAll();\r
}\r
\r
@Test\r
- public void updateCorrelationRule_call_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
- EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
- .andThrow(new CallException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
- PowerMock.replayAll();\r
- ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void updateCorrelationRule_data_format_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
- EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
- .andThrow(new DataFormatException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
- PowerMock.replayAll();\r
- ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void updateCorrelationRule_db_exception() throws Exception {\r
+ public void updateCorrelationRule_correlation_exception() throws Exception {\r
thrown.expect(WebApplicationException.class);\r
\r
final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
- .andThrow(new DbException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
- PowerMock.replayAll();\r
- ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void updateCorrelationRule_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
- EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
- .andThrow(new RuntimeException(""));\r
+ .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
PowerMock.replayAll();\r
}\r
\r
@Test\r
- public void deleteCorrelationRule_call_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
- ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
- EasyMock.expectLastCall().andThrow(new CallException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- PowerMock.replayAll();\r
- ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void deleteCorrelationRule_data_format_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
- ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
- EasyMock.expectLastCall().andThrow(new DataFormatException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- PowerMock.replayAll();\r
- ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void deleteCorrelationRule_db_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
- ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
- EasyMock.expectLastCall().andThrow(new DbException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
- PowerMock.replayAll();\r
- ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void deleteCorrelationRule_exception() throws Exception {\r
+ public void deleteCorrelationRule_correlation_exception() throws Exception {\r
thrown.expect(WebApplicationException.class);\r
\r
final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
- EasyMock.expectLastCall().andThrow(new RuntimeException(""));\r
+ EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
PowerMock.replayAll();\r
ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","\r
+ "\"enabled\":0,\"creator\":\"admin\"}";\r
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
- .andThrow(new DataFormatException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
- PowerMock.replayAll();\r
- ruleMgtResources.getCorrelationRules(request, requestStr);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void getCorrelationRules_db_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","\r
- + "\"enabled\":0,\"creator\":\"admin\"}";\r
- EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
- .andThrow(new DbException(""));\r
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
- PowerMock.replayAll();\r
- ruleMgtResources.getCorrelationRules(request, requestStr);\r
- PowerMock.verifyAll();\r
- }\r
-\r
- @Test\r
- public void getCorrelationRules_exception() throws Exception {\r
- thrown.expect(WebApplicationException.class);\r
-\r
- final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","\r
- + "\"enabled\":0,\"creator\":\"admin\"}";\r
- EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
- .andThrow(new RuntimeException(""));\r
+ .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
PowerMock.replayAll();\r
ruleMgtResources.getCorrelationRules(request, requestStr);\r
PowerMock.verifyAll();\r
}\r
\r
-\r
@Test\r
public void getCorrelationRules_normal_request_string_null() throws Exception {\r
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
import static org.hamcrest.Matchers.equalTo;\r
import static org.hamcrest.Matchers.is;\r
\r
-\r
import java.util.ArrayList;\r
import java.util.Date;\r
import java.util.List;\r
import org.junit.rules.ExpectedException;\r
import org.junit.runner.RunWith;\r
import org.openo.holmes.common.api.entity.CorrelationRule;\r
-import org.openo.holmes.common.exception.CallException;\r
-import org.openo.holmes.common.exception.DataFormatException;\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.common.utils.I18nProxy;\r
import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
\r
@Test\r
public void addCorrelationRule_name_is_null() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
\r
ruleMgtWrapper.addCorrelationRule(USER_NAME, createRuleCreateRequest(null, "This is a rule for testing.",\r
\r
@Test\r
public void addCorrelationRule_name_is_empty() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
\r
ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("", "This is a rule for testing.",\r
"Mocked contents.", 0));\r
}\r
\r
+ @Test\r
+ public void addCorrelationRule_rule_query_exception() throws Exception {\r
+\r
+ final String ruleName = "Rule-001";\r
+\r
+ RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
+ "Mocked contents.", 0);\r
+\r
+ thrown.expect(CorrelationException.class);\r
+ thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+\r
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
+ correlationRuleDaoMock);\r
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName))\r
+ .andThrow(new RuntimeException(""));\r
+\r
+ PowerMock.replayAll();\r
+\r
+ ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);\r
+\r
+ PowerMock.verifyAll();\r
+ }\r
+\r
@Test\r
public void addCorrelationRule_duplicated_rule() throws Exception {\r
\r
"Mocked contents.", 0);\r
CorrelationRule correlationRule = convertCreateRequest2CorrelationRule(ruleCreateRequest);\r
\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
"Mocked contents.", 0);\r
\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
correlationRuleDaoMock);\r
EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
"Mocked contents.", 1);\r
\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
.andReturn(true);\r
EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
"Mocked contents.", 1);\r
\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
\r
@Test\r
public void updateCorrelationRule_param_null() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
\r
ruleMgtWrapper.updateCorrelationRule(USER_NAME, null);\r
}\r
\r
+ @Test\r
+ public void updateCorrelationRule_rule_query_exception() throws Exception {\r
+ thrown.expect(CorrelationException.class);\r
+ thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+\r
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
+ correlationRuleDaoMock);\r
+ EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
+ .andThrow(new RuntimeException(""));\r
+\r
+ PowerMock.replayAll();\r
+\r
+ ruleMgtWrapper.updateCorrelationRule(USER_NAME, new RuleUpdateRequest());\r
+\r
+ PowerMock.verifyAll();\r
+ }\r
+\r
@Test\r
public void updateCorrelationRule_rule_not_exist() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
\r
@Test\r
public void updateCorrelationRule_rule_status_illegal_with_contents() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_status_illegal_with_null_contents() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_disabled_update_failure() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_disabled_deploy_verify_exception() throws Exception {\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));\r
EasyMock.expectLastCall();\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
\r
@Test\r
public void updateCorrelationRule_rule_enabled_engine_delete_failure() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_enabled_engine_deploy_failure() throws Exception {\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
.andReturn(true);\r
EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
\r
@Test\r
public void checkCorrelation_illegal_status() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
\r
RuleUpdateRequest ruleCreateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void deleteCorrelationRule_request_null() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY));\r
\r
ruleMgtWrapper.deleteCorrelationRule(null);\r
}\r
\r
+ @Test\r
+ public void deleteCorrelationRule_rule_query_exception() throws Exception {\r
+ thrown.expect(CorrelationException.class);\r
+ thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DB_ERROR));\r
+\r
+ RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
+\r
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
+ correlationRuleDaoMock).anyTimes();\r
+ EasyMock.expect(correlationRuleDaoMock.getRuleByRid(ruleDeleteRequest.getRuleId()))\r
+ .andThrow(new RuntimeException(""));\r
+\r
+ PowerMock.replayAll();\r
+\r
+ ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
+\r
+ PowerMock.verifyAll();\r
+ }\r
+\r
@Test\r
public void deleteCorrelationRule_rule_not_exit() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE));\r
\r
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
\r
@Test\r
public void deleteCorrelationRule_rule_enabled_engine_delete_exception() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED));\r
\r
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
\r
@Test\r
public void deleteCorrelationRule_rule_disabled_delete_exception() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED));\r
\r
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
\r
@Test\r
public void getCorrelationRuleByCondition_data_format_exception() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED));\r
\r
EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(\r
RuleQueryCondition.class)))\r
- .andThrow(new DataFormatException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED));\r
\r
PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);\r
\r
\r
@Test\r
public void getCorrelationRuleByCondition_db_exception() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED));\r
\r
EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(\r
RuleQueryCondition.class)))\r
- .andThrow(new DbException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED));\r
\r
PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);\r
\r