summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main/java/org/openo
diff options
context:
space:
mode:
authorGuangrong Fu <fu.guangrong@zte.com.cn>2017-08-07 12:30:35 +0800
committerGuangrong Fu <fu.guangrong@zte.com.cn>2017-08-07 12:41:11 +0800
commit20a1514bf93035472d4f940f00a357106d4bec1f (patch)
tree53c8e874f204f4b5ac7e64cbfdf783dbd2e9e019 /rulemgt/src/main/java/org/openo
parent40f54b8acefce59ecbd9e9fde60e062373243982 (diff)
Change the groupid from openo to onap
Change the groupid and package paths to onap. Change-Id: I8432e9ac2c979bbc36e10e6a702c6f04fc41446a Issue-ID: HOLMES-7 Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'rulemgt/src/main/java/org/openo')
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java61
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java58
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java27
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java31
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequest.java27
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleCreateRequest.java33
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleDeleteRequest.java28
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleQueryCondition.java34
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequest.java33
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java29
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponse.java34
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleResult4API.java42
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java66
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java88
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java29
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java107
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java129
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java48
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java168
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java245
20 files changed, 0 insertions, 1317 deletions
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java
deleted file mode 100644
index 96a1f00..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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;
-
-import io.dropwizard.setup.Environment;
-import java.io.IOException;
-import lombok.extern.slf4j.Slf4j;
-import org.openo.dropwizard.ioc.bundle.IOCApplication;
-import org.openo.holmes.common.api.entity.ServiceRegisterEntity;
-import org.openo.holmes.common.config.MicroServiceConfig;
-import org.openo.holmes.common.utils.MSBRegisterUtil;
-
-@Slf4j
-public class RuleActiveApp extends IOCApplication < RuleAppConfig > {
-
- public static void main( String[] args ) throws Exception {
- new RuleActiveApp().run( args );
- }
-
- @Override
- public String getName() {
- return "Holmes Rule Management ActiveApp APP ";
- }
-
- @Override
- public void run(RuleAppConfig configuration, Environment environment) throws Exception {
- super.run(configuration, environment);
-
- try {
- new MSBRegisterUtil().register(initServiceEntity());
- } catch (IOException e) {
- log.warn("Micro service registry httpclient close failure",e);
- }
-
- }
-
- private ServiceRegisterEntity initServiceEntity() {
- ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();
- serviceRegisterEntity.setServiceName("holmes-rule-mgmt");
- serviceRegisterEntity.setProtocol("REST");
- serviceRegisterEntity.setVersion("v1");
- serviceRegisterEntity.setUrl("/openoapi/holmes-rule-mgmt/v1");
- serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0);
- serviceRegisterEntity.setVisualRange("1|0");
- return serviceRegisterEntity;
- }
-}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
deleted file mode 100644
index 4fcb486..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import io.dropwizard.Configuration;
-import io.dropwizard.db.DataSourceFactory;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import org.hibernate.validator.constraints.NotEmpty;
-import org.jvnet.hk2.annotations.Service;
-
-@Service
-public class RuleAppConfig extends Configuration {
-
- @NotEmpty
- private String defaultName = "Holmes Rule Management";
-
- @NotEmpty
- private String apidescription = "Holmes rule management rest API";
-
- @Valid
- @NotNull
- private DataSourceFactory database = new DataSourceFactory();
-
- @JsonProperty("database")
- public DataSourceFactory getDataSourceFactory() {
- return database;
- }
-
- @JsonProperty("database")
- public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {
- this.database = dataSourceFactory;
- }
-
-
- public String getApidescription() {
- return apidescription;
- }
-
- public void setApidescription(String apidescription) {
- this.apidescription = apidescription;
- }
-
-}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java
deleted file mode 100644
index 1475ce9..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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 lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-public class CorrelationCheckRule4Engine {
-
- private String content;
-}
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
deleted file mode 100644
index 3ed4c4d..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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/CorrelationRestRequest.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequest.java
deleted file mode 100644
index 463eb2a..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequest.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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 lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-public class CorrelationRestRequest {
-
- private String rootURL;
-} \ No newline at end of file
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
deleted file mode 100644
index 9407b99..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleCreateRequest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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
deleted file mode 100644
index ac9d795..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleDeleteRequest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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
deleted file mode 100644
index c68b40d..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleQueryCondition.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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
deleted file mode 100644
index 6ce265a..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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
deleted file mode 100644
index e5597b8..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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
deleted file mode 100644
index a720eca..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponse.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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
deleted file mode 100644
index ee948d0..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleResult4API.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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/EngineService.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java
deleted file mode 100644
index e792fbf..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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 com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import lombok.extern.slf4j.Slf4j;
-import org.glassfish.jersey.client.ClientConfig;
-import org.jvnet.hk2.annotations.Service;
-import org.openo.holmes.common.config.MicroServiceConfig;
-import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
-import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-import org.openo.holmes.rulemgt.constant.RuleMgtConstant;
-
-@Slf4j
-@Service
-public class EngineService {
-
- protected Response delete(String packageName) throws IOException {
- Client client = createClient();
- WebTarget webTarget = client
- .target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH + "/" + packageName);
- return webTarget.request(MediaType.APPLICATION_JSON).delete();
- }
-
- private Client createClient() {
- ClientConfig clientConfig = new ClientConfig();
- return ClientBuilder.newClient(clientConfig);
- }
-
- protected Response check(CorrelationCheckRule4Engine correlationCheckRule4Engine)
- throws IOException {
- Client client = createClient();
- ObjectMapper mapper = new ObjectMapper();
- String content = mapper.writeValueAsString(correlationCheckRule4Engine);
- WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH);
- return webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(content, MediaType.APPLICATION_JSON));
- }
-
- protected Response deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException {
- Client client = createClient();
- ObjectMapper mapper = new ObjectMapper();
- String content = mapper.writeValueAsString(correlationDeployRule4Engine);
- WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH);
- return webTarget.request(MediaType.APPLICATION_JSON).put(Entity.entity(content, MediaType.APPLICATION_JSON));
- }
-}
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
deleted file mode 100644
index 8e9055b..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * 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 javax.inject.Inject;
-import javax.ws.rs.core.Response;
-import lombok.extern.slf4j.Slf4j;
-import net.sf.json.JSONObject;
-import org.jvnet.hk2.annotations.Service;
-import org.openo.holmes.common.exception.CorrelationException;
-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.constant.RuleMgtConstant;
-
-@Service
-@Slf4j
-public class EngineWrapper {
-
- @Inject
- private EngineService engineService;
-
- public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {
- Response response;
- try {
- response = engineService.deploy(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED, e);
- }
- if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {
- log.info("Call deploy rule rest interface in engine successfully.");
- try {
- JSONObject json = JSONObject.fromObject(response.readEntity(String.class));
- return json.get(RuleMgtConstant.PACKAGE).toString();
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR, e);
- }
- } else {
- throw new CorrelationException(I18nProxy.ENGINE_DEPLOY_RULE_FAILED);
- }
- }
-
- public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {
- Response response;
- try {
- response = engineService.delete(packageName);
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED, e);
- }
- if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {
- log.info("Call delete rule rest interface in engine successfully.");
- return true;
- } else {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED);
- }
- }
-
- public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)
- throws CorrelationException {
- log.info("content:" + correlationCheckRule4Engine.getContent());
- Response response;
- try {
- response = engineService.check(correlationCheckRule4Engine);
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED, e);
- }
- if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {
- log.info("Call check rule rest interface in engine successfully.");
- return true;
- } else {
- log.info(response.getStatus() + " " + response.getStatusInfo() + " " + response.getEntity());
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CHECK_NO_PASS);
- }
- }
-}
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
deleted file mode 100644
index a9b891a..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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 {
-
- private 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 = "package";
- public static final String ENGINE_PATH = "/openoapi/holmes-engine-mgmt/v1/rule";
- public static final int RESPONSE_STATUS_OK = 200;
-}
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
deleted file mode 100644
index 3a7f300..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * 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 java.util.List;
-import org.openo.holmes.common.api.entity.CorrelationRule;
-import org.openo.holmes.common.exception.CorrelationException;
-import org.openo.holmes.common.utils.I18nProxy;
-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;
-
-@RegisterMapper(CorrelationRuleMapper.class)
-public abstract class CorrelationRuleDao {
-
- @GetGeneratedKeys
- @SqlUpdate("INSERT INTO APLUS_RULE (NAME,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID) VALUES (:name,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,: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")
- protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
- protected 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 (!"".equals(name) && !"".equals(rid)) {
- deleteRuleByRidAndName(rid, name);
- } else if (!"".equals(rid)) {
- deleteRuleByRid(rid);
- }
- }
-
- public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- addRule(correlationRule);
- return correlationRule;
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);
- }
- }
-
- public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- updateRuleByRid(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);
- }
- }
-
- public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- deleteRule2DbInner(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);
- }
- }
-
-
- public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
- try {
- return queryRuleById(rid);
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);
- }
- }
-
- public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
- try {
- return queryRuleByName(name);
- } catch (Exception e) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);
- }
- }
-}
-
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
deleted file mode 100644
index 487684e..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * 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 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;
-import javax.inject.Inject;
-import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.openo.holmes.common.api.entity.CorrelationRule;
-import org.openo.holmes.common.exception.CorrelationException;
-import org.openo.holmes.common.utils.DbDaoUtil;
-import org.openo.holmes.common.utils.I18nProxy;
-import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.openo.holmes.rulemgt.constant.RuleMgtConstant;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
-
-@Service
-@Slf4j
-public class CorrelationRuleQueryDao {
-
- @Inject
- private DbDaoUtil dbDaoUtil;
-
- public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)
- throws CorrelationException {
- 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 CorrelationException(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.setContent((String) value.get("content"));
- correlationRule.setVendor((String) value.get("vendor"));
- correlationRule.setPackageName((String) value.get("package"));
- return correlationRule;
- }
-
- private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws CorrelationException {
- try {
- Class clazz = ruleQueryCondition.getClass();
- Field[] fields = clazz.getDeclaredFields();
- String whereSql = " WHERE ";
-
- for (Field field : fields) {
- // Jacoco will cause an exception when calculating the coverage of the UT
- // Remove this if jacoco solves this problem in the future
- if (field.getName().contains("jacoco")) {
- continue;
- }
- PropertyDescriptor pd = new PropertyDescriptor(field.getName(),
- clazz);
- Method getMethod = pd.getReadMethod();
- Object o = getMethod.invoke(ruleQueryCondition);
- if (o != null) {
- String tempName = field.getName();
- if ("enabled".equals(tempName)) {
- int enabled = (int) o;
- if (enabled != RuleMgtConstant.STATUS_RULE_ALL) {
- whereSql = whereSql + "enable =" + enabled;
- whereSql += " AND ";
- }
- } else if ("name".equals(tempName)) {
- if (!"".equals(o.toString().trim())) {
- whereSql = whereSql + field.getName() + " like '%" + o + "%' AND ";
- }
- } else if (!"".equals(o.toString().trim())) {
- whereSql = whereSql + field.getName() + "='" + o + "' AND ";
- }
- }
- }
- whereSql = whereSql.trim();
- if(!"WHERE".equals(whereSql)){
- return whereSql.substring(0, whereSql.length() - "AND".length());
- }
- return "";
- } catch (Exception e) {
- throw new CorrelationException(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
deleted file mode 100644
index 437e0dd..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.setContent(resultSet.getString("content"));
- 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
deleted file mode 100644
index f3256b2..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/**
- * 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.annotation.PostConstruct;
-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 net.sf.json.JSONObject;
-import org.jvnet.hk2.annotations.Service;
-import org.openo.holmes.common.api.entity.ServiceRegisterEntity;
-import org.openo.holmes.common.config.MicroServiceConfig;
-import org.openo.holmes.common.exception.CorrelationException;
-import org.openo.holmes.common.utils.ExceptionUtil;
-import org.openo.holmes.common.utils.I18nProxy;
-import org.openo.holmes.common.utils.JacksonUtil;
-import org.openo.holmes.common.utils.LanguageUtil;
-import org.openo.holmes.common.utils.MSBRegisterUtil;
-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.constant.RuleMgtConstant;
-import org.openo.holmes.rulemgt.wrapper.RuleMgtWrapper;
-
-@Service
-@SwaggerDefinition
-@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 (CorrelationException e) {
- log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- }
- }
-
- @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);
- log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful");
- return ruleChangeResponse;
- } catch (CorrelationException e) {
- log.error("update rule:" + ruleUpdateRequest.getContent() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- }
- }
-
- @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 (CorrelationException e) {
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- }
- }
-
- @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);
- log.info("query rule successful by condition:" + JSONObject.fromObject(ruleQueryCondition));
- return ruleQueryListResponse;
- } catch (CorrelationException e) {
- log.error("query rule failed,cause query condition conversion failure", e);
- throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,
- e.getMessage()));
- }
- }
-
- 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(RuleMgtConstant.STATUS_RULE_ALL);
- } else if (queryRequest.indexOf("enabled") == -1) {
- ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);
- }
- 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
deleted file mode 100644
index 58d461f..0000000
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/**
- * 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.annotation.PostConstruct;
-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.CorrelationException;
-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;
-
- private CorrelationRuleDao correlationRuleDao;
-
- @PostConstruct
- public void initDaoUtil() {
- correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);
- }
-
- public RuleAddAndUpdateResponse addCorrelationRule(String creator, RuleCreateRequest ruleCreateRequest)
- throws CorrelationException {
- if (ruleCreateRequest == null) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
- }
- CorrelationRule correlationRule = convertCreateRequest2Rule(creator,
- ruleCreateRequest);
- checkCorrelation(correlationRule);
- CorrelationRule ruleTemp = correlationRuleDao.queryRuleByRuleName(correlationRule.getName());
- if (ruleTemp != null) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);
- }
- correlationRule.setPackageName(deployRule2Engine(correlationRule));
- CorrelationRule result = correlationRuleDao.saveRule(correlationRule);
- RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();
- ruleAddAndUpdateResponse.setRuleId(result.getRid());
- return ruleAddAndUpdateResponse;
- }
-
- public RuleAddAndUpdateResponse updateCorrelationRule(String modifier, RuleUpdateRequest ruleUpdateRequest)
- throws CorrelationException {
- if (ruleUpdateRequest == null) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
- }
- CorrelationRule oldCorrelationRule = correlationRuleDao.queryRuleByRid(ruleUpdateRequest.getRuleId());
- if (oldCorrelationRule == null) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);
- }
- CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,
- ruleUpdateRequest, oldCorrelationRule.getName());
- checkCorrelation(newCorrelationRule);
- RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();
- ruleChangeResponse.setRuleId(newCorrelationRule.getRid());
- if (!haveChange(newCorrelationRule, oldCorrelationRule)) {
- return ruleChangeResponse;
- }
- if (oldCorrelationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {
- engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName());
- }
- newCorrelationRule.setPackageName(deployRule2Engine(newCorrelationRule));
- correlationRuleDao.updateRule(newCorrelationRule);
- return ruleChangeResponse;
- }
-
- private void checkCorrelation(CorrelationRule correlationRule) throws CorrelationException {
- int enabled = correlationRule.getEnabled();
- String ruleName = correlationRule.getName() == null ? "" : correlationRule.getName().trim();
- String content = correlationRule.getContent() == null ? "" : correlationRule.getContent().trim();
- if ("".equals(content)) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CONTENT_CANNOT_BE_EMPTY);
- }
- if (enabled != RuleMgtConstant.STATUS_RULE_CLOSE
- && enabled != RuleMgtConstant.STATUS_RULE_OPEN) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);
- }
- if ("".equals(ruleName)) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY);
- }
- }
-
- private boolean haveChange(CorrelationRule newCorrelationRule, CorrelationRule oldCorrelationRule) {
- String newContent = newCorrelationRule.getContent();
- String oldContent = oldCorrelationRule.getContent();
- int newEnabled = newCorrelationRule.getEnabled();
- int oldEnabled = oldCorrelationRule.getEnabled();
- String newDes = newCorrelationRule.getDescription();
- String oldDes = oldCorrelationRule.getDescription();
- if (newContent.equals(oldContent) && newEnabled == oldEnabled && newDes.equals(oldDes)) {
- return false;
- }
- return true;
- }
-
- public void deleteCorrelationRule(RuleDeleteRequest ruleDeleteRequest)
- throws CorrelationException {
- if (ruleDeleteRequest == null) {
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);
- }
- CorrelationRule correlationRule = correlationRuleDao.queryRuleByRid(ruleDeleteRequest.getRuleId());
- if (correlationRule == null) {
- log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId() + " does not exist the database.");
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);
- }
- if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {
- engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName());
- }
- correlationRuleDao.deleteRule(correlationRule);
- }
-
- private CorrelationRule convertCreateRequest2Rule(String userName,
- RuleCreateRequest ruleCreateRequest) throws CorrelationException {
- String tempContent = ruleCreateRequest.getContent();
- CorrelationRule correlationRule = new CorrelationRule();
- String ruleId = "rule_" + System.currentTimeMillis();
- String description = ruleCreateRequest.getDescription() == null ? "" : ruleCreateRequest.getDescription();
- correlationRule.setRid(ruleId);
- if (tempContent != null) {
- correlationRule.setContent(tempContent.trim());
- }
- correlationRule.setDescription(description);
- correlationRule.setCreateTime(new Date());
- correlationRule.setUpdateTime(new Date());
- correlationRule.setName(ruleCreateRequest.getRuleName());
- correlationRule.setEngineID("correlation-d");
- correlationRule.setEngineType("");
- correlationRule.setTemplateID(0);
- correlationRule.setVendor("");
- correlationRule.setCreator(userName);
- correlationRule.setModifier(userName);
- correlationRule.setEnabled(ruleCreateRequest.getEnabled());
- return correlationRule;
- }
-
- private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,
- RuleUpdateRequest ruleUpdateRequest, String ruleName) throws CorrelationException {
- CorrelationRule correlationRule = new CorrelationRule();
- String description = ruleUpdateRequest.getDescription() == null ? "" : ruleUpdateRequest.getDescription();
- correlationRule.setRid(ruleUpdateRequest.getRuleId());
- correlationRule.setContent(ruleUpdateRequest.getContent());
- correlationRule.setDescription(description);
- correlationRule.setEnabled(ruleUpdateRequest.getEnabled());
- correlationRule.setUpdateTime(new Date());
- correlationRule.setModifier(modifier);
- correlationRule.setName(ruleName);
- return correlationRule;
- }
-
- private String deployRule2Engine(CorrelationRule correlationRule)
- throws CorrelationException {
- if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule)) && (
- correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN)) {
- return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule));
- }
- return "";
- }
-
- public RuleQueryListResponse getCorrelationRuleByCondition(
- RuleQueryCondition ruleQueryCondition) throws CorrelationException {
- 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();
- String description = correlationRule.getDescription() == null ? "" : correlationRule.getDescription();
- ruleResult4API.setRuleId(correlationRule.getRid());
- ruleResult4API.setRuleName(correlationRule.getName());
- ruleResult4API.setDescription(description);
- 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;
- }
-}