From 20a1514bf93035472d4f940f00a357106d4bec1f Mon Sep 17 00:00:00 2001 From: Guangrong Fu Date: Mon, 7 Aug 2017 12:30:35 +0800 Subject: 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 --- .../org/onap/holmes/rulemgt/RuleActiveApp.java | 61 +++++ .../org/onap/holmes/rulemgt/RuleAppConfig.java | 58 +++++ .../bean/request/CorrelationCheckRule4Engine.java | 27 +++ .../bean/request/CorrelationDeployRule4Engine.java | 31 +++ .../bean/request/CorrelationRestRequest.java | 27 +++ .../rulemgt/bean/request/RuleCreateRequest.java | 33 +++ .../rulemgt/bean/request/RuleDeleteRequest.java | 28 +++ .../rulemgt/bean/request/RuleQueryCondition.java | 34 +++ .../rulemgt/bean/request/RuleUpdateRequest.java | 33 +++ .../bean/response/RuleAddAndUpdateResponse.java | 29 +++ .../bean/response/RuleQueryListResponse.java | 34 +++ .../rulemgt/bean/response/RuleResult4API.java | 42 ++++ .../rulemgt/bolt/enginebolt/EngineService.java | 66 ++++++ .../rulemgt/bolt/enginebolt/EngineWrapper.java | 87 ++++++++ .../holmes/rulemgt/constant/RuleMgtConstant.java | 29 +++ .../onap/holmes/rulemgt/db/CorrelationRuleDao.java | 106 +++++++++ .../holmes/rulemgt/db/CorrelationRuleQueryDao.java | 128 +++++++++++ .../rulemgt/db/mapper/CorrelationRuleMapper.java | 48 ++++ .../holmes/rulemgt/resources/RuleMgtResources.java | 161 ++++++++++++++ .../holmes/rulemgt/wrapper/RuleMgtWrapper.java | 244 ++++++++++++++++++++ .../org/openo/holmes/rulemgt/RuleActiveApp.java | 61 ----- .../org/openo/holmes/rulemgt/RuleAppConfig.java | 58 ----- .../bean/request/CorrelationCheckRule4Engine.java | 27 --- .../bean/request/CorrelationDeployRule4Engine.java | 31 --- .../bean/request/CorrelationRestRequest.java | 27 --- .../rulemgt/bean/request/RuleCreateRequest.java | 33 --- .../rulemgt/bean/request/RuleDeleteRequest.java | 28 --- .../rulemgt/bean/request/RuleQueryCondition.java | 34 --- .../rulemgt/bean/request/RuleUpdateRequest.java | 33 --- .../bean/response/RuleAddAndUpdateResponse.java | 29 --- .../bean/response/RuleQueryListResponse.java | 34 --- .../rulemgt/bean/response/RuleResult4API.java | 42 ---- .../rulemgt/bolt/enginebolt/EngineService.java | 66 ------ .../rulemgt/bolt/enginebolt/EngineWrapper.java | 88 -------- .../holmes/rulemgt/constant/RuleMgtConstant.java | 29 --- .../holmes/rulemgt/db/CorrelationRuleDao.java | 107 --------- .../holmes/rulemgt/db/CorrelationRuleQueryDao.java | 129 ----------- .../rulemgt/db/mapper/CorrelationRuleMapper.java | 48 ---- .../holmes/rulemgt/resources/RuleMgtResources.java | 168 -------------- .../holmes/rulemgt/wrapper/RuleMgtWrapper.java | 245 --------------------- 40 files changed, 1306 insertions(+), 1317 deletions(-) create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequest.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java create mode 100644 rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequest.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleCreateRequest.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleDeleteRequest.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleQueryCondition.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequest.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponse.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/response/RuleResult4API.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java delete mode 100644 rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java (limited to 'rulemgt/src/main') diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java new file mode 100644 index 0000000..8dc697c --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java @@ -0,0 +1,61 @@ +/** + * 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.onap.holmes.rulemgt; + +import io.dropwizard.setup.Environment; +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; +import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication; +import org.onap.holmes.common.api.entity.ServiceRegisterEntity; +import org.onap.holmes.common.config.MicroServiceConfig; +import org.onap.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("/onapapi/holmes-rule-mgmt/v1"); + serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0); + serviceRegisterEntity.setVisualRange("1|0"); + return serviceRegisterEntity; + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java new file mode 100644 index 0000000..20f96c2 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java @@ -0,0 +1,58 @@ +/** + * 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.onap.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/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java new file mode 100644 index 0000000..c36fce7 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java @@ -0,0 +1,27 @@ +/** + * 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.onap.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/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java new file mode 100644 index 0000000..7c94395 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java @@ -0,0 +1,31 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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/onap/holmes/rulemgt/bean/request/CorrelationRestRequest.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequest.java new file mode 100644 index 0000000..e79cc62 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequest.java @@ -0,0 +1,27 @@ +/** + * 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.onap.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/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java new file mode 100644 index 0000000..f090c3b --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java @@ -0,0 +1,33 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java new file mode 100644 index 0000000..7cc4fff --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java @@ -0,0 +1,28 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java new file mode 100644 index 0000000..f3b9b91 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java @@ -0,0 +1,34 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java new file mode 100644 index 0000000..e2811e3 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java @@ -0,0 +1,33 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java new file mode 100644 index 0000000..7fe432e --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java @@ -0,0 +1,29 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java new file mode 100644 index 0000000..17903ab --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java @@ -0,0 +1,34 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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 correlationRules = new ArrayList(); + @JsonProperty(value = "totalcount") + private int totalCount; +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java new file mode 100644 index 0000000..c444b22 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java @@ -0,0 +1,42 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java new file mode 100644 index 0000000..f3e8d5c --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java @@ -0,0 +1,66 @@ +/** + * 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.onap.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.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine; +import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine; +import org.onap.holmes.rulemgt.constant.RuleMgtConstant; +import org.onap.holmes.common.config.MicroServiceConfig; + +@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/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java new file mode 100644 index 0000000..733cae0 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java @@ -0,0 +1,87 @@ +/** + * 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.onap.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.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine; +import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine; +import org.onap.holmes.rulemgt.constant.RuleMgtConstant; +import org.onap.holmes.common.exception.CorrelationException; + +@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("Failed to call the rule deployment RESTful API.", e); + } + if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) { + log.info("Succeeded in calling the rule deployment RESTful API from the engine management service."); + try { + JSONObject json = JSONObject.fromObject(response.readEntity(String.class)); + return json.get(RuleMgtConstant.PACKAGE).toString(); + } catch (Exception e) { + throw new CorrelationException("Failed to parse the value returned by the engine management service.", e); + } + } else { + throw new CorrelationException("Failed to deploy the rule!"); + } + } + + public boolean deleteRuleFromEngine(String packageName) throws CorrelationException { + Response response; + try { + response = engineService.delete(packageName); + } catch (Exception e) { + throw new CorrelationException("Failed to call the rule deleting RESTful API.", e); + } + if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) { + log.info("Succeeded in calling the rule deleting RESTful API from the engine management service."); + return true; + } else { + throw new CorrelationException("Failed to delete the rule!"); + } + } + + public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine) + throws CorrelationException { + log.info("Rule Contents: " + correlationCheckRule4Engine.getContent()); + Response response; + try { + response = engineService.check(correlationCheckRule4Engine); + } catch (Exception e) { + throw new CorrelationException("Failed to call the rule verification RESTful API.", e); + } + if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) { + log.info("Succeeded in calling the rule verification RESTful API from the engine management service."); + return true; + } else { + log.info(response.getStatus() + " " + response.getStatusInfo() + " " + response.getEntity()); + throw new CorrelationException("Failed to verify the rule. The contents of the rule are invalid."); + } + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java new file mode 100644 index 0000000..debfb05 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java @@ -0,0 +1,29 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.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 = "/onapapi/holmes-engine-mgmt/v1/rule"; + public static final int RESPONSE_STATUS_OK = 200; +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java new file mode 100644 index 0000000..2a422c4 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java @@ -0,0 +1,106 @@ +/** + * 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.onap.holmes.rulemgt.db; + +import java.util.List; +import org.onap.holmes.common.api.entity.CorrelationRule; +import org.onap.holmes.common.exception.CorrelationException; +import org.onap.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 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("Can not access the database. Please contact the administrator for help.", e); + } + } + + public void updateRule(CorrelationRule correlationRule) throws CorrelationException { + try { + updateRuleByRid(correlationRule); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public void deleteRule(CorrelationRule correlationRule) throws CorrelationException { + try { + deleteRule2DbInner(correlationRule); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + + public CorrelationRule queryRuleByRid(String rid) throws CorrelationException { + try { + return queryRuleById(rid); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException { + try { + return queryRuleByName(name); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } +} + diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java new file mode 100644 index 0000000..322006d --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java @@ -0,0 +1,128 @@ +/** + * 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.onap.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.onap.holmes.rulemgt.bean.request.RuleQueryCondition; +import org.onap.holmes.rulemgt.constant.RuleMgtConstant; +import org.onap.holmes.common.api.entity.CorrelationRule; +import org.onap.holmes.common.exception.CorrelationException; +import org.onap.holmes.common.utils.DbDaoUtil; +import org.skife.jdbi.v2.Handle; +import org.skife.jdbi.v2.Query; + +@Service +@Slf4j +public class CorrelationRuleQueryDao { + + @Inject + private DbDaoUtil dbDaoUtil; + + public List getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition) + throws CorrelationException { + List correlationRules = new ArrayList(); + 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("Failed to query the rule: id =" + ruleQueryCondition.getRid() + "."); + throw new CorrelationException("Failed to query the rule.", 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("An error occurred while building the query SQL.", e); + } + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java new file mode 100644 index 0000000..d40253f --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/mapper/CorrelationRuleMapper.java @@ -0,0 +1,48 @@ +/** + * 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.onap.holmes.rulemgt.db.mapper; + +import org.onap.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 { + @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/onap/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java new file mode 100644 index 0000000..04578f7 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java @@ -0,0 +1,161 @@ +/** + * 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.onap.holmes.rulemgt.resources; + +import com.codahale.metrics.annotation.Timed; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.SwaggerDefinition; +import java.io.IOException; +import java.util.Locale; +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONObject; +import org.jvnet.hk2.annotations.Service; +import org.onap.holmes.common.api.entity.ServiceRegisterEntity; +import org.onap.holmes.common.config.MicroServiceConfig; +import org.onap.holmes.common.exception.CorrelationException; +import org.onap.holmes.common.utils.ExceptionUtil; +import org.onap.holmes.common.utils.JacksonUtil; +import org.onap.holmes.common.utils.LanguageUtil; +import org.onap.holmes.common.utils.MSBRegisterUtil; +import org.onap.holmes.common.utils.UserUtil; +import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest; +import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest; +import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition; +import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest; +import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse; +import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; +import org.onap.holmes.rulemgt.constant.RuleMgtConstant; +import org.onap.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.
[rulename]:required
[content]:required
[enabled]:required", 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(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.
[ruleid]:required", 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(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.
[ruleid]:required", 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(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:
" + " [ruleid]:Rule ID;
" + + "[rulename]:Rule name;
" + "[creator]:creator of the rule;
" + + "[modifier]:modifier of the rule;
" + + "[enabled]: 0 is Enabled,1 is disabled;
for example:
{\"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(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("The request format is invalid!"); + } + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java new file mode 100644 index 0000000..beffa56 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java @@ -0,0 +1,244 @@ +/** + * 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.onap.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.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine; +import org.onap.holmes.rulemgt.bean.response.RuleResult4API; +import org.onap.holmes.rulemgt.constant.RuleMgtConstant; +import org.onap.holmes.rulemgt.db.CorrelationRuleDao; +import org.onap.holmes.common.api.entity.CorrelationRule; +import org.onap.holmes.common.exception.CorrelationException; +import org.onap.holmes.common.utils.DbDaoUtil; +import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine; +import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest; +import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest; +import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition; +import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest; +import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse; +import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; +import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper; +import org.onap.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("The request object can not be empty!"); + } + CorrelationRule correlationRule = convertCreateRequest2Rule(creator, + ruleCreateRequest); + checkCorrelation(correlationRule); + CorrelationRule ruleTemp = correlationRuleDao.queryRuleByRuleName(correlationRule.getName()); + if (ruleTemp != null) { + throw new CorrelationException("A rule with the same name already exists."); + } + 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("The request object can not be empty!"); + } + CorrelationRule oldCorrelationRule = correlationRuleDao.queryRuleByRid(ruleUpdateRequest.getRuleId()); + if (oldCorrelationRule == null) { + throw new CorrelationException("You're trying to update a rule which does not exist in the system."); + } + 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("The contents of the rule can not be empty!"); + } + if (enabled != RuleMgtConstant.STATUS_RULE_CLOSE + && enabled != RuleMgtConstant.STATUS_RULE_OPEN) { + throw new CorrelationException("Invalid rule status. Only 0 (disabled) and 1 (enabled) are allowed."); + } + if ("".equals(ruleName)) { + throw new CorrelationException("The name of the rule can not 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("The request object can not be 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("You're trying to delete a rule which does not exist in the system."); + } + 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 = correlationRuleQueryDao + .getCorrelationRulesByCondition(ruleQueryCondition); + RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse(); + ruleQueryListResponse.setTotalCount(correlationRule.size()); + ruleQueryListResponse + .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule)); + return ruleQueryListResponse; + } + + private List correlationRules2RuleResult4APIs( + List correlationRules) { + List ruleResult4APIs = new ArrayList(); + 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; + } +} 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 correlationRules = new ArrayList(); - @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 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 getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition) - throws CorrelationException { - List correlationRules = new ArrayList(); - 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 { - @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.
[rulename]:required
[content]:required
[enabled]:required", 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.
[ruleid]:required", 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.
[ruleid]:required", 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:
" + " [ruleid]:Rule ID;
" - + "[rulename]:Rule name;
" + "[creator]:creator of the rule;
" - + "[modifier]:modifier of the rule;
" - + "[enabled]: 0 is Enabled,1 is disabled;
for example:
{\"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 = correlationRuleQueryDao - .getCorrelationRulesByCondition(ruleQueryCondition); - RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse(); - ruleQueryListResponse.setTotalCount(correlationRule.size()); - ruleQueryListResponse - .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule)); - return ruleQueryListResponse; - } - - private List correlationRules2RuleResult4APIs( - List correlationRules) { - List ruleResult4APIs = new ArrayList(); - 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; - } -} -- cgit 1.2.3-korg