diff options
author | youbowu <wu.youbo@zte.com.cn> | 2017-02-15 14:39:20 +0800 |
---|---|---|
committer | 6092002067 <wu.youbo@zte.com.cn> | 2017-02-15 15:15:04 +0800 |
commit | 0dfbbb4d600009094b842fe0b0d4f0413b37dfc1 (patch) | |
tree | 3f826fa10db3c10f61b5f0e26c163b6e045ce442 /rulemgt/src/main | |
parent | a7171ca0509f65fa2dc2146f40a0f93b9ea6f95a (diff) |
Add module holms-rule-management code
Issue-ID:HOLMES-4
Change-Id: I3a22053acfdf0789acb6fcbbc5e8740d25d6b2eb
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
Diffstat (limited to 'rulemgt/src/main')
15 files changed, 1052 insertions, 0 deletions
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java new file mode 100644 index 0000000..3ed4c4d --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java @@ -0,0 +1,31 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.request;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class CorrelationDeployRule4Engine {
+ @JsonProperty(value = "content")
+ private String content;
+
+ @JsonProperty(value = "engineid")
+ private String engineId;
+
+}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleCreateRequest.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleCreateRequest.java new file mode 100644 index 0000000..9407b99 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleCreateRequest.java @@ -0,0 +1,33 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.request;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Setter
+@Getter
+public class RuleCreateRequest {
+ @JsonProperty(value = "rulename")
+ private String ruleName;
+ @JsonProperty
+ private String description;
+ @JsonProperty
+ private String content;
+ @JsonProperty
+ private int enabled;
+}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleDeleteRequest.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleDeleteRequest.java new file mode 100644 index 0000000..ac9d795 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleDeleteRequest.java @@ -0,0 +1,28 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.request;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+
+@Setter
+@Getter
+public class RuleDeleteRequest {
+ @JsonProperty(value = "ruleid")
+ private String ruleId;
+}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleQueryCondition.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleQueryCondition.java new file mode 100644 index 0000000..c68b40d --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleQueryCondition.java @@ -0,0 +1,34 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.request;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class RuleQueryCondition {
+
+ @JsonProperty(value = "ruleid")
+ private String rid;
+ @JsonProperty(value = "rulename")
+ private String name;
+ private int enabled;
+ private String creator;
+ private String modifier;
+
+}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequest.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequest.java new file mode 100644 index 0000000..6ce265a --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequest.java @@ -0,0 +1,33 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.request;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class RuleUpdateRequest {
+ @JsonProperty
+ private String description;
+ @JsonProperty
+ private String content;
+ @JsonProperty
+ private int enabled;
+ @JsonProperty(value="ruleid")
+ private String ruleId;
+}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java new file mode 100644 index 0000000..e5597b8 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java @@ -0,0 +1,29 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.response;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@JsonInclude(JsonInclude.Include.ALWAYS)
+@Getter
+@Setter
+public class RuleAddAndUpdateResponse{
+ @JsonProperty(value="ruleid")
+ private String ruleId;
+}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponse.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponse.java new file mode 100644 index 0000000..a720eca --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponse.java @@ -0,0 +1,34 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.response;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@JsonInclude(JsonInclude.Include.ALWAYS)
+@Getter
+@Setter
+public class RuleQueryListResponse {
+ @JsonProperty(value = "rules")
+ private List<RuleResult4API> correlationRules = new ArrayList<RuleResult4API>();
+ @JsonProperty(value = "totalcount")
+ private int totalCount;
+}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleResult4API.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleResult4API.java new file mode 100644 index 0000000..ee948d0 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleResult4API.java @@ -0,0 +1,42 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.bean.response;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@JsonInclude(JsonInclude.Include.ALWAYS)
+@Setter
+@Getter
+public class RuleResult4API {
+ @JsonProperty(value = "ruleid")
+ private String ruleId;
+ @JsonProperty(value = "rulename")
+ private String ruleName;
+ private String description;
+ private String content;
+ @JsonProperty(value = "createtime")
+ private Date createTime;
+ private String creator;
+ @JsonProperty(value = "updatetime")
+ private Date updateTime;
+ private String modifier;
+ private int enabled;
+}
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 new file mode 100644 index 0000000..e2f4fdd --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java @@ -0,0 +1,41 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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.rulemgt.bean.request.CorrelationCheckRule4Engine;
+import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
+
+@Service
+@Slf4j
+public class EngineWrapper {
+
+
+ public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CallException {
+ return "";
+ }
+
+ public boolean deleteRuleFromEngine(String packageName) throws CallException {
+ return true;
+ }
+
+ public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)
+ throws CallException {
+ 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 new file mode 100644 index 0000000..55c3cd8 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java @@ -0,0 +1,23 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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";
+}
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 new file mode 100644 index 0000000..7a7a0eb --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java @@ -0,0 +1,85 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.db;
+
+import org.openo.holmes.common.api.entity.CorrelationRule;
+import org.openo.holmes.rulemgt.db.mapper.CorrelationRuleMapper;
+import org.skife.jdbi.v2.sqlobject.Bind;
+import org.skife.jdbi.v2.sqlobject.BindBean;
+import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
+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);
+
+ @SqlUpdate("UPDATE APLUS_RULE SET DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime WHERE RID=:rid")
+ protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
+ protected abstract int deleteRuleByRid(@Bind("rid") String rid);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
+ protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE")
+ protected abstract List<CorrelationRule> queryAllRules();
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
+ public abstract CorrelationRule queryRuleByRid(@Bind("rid") String rid);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
+ public abstract CorrelationRule queryRuleByName(@Bind("name") String name);
+
+ 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("")) {
+ deleteRuleByRidAndName(rid, name);
+ } else if (!rid.equals("")) {
+ deleteRuleByRid(rid);
+ }
+ }
+
+ public CorrelationRule saveRule(CorrelationRule correlationRule) {
+ addRule(correlationRule);
+ return correlationRule;
+ }
+
+ public void updateRule(CorrelationRule correlationRule){
+ updateRuleByRid(correlationRule);
+ }
+
+ public void deleteRule(CorrelationRule correlationRule) {
+ deleteRule2DbInner(correlationRule);
+ }
+
+
+ public CorrelationRule getRuleByRid(String rid) {
+ return queryRuleByRid(rid);
+ }
+
+ public CorrelationRule queryRuleByRuleName(String name) {
+ return queryRuleByName(name);
+ }
+}
+
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 new file mode 100644 index 0000000..9b66ae5 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java @@ -0,0 +1,127 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+@Service
+@Slf4j
+public class CorrelationRuleQueryDao {
+ @Inject
+ private DbDaoUtil dbDaoUtil;
+
+ public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {
+ List<CorrelationRule> correlationRules = new ArrayList<CorrelationRule>();
+ Handle handle = null;
+ String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);
+ try {
+ StringBuilder querySql = new StringBuilder("SELECT * FROM APLUS_RULE ").append(whereStr);
+ handle = dbDaoUtil.getHandle();
+ Query query = handle.createQuery(querySql.toString());
+ for (Object value : query.list()) {
+ CorrelationRule correlationRule = getCorrelationRule((Map) value);
+ correlationRules.add(correlationRule);
+ }
+ return correlationRules;
+ } catch (Exception e) {
+ log.warn("Query rule: rule id =" + ruleQueryCondition.getRid() + " failed");
+ throw new DbException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED, e);
+ } finally {
+ dbDaoUtil.close(handle);
+ }
+ }
+
+ private CorrelationRule getCorrelationRule(Map value) {
+ CorrelationRule correlationRule = new CorrelationRule();
+ correlationRule.setName((String) value.get("name"));
+ correlationRule.setRid((String) value.get("rid"));
+ correlationRule.setDescription((String) value.get("description"));
+ correlationRule.setEnabled((Integer) value.get("enable"));
+ correlationRule.setTemplateID((Integer) value.get("templateID"));
+ correlationRule.setEngineId((String) value.get("engineID"));
+ correlationRule.setEngineType((String) value.get("engineType"));
+ correlationRule.setCreator((String) value.get("creator"));
+ correlationRule.setCreateTime((Date) value.get("createTime"));
+ 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.setIsManual((Integer) value.get("isManual"));
+ correlationRule.setVendor((String) value.get("vendor"));
+ correlationRule.setPackageName((String) value.get("package"));
+ return correlationRule;
+ }
+
+ private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws DataFormatException {
+ try {
+ Class clazz = ruleQueryCondition.getClass();
+ Field[] fields = clazz.getDeclaredFields();
+ String whereSql = " WHERE ";
+
+ for (Field field : fields) {
+ PropertyDescriptor pd = new PropertyDescriptor(field.getName(),
+ clazz);
+ Method getMethod = pd.getReadMethod();//获得get方法
+ Object o = getMethod.invoke(ruleQueryCondition);//执行get方法返回一个Object
+ 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 ";
+ }
+ }
+ }
+ }
+ if (whereSql.indexOf("AND") > -1) {
+ whereSql = whereSql.trim();
+ return whereSql.substring(0, whereSql.length() - "AND".length());
+ }
+ return "";
+ } catch (Exception e) {
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);
+ }
+ }
+}
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 new file mode 100644 index 0000000..d318de9 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java @@ -0,0 +1,50 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.db.mapper;
+
+import org.openo.holmes.common.api.entity.CorrelationRule;
+import org.skife.jdbi.v2.StatementContext;
+import org.skife.jdbi.v2.tweak.ResultSetMapper;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+public class CorrelationRuleMapper implements ResultSetMapper<CorrelationRule> {
+ @Override
+ public CorrelationRule map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
+ CorrelationRule correlationRule = new CorrelationRule();
+ correlationRule.setName(resultSet.getString("name"));
+ correlationRule.setRid(resultSet.getString("rid"));
+ correlationRule.setDescription(resultSet.getString("description"));
+ correlationRule.setEnabled(resultSet.getInt("enable"));
+ correlationRule.setTemplateID(resultSet.getInt("templateID"));
+ correlationRule.setEngineId(resultSet.getString("engineID"));
+ correlationRule.setEngineType(resultSet.getString("engineType"));
+ correlationRule.setCreator(resultSet.getString("creator"));
+ correlationRule.setCreateTime(resultSet.getDate("createTime"));
+ 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.setIsManual(resultSet.getInt("isManual"));
+ correlationRule.setVendor(resultSet.getString("vendor"));
+ correlationRule.setPackageName(resultSet.getString("package"));
+ return correlationRule;
+ }
+
+}
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 new file mode 100644 index 0000000..71bd812 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java @@ -0,0 +1,207 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.resources;
+
+import com.codahale.metrics.annotation.Timed;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.SwaggerDefinition;
+import java.io.IOException;
+import java.util.Locale;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+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.utils.ExceptionUtil;
+import org.openo.holmes.common.utils.I18nProxy;
+import org.openo.holmes.common.utils.JacksonUtil;
+import org.openo.holmes.common.utils.LanguageUtil;
+import org.openo.holmes.common.utils.UserUtil;
+import org.openo.holmes.rulemgt.bean.request.RuleCreateRequest;
+import org.openo.holmes.rulemgt.bean.request.RuleDeleteRequest;
+import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.openo.holmes.rulemgt.bean.request.RuleUpdateRequest;
+import org.openo.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
+import org.openo.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.openo.holmes.rulemgt.wrapper.RuleMgtWrapper;
+
+@SwaggerDefinition
+@Service
+@Path("/rule")
+@Api(tags = {"CorrelationRules"})
+@Produces(MediaType.APPLICATION_JSON)
+@Slf4j
+public class RuleMgtResources {
+
+ @Inject
+ private RuleMgtWrapper ruleMgtWrapper;
+
+ @PUT
+ @Produces(MediaType.APPLICATION_JSON)
+ @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) {
+ Locale locale = LanguageUtil.getLocale(request);
+ RuleAddAndUpdateResponse ruleChangeResponse;
+ try {
+ ruleChangeResponse = ruleMgtWrapper
+ .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);
+ log.info("create rule:" + ruleCreateRequest.getRuleName() + " success.");
+ return ruleChangeResponse;
+ } catch (CallException 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));
+ }
+ }
+
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @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) {
+ Locale locale = LanguageUtil.getLocale(request);
+ RuleAddAndUpdateResponse ruleChangeResponse;
+ try {
+ ruleChangeResponse = ruleMgtWrapper
+ .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);
+ return ruleChangeResponse;
+ } catch (CallException 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) {
+ throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
+ I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));
+ }
+ }
+
+ @DELETE
+ @Produces(MediaType.APPLICATION_JSON)
+ @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) {
+ Locale locale = LanguageUtil.getLocale(request);
+ try {
+ ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
+ log.info("delete rule:" + ruleDeleteRequest.getRuleId() + " successful");
+ return true;
+ } catch (DataFormatException 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));
+ }
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @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) {
+ Locale locale = LanguageUtil.getLocale(request);
+ RuleQueryListResponse ruleQueryListResponse;
+ RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);
+ try {
+ ruleQueryListResponse = ruleMgtWrapper
+ .getCorrelationRuleByCondition(ruleQueryCondition);
+ return ruleQueryListResponse;
+ } catch (DataFormatException 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));
+ }
+ }
+
+ private RuleQueryCondition getRuleQueryCondition(String queryRequest,
+ HttpServletRequest request) {
+ Locale locale = LanguageUtil.getLocale(request);
+ try {
+ RuleQueryCondition ruleQueryCondition = JacksonUtil
+ .jsonToBean(queryRequest, RuleQueryCondition.class);
+ if (queryRequest == null) {
+ ruleQueryCondition.setEnabled(2);
+ } else if (queryRequest.indexOf("enabled") == -1) {
+ ruleQueryCondition.setEnabled(2);
+ }
+ return ruleQueryCondition;
+ } catch (IOException e) {
+ log.warn("queryRequest convert to json failed", e);
+ throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
+ 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 new file mode 100644 index 0000000..60bce08 --- /dev/null +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java @@ -0,0 +1,255 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.rulemgt.wrapper;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import javax.inject.Inject;
+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.utils.DbDaoUtil;
+import org.openo.holmes.common.utils.I18nProxy;
+import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
+import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
+import org.openo.holmes.rulemgt.bean.request.RuleCreateRequest;
+import org.openo.holmes.rulemgt.bean.request.RuleDeleteRequest;
+import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.openo.holmes.rulemgt.bean.request.RuleUpdateRequest;
+import org.openo.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
+import org.openo.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.openo.holmes.rulemgt.bean.response.RuleResult4API;
+import org.openo.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;
+import org.openo.holmes.rulemgt.db.CorrelationRuleDao;
+import org.openo.holmes.rulemgt.db.CorrelationRuleQueryDao;
+
+
+@Service
+@Singleton
+@Slf4j
+public class RuleMgtWrapper {
+
+ @Inject
+ private CorrelationRuleQueryDao correlationRuleQueryDao;
+ @Inject
+ private EngineWrapper engineWarpper;
+ @Inject
+ private DbDaoUtil daoUtil;
+
+ public RuleAddAndUpdateResponse addCorrelationRule(String creator,
+ RuleCreateRequest ruleCreateRequest)
+ throws DataFormatException, CallException, DbException {
+ CorrelationRule correlationRule = convertRuleCreateRequest2CorrelationRule(creator,
+ ruleCreateRequest);
+ if (correlationRule.getName() == null || "".equals(correlationRule.getName().trim())) {
+ throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);
+ }
+ CorrelationRule ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
+ .queryRuleByRuleName(correlationRule.getName());
+ if (ruleTemp != null) {
+ throw new DbException(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);
+ }
+ RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();
+ ruleAddAndUpdateResponse.setRuleId(correlationRule.getRid());
+ return ruleAddAndUpdateResponse;
+ }
+
+ public RuleAddAndUpdateResponse updateCorrelationRule(String modifier,
+ RuleUpdateRequest ruleUpdateRequest)
+ throws DataFormatException, DbException, CallException {
+ if (ruleUpdateRequest != null) {
+ CorrelationRule oldCorrelationRule = daoUtil
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)
+ .getRuleByRid(ruleUpdateRequest.getRuleId());
+ if (oldCorrelationRule == null) {
+ throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);
+ }
+ CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,
+ ruleUpdateRequest);
+ checkCorrelation(newCorrelationRule, oldCorrelationRule);
+ RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();
+ try {
+ if (oldCorrelationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {
+ engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName());
+ }
+ daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
+ .updateRule(newCorrelationRule);
+ } catch (RuntimeException e) {
+ throw new DbException(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);
+ }
+
+ }
+
+ public void checkCorrelation(CorrelationRule newCorrelationRule,
+ CorrelationRule oldCorrelationRule) throws DataFormatException {
+ 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);
+ }
+ }
+
+ public void deleteCorrelationRule(RuleDeleteRequest ruleDeleteRequest)
+ throws DbException, DataFormatException, CallException {
+ if (ruleDeleteRequest != null) {
+ CorrelationRule correlationRule = daoUtil
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)
+ .getRuleByRid(ruleDeleteRequest.getRuleId());
+ 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);
+ }
+ 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);
+ }
+ } else
+
+ {
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ }
+
+ }
+
+ public CorrelationRule convertRuleCreateRequest2CorrelationRule(String userName,
+ RuleCreateRequest ruleCreateRequest) throws DataFormatException {
+ 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);
+ }
+ CorrelationRule correlationRule = new CorrelationRule();
+ String ruleId = "rule_" + System.currentTimeMillis();
+ correlationRule.setRid(ruleId);
+ correlationRule.setContent(ruleCreateRequest.getContent());
+ correlationRule.setDescription(ruleCreateRequest.getDescription());
+ correlationRule.setCreateTime(new Date());
+ correlationRule.setUpdateTime(new Date());
+ correlationRule.setName(ruleCreateRequest.getRuleName());
+ correlationRule.setEngineId("correlation-d");
+ correlationRule.setEngineType("");
+ correlationRule.setIsManual(0);
+ correlationRule.setTemplateID(0);
+ correlationRule.setVendor("");
+ correlationRule.setCreator(userName);
+ correlationRule.setModifier(userName);
+ correlationRule.setEnabled(ruleCreateRequest.getEnabled());
+ return correlationRule;
+ } else {
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ }
+
+ }
+
+ private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,
+ RuleUpdateRequest ruleUpdateRequest) throws DataFormatException {
+ if (ruleUpdateRequest != null) {
+ CorrelationRule correlationRule = new CorrelationRule();
+ correlationRule.setRid(ruleUpdateRequest.getRuleId());
+ correlationRule.setContent(ruleUpdateRequest.getContent());
+ correlationRule.setDescription(ruleUpdateRequest.getDescription());
+ correlationRule.setEnabled(ruleUpdateRequest.getEnabled());
+ correlationRule.setUpdateTime(new Date());
+ correlationRule.setModifier(modifier);
+ return correlationRule;
+ } else {
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
+ }
+
+ }
+
+ private String deployRule2Engine(CorrelationRule correlationRule) throws CallException {
+ if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule))) {
+ if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {
+ return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule));
+ }
+ }
+ return "";
+ }
+
+ public RuleQueryListResponse getCorrelationRuleByCondition(
+ RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {
+ List<CorrelationRule> correlationRule = correlationRuleQueryDao
+ .getCorrelationRulesByCondition(ruleQueryCondition);
+ RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
+ ruleQueryListResponse.setTotalCount(correlationRule.size());
+ ruleQueryListResponse
+ .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));
+ return ruleQueryListResponse;
+ }
+
+ private List<RuleResult4API> correlationRules2RuleResult4APIs(
+ List<CorrelationRule> correlationRules) {
+ List<RuleResult4API> ruleResult4APIs = new ArrayList<RuleResult4API>();
+ for (CorrelationRule correlationRule : correlationRules) {
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setRuleId(correlationRule.getRid());
+ ruleResult4API.setRuleName(correlationRule.getName());
+ ruleResult4API.setDescription(correlationRule.getDescription());
+ ruleResult4API.setContent(correlationRule.getContent());
+ ruleResult4API.setCreateTime(correlationRule.getCreateTime());
+ ruleResult4API.setCreator(correlationRule.getCreator());
+ ruleResult4API.setUpdateTime(correlationRule.getUpdateTime());
+ ruleResult4API.setModifier(correlationRule.getModifier());
+ ruleResult4API.setEnabled(correlationRule.getEnabled());
+ ruleResult4APIs.add(ruleResult4API);
+ }
+ return ruleResult4APIs;
+ }
+
+ private CorrelationDeployRule4Engine correlationRules2DeployRule(
+ CorrelationRule correlationRule) {
+ CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
+ correlationDeployRule4Engine.setContent(correlationRule.getContent());
+ correlationDeployRule4Engine.setEngineId(correlationRule.getEngineId());
+ return correlationDeployRule4Engine;
+ }
+
+ private CorrelationCheckRule4Engine correlationRules2CheckRule(
+ CorrelationRule correlationRule) {
+ CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();
+ correlationCheckRule4Engine.setContent(correlationRule.getContent());
+ return correlationCheckRule4Engine;
+ }
+}
|