~ limitations under the License.\r
-->\r
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
- <modelVersion>4.0.0</modelVersion>\r
- <parent>\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <parent>\r
<groupId>org.openo.oparent</groupId>\r
<artifactId>oparent</artifactId>\r
<version>1.1.0-SNAPSHOT</version>\r
<relativePath>../oparent</relativePath>\r
</parent>\r
\r
- <groupId>org.openo.holmes.rule-management</groupId>\r
- <artifactId>holmes-rulemgt-parent</artifactId>\r
- <packaging>pom</packaging>\r
- <name>holmes-rulemgt-parent</name>\r
- <modules>\r
- <module>rulemgt</module>\r
- <!-- module>rule-standalone</module -->\r
- </modules>\r
- \r
- <properties>\r
+ <groupId>org.openo.holmes.rule-management</groupId>\r
+ <artifactId>holmes-rulemgt-parent</artifactId>\r
+ <packaging>pom</packaging>\r
+ <name>holmes-rulemgt-parent</name>\r
+ <modules>\r
+ <module>rulemgt</module>\r
+ </modules>\r
+\r
+ <properties>\r
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\r
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>\r
<maven.test.skip>false</maven.test.skip>\r
<pkgzip.dir>${basedir}/../release/pkgzip</pkgzip.dir>\r
<excludesFile>**/*$*</excludesFile>\r
<nexusproxy>https://nexus.open-o.org/content</nexusproxy>\r
- \r
- \r
- <stringtemplate.version>3.2.1</stringtemplate.version>\r
- <mysql.connector.version>5.1.38</mysql.connector.version>\r
- <dropwizard.version>0.8.0</dropwizard.version>\r
+\r
+\r
+ <stringtemplate.version>3.2.1</stringtemplate.version>\r
+ <mysql.connector.version>5.1.38</mysql.connector.version>\r
+ <dropwizard.version>0.8.0</dropwizard.version>\r
<swagger.version>1.5.3</swagger.version>\r
- <lombok.version>1.16.4</lombok.version>\r
+ <lombok.version>1.16.4</lombok.version>\r
<jersey.version>2.22.2</jersey.version>\r
<jaxrs.consumer.version>5.0</jaxrs.consumer.version>\r
<slf4j.version>1.6.1</slf4j.version>\r
- <quartz.version>2.2.1</quartz.version>\r
- </properties>\r
- \r
- <!-- scm>\r
- <connection>scm:git:ssh://git.open-o.org:29418/common-services-common-utilities.git</connection>\r
- <developerConnection>scm:git:ssh://git.open-o.org:29418/common-services-common-utilities.git</developerConnection>\r
- <tag>HEAD</tag>\r
- <url>https://wiki.open-o.orgiew/Common_Services</url>\r
- </scm -->\r
-\r
- <dependencyManagement>\r
- <dependencies>\r
- <dependency>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-core</artifactId>\r
- <version>${dropwizard.version}</version>\r
- <scope>provided</scope>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-db</artifactId>\r
- <version>${dropwizard.version}</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>io.swagger</groupId>\r
- <artifactId>swagger-jersey2-jaxrs</artifactId>\r
- <version>${swagger.version}</version>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>org.projectlombok</groupId>\r
- <artifactId>lombok</artifactId>\r
- <version>${lombok.version}</version>\r
- </dependency>\r
-\r
-\r
- <dependency>\r
- <groupId>org.slf4j</groupId>\r
- <artifactId>slf4j-api</artifactId>\r
- <version>${slf4j.version}</version>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>mysql</groupId>\r
- <artifactId>mysql-connector-java</artifactId>\r
- <version>${mysql.connector.version}</version>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>org.antlr</groupId>\r
- <artifactId>stringtemplate</artifactId>\r
- <version>${stringtemplate.version}</version>\r
- </dependency>\r
- \r
- <dependency>\r
- <groupId>org.openo.common-services.common-utilities</groupId>\r
- <artifactId>dropwizard-ioc-container</artifactId>\r
- <version>${project.version}</version>\r
- </dependency>\r
- \r
- <dependency>\r
- <groupId>org.quartz-scheduler</groupId>\r
- <artifactId>quartz</artifactId>\r
- <version>${quartz.version}</version>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>junit</groupId>\r
- <artifactId>junit</artifactId>\r
- <version>4.8.2</version>\r
- <scope>test</scope>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>org.hamcrest</groupId>\r
- <artifactId>hamcrest-core</artifactId>\r
- <version>1.3</version>\r
- <scope>test</scope>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>org.powermock</groupId>\r
- <artifactId>powermock-module-junit4</artifactId>\r
- <version>1.6.4</version>\r
- <scope>test</scope>\r
- </dependency>\r
- </dependencies>\r
- </dependencyManagement>\r
- \r
+ <quartz.version>2.2.1</quartz.version>\r
+ </properties>\r
+ <dependencyManagement>\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>org.openo.holmes.actions</groupId>\r
+ <artifactId>holmes-actions</artifactId>\r
+ <version>${project.version}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-core</artifactId>\r
+ <version>${dropwizard.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-db</artifactId>\r
+ <version>${dropwizard.version}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>io.swagger</groupId>\r
+ <artifactId>swagger-jersey2-jaxrs</artifactId>\r
+ <version>${swagger.version}</version>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.projectlombok</groupId>\r
+ <artifactId>lombok</artifactId>\r
+ <version>${lombok.version}</version>\r
+ </dependency>\r
+\r
+\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-api</artifactId>\r
+ <version>${slf4j.version}</version>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>mysql</groupId>\r
+ <artifactId>mysql-connector-java</artifactId>\r
+ <version>${mysql.connector.version}</version>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.antlr</groupId>\r
+ <artifactId>stringtemplate</artifactId>\r
+ <version>${stringtemplate.version}</version>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.openo.common-services.common-utilities</groupId>\r
+ <artifactId>dropwizard-ioc-container</artifactId>\r
+ <version>${project.version}</version>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.quartz-scheduler</groupId>\r
+ <artifactId>quartz</artifactId>\r
+ <version>${quartz.version}</version>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>junit</groupId>\r
+ <artifactId>junit</artifactId>\r
+ <version>4.8.2</version>\r
+ <scope>test</scope>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.hamcrest</groupId>\r
+ <artifactId>hamcrest-core</artifactId>\r
+ <version>1.3</version>\r
+ <scope>test</scope>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.powermock</groupId>\r
+ <artifactId>powermock-module-junit4</artifactId>\r
+ <version>1.6.4</version>\r
+ <scope>test</scope>\r
+ </dependency>\r
+ </dependencies>\r
+ </dependencyManagement>\r
+\r
</project>\r
\r
<packaging>jar</packaging>
<dependencies>
+ <dependency>
+ <groupId>org.openo.holmes.actions</groupId>
+ <artifactId>holmes-actions</artifactId>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-db</artifactId>
</dependency>
-
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.4.10</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>1.4.10</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.15.0-GA</version>
<scope>test</scope>
</dependency>
-
</dependencies>
<build>
<plugins>
</archive>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.3</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.request;\r
+\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+@Getter\r
+@Setter\r
+public class CorrelationDeployRule4Engine {\r
+ @JsonProperty(value = "content")\r
+ private String content;\r
+\r
+ @JsonProperty(value = "engineid")\r
+ private String engineId;\r
+\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.request;\r
+\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+@Setter\r
+@Getter\r
+public class RuleCreateRequest {\r
+ @JsonProperty(value = "rulename")\r
+ private String ruleName;\r
+ @JsonProperty\r
+ private String description;\r
+ @JsonProperty\r
+ private String content;\r
+ @JsonProperty\r
+ private int enabled;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.request;\r
+\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+\r
+@Setter\r
+@Getter\r
+public class RuleDeleteRequest {\r
+ @JsonProperty(value = "ruleid")\r
+ private String ruleId;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.request;\r
+\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+@Getter\r
+@Setter\r
+public class RuleQueryCondition {\r
+\r
+ @JsonProperty(value = "ruleid")\r
+ private String rid;\r
+ @JsonProperty(value = "rulename")\r
+ private String name;\r
+ private int enabled;\r
+ private String creator;\r
+ private String modifier;\r
+\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.request;\r
+\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+@Getter\r
+@Setter\r
+public class RuleUpdateRequest {\r
+ @JsonProperty\r
+ private String description;\r
+ @JsonProperty\r
+ private String content;\r
+ @JsonProperty\r
+ private int enabled;\r
+ @JsonProperty(value="ruleid")\r
+ private String ruleId;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.response;\r
+\r
+import com.fasterxml.jackson.annotation.JsonInclude;\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+@JsonInclude(JsonInclude.Include.ALWAYS)\r
+@Getter\r
+@Setter\r
+public class RuleAddAndUpdateResponse{\r
+ @JsonProperty(value="ruleid")\r
+ private String ruleId;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.response;\r
+\r
+import com.fasterxml.jackson.annotation.JsonInclude;\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+@JsonInclude(JsonInclude.Include.ALWAYS)\r
+@Getter\r
+@Setter\r
+public class RuleQueryListResponse {\r
+ @JsonProperty(value = "rules")\r
+ private List<RuleResult4API> correlationRules = new ArrayList<RuleResult4API>();\r
+ @JsonProperty(value = "totalcount")\r
+ private int totalCount;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bean.response;\r
+\r
+import com.fasterxml.jackson.annotation.JsonInclude;\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+import java.util.Date;\r
+\r
+@JsonInclude(JsonInclude.Include.ALWAYS)\r
+@Setter\r
+@Getter\r
+public class RuleResult4API {\r
+ @JsonProperty(value = "ruleid")\r
+ private String ruleId;\r
+ @JsonProperty(value = "rulename")\r
+ private String ruleName;\r
+ private String description;\r
+ private String content;\r
+ @JsonProperty(value = "createtime")\r
+ private Date createTime;\r
+ private String creator;\r
+ @JsonProperty(value = "updatetime")\r
+ private Date updateTime;\r
+ private String modifier;\r
+ private int enabled;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bolt.enginebolt;\r
+\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.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
+import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
+\r
+@Service\r
+@Slf4j\r
+public class EngineWrapper {\r
+\r
+\r
+ public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CallException {\r
+ return "";\r
+ }\r
+\r
+ public boolean deleteRuleFromEngine(String packageName) throws CallException {\r
+ return true;\r
+ }\r
+\r
+ public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
+ throws CallException {\r
+ return true;\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.constant;\r
+\r
+public class RuleMgtConstant {\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
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.db;\r
+\r
+import org.openo.holmes.common.api.entity.CorrelationRule;\r
+import org.openo.holmes.rulemgt.db.mapper.CorrelationRuleMapper;\r
+import org.skife.jdbi.v2.sqlobject.Bind;\r
+import org.skife.jdbi.v2.sqlobject.BindBean;\r
+import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;\r
+import org.skife.jdbi.v2.sqlobject.SqlQuery;\r
+import org.skife.jdbi.v2.sqlobject.SqlUpdate;\r
+import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;\r
+\r
+import java.util.List;\r
+\r
+@RegisterMapper(CorrelationRuleMapper.class)\r
+public abstract class CorrelationRuleDao {\r
+ @GetGeneratedKeys\r
+ @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)")\r
+ protected abstract int addRule(@BindBean CorrelationRule correlationRule);\r
+\r
+ @SqlUpdate("UPDATE APLUS_RULE SET DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime WHERE RID=:rid")\r
+ protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);\r
+\r
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")\r
+ protected abstract int deleteRuleByRid(@Bind("rid") String rid);\r
+\r
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")\r
+ protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);\r
+\r
+ @SqlQuery("SELECT * FROM APLUS_RULE")\r
+ protected abstract List<CorrelationRule> queryAllRules();\r
+\r
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")\r
+ public abstract CorrelationRule queryRuleByRid(@Bind("rid") String rid);\r
+\r
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")\r
+ public abstract CorrelationRule queryRuleByName(@Bind("name") String name);\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
+ deleteRuleByRidAndName(rid, name);\r
+ } else if (!rid.equals("")) {\r
+ deleteRuleByRid(rid);\r
+ }\r
+ }\r
+\r
+ public CorrelationRule saveRule(CorrelationRule correlationRule) {\r
+ addRule(correlationRule);\r
+ return correlationRule;\r
+ }\r
+\r
+ public void updateRule(CorrelationRule correlationRule){\r
+ updateRuleByRid(correlationRule);\r
+ }\r
+\r
+ public void deleteRule(CorrelationRule correlationRule) {\r
+ deleteRule2DbInner(correlationRule);\r
+ }\r
+\r
+\r
+ public CorrelationRule getRuleByRid(String rid) {\r
+ return queryRuleByRid(rid);\r
+ }\r
+\r
+ public CorrelationRule queryRuleByRuleName(String name) {\r
+ return queryRuleByName(name);\r
+ }\r
+}\r
+\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\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.ArrayList;\r
+import java.util.Date;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+@Service\r
+@Slf4j\r
+public class CorrelationRuleQueryDao {\r
+ @Inject\r
+ private DbDaoUtil dbDaoUtil;\r
+\r
+ public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {\r
+ List<CorrelationRule> correlationRules = new ArrayList<CorrelationRule>();\r
+ Handle handle = null;\r
+ String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);\r
+ try {\r
+ StringBuilder querySql = new StringBuilder("SELECT * FROM APLUS_RULE ").append(whereStr);\r
+ handle = dbDaoUtil.getHandle();\r
+ Query query = handle.createQuery(querySql.toString());\r
+ for (Object value : query.list()) {\r
+ CorrelationRule correlationRule = getCorrelationRule((Map) value);\r
+ correlationRules.add(correlationRule);\r
+ }\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
+ } finally {\r
+ dbDaoUtil.close(handle);\r
+ }\r
+ }\r
+\r
+ private CorrelationRule getCorrelationRule(Map value) {\r
+ CorrelationRule correlationRule = new CorrelationRule();\r
+ correlationRule.setName((String) value.get("name"));\r
+ correlationRule.setRid((String) value.get("rid"));\r
+ correlationRule.setDescription((String) value.get("description"));\r
+ correlationRule.setEnabled((Integer) value.get("enable"));\r
+ correlationRule.setTemplateID((Integer) value.get("templateID"));\r
+ correlationRule.setEngineId((String) value.get("engineID"));\r
+ correlationRule.setEngineType((String) value.get("engineType"));\r
+ correlationRule.setCreator((String) value.get("creator"));\r
+ correlationRule.setCreateTime((Date) value.get("createTime"));\r
+ correlationRule.setModifier((String) value.get("updator"));\r
+ correlationRule.setUpdateTime((Date) value.get("updateTime"));\r
+ correlationRule.setParams((Properties) value.get("params"));\r
+ correlationRule.setDomain((String) value.get("domain"));\r
+ correlationRule.setContent((String) value.get("content"));\r
+ correlationRule.setIsManual((Integer) value.get("isManual"));\r
+ correlationRule.setVendor((String) value.get("vendor"));\r
+ correlationRule.setPackageName((String) value.get("package"));\r
+ return correlationRule;\r
+ }\r
+\r
+ private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws DataFormatException {\r
+ try {\r
+ Class clazz = ruleQueryCondition.getClass();\r
+ Field[] fields = clazz.getDeclaredFields();\r
+ String whereSql = " WHERE ";\r
+\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
+ 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
+ }\r
+ }\r
+ }\r
+ if (whereSql.indexOf("AND") > -1) {\r
+ whereSql = whereSql.trim();\r
+ return whereSql.substring(0, whereSql.length() - "AND".length());\r
+ }\r
+ return "";\r
+ } catch (Exception e) {\r
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.db.mapper;\r
+\r
+import org.openo.holmes.common.api.entity.CorrelationRule;\r
+import org.skife.jdbi.v2.StatementContext;\r
+import org.skife.jdbi.v2.tweak.ResultSetMapper;\r
+\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+import java.util.Properties;\r
+\r
+public class CorrelationRuleMapper implements ResultSetMapper<CorrelationRule> {\r
+ @Override\r
+ public CorrelationRule map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {\r
+ CorrelationRule correlationRule = new CorrelationRule();\r
+ correlationRule.setName(resultSet.getString("name"));\r
+ correlationRule.setRid(resultSet.getString("rid"));\r
+ correlationRule.setDescription(resultSet.getString("description"));\r
+ correlationRule.setEnabled(resultSet.getInt("enable"));\r
+ correlationRule.setTemplateID(resultSet.getInt("templateID"));\r
+ correlationRule.setEngineId(resultSet.getString("engineID"));\r
+ correlationRule.setEngineType(resultSet.getString("engineType"));\r
+ correlationRule.setCreator(resultSet.getString("creator"));\r
+ correlationRule.setCreateTime(resultSet.getDate("createTime"));\r
+ correlationRule.setModifier(resultSet.getString("updator"));\r
+ correlationRule.setUpdateTime(resultSet.getDate("updateTime"));\r
+ correlationRule.setParams((Properties)resultSet.getObject("params"));\r
+ correlationRule.setDomain(resultSet.getString("domain"));\r
+ correlationRule.setContent(resultSet.getString("content"));\r
+ correlationRule.setIsManual(resultSet.getInt("isManual"));\r
+ correlationRule.setVendor(resultSet.getString("vendor"));\r
+ correlationRule.setPackageName(resultSet.getString("package"));\r
+ return correlationRule;\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.resources;\r
+\r
+import com.codahale.metrics.annotation.Timed;\r
+import io.swagger.annotations.Api;\r
+import io.swagger.annotations.ApiOperation;\r
+import io.swagger.annotations.ApiParam;\r
+import io.swagger.annotations.SwaggerDefinition;\r
+import java.io.IOException;\r
+import java.util.Locale;\r
+import javax.inject.Inject;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.ws.rs.DELETE;\r
+import javax.ws.rs.GET;\r
+import javax.ws.rs.POST;\r
+import javax.ws.rs.PUT;\r
+import javax.ws.rs.Path;\r
+import javax.ws.rs.Produces;\r
+import javax.ws.rs.QueryParam;\r
+import javax.ws.rs.core.Context;\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.utils.ExceptionUtil;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
+import org.openo.holmes.common.utils.JacksonUtil;\r
+import org.openo.holmes.common.utils.LanguageUtil;\r
+import org.openo.holmes.common.utils.UserUtil;\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
+import org.openo.holmes.rulemgt.bean.request.RuleUpdateRequest;\r
+import org.openo.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;\r
+import org.openo.holmes.rulemgt.bean.response.RuleQueryListResponse;\r
+import org.openo.holmes.rulemgt.wrapper.RuleMgtWrapper;\r
+\r
+@SwaggerDefinition\r
+@Service\r
+@Path("/rule")\r
+@Api(tags = {"CorrelationRules"})\r
+@Produces(MediaType.APPLICATION_JSON)\r
+@Slf4j\r
+public class RuleMgtResources {\r
+\r
+ @Inject\r
+ private RuleMgtWrapper ruleMgtWrapper;\r
+\r
+ @PUT\r
+ @Produces(MediaType.APPLICATION_JSON)\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
+ Locale locale = LanguageUtil.getLocale(request);\r
+ RuleAddAndUpdateResponse ruleChangeResponse;\r
+ try {\r
+ ruleChangeResponse = ruleMgtWrapper\r
+ .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);\r
+ log.info("create rule:" + ruleCreateRequest.getRuleName() + " success.");\r
+ return ruleChangeResponse;\r
+ } catch (CallException 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
+ }\r
+ }\r
+\r
+ @POST\r
+ @Produces(MediaType.APPLICATION_JSON)\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
+ Locale locale = LanguageUtil.getLocale(request);\r
+ RuleAddAndUpdateResponse ruleChangeResponse;\r
+ try {\r
+ ruleChangeResponse = ruleMgtWrapper\r
+ .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
+ return ruleChangeResponse;\r
+ } catch (CallException 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
+ throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
+ I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+ }\r
+ }\r
+\r
+ @DELETE\r
+ @Produces(MediaType.APPLICATION_JSON)\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
+ 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
+ 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
+ }\r
+ }\r
+\r
+ @GET\r
+ @Produces(MediaType.APPLICATION_JSON)\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
+ Locale locale = LanguageUtil.getLocale(request);\r
+ RuleQueryListResponse ruleQueryListResponse;\r
+ RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);\r
+ try {\r
+ ruleQueryListResponse = ruleMgtWrapper\r
+ .getCorrelationRuleByCondition(ruleQueryCondition);\r
+ return ruleQueryListResponse;\r
+ } catch (DataFormatException 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
+ }\r
+ }\r
+\r
+ private RuleQueryCondition getRuleQueryCondition(String queryRequest,\r
+ HttpServletRequest request) {\r
+ Locale locale = LanguageUtil.getLocale(request);\r
+ try {\r
+ RuleQueryCondition ruleQueryCondition = JacksonUtil\r
+ .jsonToBean(queryRequest, RuleQueryCondition.class);\r
+ if (queryRequest == null) {\r
+ ruleQueryCondition.setEnabled(2);\r
+ } else if (queryRequest.indexOf("enabled") == -1) {\r
+ ruleQueryCondition.setEnabled(2);\r
+ }\r
+ return ruleQueryCondition;\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
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.wrapper;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Date;\r
+import java.util.List;\r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\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.utils.DbDaoUtil;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
+import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
+import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\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
+import org.openo.holmes.rulemgt.bean.request.RuleUpdateRequest;\r
+import org.openo.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;\r
+import org.openo.holmes.rulemgt.bean.response.RuleQueryListResponse;\r
+import org.openo.holmes.rulemgt.bean.response.RuleResult4API;\r
+import org.openo.holmes.rulemgt.bolt.enginebolt.EngineWrapper;\r
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
+import org.openo.holmes.rulemgt.db.CorrelationRuleDao;\r
+import org.openo.holmes.rulemgt.db.CorrelationRuleQueryDao;\r
+\r
+\r
+@Service\r
+@Singleton\r
+@Slf4j\r
+public class RuleMgtWrapper {\r
+\r
+ @Inject\r
+ private CorrelationRuleQueryDao correlationRuleQueryDao;\r
+ @Inject\r
+ private EngineWrapper engineWarpper;\r
+ @Inject\r
+ private DbDaoUtil daoUtil;\r
+\r
+ public RuleAddAndUpdateResponse addCorrelationRule(String creator,\r
+ RuleCreateRequest ruleCreateRequest)\r
+ throws DataFormatException, CallException, DbException {\r
+ CorrelationRule correlationRule = convertRuleCreateRequest2CorrelationRule(creator,\r
+ ruleCreateRequest);\r
+ if (correlationRule.getName() == null || "".equals(correlationRule.getName().trim())) {\r
+ throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\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
+ }\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
+ }\r
+ RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();\r
+ ruleAddAndUpdateResponse.setRuleId(correlationRule.getRid());\r
+ return ruleAddAndUpdateResponse;\r
+ }\r
+\r
+ public RuleAddAndUpdateResponse updateCorrelationRule(String modifier,\r
+ RuleUpdateRequest ruleUpdateRequest)\r
+ throws DataFormatException, DbException, CallException {\r
+ if (ruleUpdateRequest != null) {\r
+ CorrelationRule oldCorrelationRule = daoUtil\r
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+ .getRuleByRid(ruleUpdateRequest.getRuleId());\r
+ if (oldCorrelationRule == null) {\r
+ throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
+ }\r
+ CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,\r
+ ruleUpdateRequest);\r
+ checkCorrelation(newCorrelationRule, oldCorrelationRule);\r
+ RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();\r
+ try {\r
+ if (oldCorrelationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\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
+ }\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
+ }\r
+\r
+ }\r
+\r
+ public void checkCorrelation(CorrelationRule newCorrelationRule,\r
+ CorrelationRule oldCorrelationRule) throws DataFormatException {\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
+ }\r
+ }\r
+\r
+ public void deleteCorrelationRule(RuleDeleteRequest ruleDeleteRequest)\r
+ throws DbException, DataFormatException, CallException {\r
+ if (ruleDeleteRequest != null) {\r
+ CorrelationRule correlationRule = daoUtil\r
+ .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+ .getRuleByRid(ruleDeleteRequest.getRuleId());\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
+ }\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
+ }\r
+ } else\r
+\r
+ {\r
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ }\r
+\r
+ }\r
+\r
+ public CorrelationRule convertRuleCreateRequest2CorrelationRule(String userName,\r
+ RuleCreateRequest ruleCreateRequest) throws DataFormatException {\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
+ }\r
+ CorrelationRule correlationRule = new CorrelationRule();\r
+ String ruleId = "rule_" + System.currentTimeMillis();\r
+ correlationRule.setRid(ruleId);\r
+ correlationRule.setContent(ruleCreateRequest.getContent());\r
+ correlationRule.setDescription(ruleCreateRequest.getDescription());\r
+ correlationRule.setCreateTime(new Date());\r
+ correlationRule.setUpdateTime(new Date());\r
+ correlationRule.setName(ruleCreateRequest.getRuleName());\r
+ correlationRule.setEngineId("correlation-d");\r
+ correlationRule.setEngineType("");\r
+ correlationRule.setIsManual(0);\r
+ correlationRule.setTemplateID(0);\r
+ correlationRule.setVendor("");\r
+ correlationRule.setCreator(userName);\r
+ correlationRule.setModifier(userName);\r
+ correlationRule.setEnabled(ruleCreateRequest.getEnabled());\r
+ return correlationRule;\r
+ } else {\r
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ }\r
+\r
+ }\r
+\r
+ private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,\r
+ RuleUpdateRequest ruleUpdateRequest) throws DataFormatException {\r
+ if (ruleUpdateRequest != null) {\r
+ CorrelationRule correlationRule = new CorrelationRule();\r
+ correlationRule.setRid(ruleUpdateRequest.getRuleId());\r
+ correlationRule.setContent(ruleUpdateRequest.getContent());\r
+ correlationRule.setDescription(ruleUpdateRequest.getDescription());\r
+ correlationRule.setEnabled(ruleUpdateRequest.getEnabled());\r
+ correlationRule.setUpdateTime(new Date());\r
+ correlationRule.setModifier(modifier);\r
+ return correlationRule;\r
+ } else {\r
+ throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+ }\r
+\r
+ }\r
+\r
+ private String deployRule2Engine(CorrelationRule correlationRule) throws CallException {\r
+ if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule))) {\r
+ if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
+ return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule));\r
+ }\r
+ }\r
+ return "";\r
+ }\r
+\r
+ public RuleQueryListResponse getCorrelationRuleByCondition(\r
+ RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {\r
+ List<CorrelationRule> correlationRule = correlationRuleQueryDao\r
+ .getCorrelationRulesByCondition(ruleQueryCondition);\r
+ RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();\r
+ ruleQueryListResponse.setTotalCount(correlationRule.size());\r
+ ruleQueryListResponse\r
+ .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));\r
+ return ruleQueryListResponse;\r
+ }\r
+\r
+ private List<RuleResult4API> correlationRules2RuleResult4APIs(\r
+ List<CorrelationRule> correlationRules) {\r
+ List<RuleResult4API> ruleResult4APIs = new ArrayList<RuleResult4API>();\r
+ for (CorrelationRule correlationRule : correlationRules) {\r
+ RuleResult4API ruleResult4API = new RuleResult4API();\r
+ ruleResult4API.setRuleId(correlationRule.getRid());\r
+ ruleResult4API.setRuleName(correlationRule.getName());\r
+ ruleResult4API.setDescription(correlationRule.getDescription());\r
+ ruleResult4API.setContent(correlationRule.getContent());\r
+ ruleResult4API.setCreateTime(correlationRule.getCreateTime());\r
+ ruleResult4API.setCreator(correlationRule.getCreator());\r
+ ruleResult4API.setUpdateTime(correlationRule.getUpdateTime());\r
+ ruleResult4API.setModifier(correlationRule.getModifier());\r
+ ruleResult4API.setEnabled(correlationRule.getEnabled());\r
+ ruleResult4APIs.add(ruleResult4API);\r
+ }\r
+ return ruleResult4APIs;\r
+ }\r
+\r
+ private CorrelationDeployRule4Engine correlationRules2DeployRule(\r
+ CorrelationRule correlationRule) {\r
+ CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
+ correlationDeployRule4Engine.setContent(correlationRule.getContent());\r
+ correlationDeployRule4Engine.setEngineId(correlationRule.getEngineId());\r
+ return correlationDeployRule4Engine;\r
+ }\r
+\r
+ private CorrelationCheckRule4Engine correlationRules2CheckRule(\r
+ CorrelationRule correlationRule) {\r
+ CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();\r
+ correlationCheckRule4Engine.setContent(correlationRule.getContent());\r
+ return correlationCheckRule4Engine;\r
+ }\r
+}\r