From 8b3c9e2b928e3a0308974482e2645ace4838c468 Mon Sep 17 00:00:00 2001 From: Guangrong Fu Date: Mon, 31 Jul 2017 19:20:25 +0800 Subject: Change the package name from openo to onap Change the package name & maven from openo to onap Change-Id: I9c1fcaaa1c357fbd2b5c3bc2108d7cebd2b0ffc6 Issue-ID: HOLMES-10 Signed-off-by: Guangrong Fu --- holmes-actions/pom.xml | 23 +- .../common/api/entity/AlarmsCorrelation.java | 53 +++ .../common/api/entity/CorrelationResult.java | 44 +++ .../holmes/common/api/entity/CorrelationRule.java | 57 +++ .../onap/holmes/common/api/entity/ServiceNode.java | 39 ++ .../common/api/entity/ServiceRegisterEntity.java | 54 +++ .../org/onap/holmes/common/api/stat/Alarm.java | 279 +++++++++++++ .../org/onap/holmes/common/api/stat/AplusData.java | 43 +++ .../onap/holmes/common/api/stat/AplusResult.java | 66 ++++ .../org/onap/holmes/common/config/MQConfig.java | 39 ++ .../holmes/common/config/MicroServiceConfig.java | 38 ++ .../onap/holmes/common/constant/AlarmConst.java | 41 ++ .../dropwizard/ioc/annotation/BaseService.java | 34 ++ .../common/dropwizard/ioc/annotation/Lazy.java | 34 ++ .../dropwizard/ioc/annotation/PostBaseService.java | 34 ++ .../dropwizard/ioc/annotation/PreBaseService.java | 34 ++ .../common/dropwizard/ioc/annotation/PreLoad.java | 34 ++ .../dropwizard/ioc/annotation/PreServiceLoad.java | 35 ++ .../dropwizard/ioc/bundle/AutoConfigBundle.java | 430 +++++++++++++++++++++ .../ioc/bundle/AutoConfigBundleBuider.java | 42 ++ .../dropwizard/ioc/bundle/IOCApplication.java | 42 ++ .../ioc/bundle/ServiceLocatorManaged.java | 51 +++ .../common/dropwizard/ioc/utils/ServiceBinder.java | 52 +++ .../dropwizard/ioc/utils/ServiceLocatorHolder.java | 36 ++ .../common/exception/CorrelationException.java | 27 ++ .../holmes/common/msb/MicroserviceBusRest.java | 36 ++ .../onap/holmes/common/producer/MQProducer.java | 107 +++++ .../org/onap/holmes/common/utils/DbDaoUtil.java | 92 +++++ .../onap/holmes/common/utils/ExceptionUtil.java | 34 ++ .../org/onap/holmes/common/utils/JacksonUtil.java | 40 ++ .../onap/holmes/common/utils/JudgeNullUtil.java | 49 +++ .../org/onap/holmes/common/utils/LanguageUtil.java | 52 +++ .../onap/holmes/common/utils/MSBRegisterUtil.java | 74 ++++ .../org/onap/holmes/common/utils/UserUtil.java | 35 ++ .../common/api/entity/AlarmsCorrelation.java | 53 --- .../common/api/entity/CorrelationResult.java | 44 --- .../holmes/common/api/entity/CorrelationRule.java | 57 --- .../holmes/common/api/entity/ServiceNode.java | 39 -- .../common/api/entity/ServiceRegisterEntity.java | 54 --- .../org/openo/holmes/common/api/stat/Alarm.java | 279 ------------- .../openo/holmes/common/api/stat/AplusData.java | 43 --- .../openo/holmes/common/api/stat/AplusResult.java | 66 ---- .../org/openo/holmes/common/config/MQConfig.java | 39 -- .../holmes/common/config/MicroServiceConfig.java | 38 -- .../openo/holmes/common/constant/AlarmConst.java | 41 -- .../common/exception/CorrelationException.java | 27 -- .../holmes/common/i18n/correlation-i18n-en-US.json | 34 -- .../holmes/common/i18n/correlation-i18n-zh-CN.json | 31 -- .../holmes/common/msb/MicroserviceBusRest.java | 36 -- .../openo/holmes/common/producer/MQProducer.java | 107 ----- .../org/openo/holmes/common/utils/DbDaoUtil.java | 92 ----- .../openo/holmes/common/utils/ExceptionUtil.java | 34 -- .../org/openo/holmes/common/utils/I18nProxy.java | 111 ------ .../org/openo/holmes/common/utils/JacksonUtil.java | 40 -- .../openo/holmes/common/utils/JudgeNullUtil.java | 49 --- .../openo/holmes/common/utils/LanguageUtil.java | 52 --- .../openo/holmes/common/utils/MSBRegisterUtil.java | 74 ---- .../org/openo/holmes/common/utils/UserUtil.java | 35 -- .../common/api/entity/AlarmsCorrelationTest.java | 132 +++++++ .../common/api/entity/CorrelationResultTest.java | 78 ++++ .../common/api/entity/CorrelationRuleTest.java | 146 +++++++ .../holmes/common/api/entity/ServiceNodeTest.java | 48 +++ .../api/entity/ServiceRegisterEntityTest.java | 62 +++ .../org/onap/holmes/common/api/stat/AlarmTest.java | 207 ++++++++++ .../onap/holmes/common/config/MQConfigTest.java | 28 ++ .../common/config/MicroServiceConfigTest.java | 39 ++ .../common/exception/CorrelationExceptionTest.java | 29 ++ .../holmes/common/producer/MQProducerTest.java | 173 +++++++++ .../onap/holmes/common/utils/DbDaoUtilTest.java | 188 +++++++++ .../holmes/common/utils/ExceptionUtilTest.java | 29 ++ .../onap/holmes/common/utils/JacksonUtilTest.java | 49 +++ .../holmes/common/utils/JudgeNullUtilTest.java | 43 +++ .../onap/holmes/common/utils/LanguageUtilTest.java | 118 ++++++ .../holmes/common/utils/MSBRegisterUtilTest.java | 72 ++++ .../org/onap/holmes/common/utils/UserUtilTest.java | 67 ++++ .../onap/holmes/common/utils/bean/TestBean.java | 32 ++ .../common/api/entity/AlarmsCorrelationTest.java | 133 ------- .../common/api/entity/CorrelationResultTest.java | 78 ---- .../common/api/entity/CorrelationRuleTest.java | 146 ------- .../holmes/common/api/entity/ServiceNodeTest.java | 48 --- .../api/entity/ServiceRegisterEntityTest.java | 62 --- .../openo/holmes/common/api/stat/AlarmTest.java | 207 ---------- .../openo/holmes/common/config/MQConfigTest.java | 28 -- .../common/config/MicroServiceConfigTest.java | 39 -- .../common/exception/CorrelationExceptionTest.java | 29 -- .../holmes/common/producer/MQProducerTest.java | 173 --------- .../openo/holmes/common/utils/DbDaoUtilTest.java | 188 --------- .../holmes/common/utils/ExceptionUtilTest.java | 31 -- .../openo/holmes/common/utils/I18nProxyTest.java | 62 --- .../openo/holmes/common/utils/JacksonUtilTest.java | 49 --- .../holmes/common/utils/JudgeNullUtilTest.java | 43 --- .../holmes/common/utils/LanguageUtilTest.java | 118 ------ .../holmes/common/utils/MSBRegisterUtilTest.java | 72 ---- .../openo/holmes/common/utils/UserUtilTest.java | 67 ---- .../openo/holmes/common/utils/bean/TestBean.java | 32 -- pom.xml | 22 +- 96 files changed, 3716 insertions(+), 3106 deletions(-) create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusData.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusResult.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/exception/CorrelationException.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/msb/MicroserviceBusRest.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/ExceptionUtil.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/JacksonUtil.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/JudgeNullUtil.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/LanguageUtil.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/UserUtil.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceNode.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceRegisterEntity.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/config/MicroServiceConfig.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/exception/CorrelationException.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/msb/MicroserviceBusRest.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java delete mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java create mode 100644 holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java delete mode 100644 holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml index 1ca8a8a..e412348 100644 --- a/holmes-actions/pom.xml +++ b/holmes-actions/pom.xml @@ -11,9 +11,9 @@ 4.0.0 - org.openo.holmes.actions + org.onap.holmes.actions holmes-actions-parent - 1.1.0-SNAPSHOT + 1.0.0-SNAPSHOT holmes-actions-service @@ -32,10 +32,6 @@ org.apache.activemq activemq-pool - - org.openo.common-services.common-utilities - baseservice-i18n - org.antlr stringtemplate @@ -90,10 +86,6 @@ org.jdom jdom - - org.openo.common-services.common-utilities - dropwizard-ioc-container - org.easymock easymock @@ -122,6 +114,17 @@ consumer ${jaxrs.consumer.version} + + org.glassfish.jersey.containers + jersey-container-servlet-core + ${jersey.version} + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java new file mode 100644 index 0000000..ee32be2 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java @@ -0,0 +1,53 @@ +/** + * 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.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Date; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class AlarmsCorrelation { + + @JsonProperty(value = "ruleid") + private String ruleId; + + @JsonProperty(value = "ruleinfo") + private String ruleInfo; + + @JsonProperty(value = "resulttype") + private byte resultType; + + @JsonProperty(value = "createtime") + private Date createTime; + + @JsonProperty(value = "parentalarmid") + private long parentAlarmId; + + @JsonProperty(value = "childalarmid") + private long childAlarmId; + + @JsonProperty(defaultValue = "-1") + private long reserve1 = -1; + + @JsonProperty(defaultValue = "-1") + private long reserve2 = -1; + + @JsonProperty(defaultValue = "-1") + private long reserve3 = -1; +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java new file mode 100644 index 0000000..6802696 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java @@ -0,0 +1,44 @@ +/** + * 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.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.onap.holmes.common.api.stat.Alarm; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Setter +@Getter +@NoArgsConstructor +@ToString +public class CorrelationResult implements Serializable{ + + @JsonProperty + private String ruleId; + + @JsonProperty + private long createTimeL; + + @JsonProperty + private byte resultType; + + @JsonProperty + private Alarm[] affectedAlarms; +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java new file mode 100644 index 0000000..6b91bd3 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java @@ -0,0 +1,57 @@ +/** + * 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.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Date; +import java.util.Properties; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CorrelationRule { + + @JsonProperty(value = "ruleid") + private String rid; + @JsonProperty(value = "rulename") + private String name; + @JsonProperty + private String description; + @JsonProperty + private int enabled; + @JsonProperty + private int templateID; + private String engineID; + @JsonProperty + private String engineType; + @JsonProperty + private String creator; + @JsonProperty + private String modifier; + @JsonProperty + private Properties params; + @JsonProperty + private String content; + @JsonProperty + private String vendor; + @JsonProperty(value = "createtime") + private Date createTime; + @JsonProperty(value = "updatetime") + private Date updateTime; + @JsonProperty(value = "package") + private String packageName; +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java new file mode 100644 index 0000000..d456910 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java @@ -0,0 +1,39 @@ +/** + * 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.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +@Setter +public class ServiceNode { + + private String ip; + private String port; + private int ttl; + +} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java new file mode 100644 index 0000000..7804082 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java @@ -0,0 +1,54 @@ +/** + * 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.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@Setter +@Getter +public class ServiceRegisterEntity { + + private String serviceName; + private String version; + private String url; + private String protocol; + private String visualRange = "1"; + private List nodes = new ArrayList<>(); + + public void setSingleNode(String ip, String port, int ttl) { + ServiceNode node = new ServiceNode(); + if (ip != null && ip.length() > 0) { + node.setIp(ip); + } else { + node.setIp(null); + } + node.setPort(port); + node.setTtl(ttl); + nodes.add(node); + } +} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java new file mode 100644 index 0000000..be876e0 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java @@ -0,0 +1,279 @@ +/** + * 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.common.api.stat; + +import java.io.Serializable; +import java.io.StringReader; +import java.lang.reflect.Field; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import lombok.Getter; +import lombok.Setter; +import org.jdom.Attribute; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; +import org.jdom.output.XMLOutputter; + + +@Getter +@Setter +public class Alarm implements AplusData, Cloneable, Serializable { + + public static final byte EVENT_CLEARED_ALARM = 3; + + public static final byte EVENT_CHANGED = 2; + + public static final byte EVENT_CLEARED = 1; + + public static final byte EVENT_RAISED = 0; + + private static final long serialVersionUID = 4520003737132012000L; + private final static Date clearedServerTime = null; + private final Map linkIdNodeIdxMap = new HashMap(); + private byte eventType = EVENT_RAISED; + private long id = 0L; + private String alarmKey = ""; + private String network = ""; + private String neType = ""; + private String equipType = ""; + private String position1 = ""; + private String subPosition1 = null; + private String position2 = null; + private String subPosition2 = null; + private byte severity = -1; + private byte alarmType = -1; + private long probableCause = -1; + private String specificProblem = null; + private String additionalText = null; + private Date raisedTime = new Date(); + private Date raisedServerTime = new Date(); + private Date clearedTime = null; + private String region = null; + private String site = null; + private String aid = null; + private short systemType = -1; + private boolean rootAlarmFlag = false; + private int linkId = -1; + private int nodeIdx = -1; + private Set linkIds = new HashSet(); + private HashMap priorityMap = new HashMap(); + private HashMap rootAlarmTypeMap = new HashMap(); + private int rootAlarmType = -1; + private boolean keyAlarmFlag = false; + private int keyAlarmType = -1; + private int networkLevel = -1; + private int linkType = -1; + private int centerType; + + public static Alarm valueOf(String xmlString) { + Element element; + try { + StringReader sb = new StringReader(xmlString); + element = new SAXBuilder().build(sb).getRootElement(); + sb.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + Alarm alarm = new Alarm(); + @SuppressWarnings("unchecked") + List list = element.getAttributes(); + for (Attribute attr : list) { + String attrName = attr.getName(); + try { + Field field = Alarm.class.getDeclaredField(attrName); + if (!attrName.endsWith("Time")) { + String type = field.getType().getSimpleName(); + if ("byte".equals(type)) { + field.set(alarm, Byte.parseByte(attr.getValue())); + } else if ("long".equals(type)) { + field.set(alarm, Long.parseLong(attr.getValue())); + } else if ("String".equals(type)) { + field.set(alarm, attr.getValue()); + } else { + throw new RuntimeException("unknow attr type: " + type.toString()); + } + } else { + Date date = new Date(); + date.setTime(Long.parseLong(attr.getValue())); + field.set(alarm, date); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + return alarm; + } + + public void addLinkIdNodeIdx(int linkId, int index) { + linkIdNodeIdxMap.put(linkId, index); + } + + /** + * Comparison of the location of different links: 999 the same link: the location of the node + * number less than otherIdIdx in the location of the number (in the otherIdIdx upstream):-1, + * the same link: the node position number is equal to the number of position in the otherIdIdx + * (in the same site otherIdIdx):0, the same link: the node location number is greater than the + * number of locations in otherIdIdx (otherIdIdx) with the site):1, + */ + public int CompareLinkPosition(Map otherIdIdx) { + Set myIdSet = new HashSet(); + myIdSet.addAll(this.linkIdNodeIdxMap.keySet()); + myIdSet.retainAll(otherIdIdx.keySet()); + + if (myIdSet.isEmpty()) { + return 999; + } + + for (int tempLinkId : myIdSet) { + return this.linkIdNodeIdxMap.get(tempLinkId) - otherIdIdx.get(tempLinkId); + } + return 999; + } + + public boolean containNode(int linkId, int index) { + return linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index; + } + + @Override + public byte getDataType() { + return APLUS_EVENT; + } + + @Override + public String toString() { + final String nullStr = ""; + + Element el = new Element("Alarm"); + el.setAttribute("id", String.valueOf(id)); + el.setAttribute("aid", String.valueOf(aid)); + el.setAttribute("alarmKey", String.valueOf(alarmKey)); + el.setAttribute("eventType", String.valueOf(eventType)); + el.setAttribute("region", region == null ? nullStr : region); + el.setAttribute("site", site == null ? nullStr : site); + el.setAttribute("network", network); + el.setAttribute("neType", neType); + el.setAttribute("equipType", equipType); + el.setAttribute("position1", position1); + el.setAttribute("subPosition1", subPosition1 == null ? nullStr : subPosition1); + el.setAttribute("position2", position2 == null ? nullStr : position2); + el.setAttribute("subPosition2", subPosition2 == null ? nullStr : subPosition2); + el.setAttribute("severity", String.valueOf(severity)); + el.setAttribute("alarmType", String.valueOf(alarmType)); + el.setAttribute("probableCause", String.valueOf(probableCause)); + el.setAttribute("specificProblem", specificProblem == null ? nullStr : specificProblem); + el.setAttribute("additionalText", additionalText == null ? nullStr : additionalText); + el.setAttribute("raisedTime", String.valueOf(raisedTime.getTime())); + el.setAttribute("raisedServerTime", String.valueOf(raisedServerTime.getTime())); + if (clearedTime != null) { + el.setAttribute("clearedTime", String.valueOf(clearedTime.getTime())); + } + if (clearedServerTime != null) { + el.setAttribute("clearedServerTime", String.valueOf(clearedServerTime.getTime())); + } + + return new XMLOutputter().outputString(el); + } + + @Override + public int hashCode() { + return this.getAlarmKey().hashCode(); + } + + @Override + public boolean equals(Object arg0) { + if (arg0 == null || !(arg0 instanceof Alarm)) { + return false; + } + return this.alarmKey.equals(((Alarm) arg0).getAlarmKey()); + } + + @Override + public Object clone() throws CloneNotSupportedException { + super.clone(); + + Alarm alarm = new Alarm(); + + alarm.setEventType(this.getEventType()); + + alarm.setAid(this.getAid()); + alarm.setId(this.getId()); + alarm.setAlarmKey(this.getAlarmKey()); + + alarm.setNetwork(this.getNetwork()); + alarm.setEquipType(this.getEquipType()); + alarm.setNeType(this.getNeType()); + alarm.setPosition1(this.getPosition1()); + alarm.setSubPosition1(this.getSubPosition1()); + alarm.setPosition2(this.getPosition2()); + alarm.setSubPosition2(this.getSubPosition2()); + alarm.setRegion(this.getRegion()); + alarm.setSite(this.getSite()); + + alarm.setSeverity(this.getSeverity()); + alarm.setAlarmType(this.getAlarmType()); + alarm.setSystemType(this.getSystemType()); + alarm.setSpecificProblem(this.getSpecificProblem()); + alarm.setAdditionalText(this.getAdditionalText()); + alarm.setProbableCause(this.getProbableCause()); + + alarm.setRaisedTime(this.getRaisedTime()); + alarm.setRaisedServerTime(this.getRaisedServerTime()); + alarm.setClearedTime(this.getClearedTime()); + + return alarm; + } + + @Override + public String getObjectId() { + return String.valueOf(id); + } + + public void addLinkIds(int linkId) { + linkIds.add(linkId); + } + + + public boolean containsPriority(String ruleId) { + if (priorityMap.keySet().contains(ruleId)) { + return true; + } + return false; + } + + public int getPriority(String ruleId) { + Integer priority = this.priorityMap.get(ruleId); + if (priority == null) { + priority = 0; + } + return priority; + } + + public int getRootAlarmType(String ruleId) { + Integer rootAlarmType = this.rootAlarmTypeMap.get(ruleId); + if (rootAlarmType == null) { + rootAlarmType = -1; + } + return rootAlarmType; + } + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusData.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusData.java new file mode 100644 index 0000000..50d28db --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusData.java @@ -0,0 +1,43 @@ +/** + * 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.common.api.stat; + +import java.io.Serializable; + +public interface AplusData extends Serializable { + + /** + * The data to be analyzed with aging characteristics - 0 + */ + byte APLUS_EVENT = 0; + + /** + * The data to be analyzed without aging characteristics - 1 + */ + byte APLUS_FACT = 1; + + + /** + * @see #APLUS_EVENT + * @see #APLUS_FACT + */ + byte getDataType(); + + /** + * @return String + */ + String getObjectId(); +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusResult.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusResult.java new file mode 100644 index 0000000..6e46608 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/AplusResult.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.common.api.stat; + +import java.io.Serializable; + +public interface AplusResult extends Serializable { + + /** + * Derived new alarm type - 0 + */ + byte APLUS_RAISED = 0; + + /** + * Correlation alarm, root-child alarm - 1 + */ + byte APLUS_CORRELATION = 1; + + /** + * cleared + */ + byte APLUS_CLEAR = 2; + + + int getId(); + + void setId(int id); + + String getRuleInfo(); + + void setRuleInfo(String ruleInfo); + + String getRuleType(); + + void setRuleType(String ruleType); + + void setRuleId(String ruleId); + + String getRuleId(); + + long getCreateTime(); + + void setCreateTime(long createTime); + + byte getResultType(); + + void setResultType(byte resultType); + + Alarm[] getAffectedAlarms(); + + void setAffectedAlarms(Alarm[] affectedAlarms); + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java new file mode 100644 index 0000000..e1b333b --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java @@ -0,0 +1,39 @@ +/** + * 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.common.config; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.HashMap; +import java.util.Map; +import javax.validation.constraints.NotNull; + +public class MQConfig { + + @JsonProperty + @NotNull + public String brokerIp; + + @JsonProperty + @NotNull + public int brokerPort; + + @JsonProperty + public String brokerUsername; + + @JsonProperty + public String brokerPassword; +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java new file mode 100644 index 0000000..6f5a67c --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java @@ -0,0 +1,38 @@ +/** + * 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.common.config; + +import org.onap.holmes.common.constant.AlarmConst; + +public class MicroServiceConfig { + + private static String getProperty(String name) { + String value = System.getenv(name); + if (value == null) { + value = System.getProperty(name); + } + return value; + } + + public static String getMsbServerAddr() { + return AlarmConst.HTTP + getProperty("MSB_ADDR"); + } + + public static String getServiceIp() { + return getProperty("SERVICE_IP"); + } + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java b/holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java new file mode 100644 index 0000000..e9e5361 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java @@ -0,0 +1,41 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.holmes.common.constant; + +public interface AlarmConst { + + String MQ_TOPIC_NAME_ALARMS_CORRELATION = "topic://voss/fm/alarms_correlation"; + + String MQ_TOPIC_NAME_ALARM = "topic://voss/fm/alarm"; + + String NFVO_PATH = "/onapapi/umc/v1/fm/curalarms/findAll"; + + int NFVO_STATUS_OK = 200; + + String I18N_EN = "en"; + + String I18N_ZH = "zh"; + + String ZH_CN = "zh_CN"; + + String ADMIN = "admin"; + + int MICRO_SERVICE_STATUS_SUCCESS = 201; + + int MICRO_SERVICE_PORT = 8086; + + String HTTP = "http://"; +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.java new file mode 100644 index 0000000..9f0ae67 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.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.common.dropwizard.ioc.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * basic services for identification + * @author hu.rui + * + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface BaseService { + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.java new file mode 100644 index 0000000..4f7d046 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.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.common.dropwizard.ioc.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * lazy loading of related services + * @author hu.rui + * + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Lazy { + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.java new file mode 100644 index 0000000..4787bec --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.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.common.dropwizard.ioc.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * load on after basic services + * @author hu.rui + * + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface PostBaseService { + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.java new file mode 100644 index 0000000..669bceb --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.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.common.dropwizard.ioc.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * prior to basic service loading + * @author hu.rui + * + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface PreBaseService { + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.java new file mode 100644 index 0000000..dce3e58 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.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.common.dropwizard.ioc.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * load before general service + * @author hu.rui + * + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface PreLoad { + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java new file mode 100644 index 0000000..815c1d7 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java @@ -0,0 +1,35 @@ +/** + * 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.common.dropwizard.ioc.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * load before general service,after PreLoad + * @author hu.rui + * + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface PreServiceLoad { + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java new file mode 100644 index 0000000..2b8e114 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java @@ -0,0 +1,430 @@ +/** + * 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.common.dropwizard.ioc.bundle; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.ws.rs.Path; +import javax.ws.rs.ext.Provider; + +import org.eclipse.jetty.util.component.LifeCycle; +import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.hk2.api.ServiceLocatorFactory; +import org.glassfish.hk2.utilities.ServiceLocatorUtilities; +import org.glassfish.hk2.utilities.binding.AbstractBinder; +import org.glassfish.jersey.servlet.ServletProperties; +import org.jvnet.hk2.annotations.Service; +import org.onap.holmes.common.dropwizard.ioc.annotation.BaseService; +import org.onap.holmes.common.dropwizard.ioc.annotation.Lazy; +import org.onap.holmes.common.dropwizard.ioc.annotation.PostBaseService; +import org.onap.holmes.common.dropwizard.ioc.annotation.PreBaseService; +import org.onap.holmes.common.dropwizard.ioc.annotation.PreLoad; +import org.onap.holmes.common.dropwizard.ioc.annotation.PreServiceLoad; +import org.onap.holmes.common.dropwizard.ioc.utils.ServiceBinder; +import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder; +import org.reflections.Reflections; +import org.reflections.scanners.SubTypesScanner; +import org.reflections.scanners.TypeAnnotationsScanner; +import org.reflections.util.ClasspathHelper; +import org.reflections.util.ConfigurationBuilder; +import org.reflections.util.FilterBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.codahale.metrics.health.HealthCheck; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; + +import io.dropwizard.Configuration; +import io.dropwizard.ConfiguredBundle; +import io.dropwizard.configuration.ConfigurationSourceProvider; +import io.dropwizard.lifecycle.Managed; +import io.dropwizard.lifecycle.ServerLifecycleListener; +import io.dropwizard.servlets.tasks.Task; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; + +/** + * complete the integration of hK2 container and dropwizard + * + * @author hu.rui + * + */ + +public class AutoConfigBundle implements ConfiguredBundle { + + private static final Logger LOG = LoggerFactory.getLogger(AutoConfigBundle.class); + + private ServiceLocator locator; + private Reflections reflections; + private Set> services; + + private Bootstrap bootstrap; + + + AutoConfigBundle(final String packageName) { + this(Lists.newArrayList(packageName)); + } + + AutoConfigBundle(List packageNames) { + FilterBuilder filterBuilder = new FilterBuilder(); + + packageNames.stream().forEach(packageName -> { + filterBuilder.include(FilterBuilder.prefix(packageName)); + }); + ConfigurationBuilder reflectionCfg = new ConfigurationBuilder(); + + packageNames.stream().forEach(packageName -> { + reflectionCfg.addUrls(ClasspathHelper.forPackage(packageName)); + }); + + reflectionCfg.filterInputsBy(filterBuilder).setScanners(new SubTypesScanner(), + new TypeAnnotationsScanner()); + reflections = new Reflections(reflectionCfg); + + locator = ServiceLocatorFactory.getInstance().create("dw-hk2"); + + ServiceLocatorHolder.setLocator(locator); + + } + + public static AutoConfigBundleBuider newBuilder() { + return new AutoConfigBundleBuider(); + } + + @Override + public void initialize(final Bootstrap bootstrap) { + + this.bootstrap = bootstrap; + registerPreLoadService(); + + LOG.debug("Intialzing auto config bundle."); + } + + private void registerPreLoadService() { + + registerService(PreLoad.class); + + } + + + @Override + public void run(final T configuration, final Environment environment) throws Exception { + + registerConfigurationProvider(configuration, environment); + + + registerEnvironment(environment); + registerObjectMapper(environment); + + environment.getApplicationContext().getServletContext() + .setAttribute(ServletProperties.SERVICE_LOCATOR, locator); + + registerService(PreBaseService.class); + registerService(BaseService.class); + registerService(PostBaseService.class); + this.registerService(PreServiceLoad.class); + + + registerServices(); + + // registerManaged(environment); + registerLifecycle(environment); + registerServerLifecycleListeners(environment); + registerJettyLifeCycleListener(environment); + registerTasks(environment); + registerHealthChecks(environment); + registerProviders(environment); + registerResources(environment); + + environment.lifecycle().manage(new ServiceLocatorManaged(locator)); + + } + + + + private void registerProviders(Environment environment) { + reflections.getSubTypesOf(Provider.class).stream().filter(services::contains) + .forEach(providerKlass -> { + try { + environment.jersey().register(locator.getService(providerKlass)); + } catch (Exception e) { + LOG.warn("", e); + } + + LOG.info("Registering Dropwizard Provider, class name : {}", providerKlass.getName()); + + }); + + } + + private void registerTasks(Environment environment) { + reflections.getSubTypesOf(Task.class).stream().filter(services::contains).forEach(taskKlass -> { + try { + environment.admin().addTask(locator.getService(taskKlass)); + } catch (Exception e) { + LOG.warn("", e); + } + LOG.info("Registering Dropwizard Task, class name : {}", taskKlass.getName()); + }); + + } + + private void registerJettyLifeCycleListener(Environment environment) { + reflections.getSubTypesOf(LifeCycle.Listener.class).stream().filter(services::contains) + .forEach(lifecycleListenerKlass -> { + + try { + environment.lifecycle() + .addLifeCycleListener(locator.getService(lifecycleListenerKlass)); + } catch (Exception e) { + LOG.warn("", e); + } + LOG.info("Registering Dropwizard lifecycleListener, class name : {}", + lifecycleListenerKlass.getName()); + }); + + } + + private void registerServerLifecycleListeners(Environment environment) { + + reflections.getSubTypesOf(ServerLifecycleListener.class).stream().filter(services::contains) + .forEach(serverLifecycleListenerKlass -> { + try { + environment.lifecycle() + .addServerLifecycleListener(locator.getService(serverLifecycleListenerKlass)); + } catch (Exception e) { + LOG.warn("", e); + } + LOG.info("Registering Dropwizard serverLifecycleListener, class name : {}", + serverLifecycleListenerKlass.getName()); + }); + + } + + private void registerLifecycle(Environment environment) { + reflections.getSubTypesOf(LifeCycle.class).stream().filter(services::contains) + .forEach(lifeCycleKlass -> { + try { + environment.lifecycle().manage(locator.getService(lifeCycleKlass)); + } catch (Exception e) { + LOG.warn("", e); + } + LOG.info("Registering Dropwizard LifeCycle, class name : {}", lifeCycleKlass.getName()); + }); + } + + /* + * private void registerManaged(Environment environment) { + * + * reflections.getSubTypesOf(Managed.class).stream().filter(services::contains) + * .forEach(managedKlass -> { try { + * environment.lifecycle().manage(locator.getService(managedKlass)); } catch (Exception e) { + * LOG.warn("", e); } LOG.info("Registering Dropwizard managed, class name : {}", + * managedKlass.getName()); }); + * + * } + */ + + private void registerObjectMapper(Environment environment) { + + final ObjectMapper objectMapper = environment.getObjectMapper(); + + ServiceLocatorUtilities.bind(locator, new AbstractBinder() { + @Override + protected void configure() { + bind(objectMapper).to(ObjectMapper.class); + + LOG.info("Registering Dropwizard objectMapper, class name : {}", + objectMapper.getClass().getName()); + } + }); + + } + + private void registerEnvironment(final Environment environment) { + + ServiceLocatorUtilities.bind(locator, new AbstractBinder() { + @Override + protected void configure() { + bind(environment).to(Environment.class); + + LOG.info("Registering Dropwizard environment, class name : {}", + environment.getClass().getName()); + } + }); + + } + + private void registerConfigurationProvider(final T configuration, final Environment environment) { + + ServiceLocatorUtilities.bind(locator, new AbstractBinder() { + @Override + protected void configure() { + bind(configuration); + LOG.info("Registering Dropwizard Configuration class name:{}", + configuration.getClass().getName()); + if (configuration instanceof Configuration) { + bind((Configuration) configuration).to(Configuration.class); + LOG.info("Registering Dropwizard Configuration class name:{}", + Configuration.class.getName()); + } + + } + }); + + registerSubConfigure(configuration, environment); + + } + + private void registerSubConfigure(final T configuration, final Environment environment) { + final List subDeclaredFields = + Arrays.asList(configuration.getClass().getDeclaredFields()); + List parentDeclaredFields = Arrays.asList(Configuration.class.getDeclaredFields()); + + List filtersubDeclaredFields = subDeclaredFields.stream() + .filter(subDeclaredField -> !subDeclaredField.getType().isPrimitive()) + .filter(subDeclaredField -> !subDeclaredField.getType().equals(String.class)) + .filter(subDeclaredField -> !parentDeclaredFields.contains(subDeclaredField)) + .collect(Collectors.toList()); + + ServiceLocatorUtilities.bind(locator, new AbstractBinder() { + @Override + protected void configure() { + filtersubDeclaredFields.forEach(subField -> { + subField.setAccessible(true); + try { + Object subConfig = subField.get(configuration); + if (subConfig != null) { + bind(subConfig); + LOG.info("Registering Dropwizard Sub Configuration class name {}", + subConfig.getClass().getName()); + } + + } catch (Exception e) { + LOG.error("bind sub config:{} fail", subField); + } + }); + } + }); + + } + + private void registerServices() { + services = this.reflections.getTypesAnnotatedWith(Service.class, true); + if (!services.isEmpty()) { + ServiceLocatorUtilities.bind(locator, new ServiceBinder(services)); + + services.forEach(s -> { + LOG.info("Registering Dropwizard service, class name : {}", s.getName()); + }); + + services.stream().filter(serviceClazz -> (serviceClazz.getAnnotation(Lazy.class) == null)) + .peek(serviceClazz -> LOG.info("active service, class name : {}", serviceClazz.getName())) + .forEach(serviceClazz -> { + try { + long startTime = System.currentTimeMillis(); + locator.getService(serviceClazz); + LOG.info("active service, class name : {},cost time:{}", serviceClazz.getName(), + (System.currentTimeMillis() - startTime)); + } catch (Exception e) { + LOG.warn("", e); + } + + }); + + } else { + LOG.warn("Registering Dropwizard service is empty"); + + } + + } + + private void registerResources(final Environment environment) { + reflections.getTypesAnnotatedWith(Path.class).stream().forEach(resourceClass -> { + + LOG.info("begin Registering Dropwizard resource, class name : {}", resourceClass.getName()); + try { + Object resourceObject = locator.getService(resourceClass); + if (resourceObject != null) { + environment.jersey().register(resourceObject); + LOG.info("Registering Dropwizard resource, class name : {}", resourceClass.getName()); + } else { + LOG.warn(resourceClass.getName() + " not use Service annotation"); + } + } catch (Exception e) { + LOG.error("", e); + } + + + }); + } + + private void registerHealthChecks(final Environment env) { + + reflections.getSubTypesOf(HealthCheck.class).stream().filter(services::contains) + .forEach(healthCheckKlass -> { + try { + env.healthChecks().register(healthCheckKlass.getName(), + locator.getService(healthCheckKlass)); + } catch (Exception e) { + LOG.warn("", e); + } + LOG.info("Registering Dropwizard healthCheck, class name : {}", + healthCheckKlass.getName()); + }); + + } + + + + private void registerService(Class annotationClazz) { + + Set> services = this.reflections.getTypesAnnotatedWith(annotationClazz, true); + if (!services.isEmpty()) { + ServiceLocatorUtilities.bind(locator, new ServiceBinder(services)); + + services.forEach(s -> { + LOG.info("{} Registering service, class name : {}", annotationClazz.getName(), + s.getName()); + }); + + services.stream().filter(serviceClazz -> (serviceClazz.getAnnotation(Lazy.class) == null)) + .peek(serviceClazz -> LOG.info("active service, class name : {}", serviceClazz.getName())) + .forEach(serviceClazz -> { + try { + long startTime = System.currentTimeMillis(); + locator.getService(serviceClazz); + LOG.info("active service, class name : {},cost time:{}", serviceClazz.getName(), + (System.currentTimeMillis() - startTime)); + } catch (Exception e) { + LOG.warn("", e); + } + + }); + + } else { + LOG.warn("Registering {} service is empty", annotationClazz.getName()); + + } + + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.java new file mode 100644 index 0000000..a439ff0 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.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.common.dropwizard.ioc.bundle; + +import java.util.ArrayList; +import java.util.List; + +import io.dropwizard.Configuration; + +public class AutoConfigBundleBuider { + + private static final String DEFAULT_PACKAGE_NAME="org.onap"; + + private List packageNames=new ArrayList<>(); + + public AutoConfigBundleBuider(){ + packageNames.add( DEFAULT_PACKAGE_NAME); + } + + public AutoConfigBundleBuider addPackageName(String packageName) { + this.packageNames.add(packageName); + return this; + } + + + public AutoConfigBundle build() { + return new AutoConfigBundle(packageNames); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.java new file mode 100644 index 0000000..6025028 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.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.common.dropwizard.ioc.bundle; + +import io.dropwizard.Application; +import io.dropwizard.Configuration; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; + +/** + * complete IOC container startup + * + * @author hu.rui2 + * + */ +public abstract class IOCApplication extends Application { + + + @Override + public void initialize(Bootstrap bootstrap) { + super.initialize(bootstrap); + bootstrap.addBundle(new AutoConfigBundleBuider().build()); + } + + @Override + public void run(T configuration, Environment environment) throws Exception { + + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java new file mode 100644 index 0000000..d6c0563 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java @@ -0,0 +1,51 @@ +/** + * 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.common.dropwizard.ioc.bundle; + +import org.glassfish.hk2.api.ServiceLocator; + +import io.dropwizard.lifecycle.Managed; + +/** + * Life cycle management for IOC containers + * @author hu.rui + * + */ +public class ServiceLocatorManaged implements Managed{ + + + + private ServiceLocator locator; + + + + public ServiceLocatorManaged(ServiceLocator locator) { + super(); + this.locator = locator; + } + + @Override + public void start() throws Exception { + + + } + + @Override + public void stop() throws Exception { + locator.shutdown(); + } + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java new file mode 100644 index 0000000..f5801c8 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java @@ -0,0 +1,52 @@ +/** + * 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.common.dropwizard.ioc.utils; + +import java.util.Set; + +import org.glassfish.hk2.utilities.binding.AbstractBinder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author hu.rui + * + */ +public class ServiceBinder extends AbstractBinder { + + private static final Logger LOG = LoggerFactory.getLogger(ServiceBinder.class); + + final Set> klasses; + + public ServiceBinder(Set> services) { + this.klasses = services; + } + + @Override + protected void configure() { + for (Class klass : this.klasses) { + + try{ + LOG.info("start active class:"+klass.getName()); + addActiveDescriptor(klass); + }catch(Exception e){ + LOG.info("active class error:"+klass.getName(),e); + } + + + } + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java new file mode 100644 index 0000000..394ab6c --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java @@ -0,0 +1,36 @@ +/** + * 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.common.dropwizard.ioc.utils; + +import org.glassfish.hk2.api.ServiceLocator; + +/** + * @author hu.rui + * + */ +public class ServiceLocatorHolder { + + private static ServiceLocator locator; + + public static ServiceLocator getLocator() { + return locator; + } + + public static void setLocator(ServiceLocator locator) { + ServiceLocatorHolder.locator = locator; + } + +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/exception/CorrelationException.java b/holmes-actions/src/main/java/org/onap/holmes/common/exception/CorrelationException.java new file mode 100644 index 0000000..3360618 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/exception/CorrelationException.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.common.exception; + +public class CorrelationException extends Exception { + + public CorrelationException(String msg, Exception e) { + super(msg, e); + } + + public CorrelationException(String msg) { + super(msg); + } +} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/msb/MicroserviceBusRest.java b/holmes-actions/src/main/java/org/onap/holmes/common/msb/MicroserviceBusRest.java new file mode 100644 index 0000000..10ecda3 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/msb/MicroserviceBusRest.java @@ -0,0 +1,36 @@ +/** + * 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.common.msb; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import org.onap.holmes.common.api.entity.ServiceRegisterEntity; + +@Path("/onapapi/microservices/v1/services") +public interface MicroserviceBusRest { + + @Path("") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate, + ServiceRegisterEntity entity); +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java b/holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java new file mode 100644 index 0000000..6aaa860 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java @@ -0,0 +1,107 @@ +/** + * 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.common.producer; + +import java.io.Serializable; +import javax.inject.Inject; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Session; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.glassfish.hk2.api.IterableProvider; +import org.jvnet.hk2.annotations.Service; +import org.onap.holmes.common.api.stat.Alarm; +import org.onap.holmes.common.constant.AlarmConst; +import org.onap.holmes.common.api.entity.CorrelationResult; +import org.onap.holmes.common.api.stat.AplusResult; +import org.onap.holmes.common.config.MQConfig; +import org.apache.activemq.ActiveMQConnectionFactory; + +@Service +@Slf4j +@NoArgsConstructor +public class MQProducer { + + @Inject + private IterableProvider mqConfigProvider; + private ConnectionFactory connectionFactory; + + public void init() { + + String brokerURL = + "tcp://" + mqConfigProvider.get().brokerIp + ":" + mqConfigProvider.get().brokerPort; + connectionFactory = new ActiveMQConnectionFactory(mqConfigProvider.get().brokerUsername, + mqConfigProvider.get().brokerPassword, brokerURL); + } + + public void sendAlarmMQTopicMsg(Alarm alarm) { + sendMQTopicMsg(alarm); + } + + public void sendCorrelationMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm, + Alarm childAlarm) { + CorrelationResult correlationResult = getCorrelationResult(ruleId, createTimeL, parentAlarm, childAlarm); + sendMQTopicMsg(correlationResult); + } + + private void sendMQTopicMsg(T t) { + Serializable msgEntity = (Serializable) t; + Connection connection = null; + Session session; + Destination destination = null; + MessageProducer messageProducer; + + try { + connection = connectionFactory.createConnection(); + connection.start(); + session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); + if (t instanceof CorrelationResult) { + destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION); + } else if (t instanceof Alarm) { + destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM); + } + messageProducer = session.createProducer(destination); + ObjectMessage message = session.createObjectMessage(msgEntity); + messageProducer.send(message); + session.commit(); + } catch (Exception e) { + log.error("Failed send correlation." + e.getMessage(), e); + } finally { + if (connection != null) { + try { + connection.close(); + } catch (JMSException e) { + log.error("Failed close connection." + e.getMessage(), e); + } + } + } + } + + private CorrelationResult getCorrelationResult(String ruleId, long createTimeL, Alarm parentAlarm, + Alarm childAlarm) { + CorrelationResult correlationResult = new CorrelationResult(); + correlationResult.setRuleId(ruleId); + correlationResult.setCreateTimeL(createTimeL); + correlationResult.setResultType(AplusResult.APLUS_CORRELATION); + correlationResult.setAffectedAlarms(new Alarm[]{parentAlarm, childAlarm}); + return correlationResult; + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java new file mode 100644 index 0000000..76e11ba --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java @@ -0,0 +1,92 @@ +/** + * 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.common.utils; + +import io.dropwizard.db.DataSourceFactory; +import io.dropwizard.jdbi.DBIFactory; +import io.dropwizard.setup.Environment; +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.skife.jdbi.v2.DBI; +import org.skife.jdbi.v2.Handle; + +@Singleton +@Service +@Slf4j +public class DbDaoUtil { + + private DBI jdbi; + @Inject + private Environment environmentProvider; + @Inject + private DataSourceFactory dataSourceFactoryProvider; + + private DBIFactory factory = new DBIFactory(); + + @PostConstruct + public void init() { + if (jdbi == null) { + synchronized (DbDaoUtil.class) { + if (jdbi == null) { + jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "mysql"); + } + } + } + } + + public K getDao(Class clazz) { + try { + return jdbi.open(clazz); + } catch (Exception e) { + log.warn("get object instance of Dao error.", e); + } + return null; + } + + public Handle getHandle() { + try { + return jdbi.open(); + } catch (Exception e) { + log.warn("get object instance of Dao error.", e); + } + return null; + } + + public void close(Object obj) { + if (obj != null) { + try { + jdbi.close(obj); + } catch (Exception e) { + log.warn("close jdbi connection error.", e); + } + } + } + + public T getJdbiDaoByOnDemand(Class daoClazz) { + + return jdbi.onDemand(daoClazz); + + } + + public T getJdbiDaoByOpen(Class daoClazz) { + + return jdbi.open(daoClazz); + + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/ExceptionUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/ExceptionUtil.java new file mode 100644 index 0000000..419dce5 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/ExceptionUtil.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.common.utils; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +public class ExceptionUtil { + + private static final int EXCEPTION_CODE = 499; + + private ExceptionUtil() { + + } + + public static WebApplicationException buildExceptionResponse(String message) { + Response response = Response.status(EXCEPTION_CODE).entity(message).type(MediaType.TEXT_PLAIN).build(); + return new WebApplicationException(response); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JacksonUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JacksonUtil.java new file mode 100644 index 0000000..c5c52c2 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JacksonUtil.java @@ -0,0 +1,40 @@ +/** + * 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.common.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; + +public class JacksonUtil { + + private JacksonUtil() { + + } + + public static String beanToJson(Object obj) throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.writeValueAsString(obj); + } + + public static T jsonToBean(String json, Class cls) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + if (json == null) { + return objectMapper.readValue("{}", cls); + } + return objectMapper.readValue(json, cls); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JudgeNullUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JudgeNullUtil.java new file mode 100644 index 0000000..9383d22 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JudgeNullUtil.java @@ -0,0 +1,49 @@ +/** + * 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.common.utils; + +import java.util.List; + +public class JudgeNullUtil { + + private JudgeNullUtil() { + + } + + public static boolean isEmpty( short[] shorts ) { + return shorts == null || shorts.length == 0; + } + + public static boolean isEmpty( int[] ints ) { + return ints == null || ints.length == 0; + } + + public static boolean isEmpty( long[] longs ) { + return longs == null || longs.length == 0; + } + + public static boolean isEmpty( Object[] obj ) { + return obj == null || obj.length == 0; + } + + public static boolean isEmpty( String str ) { + return str == null || "".equals( str.trim() ); + } + + public static boolean isEmpty( List < ? > list ) { + return list == null || list.isEmpty(); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/LanguageUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/LanguageUtil.java new file mode 100644 index 0000000..5c2c12c --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/LanguageUtil.java @@ -0,0 +1,52 @@ +/** + * 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.common.utils; + +import java.util.Locale; +import javax.servlet.http.HttpServletRequest; +import org.onap.holmes.common.constant.AlarmConst; + +public class LanguageUtil { + + private LanguageUtil() { + } + + public static String getLanguage(HttpServletRequest servletRequest) { + String language = servletRequest.getHeader("language-option"); + if (JudgeNullUtil.isEmpty(language)) { + language = AlarmConst.I18N_EN; + } + if (language.startsWith(AlarmConst.I18N_ZH)) { + language = AlarmConst.I18N_ZH; + } else if (language.startsWith(AlarmConst.I18N_EN)) { + language = AlarmConst.I18N_EN; + } + return language; + } + + public static Locale getLocale(HttpServletRequest servletRequest) { + String language = servletRequest.getHeader("language-option"); + if (JudgeNullUtil.isEmpty(language)) { + language = AlarmConst.I18N_EN; + } + if (language.startsWith(AlarmConst.I18N_ZH)) { + language = AlarmConst.I18N_ZH; + } else if (language.startsWith(AlarmConst.I18N_EN)) { + language = AlarmConst.I18N_EN; + } + return new Locale(language); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java new file mode 100644 index 0000000..1bb3fe3 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java @@ -0,0 +1,74 @@ +/** + * 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.common.utils; + +import com.eclipsesource.jaxrs.consumer.ConsumerFactory; +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; +import org.jvnet.hk2.annotations.Service; +import org.onap.holmes.common.msb.MicroserviceBusRest; +import org.onap.holmes.common.api.entity.ServiceRegisterEntity; +import org.onap.holmes.common.config.MicroServiceConfig; + +@Slf4j +@Service +public class MSBRegisterUtil { + + public void register(ServiceRegisterEntity entity) throws IOException { + log.info("start holmes micro service register"); + boolean flag = false; + int retry = 0; + while (!flag && retry < 20) { + log.info("Holmes microservice register. retry:" + retry); + retry++; + flag = innerRegister(entity); + if (!flag) { + log.warn("micro service register failed, sleep 30S and try again."); + threadSleep(30000); + } else { + log.info("micro service register success!"); + break; + } + } + log.info("holmes micro service register end."); + } + + private boolean innerRegister(ServiceRegisterEntity entity) { + try { + log.info("msbServerAddr:" + MicroServiceConfig.getMsbServerAddr()); + log.info("entity:" + entity); + MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer( + MicroServiceConfig.getMsbServerAddr(), MicroserviceBusRest.class); + resourceserviceproxy.registerServce("false", entity); + } catch (Exception error) { + log.error("microservice register failed!" + error.getMessage(), error); + return false; + } + return true; + } + + private void threadSleep(int second) { + log.info("start sleep ...."); + try { + Thread.sleep(second); + } catch (InterruptedException error) { + log.error("thread sleep error.errorMsg:" + error.getMessage(), error); + Thread.currentThread().interrupt(); + } + log.info("sleep end ."); + } +} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/UserUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/UserUtil.java new file mode 100644 index 0000000..f0ff8d9 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/UserUtil.java @@ -0,0 +1,35 @@ +/** + * 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.common.utils; + +import javax.servlet.http.HttpServletRequest; +import org.onap.holmes.common.constant.AlarmConst; + +public class UserUtil { + + private UserUtil() { + + } + + public static String getUserName(HttpServletRequest request) { + String userName = AlarmConst.ADMIN; + String sessionName = request.getHeader("username"); + if (sessionName != null) { + userName = sessionName.toLowerCase(); + } + return userName; + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java deleted file mode 100644 index de1005c..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java +++ /dev/null @@ -1,53 +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.common.api.entity; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Date; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -public class AlarmsCorrelation { - - @JsonProperty(value = "ruleid") - private String ruleId; - - @JsonProperty(value = "ruleinfo") - private String ruleInfo; - - @JsonProperty(value = "resulttype") - private byte resultType; - - @JsonProperty(value = "createtime") - private Date createTime; - - @JsonProperty(value = "parentalarmid") - private long parentAlarmId; - - @JsonProperty(value = "childalarmid") - private long childAlarmId; - - @JsonProperty(defaultValue = "-1") - private long reserve1 = -1; - - @JsonProperty(defaultValue = "-1") - private long reserve2 = -1; - - @JsonProperty(defaultValue = "-1") - private long reserve3 = -1; -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java deleted file mode 100644 index d78619d..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java +++ /dev/null @@ -1,44 +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.common.api.entity; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; -import org.openo.holmes.common.api.stat.Alarm; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -@Setter -@Getter -@NoArgsConstructor -@ToString -public class CorrelationResult implements Serializable{ - - @JsonProperty - private String ruleId; - - @JsonProperty - private long createTimeL; - - @JsonProperty - private byte resultType; - - @JsonProperty - private Alarm[] affectedAlarms; -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java deleted file mode 100644 index 24f5bc9..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java +++ /dev/null @@ -1,57 +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.common.api.entity; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Date; -import java.util.Properties; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class CorrelationRule { - - @JsonProperty(value = "ruleid") - private String rid; - @JsonProperty(value = "rulename") - private String name; - @JsonProperty - private String description; - @JsonProperty - private int enabled; - @JsonProperty - private int templateID; - private String engineID; - @JsonProperty - private String engineType; - @JsonProperty - private String creator; - @JsonProperty - private String modifier; - @JsonProperty - private Properties params; - @JsonProperty - private String content; - @JsonProperty - private String vendor; - @JsonProperty(value = "createtime") - private Date createTime; - @JsonProperty(value = "updatetime") - private Date updateTime; - @JsonProperty(value = "package") - private String packageName; -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceNode.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceNode.java deleted file mode 100644 index e6cf4c3..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceNode.java +++ /dev/null @@ -1,39 +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.common.api.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -@Getter -@Setter -public class ServiceNode { - - private String ip; - private String port; - private int ttl; - -} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceRegisterEntity.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceRegisterEntity.java deleted file mode 100644 index 6db084b..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/ServiceRegisterEntity.java +++ /dev/null @@ -1,54 +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.common.api.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import java.util.ArrayList; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -@Setter -@Getter -public class ServiceRegisterEntity { - - private String serviceName; - private String version; - private String url; - private String protocol; - private String visualRange = "1"; - private List nodes = new ArrayList<>(); - - public void setSingleNode(String ip, String port, int ttl) { - ServiceNode node = new ServiceNode(); - if (ip != null && ip.length() > 0) { - node.setIp(ip); - } else { - node.setIp(null); - } - node.setPort(port); - node.setTtl(ttl); - nodes.add(node); - } -} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java deleted file mode 100644 index c12b549..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java +++ /dev/null @@ -1,279 +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.common.api.stat; - -import java.io.Serializable; -import java.io.StringReader; -import java.lang.reflect.Field; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import lombok.Getter; -import lombok.Setter; -import org.jdom.Attribute; -import org.jdom.Element; -import org.jdom.input.SAXBuilder; -import org.jdom.output.XMLOutputter; - - -@Getter -@Setter -public class Alarm implements AplusData, Cloneable, Serializable { - - public static final byte EVENT_CLEARED_ALARM = 3; - - public static final byte EVENT_CHANGED = 2; - - public static final byte EVENT_CLEARED = 1; - - public static final byte EVENT_RAISED = 0; - - private static final long serialVersionUID = 4520003737132012000L; - private final static Date clearedServerTime = null; - private final Map linkIdNodeIdxMap = new HashMap(); - private byte eventType = EVENT_RAISED; - private long id = 0L; - private String alarmKey = ""; - private String network = ""; - private String neType = ""; - private String equipType = ""; - private String position1 = ""; - private String subPosition1 = null; - private String position2 = null; - private String subPosition2 = null; - private byte severity = -1; - private byte alarmType = -1; - private long probableCause = -1; - private String specificProblem = null; - private String additionalText = null; - private Date raisedTime = new Date(); - private Date raisedServerTime = new Date(); - private Date clearedTime = null; - private String region = null; - private String site = null; - private String aid = null; - private short systemType = -1; - private boolean rootAlarmFlag = false; - private int linkId = -1; - private int nodeIdx = -1; - private Set linkIds = new HashSet(); - private HashMap priorityMap = new HashMap(); - private HashMap rootAlarmTypeMap = new HashMap(); - private int rootAlarmType = -1; - private boolean keyAlarmFlag = false; - private int keyAlarmType = -1; - private int networkLevel = -1; - private int linkType = -1; - private int centerType; - - public static Alarm valueOf(String xmlString) { - Element element; - try { - StringReader sb = new StringReader(xmlString); - element = new SAXBuilder().build(sb).getRootElement(); - sb.close(); - } catch (Exception e) { - throw new RuntimeException(e); - } - - Alarm alarm = new Alarm(); - @SuppressWarnings("unchecked") - List list = element.getAttributes(); - for (Attribute attr : list) { - String attrName = attr.getName(); - try { - Field field = Alarm.class.getDeclaredField(attrName); - if (!attrName.endsWith("Time")) { - String type = field.getType().getSimpleName(); - if ("byte".equals(type)) { - field.set(alarm, Byte.parseByte(attr.getValue())); - } else if ("long".equals(type)) { - field.set(alarm, Long.parseLong(attr.getValue())); - } else if ("String".equals(type)) { - field.set(alarm, attr.getValue()); - } else { - throw new RuntimeException("unknow attr type: " + type.toString()); - } - } else { - Date date = new Date(); - date.setTime(Long.parseLong(attr.getValue())); - field.set(alarm, date); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - return alarm; - } - - public void addLinkIdNodeIdx(int linkId, int index) { - linkIdNodeIdxMap.put(linkId, index); - } - - /** - * Comparison of the location of different links: 999 the same link: the location of the node - * number less than otherIdIdx in the location of the number (in the otherIdIdx upstream):-1, - * the same link: the node position number is equal to the number of position in the otherIdIdx - * (in the same site otherIdIdx):0, the same link: the node location number is greater than the - * number of locations in otherIdIdx (otherIdIdx) with the site):1, - */ - public int CompareLinkPosition(Map otherIdIdx) { - Set myIdSet = new HashSet(); - myIdSet.addAll(this.linkIdNodeIdxMap.keySet()); - myIdSet.retainAll(otherIdIdx.keySet()); - - if (myIdSet.isEmpty()) { - return 999; - } - - for (int tempLinkId : myIdSet) { - return this.linkIdNodeIdxMap.get(tempLinkId) - otherIdIdx.get(tempLinkId); - } - return 999; - } - - public boolean containNode(int linkId, int index) { - return linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index; - } - - @Override - public byte getDataType() { - return APLUS_EVENT; - } - - @Override - public String toString() { - final String nullStr = ""; - - Element el = new Element("Alarm"); - el.setAttribute("id", String.valueOf(id)); - el.setAttribute("aid", String.valueOf(aid)); - el.setAttribute("alarmKey", String.valueOf(alarmKey)); - el.setAttribute("eventType", String.valueOf(eventType)); - el.setAttribute("region", region == null ? nullStr : region); - el.setAttribute("site", site == null ? nullStr : site); - el.setAttribute("network", network); - el.setAttribute("neType", neType); - el.setAttribute("equipType", equipType); - el.setAttribute("position1", position1); - el.setAttribute("subPosition1", subPosition1 == null ? nullStr : subPosition1); - el.setAttribute("position2", position2 == null ? nullStr : position2); - el.setAttribute("subPosition2", subPosition2 == null ? nullStr : subPosition2); - el.setAttribute("severity", String.valueOf(severity)); - el.setAttribute("alarmType", String.valueOf(alarmType)); - el.setAttribute("probableCause", String.valueOf(probableCause)); - el.setAttribute("specificProblem", specificProblem == null ? nullStr : specificProblem); - el.setAttribute("additionalText", additionalText == null ? nullStr : additionalText); - el.setAttribute("raisedTime", String.valueOf(raisedTime.getTime())); - el.setAttribute("raisedServerTime", String.valueOf(raisedServerTime.getTime())); - if (clearedTime != null) { - el.setAttribute("clearedTime", String.valueOf(clearedTime.getTime())); - } - if (clearedServerTime != null) { - el.setAttribute("clearedServerTime", String.valueOf(clearedServerTime.getTime())); - } - - return new XMLOutputter().outputString(el); - } - - @Override - public int hashCode() { - return this.getAlarmKey().hashCode(); - } - - @Override - public boolean equals(Object arg0) { - if (arg0 == null || !(arg0 instanceof Alarm)) { - return false; - } - return this.alarmKey.equals(((Alarm) arg0).getAlarmKey()); - } - - @Override - public Object clone() throws CloneNotSupportedException { - super.clone(); - - Alarm alarm = new Alarm(); - - alarm.setEventType(this.getEventType()); - - alarm.setAid(this.getAid()); - alarm.setId(this.getId()); - alarm.setAlarmKey(this.getAlarmKey()); - - alarm.setNetwork(this.getNetwork()); - alarm.setEquipType(this.getEquipType()); - alarm.setNeType(this.getNeType()); - alarm.setPosition1(this.getPosition1()); - alarm.setSubPosition1(this.getSubPosition1()); - alarm.setPosition2(this.getPosition2()); - alarm.setSubPosition2(this.getSubPosition2()); - alarm.setRegion(this.getRegion()); - alarm.setSite(this.getSite()); - - alarm.setSeverity(this.getSeverity()); - alarm.setAlarmType(this.getAlarmType()); - alarm.setSystemType(this.getSystemType()); - alarm.setSpecificProblem(this.getSpecificProblem()); - alarm.setAdditionalText(this.getAdditionalText()); - alarm.setProbableCause(this.getProbableCause()); - - alarm.setRaisedTime(this.getRaisedTime()); - alarm.setRaisedServerTime(this.getRaisedServerTime()); - alarm.setClearedTime(this.getClearedTime()); - - return alarm; - } - - @Override - public String getObjectId() { - return String.valueOf(id); - } - - public void addLinkIds(int linkId) { - linkIds.add(linkId); - } - - - public boolean containsPriority(String ruleId) { - if (priorityMap.keySet().contains(ruleId)) { - return true; - } - return false; - } - - public int getPriority(String ruleId) { - Integer priority = this.priorityMap.get(ruleId); - if (priority == null) { - priority = 0; - } - return priority; - } - - public int getRootAlarmType(String ruleId) { - Integer rootAlarmType = this.rootAlarmTypeMap.get(ruleId); - if (rootAlarmType == null) { - rootAlarmType = -1; - } - return rootAlarmType; - } - -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java deleted file mode 100644 index ce95a8d..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java +++ /dev/null @@ -1,43 +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.common.api.stat; - -import java.io.Serializable; - -public interface AplusData extends Serializable { - - /** - * The data to be analyzed with aging characteristics - 0 - */ - byte APLUS_EVENT = 0; - - /** - * The data to be analyzed without aging characteristics - 1 - */ - byte APLUS_FACT = 1; - - - /** - * @see #APLUS_EVENT - * @see #APLUS_FACT - */ - byte getDataType(); - - /** - * @return String - */ - String getObjectId(); -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.java deleted file mode 100644 index 53c6729..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.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.common.api.stat; - -import java.io.Serializable; - -public interface AplusResult extends Serializable { - - /** - * Derived new alarm type - 0 - */ - byte APLUS_RAISED = 0; - - /** - * Correlation alarm, root-child alarm - 1 - */ - byte APLUS_CORRELATION = 1; - - /** - * cleared - */ - byte APLUS_CLEAR = 2; - - - int getId(); - - void setId(int id); - - String getRuleInfo(); - - void setRuleInfo(String ruleInfo); - - String getRuleType(); - - void setRuleType(String ruleType); - - void setRuleId(String ruleId); - - String getRuleId(); - - long getCreateTime(); - - void setCreateTime(long createTime); - - byte getResultType(); - - void setResultType(byte resultType); - - Alarm[] getAffectedAlarms(); - - void setAffectedAlarms(Alarm[] affectedAlarms); - -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java b/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java deleted file mode 100644 index 3200ec0..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/config/MQConfig.java +++ /dev/null @@ -1,39 +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.common.config; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.HashMap; -import java.util.Map; -import javax.validation.constraints.NotNull; - -public class MQConfig { - - @JsonProperty - @NotNull - public String brokerIp; - - @JsonProperty - @NotNull - public int brokerPort; - - @JsonProperty - public String brokerUsername; - - @JsonProperty - public String brokerPassword; -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/config/MicroServiceConfig.java b/holmes-actions/src/main/java/org/openo/holmes/common/config/MicroServiceConfig.java deleted file mode 100644 index 05273b8..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/config/MicroServiceConfig.java +++ /dev/null @@ -1,38 +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.common.config; - -import org.openo.holmes.common.constant.AlarmConst; - -public class MicroServiceConfig { - - private static String getProperty(String name) { - String value = System.getenv(name); - if (value == null) { - value = System.getProperty(name); - } - return value; - } - - public static String getMsbServerAddr() { - return AlarmConst.HTTP + getProperty("MSB_ADDR"); - } - - public static String getServiceIp() { - return getProperty("SERVICE_IP"); - } - -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java b/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java deleted file mode 100644 index 9e83d4c..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java +++ /dev/null @@ -1,41 +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.common.constant; - -public interface AlarmConst { - - String MQ_TOPIC_NAME_ALARMS_CORRELATION = "topic://voss/fm/alarms_correlation"; - - String MQ_TOPIC_NAME_ALARM = "topic://voss/fm/alarm"; - - String NFVO_PATH = "/openoapi/umc/v1/fm/curalarms/findAll"; - - int NFVO_STATUS_OK = 200; - - String I18N_EN = "en"; - - String I18N_ZH = "zh"; - - String ZH_CN = "zh_CN"; - - String ADMIN = "admin"; - - int MICRO_SERVICE_STATUS_SUCCESS = 201; - - int MICRO_SERVICE_PORT = 8086; - - String HTTP = "http://"; -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/exception/CorrelationException.java b/holmes-actions/src/main/java/org/openo/holmes/common/exception/CorrelationException.java deleted file mode 100644 index dfe5373..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/exception/CorrelationException.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.common.exception; - -public class CorrelationException extends Exception { - - public CorrelationException(String msg, Exception e) { - super(msg, e); - } - - public CorrelationException(String msg) { - super(msg); - } -} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json deleted file mode 100644 index f45b92b..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "ENGINE_CONTENT_ILLEGALITY": "The rule content have error:{0}", - "ENGINE_DEPLOY_RULE_FAILED": "Deploy rule failed", - "ENGINE_DELETE_RULE_NULL": "The rule do not exist :{0}", - "ENGINE_DELETE_RULE_FAILED": "The rule remove failed :{0}", - "ENGINE_INSERT_RULE_CACHE_FAILED": "insert rule failed in cache", - "ENGINE_DELETE_RULE_FAILED_FROM_CACHE": "delete rule failed in cache", - "ENGINE_CONTAINS_PACKAGE": "Is included in the package name, please amend", - "ENGINE_QUERY_CACHE_FAILED": "Failed query cache", - "DSA_QUERY_CURRENT_ALARM_FAILED":"query current alarm failed", - "DSA_REQUEST_ANALYSIS_ERROR":"request analysis error", - "DSA_REQUEST_EXECUTE_FAILED":"send request failed", - "DSA_HTTP_CLIENT_CLOSE_FAILED":"httpclient close failed", - "EXCEPTION_DB_RULE_NOT_EXIST_ERROR": "This rule does not exist in the database.", - "EXCEPTION_DB_RULE_SAVE_ERROR": "Error saving rule to database", - "EXCEPTION_DB_RULE_GET_ERROR": "Error when get rule from database", - "EXCEPTION_REQUEST_IS_EMPTY": "The request object is empty", - "RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED": "Delete rules from engine call interface failure ", - "RULE_MANAGEMENT_DELETE_RULE_FAILED":"To delete rules from the engine failure", - "RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED": "From the rules engine calls the deployment of interface failure", - "RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED": "From the rules engine calls the check of interface failure", - "RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED": "Create query exception", - "RULE_MANAGEMENT_QUERY_RULE_FAILED": "Query rule failed", - "RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY": "Request object is empty", - "RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE": "Rule does not exist", - "RULE_MANAGEMENT_REPEAT_RULE_NAME": "Rule name repetition", - "RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY": "Rule name cannot be empty", - "RULE_MANAGEMENT_DATA_FORMAT_ERROR": "Data format error", - "RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR": "Parameter enabled can only be 0 (not enabled) and 1 (enabled)", - "RULE_MANAGEMENT_DB_ERROR": "db error", - "RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR":"Parsing call deployment rule return the result of the failure", - "RULE_MANAGEMENT_CHECK_NO_PASS":"Content inspection not by rule", - "RULE_MANAGEMENT_CONTENT_CANNOT_BE_EMPTY":"Content cannot be empty" -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json deleted file mode 100644 index 39b0e82..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "ENGINE_CONTENT_ILLEGALITY": "规则内容有误:{0}", - "ENGINE_DEPLOY_RULE_FAILED": "部署规则失败", - "ENGINE_DELETE_RULE_NULL": "引擎不包含这个规则:{0}", - "ENGINE_DELETE_RULE_FAILED": "删除规则失败{0}", - "ENGINE_INSERT_RULE_CACHE_FAILED": "插入数据到缓存失败", - "ENGINE_DELETE_RULE_FAILED_FROM_CACHE": "从缓存删除数据失败", - "ENGINE_CONTAINS_PACKAGE": "package 名字已包含,请修改", - "ENGINE_QUERY_CACHE_FAILED":"查询缓存失败", - "DSA_QUERY_CURRENT_ALARM_FAILED":"查询当前所有告警失败", - "DSA_REQUEST_ANALYSIS_ERROR":"解析请求数据失败", - "DSA_REQUEST_EXECUTE_FAILED":"发送请求失败", - "DSA_HTTP_CLIENT_CLOSE_FAILED":"httpclient 关闭失败", - "RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED": "从引擎调用删除规则接口失败", - "RULE_MANAGEMENT_DELETE_RULE_FAILED":"从引擎中删除规则失败", - "RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED": "从引擎调用部署规则接口失败", - "RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED": "从引擎调用校验规则接口失败", - "RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED": "创建查询语句异常", - "RULE_MANAGEMENT_QUERY_RULE_FAILED": "查询规则失败", - "RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY":"请求对象为空", - "RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE": "规则不存在", - "RULE_MANAGEMENT_REPEAT_RULE_NAME" : "规则名字重复", - "RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY" : "规则名字不能为空", - "RULE_MANAGEMENT_DATA_FORMAT_ERROR": "数据格式异常", - "RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR" : "参数enabled只能为0(未启用)和1(启用)", - "RULE_MANAGEMENT_DB_ERROR" : "数据库异常", - "RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR":"解析调用部署规则返回的结果错误", - "RULE_MANAGEMENT_CHECK_NO_PASS":"规则内容检查不通过", - "RULE_MANAGEMENT_CONTENT_CANNOT_BE_EMPTY":"规则内容不能为空" - -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/msb/MicroserviceBusRest.java b/holmes-actions/src/main/java/org/openo/holmes/common/msb/MicroserviceBusRest.java deleted file mode 100644 index c8e03e9..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/msb/MicroserviceBusRest.java +++ /dev/null @@ -1,36 +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.common.msb; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import org.openo.holmes.common.api.entity.ServiceRegisterEntity; - -@Path("/openoapi/microservices/v1/services") -public interface MicroserviceBusRest { - - @Path("") - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate, - ServiceRegisterEntity entity); -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java b/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.java deleted file mode 100644 index d258695..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/producer/MQProducer.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.common.producer; - -import java.io.Serializable; -import javax.inject.Inject; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Session; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.glassfish.hk2.api.IterableProvider; -import org.jvnet.hk2.annotations.Service; -import org.openo.holmes.common.api.entity.CorrelationResult; -import org.openo.holmes.common.api.stat.Alarm; -import org.openo.holmes.common.api.stat.AplusResult; -import org.openo.holmes.common.config.MQConfig; -import org.openo.holmes.common.constant.AlarmConst; -import org.apache.activemq.ActiveMQConnectionFactory; - -@Service -@Slf4j -@NoArgsConstructor -public class MQProducer { - - @Inject - private IterableProvider mqConfigProvider; - private ConnectionFactory connectionFactory; - - public void init() { - - String brokerURL = - "tcp://" + mqConfigProvider.get().brokerIp + ":" + mqConfigProvider.get().brokerPort; - connectionFactory = new ActiveMQConnectionFactory(mqConfigProvider.get().brokerUsername, - mqConfigProvider.get().brokerPassword, brokerURL); - } - - public void sendAlarmMQTopicMsg(Alarm alarm) { - sendMQTopicMsg(alarm); - } - - public void sendCorrelationMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm, - Alarm childAlarm) { - CorrelationResult correlationResult = getCorrelationResult(ruleId, createTimeL, parentAlarm, childAlarm); - sendMQTopicMsg(correlationResult); - } - - private void sendMQTopicMsg(T t) { - Serializable msgEntity = (Serializable) t; - Connection connection = null; - Session session; - Destination destination = null; - MessageProducer messageProducer; - - try { - connection = connectionFactory.createConnection(); - connection.start(); - session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); - if (t instanceof CorrelationResult) { - destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION); - } else if (t instanceof Alarm) { - destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM); - } - messageProducer = session.createProducer(destination); - ObjectMessage message = session.createObjectMessage(msgEntity); - messageProducer.send(message); - session.commit(); - } catch (Exception e) { - log.error("Failed send correlation." + e.getMessage(), e); - } finally { - if (connection != null) { - try { - connection.close(); - } catch (JMSException e) { - log.error("Failed close connection." + e.getMessage(), e); - } - } - } - } - - private CorrelationResult getCorrelationResult(String ruleId, long createTimeL, Alarm parentAlarm, - Alarm childAlarm) { - CorrelationResult correlationResult = new CorrelationResult(); - correlationResult.setRuleId(ruleId); - correlationResult.setCreateTimeL(createTimeL); - correlationResult.setResultType(AplusResult.APLUS_CORRELATION); - correlationResult.setAffectedAlarms(new Alarm[]{parentAlarm, childAlarm}); - return correlationResult; - } -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java deleted file mode 100644 index 18890ce..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java +++ /dev/null @@ -1,92 +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.common.utils; - -import io.dropwizard.db.DataSourceFactory; -import io.dropwizard.jdbi.DBIFactory; -import io.dropwizard.setup.Environment; -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.skife.jdbi.v2.DBI; -import org.skife.jdbi.v2.Handle; - -@Singleton -@Service -@Slf4j -public class DbDaoUtil { - - private DBI jdbi; - @Inject - private Environment environmentProvider; - @Inject - private DataSourceFactory dataSourceFactoryProvider; - - private DBIFactory factory = new DBIFactory(); - - @PostConstruct - public void init() { - if (jdbi == null) { - synchronized (DbDaoUtil.class) { - if (jdbi == null) { - jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "mysql"); - } - } - } - } - - public K getDao(Class clazz) { - try { - return jdbi.open(clazz); - } catch (Exception e) { - log.warn("get object instance of Dao error.", e); - } - return null; - } - - public Handle getHandle() { - try { - return jdbi.open(); - } catch (Exception e) { - log.warn("get object instance of Dao error.", e); - } - return null; - } - - public void close(Object obj) { - if (obj != null) { - try { - jdbi.close(obj); - } catch (Exception e) { - log.warn("close jdbi connection error.", e); - } - } - } - - public T getJdbiDaoByOnDemand(Class daoClazz) { - - return jdbi.onDemand(daoClazz); - - } - - public T getJdbiDaoByOpen(Class daoClazz) { - - return jdbi.open(daoClazz); - - } -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java deleted file mode 100644 index 1154f38..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.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.common.utils; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -public class ExceptionUtil { - - private static final int EXCEPTION_CODE = 499; - - private ExceptionUtil() { - - } - - public static WebApplicationException buildExceptionResponse(String message) { - Response response = Response.status(EXCEPTION_CODE).entity(message).type(MediaType.TEXT_PLAIN).build(); - return new WebApplicationException(response); - } -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java deleted file mode 100644 index 6e9a844..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java +++ /dev/null @@ -1,111 +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.common.utils; - -import com.fasterxml.jackson.core.JsonProcessingException; -import java.util.Arrays; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; -import lombok.extern.slf4j.Slf4j; -import org.openo.baseservice.i18n.I18n; - -@Slf4j -public class I18nProxy { - - /*-----------------------Engine------------------------------- */ - public static final String ENGINE_CONTENT_ILLEGALITY = "ENGINE_CONTENT_ILLEGALITY"; - public static final String ENGINE_DEPLOY_RULE_FAILED = "ENGINE_DEPLOY_RULE_FAILED"; - public static final String ENGINE_DELETE_RULE_NULL = "ENGINE_DELETE_RULE_NULL"; - public static final String ENGINE_DELETE_RULE_FAILED = "ENGINE_DELETE_RULE_FAILED"; - public static final String ENGINE_INSERT_RULE_CACHE_FAILED = "ENGINE_INSERT_RULE_CACHE_FAILED"; - public static final String ENGINE_DELETE_RULE_FAILED_FROM_CACHE = "ENGINE_DELETE_RULE_FAILED_FROM_CACHE"; - public static final String ENGINE_CONTAINS_PACKAGE = "ENGINE_CONTAINS_PACKAGE"; - public static final String ENGINE_QUERY_CACHE_FAILED = "ENGINE_QUERY_CACHE_FAILED"; - /*-----------------------DSA ------------------------------- */ - public static final String DSA_QUERY_CURRENT_ALARM_FAILED = "DSA_QUERY_CURRENT_ALARM_FAILED"; - public static final String DSA_REQUEST_ANALYSIS_FAILED = "DSA_REQUEST_ANALYSIS_ERROR"; - public static final String DSA_REQUEST_EXECUTE_FAILED = "DSA_REQUEST_EXECUTE_FAILED"; - public static final String DSA_HTTP_CLIENT_CLOSE_FAILED = "DSA_HTTP_CLIENT_CLOSE_FAILED"; - - /*-----------------------Rule Management------------------------------- */ - public static final String RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED = "RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED"; - public static final String RULE_MANAGEMENT_DELETE_RULE_FAILED = "RULE_MANAGEMENT_DELETE_RULE_FAILED"; - public static final String RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED = "RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED"; - public static final String RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED = "RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED"; - public static final String RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED = "RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED"; - public static final String RULE_MANAGEMENT_QUERY_RULE_FAILED = "RULE_MANAGEMENT_QUERY_RULE_FAILED"; - public static final String RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY = "RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY"; - public static final String RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY = "RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY"; - public static final String RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE = "RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE"; - public static final String RULE_MANAGEMENT_REPEAT_RULE_NAME = "RULE_MANAGEMENT_REPEAT_RULE_NAME"; - public static final String RULE_MANAGEMENT_DATA_FORMAT_ERROR = "RULE_MANAGEMENT_DATA_FORMAT_ERROR"; - public static final String RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR = "RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR"; - public static final String RULE_MANAGEMENT_DB_ERROR = "RULE_MANAGEMENT_DB_ERROR"; - public static final String RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR = "RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR"; - public static final String RULE_MANAGEMENT_CHECK_NO_PASS = "RULE_MANAGEMENT_CHECK_NO_PASS"; - public static final String RULE_MANAGEMENT_CONTENT_CANNOT_BE_EMPTY = "RULE_MANAGEMENT_CONTENT_CANNOT_BE_EMPTY"; - private Optional optional = null; - - private I18nProxy() { - optional = I18n.getInstance("correlation"); - } - - private static class I18nProxyHolder { - - private static final I18nProxy INSTANCE = new I18nProxy(); - - private I18nProxyHolder() { - - } - } - - public static I18nProxy getInstance() { - return I18nProxyHolder.INSTANCE; - } - - public String getValue(Locale locale, String key) { - return optional.get().getLabelValue(key, locale); - } - - public String getValueByArgs(Locale locale, String key, String[] arguments) { - return optional.get().getLabelValue(key, locale, arguments); - } - - public Map getValue(String key) { - return optional.get().getLabelValues(key); - } - - public String jsonI18n(String key) { - - return optional.get().getCanonicalLabelValues(key); - } - - public String i18nWithArgs(String key, String[] args) { - String value = ""; - try { - value = JacksonUtil.beanToJson(optional.get().getLabelValues(key, args)); - } catch (JsonProcessingException e) { - log.warn("get i18n error, key is :" + key, e); - } catch (IllegalArgumentException e) { - log.warn("get i18n error IllegalArgumentException, key is :" + key + ",args is : " + Arrays.toString(args), - e); - } - - return value; - } - -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java deleted file mode 100644 index f030d3d..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java +++ /dev/null @@ -1,40 +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.common.utils; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; - -public class JacksonUtil { - - private JacksonUtil() { - - } - - public static String beanToJson(Object obj) throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.writeValueAsString(obj); - } - - public static T jsonToBean(String json, Class cls) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - if (json == null) { - return objectMapper.readValue("{}", cls); - } - return objectMapper.readValue(json, cls); - } -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java deleted file mode 100644 index beed186..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java +++ /dev/null @@ -1,49 +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.common.utils; - -import java.util.List; - -public class JudgeNullUtil { - - private JudgeNullUtil() { - - } - - public static boolean isEmpty( short[] shorts ) { - return shorts == null || shorts.length == 0; - } - - public static boolean isEmpty( int[] ints ) { - return ints == null || ints.length == 0; - } - - public static boolean isEmpty( long[] longs ) { - return longs == null || longs.length == 0; - } - - public static boolean isEmpty( Object[] obj ) { - return obj == null || obj.length == 0; - } - - public static boolean isEmpty( String str ) { - return str == null || "".equals( str.trim() ); - } - - public static boolean isEmpty( List < ? > list ) { - return list == null || list.isEmpty(); - } -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java deleted file mode 100644 index 930905a..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java +++ /dev/null @@ -1,52 +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.common.utils; - -import java.util.Locale; -import javax.servlet.http.HttpServletRequest; -import org.openo.holmes.common.constant.AlarmConst; - -public class LanguageUtil { - - private LanguageUtil() { - } - - public static String getLanguage(HttpServletRequest servletRequest) { - String language = servletRequest.getHeader("language-option"); - if (JudgeNullUtil.isEmpty(language)) { - language = AlarmConst.I18N_EN; - } - if (language.startsWith(AlarmConst.I18N_ZH)) { - language = AlarmConst.I18N_ZH; - } else if (language.startsWith(AlarmConst.I18N_EN)) { - language = AlarmConst.I18N_EN; - } - return language; - } - - public static Locale getLocale(HttpServletRequest servletRequest) { - String language = servletRequest.getHeader("language-option"); - if (JudgeNullUtil.isEmpty(language)) { - language = AlarmConst.I18N_EN; - } - if (language.startsWith(AlarmConst.I18N_ZH)) { - language = AlarmConst.I18N_ZH; - } else if (language.startsWith(AlarmConst.I18N_EN)) { - language = AlarmConst.I18N_EN; - } - return new Locale(language); - } -} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java deleted file mode 100644 index 904a853..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java +++ /dev/null @@ -1,74 +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.common.utils; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; -import java.io.IOException; -import lombok.extern.slf4j.Slf4j; -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.msb.MicroserviceBusRest; - -@Slf4j -@Service -public class MSBRegisterUtil { - - public void register(ServiceRegisterEntity entity) throws IOException { - log.info("start holmes micro service register"); - boolean flag = false; - int retry = 0; - while (!flag && retry < 20) { - log.info("Holmes microservice register. retry:" + retry); - retry++; - flag = innerRegister(entity); - if (!flag) { - log.warn("micro service register failed, sleep 30S and try again."); - threadSleep(30000); - } else { - log.info("micro service register success!"); - break; - } - } - log.info("holmes micro service register end."); - } - - private boolean innerRegister(ServiceRegisterEntity entity) { - try { - log.info("msbServerAddr:" + MicroServiceConfig.getMsbServerAddr()); - log.info("entity:" + entity); - MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer( - MicroServiceConfig.getMsbServerAddr(), MicroserviceBusRest.class); - resourceserviceproxy.registerServce("false", entity); - } catch (Exception error) { - log.error("microservice register failed!" + error.getMessage(), error); - return false; - } - return true; - } - - private void threadSleep(int second) { - log.info("start sleep ...."); - try { - Thread.sleep(second); - } catch (InterruptedException error) { - log.error("thread sleep error.errorMsg:" + error.getMessage(), error); - Thread.currentThread().interrupt(); - } - log.info("sleep end ."); - } -} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java deleted file mode 100644 index ec8fda6..0000000 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java +++ /dev/null @@ -1,35 +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.common.utils; - -import javax.servlet.http.HttpServletRequest; -import org.openo.holmes.common.constant.AlarmConst; - -public class UserUtil { - - private UserUtil() { - - } - - public static String getUserName(HttpServletRequest request) { - String userName = AlarmConst.ADMIN; - String sessionName = request.getHeader("username"); - if (sessionName != null) { - userName = sessionName.toLowerCase(); - } - return userName; - } -} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java new file mode 100644 index 0000000..dd940c4 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java @@ -0,0 +1,132 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Date; +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +public class AlarmsCorrelationTest { + + private AlarmsCorrelation alarmsCorrelation; + + @Before + public void before() throws Exception { + alarmsCorrelation = new AlarmsCorrelation(); + } + + @After + public void after() throws Exception { + + } + + + @Test + public void getterAndSetter4RuleId() throws Exception { + final String ruleId = "ruleId"; + alarmsCorrelation.setRuleId(ruleId); + assertThat(alarmsCorrelation.getRuleId(), equalTo(ruleId)); + } + + + @Test + public void getterAndSetter4RuleInfo() throws Exception { + final String ruleInfo = "ruleInfo"; + alarmsCorrelation.setRuleInfo(ruleInfo); + assertThat(alarmsCorrelation.getRuleInfo(), equalTo(ruleInfo)); + } + + + @Test + public void getterAndSetter4ResultType() throws Exception { + final byte resultType = 1; + alarmsCorrelation.setResultType(resultType); + assertThat(alarmsCorrelation.getResultType(), equalTo(resultType)); + } + + + @Test + public void getterAndSetter4CreateTime() throws Exception { + final Date createTime = new Date(); + alarmsCorrelation.setCreateTime(createTime); + assertThat(alarmsCorrelation.getCreateTime(), equalTo(createTime)); + } + + + @Test + public void getterAndSetter4ParentAlarmId() throws Exception { + final long pad = 11L; + alarmsCorrelation.setParentAlarmId(pad); + assertThat(alarmsCorrelation.getParentAlarmId(), equalTo(pad)); + } + + + @Test + public void getterAndSetter4ChildAlarmId() throws Exception { + final long childAlarmId = 11L; + alarmsCorrelation.setChildAlarmId(childAlarmId); + assertThat(alarmsCorrelation.getChildAlarmId(), equalTo(childAlarmId)); + } + + + @Test + public void getterAndSetter4Reserve1() throws Exception { + final long reserve1 = 11L; + alarmsCorrelation.setReserve1(reserve1); + assertThat(alarmsCorrelation.getReserve1(), equalTo(reserve1)); + } + + + @Test + public void getterAndSetter4Reserve2() throws Exception { + final long reserve2 = 11L; + alarmsCorrelation.setReserve2(reserve2); + assertThat(alarmsCorrelation.getReserve2(), equalTo(reserve2)); + } + + + @Test + public void getterAndSetter4Reserve3() throws Exception { + final long reserve3 = 11L; + alarmsCorrelation.setReserve3(reserve3); + assertThat(alarmsCorrelation.getReserve3(), equalTo(reserve3)); + } + + + @Test + public void testToString() throws Exception { + final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); + String ruleId = "ruleId"; + alarmsCorrelationTemp.setRuleId(ruleId); + alarmsCorrelation.setRuleId(ruleId); + assertThat(alarmsCorrelation.toString(), equalTo(alarmsCorrelationTemp.toString())); + } + + + @Test + public void testEqualsAndHashCode() throws Exception { + final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); + String ruleId = "ruleId"; + alarmsCorrelationTemp.setRuleId(ruleId); + alarmsCorrelation.setRuleId(ruleId); + assertThat(alarmsCorrelation, equalTo(alarmsCorrelationTemp)); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java new file mode 100644 index 0000000..1e30fab --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationResultTest.java @@ -0,0 +1,78 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Date; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.holmes.common.api.stat.Alarm; + +public class CorrelationResultTest { + + private CorrelationResult correlationResult; + + @Before + public void before() throws Exception { + correlationResult = new CorrelationResult(); + } + + @After + public void after() throws Exception { + } + + @Test + public void getterAndSetter4RuleId() throws Exception { + final String ruleId = "ruleId"; + correlationResult.setRuleId(ruleId); + assertThat(correlationResult.getRuleId(), equalTo(ruleId)); + } + + @Test + public void getterAndSetter4CreateTimeL() throws Exception { + final long createTimeL = new Date().getTime(); + correlationResult.setCreateTimeL( + createTimeL); + assertThat(correlationResult.getCreateTimeL(), equalTo(createTimeL)); + } + + @Test + public void getterAndSetter4GetResultType() throws Exception { + final byte resultType = 2; + correlationResult.setResultType(resultType); + assertThat(correlationResult.getResultType(), equalTo(resultType)); + } + + @Test + public void getterAndSetter4AffectedAlarms() throws Exception { + final Alarm alarm[] = new Alarm[2]; + correlationResult.setAffectedAlarms(alarm); + assertThat(correlationResult.getAffectedAlarms(), equalTo(alarm)); + } + + @Test + public void testToString() throws Exception { + CorrelationResult resultTemp = new CorrelationResult(); + final String tempStr = "aa"; + resultTemp.setRuleId(tempStr); + correlationResult.setRuleId(tempStr); + assertThat(correlationResult.toString(), equalTo(resultTemp.toString())); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java new file mode 100644 index 0000000..25ee5c6 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java @@ -0,0 +1,146 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Date; +import java.util.Properties; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CorrelationRuleTest { + + private CorrelationRule correlationRule; + + @Before + public void before() throws Exception { + correlationRule = new CorrelationRule(); + } + + @After + public void after() throws Exception { + + } + + @Test + public void getterAndSetter4Rid() throws Exception { + final String rid = "rid"; + correlationRule.setRid(rid); + assertThat(correlationRule.getRid(), equalTo(rid)); + } + + @Test + public void getterAndSetter4Name() throws Exception { + final String name = "name"; + correlationRule.setName(name); + assertThat(correlationRule.getName(), equalTo(name)); + } + + @Test + public void getterAndSetter4Description() throws Exception { + final String description = "description"; + correlationRule.setDescription(description); + assertThat(correlationRule.getDescription(), equalTo(description)); + } + + @Test + public void getterAndSetter4Enabled() throws Exception { + final int enabled = 1; + correlationRule.setEnabled(enabled); + assertThat(correlationRule.getEnabled(), equalTo(enabled)); + } + + @Test + public void getterAndSetter4TemplateID() throws Exception { + final int templateId = 1; + correlationRule.setTemplateID(templateId); + assertThat(correlationRule.getTemplateID(), equalTo(templateId)); + } + + @Test + public void getterAndSetter4EngineId() throws Exception { + final String engineId = "engineId"; + correlationRule.setEngineID(engineId); + assertThat(correlationRule.getEngineID(), equalTo(engineId)); + } + + @Test + public void getterAndSetter4EngineType() throws Exception { + final String engineType = "engineType"; + correlationRule.setEngineType(engineType); + assertThat(correlationRule.getEngineType(), equalTo(engineType)); + } + + @Test + public void getterAndSetter4Creator() throws Exception { + final String creator = "creator"; + correlationRule.setCreator(creator); + assertThat(correlationRule.getCreator(), equalTo(creator)); + } + + @Test + public void getterAndSetter4Modifier() throws Exception { + final String modifier = "modifier"; + correlationRule.setModifier(modifier); + assertThat(correlationRule.getModifier(), equalTo(modifier)); + } + + @Test + public void getterAndSetter4Params() throws Exception { + final Properties params = new Properties(); + correlationRule.setParams(params); + assertThat(correlationRule.getParams(), equalTo(params)); + } + + @Test + public void getterAndSetter4Content() throws Exception { + final String content = "content"; + correlationRule.setContent(content); + assertThat(correlationRule.getContent(), equalTo(content)); + } + + @Test + public void getterAndSetter4Vendor() throws Exception { + final String vendor = "vendor"; + correlationRule.setVendor(vendor); + assertThat(correlationRule.getVendor(), equalTo(vendor)); + } + + @Test + public void getterAndSetter4CreateTime() throws Exception { + Date createTime = new Date(); + correlationRule.setCreateTime(createTime); + assertThat(correlationRule.getCreateTime(), equalTo(createTime)); + } + + @Test + public void getterAndSetter4UpdateTime() throws Exception { + final Date updateTime = new Date(); + correlationRule.setUpdateTime(updateTime); + assertThat(correlationRule.getUpdateTime(), equalTo(updateTime)); + } + + @Test + public void getterAndSetter4PackageName() throws Exception { + final String packageName = "packageName"; + correlationRule.setPackageName(packageName); + assertThat(correlationRule.getPackageName(), equalTo(packageName)); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.java new file mode 100644 index 0000000..d1b800b --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceNodeTest.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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class ServiceNodeTest { + + private ServiceNode serviceNode = new ServiceNode(); + + @Test + public void getterAndSetter4ip() { + String ip = "test"; + serviceNode.setIp(ip); + assertThat(serviceNode.getIp(), equalTo(ip)); + } + + @Test + public void getterAndSetter4port() { + String port = "test"; + serviceNode.setPort(port); + assertThat(serviceNode.getPort(), equalTo(port)); + } + + @Test + public void getterAndSetter4ttl() { + int ttl = 1; + serviceNode.setTtl(ttl); + assertThat(serviceNode.getTtl(), equalTo(ttl)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java new file mode 100644 index 0000000..266c8bc --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/ServiceRegisterEntityTest.java @@ -0,0 +1,62 @@ +/** + * 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.common.api.entity; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class ServiceRegisterEntityTest { + + private ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); + + @Test + public void getterAndSetter4protocol() { + String protocol = "test"; + serviceRegisterEntity.setProtocol(protocol); + assertThat(serviceRegisterEntity.getProtocol(), equalTo(protocol)); + } + + @Test + public void getterAndSetter4serviceName() { + String serviceName = "test"; + serviceRegisterEntity.setServiceName(serviceName); + assertThat(serviceRegisterEntity.getServiceName(), equalTo(serviceName)); + } + + @Test + public void getterAndSetter4url() { + String url = "test"; + serviceRegisterEntity.setUrl(url); + assertThat(serviceRegisterEntity.getUrl(), equalTo(url)); + } + + @Test + public void getterAndSetter4version() { + String version = "test"; + serviceRegisterEntity.setVersion(version); + assertThat(serviceRegisterEntity.getVersion(), equalTo(version)); + } + + @Test + public void getterAndSetter4visualRange() { + String visualRange = "test"; + serviceRegisterEntity.setVisualRange(visualRange); + assertThat(serviceRegisterEntity.getVisualRange(), equalTo(visualRange)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java new file mode 100644 index 0000000..b0e3690 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java @@ -0,0 +1,207 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.holmes.common.api.stat; + +import java.util.Date; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class AlarmTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private Alarm alarm; + + @Before + public void before() throws Exception { + alarm = new Alarm(); + } + + @After + public void after() throws Exception { + } + + @Test + public void testCompareLinkPosition_isEmpty() throws Exception { + final Map otherIdIdx = new HashMap<>(); + assertThat(999, equalTo(alarm.CompareLinkPosition(otherIdIdx))); + } + + @Test + public void testCompareLinkPosition_TempLinkId() throws Exception { + final Map otherIdIdx = new HashMap<>(); + otherIdIdx.put(1, 2); + alarm.addLinkIdNodeIdx(1, 3); + assertThat(1, equalTo(alarm.CompareLinkPosition(otherIdIdx))); + } + + @Test + public void testContainNode_NoContainLink() throws Exception { + alarm.addLinkIdNodeIdx(1, 2); + assertThat(false, equalTo(alarm.containNode(2, 2))); + } + + @Test + public void testContainNode_ContainLinkNoIdx() throws Exception { + alarm.addLinkIdNodeIdx(1, 2); + assertFalse(alarm.containNode(1, 3)); + } + + @Test + public void testContainNode_ContainLinkAndIdx() throws Exception { + alarm.addLinkIdNodeIdx(1, 2); + assertTrue(alarm.containNode(1, 2)); + } + + @Test + public void testGetDataType() throws Exception { + assertThat(Alarm.APLUS_EVENT, equalTo(alarm.getDataType())); + } + + @Test + public void testToString() throws Exception { + Alarm alarmTempA = new Alarm(); + Alarm alarmTempB = new Alarm(); + Date date = new Date(); + alarmTempA.setClearedTime(date); + alarmTempA.setRaisedTime(date); + alarmTempA.setRaisedServerTime(date); + alarmTempB.setClearedTime(date); + alarmTempB.setRaisedTime(date); + alarmTempB.setRaisedServerTime(date); + assertThat(alarmTempA.toString(),equalTo(alarmTempB.toString())); + } + + @Test + public void testHashCode() throws Exception { + final Alarm alarmTemp = new Alarm(); + final String alarmKey = "alarmKey"; + alarm.setAlarmKey(alarmKey); + alarmTemp.setAlarmKey(alarmKey); + assertThat(alarm.hashCode(), equalTo(alarmTemp.hashCode())); + } + + @Test + public void testEqualsAnd_NotNull() throws Exception { + final Alarm alarmTemp = new Alarm(); + final String alarmKey = "alarmKey"; + alarm.setAlarmKey(alarmKey); + alarmTemp.setAlarmKey(alarmKey); + assertTrue(alarm.equals(alarmTemp)); + } + + @Test + public void testEqualsAndH_isNull() throws Exception { + assertFalse(alarm.equals(null)); + } + + @Test + public void testClone() throws Exception { + alarm.setAlarmKey("alarmKey"); + Alarm alarmTemp = (Alarm) alarm.clone(); + assertTrue(alarm.equals(alarmTemp)); + assertFalse(alarm == alarmTemp); + } + + @Test + public void testGetObjectId() throws Exception { + alarm.setId(11); + assertThat("11", equalTo(alarm.getObjectId())); + } + + @Test + public void testAddLinkIds() throws Exception { + final int linkId = 11; + alarm.addLinkIds(linkId); + assertTrue(alarm.getLinkIds().contains(linkId)); + } + + @Test + public void testContainsPriority_true() throws Exception { + String ruleId = "ruleId"; + alarm.getPriorityMap().put(ruleId, 2); + assertTrue(alarm.containsPriority(ruleId)); + } + + @Test + public void testContainsPriority_false() throws Exception { + final String ruleId = "ruleId"; + assertFalse(alarm.containsPriority(ruleId)); + } + + @Test + public void testGetPriority_isNull() throws Exception { + final String ruleId = "ruleId"; + alarm.getPriorityMap().put(ruleId, null); + assertThat(0, equalTo(alarm.getPriority(ruleId))); + } + + @Test + public void testGetPriority_notNull() throws Exception { + final String ruleId = "ruleId"; + final int priority = 2; + alarm.getPriorityMap().put(ruleId, priority); + assertThat(priority, equalTo(alarm.getPriority(ruleId))); + } + + @Test + public void testGetAlarmTypeRuleId_isNull() throws Exception { + final String ruleId = "ruleId"; + alarm.getRootAlarmTypeMap().put(ruleId, null); + assertThat(-1, equalTo(alarm.getRootAlarmType(ruleId))); + } + + @Test + public void testGetAlarmTypeRuleId_notNull() throws Exception { + final String ruleId = "ruleId"; + final int rootAlarmType = 2; + alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmType); + assertThat(rootAlarmType, equalTo(alarm.getRootAlarmType(ruleId))); + } + + @Test + public void getterAndSetter4CenterType() throws Exception { + final int centerType = 1; + alarm.setCenterType(centerType); + assertThat(centerType, equalTo(alarm.getCenterType())); + } + + @Test + public void valueOf_exception() { + thrown.expect(Exception.class); + String xmlString = ""; + Alarm.valueOf(xmlString); + } + + @Test + public void valueOf_normal() { + String xmlString = alarm.toString(); + Alarm alarmValue = Alarm.valueOf(xmlString); + assertThat(alarmValue, equalTo(alarm)); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java new file mode 100644 index 0000000..cc9dced --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.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.common.config; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +public class MQConfigTest { + @Test + public void testNewClass() { + MQConfig mqConfig= new MQConfig(); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java new file mode 100644 index 0000000..33431ff --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java @@ -0,0 +1,39 @@ +/** + * 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.common.config; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class MicroServiceConfigTest { + + @Test + public void getMsbServerAddrTest() { + System.setProperty("MSB_ADDR", "test"); + assertThat("http://test", equalTo(MicroServiceConfig.getMsbServerAddr())); + System.clearProperty("MSB_ADDR"); + } + + @Test + public void getServiceIpTest() { + System.setProperty("SERVICE_IP", "test"); + assertThat("test", equalTo(MicroServiceConfig.getServiceIp())); + System.clearProperty("SERVICE_IP"); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.java new file mode 100644 index 0000000..d924533 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/exception/CorrelationExceptionTest.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.common.exception; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +public class CorrelationExceptionTest { + @Test + public void testConstructors() throws Exception { + CorrelationException ce1 = new CorrelationException("msg", new Exception()); + CorrelationException ce2 = new CorrelationException("msg"); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java new file mode 100644 index 0000000..7c561b0 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java @@ -0,0 +1,173 @@ +/** + * 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.common.producer; + +import static org.easymock.EasyMock.anyBoolean; +import static org.easymock.EasyMock.anyInt; +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Session; +import javax.jms.Topic; +import org.glassfish.hk2.api.IterableProvider; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.holmes.common.api.stat.Alarm; +import org.onap.holmes.common.api.entity.CorrelationResult; +import org.onap.holmes.common.config.MQConfig; +import org.powermock.api.easymock.PowerMock; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.powermock.reflect.Whitebox; + +public class MQProducerTest { + + @Rule + public PowerMockRule powerMockRule = new PowerMockRule(); + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private IterableProvider mqConfigProvider; + + private ConnectionFactory connectionFactory; + + private MQProducer mqProducer; + + @Before + public void before() throws Exception { + mqProducer = new MQProducer(); + + mqConfigProvider = PowerMock.createMock(IterableProvider.class); + connectionFactory = PowerMock.createMock(ConnectionFactory.class); + + Whitebox.setInternalState(mqProducer, "mqConfigProvider", mqConfigProvider); + Whitebox.setInternalState(mqProducer, "connectionFactory", connectionFactory); + PowerMock.resetAll(); + } + + @Test + public void init() { + MQConfig mqConfig = new MQConfig(); + mqConfig.brokerIp = "127.0.0.1"; + mqConfig.brokerPort = 61616; + mqConfig.brokerPassword = "admin"; + mqConfig.brokerUsername = "admin"; + expect(mqConfigProvider.get()).andReturn(mqConfig).anyTimes(); + + PowerMock.replayAll(); + + mqProducer.init(); + + PowerMock.verifyAll(); + } + + @Test + public void sendAlarmMQTopicMsg() throws Exception { + Alarm alarm = new Alarm(); + Connection connection = PowerMock.createMock(Connection.class); + Session session = PowerMock.createMock(Session.class); + Destination destination = PowerMock.createMock(Topic.class); + MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); + ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); + + expect(connectionFactory.createConnection()).andReturn(connection); + connection.start(); + expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); + expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); + expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); + + expect(session.createObjectMessage(anyObject(Alarm.class))).andReturn(objMessage); + messageProducer.send(objMessage); + session.commit(); + connection.close(); + + PowerMock.replayAll(); + + mqProducer.sendAlarmMQTopicMsg(alarm); + + PowerMock.verifyAll(); + + } + + @Test + public void sendAlarmMQTopicMsg_exception() throws Exception { + thrown.expect(JMSException.class); + Alarm alarm = new Alarm(); + + expect(connectionFactory.createConnection()).andThrow(new JMSException("")); + + PowerMock.replayAll(); + + mqProducer.sendAlarmMQTopicMsg(alarm); + + PowerMock.verifyAll(); + } + + @Test + public void sendCorrelationMQTopicMsg() throws Exception { + + Connection connection = PowerMock.createMock(Connection.class); + Session session = PowerMock.createMock(Session.class); + Destination destination = PowerMock.createMock(Topic.class); + MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); + ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); + + expect(connectionFactory.createConnection()).andReturn(connection); + connection.start(); + expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); + expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); + expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); + + expect(session.createObjectMessage(anyObject(CorrelationResult.class))) + .andReturn(objMessage); + messageProducer.send(objMessage); + session.commit(); + connection.close(); + + PowerMock.replayAll(); + + Alarm parentAlarm = new Alarm(); + Alarm childAlarm = new Alarm(); + mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); + + PowerMock.verifyAll(); + + } + + @Test + public void sendCorrelationMQTopicMsg_exception() throws Exception { + thrown.expect(JMSException.class); + + expect(connectionFactory.createConnection()).andThrow(new JMSException("")); + + PowerMock.replayAll(); + + Alarm parentAlarm = new Alarm(); + Alarm childAlarm = new Alarm(); + mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); + + PowerMock.verifyAll(); + + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java new file mode 100644 index 0000000..e942eb4 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java @@ -0,0 +1,188 @@ +/** + * 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.common.utils; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import io.dropwizard.db.DataSourceFactory; +import io.dropwizard.jdbi.DBIFactory; +import io.dropwizard.setup.Environment; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.powermock.api.easymock.PowerMock; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.powermock.reflect.Whitebox; +import org.skife.jdbi.v2.DBI; +import org.skife.jdbi.v2.Handle; + +public class DbDaoUtilTest { + + @Rule + public PowerMockRule powerMockRule = new PowerMockRule(); + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private DBI jdbi; + + private Environment environmentProvider; + + private DataSourceFactory dataSourceFactoryProvider; + + private DbDaoUtil dbDaoUtil; + + private DBIFactory factory; + + @Before + public void before() throws Exception { + dbDaoUtil = new DbDaoUtil(); + + jdbi = PowerMock.createMock(DBI.class); + environmentProvider = PowerMock.createMock(Environment.class); + dataSourceFactoryProvider = PowerMock.createMock(DataSourceFactory.class); + factory = PowerMock.createMock(DBIFactory.class); + + Whitebox.setInternalState(dbDaoUtil, "environmentProvider", environmentProvider); + Whitebox.setInternalState(dbDaoUtil, "dataSourceFactoryProvider", + dataSourceFactoryProvider); + Whitebox.setInternalState(dbDaoUtil, "factory", factory); + + PowerMock.resetAll(); + } + + @Test + public void init() throws Exception { + DBI jdbi = PowerMock.createMock(DBI.class); + + expect(factory.build(anyObject(Environment.class), anyObject(DataSourceFactory.class), + anyObject(String.class))).andReturn(jdbi); + + PowerMock.replayAll(); + + dbDaoUtil.init(); + + PowerMock.verifyAll(); + } + + @Test + public void getDao_normal() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); + + PowerMock.replayAll(); + + dbDaoUtil.getDao(String.class); + + PowerMock.verifyAll(); + } + + @Test + public void getDao_exception() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + + expect(jdbi.open(anyObject(Class.class))).andThrow(new RuntimeException("")); + + PowerMock.replayAll(); + + Object o = dbDaoUtil.getDao(String.class); + + PowerMock.verifyAll(); + + assertThat(o, equalTo(null)); + } + + @Test + public void getHandle_normal() throws Exception { + Handle handle = PowerMock.createMock(Handle.class); + + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open()).andReturn(handle); + + PowerMock.replayAll(); + + dbDaoUtil.getHandle(); + + PowerMock.verifyAll(); + } + @Test + public void getHandle_exception() throws Exception { + Handle handle = PowerMock.createMock(Handle.class); + + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open()).andThrow(new RuntimeException("")); + + PowerMock.replayAll(); + + Handle handle1 = dbDaoUtil.getHandle(); + + PowerMock.verifyAll(); + + assertThat(handle1, equalTo(null)); + } + + @Test + public void close_normal() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + jdbi.close(anyObject()); + + PowerMock.replayAll(); + + dbDaoUtil.close(new Object()); + + PowerMock.verifyAll(); + } + + @Test + public void close_exception() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + jdbi.close(anyObject()); + EasyMock.expectLastCall().andThrow(new RuntimeException("")); + PowerMock.replayAll(); + + dbDaoUtil.close(new Object()); + + PowerMock.verifyAll(); + } + @Test + public void testGetJdbiDaoByOnDemand() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.onDemand(anyObject(Class.class))).andReturn(Class.class); + + PowerMock.replayAll(); + + dbDaoUtil.getJdbiDaoByOnDemand(String.class); + + PowerMock.verifyAll(); + } + + @Test + public void testGetJdbiDaoByOpen() throws Exception { + Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); + expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); + + PowerMock.replayAll(); + + dbDaoUtil.getJdbiDaoByOpen(String.class); + + PowerMock.verifyAll(); + } +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.java new file mode 100644 index 0000000..98cac63 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/ExceptionUtilTest.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.common.utils; + +import org.junit.Test; + +public class ExceptionUtilTest { + + @Test + public void testBuildExceptionResponse() throws Exception { + ExceptionUtil.buildExceptionResponse("test"); + } + + +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java new file mode 100644 index 0000000..5f90c2d --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java @@ -0,0 +1,49 @@ +/** + * Copyright 2016 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.onap.holmes.common.utils.bean.TestBean; + +public class JacksonUtilTest { + + @Test + public void testBeanToJson() throws Exception { + TestBean o = new TestBean(); + o.setId("id"); + String result = JacksonUtil.beanToJson(o); + assertThat("{\"id\":\"id\"}", equalTo(result)); + } + + @Test + public void jsonToBean_json_null() throws Exception { + String jsonNull = null; + TestBean testBean = JacksonUtil.jsonToBean(jsonNull, TestBean.class); + assertThat(testBean.getId(), equalTo(null)); + } + + @Test + public void jsonToBean_json_normal() throws Exception { + String json = "{\"id\":\"id\"}"; + TestBean testBean = JacksonUtil.jsonToBean(json, TestBean.class); + assertThat(testBean.getId(), equalTo("id")); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java new file mode 100644 index 0000000..5d38229 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JudgeNullUtilTest.java @@ -0,0 +1,43 @@ +/** + * Copyright 2016 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.List; +import org.junit.Test; + +public class JudgeNullUtilTest { + + @Test + public void isEmpty_array_length_zero() { + boolean resultShorts = JudgeNullUtil.isEmpty(new short[]{}); + boolean resultInts = JudgeNullUtil.isEmpty(new int[]{}); + boolean resultLongs = JudgeNullUtil.isEmpty(new long[]{}); + boolean resultObjects = JudgeNullUtil.isEmpty(new Object[]{}); + boolean resultStrings = JudgeNullUtil.isEmpty(new String[]{}); + boolean resultLists = JudgeNullUtil.isEmpty(new List[]{}); + assertThat(true, equalTo(resultShorts)); + assertThat(true, equalTo(resultInts)); + assertThat(true, equalTo(resultLongs)); + assertThat(true, equalTo(resultObjects)); + assertThat(true, equalTo(resultStrings)); + assertThat(true, equalTo(resultLists)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java new file mode 100644 index 0000000..06759ec --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/LanguageUtilTest.java @@ -0,0 +1,118 @@ +/** + * 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Locale; +import javax.servlet.http.HttpServletRequest; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; +import org.onap.holmes.common.constant.AlarmConst; +import org.powermock.api.easymock.PowerMock; + + +public class LanguageUtilTest { + + private HttpServletRequest request; + + @Before + public void setUp() { + request = PowerMock.createMock(HttpServletRequest.class); + } + + @Test + public void getLanguage_header_language_empty() { + EasyMock.expect(request.getHeader("language-option")).andReturn(""); + + PowerMock.replayAll(); + + String language = LanguageUtil.getLanguage(request); + + PowerMock.verifyAll(); + + assertThat(AlarmConst.I18N_EN, equalTo(language)); + } + + @Test + public void getLanguage_zh() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); + + PowerMock.replayAll(); + + String language = LanguageUtil.getLanguage(request); + + PowerMock.verifyAll(); + + assertThat(AlarmConst.I18N_ZH, equalTo(language)); + } + + @Test + public void getLanguage_en() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); + + PowerMock.replayAll(); + + String language = LanguageUtil.getLanguage(request); + + PowerMock.verifyAll(); + + assertThat(AlarmConst.I18N_EN, equalTo(language)); + } + + @Test + public void getLocale_header_language_empty() { + EasyMock.expect(request.getHeader("language-option")).andReturn(""); + + PowerMock.replayAll(); + + Locale locale = LanguageUtil.getLocale(request); + + PowerMock.verifyAll(); + + assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); + } + + @Test + public void getLocale_zh() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); + + PowerMock.replayAll(); + + Locale locale = LanguageUtil.getLocale(request); + + PowerMock.verifyAll(); + + assertThat(new Locale(AlarmConst.I18N_ZH), equalTo(locale)); + } + + @Test + public void getLocale_en() { + EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); + + PowerMock.replayAll(); + + Locale locale = LanguageUtil.getLocale(request); + + PowerMock.verifyAll(); + + assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java new file mode 100644 index 0000000..a38c26e --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java @@ -0,0 +1,72 @@ +/** + * 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.common.utils; + +import com.eclipsesource.jaxrs.consumer.ConsumerFactory; +import javax.ws.rs.QueryParam; +import org.easymock.EasyMock; +import org.junit.Rule; +import org.junit.Test; +import org.onap.holmes.common.msb.MicroserviceBusRest; +import org.onap.holmes.common.api.entity.ServiceRegisterEntity; +import org.onap.holmes.common.config.MicroServiceConfig; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.rule.PowerMockRule; + +@PrepareForTest(ConsumerFactory.class) +public class MSBRegisterUtilTest { + + @Rule + public PowerMockRule powerMockRule = new PowerMockRule(); + private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil(); + private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy(); + + @Test + public void registerTest() throws Exception { + ServiceRegisterEntity entity = initServiceEntity(); + PowerMock.mockStatic(ConsumerFactory.class); + EasyMock.expect(ConsumerFactory + .createConsumer(EasyMock.anyObject(String.class), EasyMock.anyObject(Class.class))) + .andReturn(microserviceBusRest); + PowerMock.replayAll(); + + msbRegisterUtil.register(initServiceEntity()); + + PowerMock.verifyAll(); + } + + 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; + } + + class MicroserviceBusRestProxy implements MicroserviceBusRest { + + @Override + public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate, + ServiceRegisterEntity entity) { + return null; + } + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java new file mode 100644 index 0000000..d88525a --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/UserUtilTest.java @@ -0,0 +1,67 @@ +/** + * 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.common.utils; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import javax.servlet.http.HttpServletRequest; +import org.easymock.EasyMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.powermock.api.easymock.PowerMock; +public class UserUtilTest { + + private HttpServletRequest request; + + @Before + public void before() throws Exception { + request = PowerMock.createMock(HttpServletRequest.class); + } + + @After + public void after() throws Exception { + } + + @Test + public void getUserName_header_name_empty() throws Exception { + EasyMock.expect(request.getHeader("username")).andReturn(null); + + PowerMock.replayAll(); + + String userName = UserUtil.getUserName(request); + + PowerMock.verifyAll(); + + assertThat("admin", equalTo(userName)); + } + + @Test + public void getUserName_normal() throws Exception { + EasyMock.expect(request.getHeader("username")).andReturn("name1"); + + PowerMock.replayAll(); + + String userName = UserUtil.getUserName(request); + + PowerMock.verifyAll(); + + assertThat("name1", equalTo(userName)); + } + +} diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java new file mode 100644 index 0000000..d8466d4 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/bean/TestBean.java @@ -0,0 +1,32 @@ +/** + * Copyright 2016 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.common.utils.bean; + +import java.io.Serializable; + +public class TestBean implements Serializable { + String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java deleted file mode 100644 index 7dc1fab..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/AlarmsCorrelationTest.java +++ /dev/null @@ -1,133 +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.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import org.junit.Test; -import org.junit.Before; -import org.junit.After; -import sun.util.resources.cldr.ga.LocaleNames_ga; - -public class AlarmsCorrelationTest { - - private AlarmsCorrelation alarmsCorrelation; - - @Before - public void before() throws Exception { - alarmsCorrelation = new AlarmsCorrelation(); - } - - @After - public void after() throws Exception { - - } - - - @Test - public void getterAndSetter4RuleId() throws Exception { - final String ruleId = "ruleId"; - alarmsCorrelation.setRuleId(ruleId); - assertThat(alarmsCorrelation.getRuleId(), equalTo(ruleId)); - } - - - @Test - public void getterAndSetter4RuleInfo() throws Exception { - final String ruleInfo = "ruleInfo"; - alarmsCorrelation.setRuleInfo(ruleInfo); - assertThat(alarmsCorrelation.getRuleInfo(), equalTo(ruleInfo)); - } - - - @Test - public void getterAndSetter4ResultType() throws Exception { - final byte resultType = 1; - alarmsCorrelation.setResultType(resultType); - assertThat(alarmsCorrelation.getResultType(), equalTo(resultType)); - } - - - @Test - public void getterAndSetter4CreateTime() throws Exception { - final Date createTime = new Date(); - alarmsCorrelation.setCreateTime(createTime); - assertThat(alarmsCorrelation.getCreateTime(), equalTo(createTime)); - } - - - @Test - public void getterAndSetter4ParentAlarmId() throws Exception { - final long pad = 11L; - alarmsCorrelation.setParentAlarmId(pad); - assertThat(alarmsCorrelation.getParentAlarmId(), equalTo(pad)); - } - - - @Test - public void getterAndSetter4ChildAlarmId() throws Exception { - final long childAlarmId = 11L; - alarmsCorrelation.setChildAlarmId(childAlarmId); - assertThat(alarmsCorrelation.getChildAlarmId(), equalTo(childAlarmId)); - } - - - @Test - public void getterAndSetter4Reserve1() throws Exception { - final long reserve1 = 11L; - alarmsCorrelation.setReserve1(reserve1); - assertThat(alarmsCorrelation.getReserve1(), equalTo(reserve1)); - } - - - @Test - public void getterAndSetter4Reserve2() throws Exception { - final long reserve2 = 11L; - alarmsCorrelation.setReserve2(reserve2); - assertThat(alarmsCorrelation.getReserve2(), equalTo(reserve2)); - } - - - @Test - public void getterAndSetter4Reserve3() throws Exception { - final long reserve3 = 11L; - alarmsCorrelation.setReserve3(reserve3); - assertThat(alarmsCorrelation.getReserve3(), equalTo(reserve3)); - } - - - @Test - public void testToString() throws Exception { - final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); - String ruleId = "ruleId"; - alarmsCorrelationTemp.setRuleId(ruleId); - alarmsCorrelation.setRuleId(ruleId); - assertThat(alarmsCorrelation.toString(), equalTo(alarmsCorrelationTemp.toString())); - } - - - @Test - public void testEqualsAndHashCode() throws Exception { - final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation(); - String ruleId = "ruleId"; - alarmsCorrelationTemp.setRuleId(ruleId); - alarmsCorrelation.setRuleId(ruleId); - assertThat(alarmsCorrelation, equalTo(alarmsCorrelationTemp)); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java deleted file mode 100644 index 14a52c0..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationResultTest.java +++ /dev/null @@ -1,78 +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.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openo.holmes.common.api.stat.Alarm; - -public class CorrelationResultTest { - - private CorrelationResult correlationResult; - - @Before - public void before() throws Exception { - correlationResult = new CorrelationResult(); - } - - @After - public void after() throws Exception { - } - - @Test - public void getterAndSetter4RuleId() throws Exception { - final String ruleId = "ruleId"; - correlationResult.setRuleId(ruleId); - assertThat(correlationResult.getRuleId(), equalTo(ruleId)); - } - - @Test - public void getterAndSetter4CreateTimeL() throws Exception { - final long createTimeL = new Date().getTime(); - correlationResult.setCreateTimeL( - createTimeL); - assertThat(correlationResult.getCreateTimeL(), equalTo(createTimeL)); - } - - @Test - public void getterAndSetter4GetResultType() throws Exception { - final byte resultType = 2; - correlationResult.setResultType(resultType); - assertThat(correlationResult.getResultType(), equalTo(resultType)); - } - - @Test - public void getterAndSetter4AffectedAlarms() throws Exception { - final Alarm alarm[] = new Alarm[2]; - correlationResult.setAffectedAlarms(alarm); - assertThat(correlationResult.getAffectedAlarms(), equalTo(alarm)); - } - - @Test - public void testToString() throws Exception { - CorrelationResult resultTemp = new CorrelationResult(); - final String tempStr = "aa"; - resultTemp.setRuleId(tempStr); - correlationResult.setRuleId(tempStr); - assertThat(correlationResult.toString(), equalTo(resultTemp.toString())); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java deleted file mode 100644 index 8b6268c..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/CorrelationRuleTest.java +++ /dev/null @@ -1,146 +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.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import java.util.Properties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class CorrelationRuleTest { - - private CorrelationRule correlationRule; - - @Before - public void before() throws Exception { - correlationRule = new CorrelationRule(); - } - - @After - public void after() throws Exception { - - } - - @Test - public void getterAndSetter4Rid() throws Exception { - final String rid = "rid"; - correlationRule.setRid(rid); - assertThat(correlationRule.getRid(), equalTo(rid)); - } - - @Test - public void getterAndSetter4Name() throws Exception { - final String name = "name"; - correlationRule.setName(name); - assertThat(correlationRule.getName(), equalTo(name)); - } - - @Test - public void getterAndSetter4Description() throws Exception { - final String description = "description"; - correlationRule.setDescription(description); - assertThat(correlationRule.getDescription(), equalTo(description)); - } - - @Test - public void getterAndSetter4Enabled() throws Exception { - final int enabled = 1; - correlationRule.setEnabled(enabled); - assertThat(correlationRule.getEnabled(), equalTo(enabled)); - } - - @Test - public void getterAndSetter4TemplateID() throws Exception { - final int templateId = 1; - correlationRule.setTemplateID(templateId); - assertThat(correlationRule.getTemplateID(), equalTo(templateId)); - } - - @Test - public void getterAndSetter4EngineId() throws Exception { - final String engineId = "engineId"; - correlationRule.setEngineID(engineId); - assertThat(correlationRule.getEngineID(), equalTo(engineId)); - } - - @Test - public void getterAndSetter4EngineType() throws Exception { - final String engineType = "engineType"; - correlationRule.setEngineType(engineType); - assertThat(correlationRule.getEngineType(), equalTo(engineType)); - } - - @Test - public void getterAndSetter4Creator() throws Exception { - final String creator = "creator"; - correlationRule.setCreator(creator); - assertThat(correlationRule.getCreator(), equalTo(creator)); - } - - @Test - public void getterAndSetter4Modifier() throws Exception { - final String modifier = "modifier"; - correlationRule.setModifier(modifier); - assertThat(correlationRule.getModifier(), equalTo(modifier)); - } - - @Test - public void getterAndSetter4Params() throws Exception { - final Properties params = new Properties(); - correlationRule.setParams(params); - assertThat(correlationRule.getParams(), equalTo(params)); - } - - @Test - public void getterAndSetter4Content() throws Exception { - final String content = "content"; - correlationRule.setContent(content); - assertThat(correlationRule.getContent(), equalTo(content)); - } - - @Test - public void getterAndSetter4Vendor() throws Exception { - final String vendor = "vendor"; - correlationRule.setVendor(vendor); - assertThat(correlationRule.getVendor(), equalTo(vendor)); - } - - @Test - public void getterAndSetter4CreateTime() throws Exception { - Date createTime = new Date(); - correlationRule.setCreateTime(createTime); - assertThat(correlationRule.getCreateTime(), equalTo(createTime)); - } - - @Test - public void getterAndSetter4UpdateTime() throws Exception { - final Date updateTime = new Date(); - correlationRule.setUpdateTime(updateTime); - assertThat(correlationRule.getUpdateTime(), equalTo(updateTime)); - } - - @Test - public void getterAndSetter4PackageName() throws Exception { - final String packageName = "packageName"; - correlationRule.setPackageName(packageName); - assertThat(correlationRule.getPackageName(), equalTo(packageName)); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.java deleted file mode 100644 index 383cb91..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceNodeTest.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.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class ServiceNodeTest { - - private ServiceNode serviceNode = new ServiceNode(); - - @Test - public void getterAndSetter4ip() { - String ip = "test"; - serviceNode.setIp(ip); - assertThat(serviceNode.getIp(), equalTo(ip)); - } - - @Test - public void getterAndSetter4port() { - String port = "test"; - serviceNode.setPort(port); - assertThat(serviceNode.getPort(), equalTo(port)); - } - - @Test - public void getterAndSetter4ttl() { - int ttl = 1; - serviceNode.setTtl(ttl); - assertThat(serviceNode.getTtl(), equalTo(ttl)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java deleted file mode 100644 index 442549d..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/entity/ServiceRegisterEntityTest.java +++ /dev/null @@ -1,62 +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.common.api.entity; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class ServiceRegisterEntityTest { - - private ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); - - @Test - public void getterAndSetter4protocol() { - String protocol = "test"; - serviceRegisterEntity.setProtocol(protocol); - assertThat(serviceRegisterEntity.getProtocol(), equalTo(protocol)); - } - - @Test - public void getterAndSetter4serviceName() { - String serviceName = "test"; - serviceRegisterEntity.setServiceName(serviceName); - assertThat(serviceRegisterEntity.getServiceName(), equalTo(serviceName)); - } - - @Test - public void getterAndSetter4url() { - String url = "test"; - serviceRegisterEntity.setUrl(url); - assertThat(serviceRegisterEntity.getUrl(), equalTo(url)); - } - - @Test - public void getterAndSetter4version() { - String version = "test"; - serviceRegisterEntity.setVersion(version); - assertThat(serviceRegisterEntity.getVersion(), equalTo(version)); - } - - @Test - public void getterAndSetter4visualRange() { - String visualRange = "test"; - serviceRegisterEntity.setVisualRange(visualRange); - assertThat(serviceRegisterEntity.getVisualRange(), equalTo(visualRange)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java deleted file mode 100644 index c42ee60..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java +++ /dev/null @@ -1,207 +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.common.api.stat; - -import java.util.Date; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class AlarmTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private Alarm alarm; - - @Before - public void before() throws Exception { - alarm = new Alarm(); - } - - @After - public void after() throws Exception { - } - - @Test - public void testCompareLinkPosition_isEmpty() throws Exception { - final Map otherIdIdx = new HashMap<>(); - assertThat(999, equalTo(alarm.CompareLinkPosition(otherIdIdx))); - } - - @Test - public void testCompareLinkPosition_TempLinkId() throws Exception { - final Map otherIdIdx = new HashMap<>(); - otherIdIdx.put(1, 2); - alarm.addLinkIdNodeIdx(1, 3); - assertThat(1, equalTo(alarm.CompareLinkPosition(otherIdIdx))); - } - - @Test - public void testContainNode_NoContainLink() throws Exception { - alarm.addLinkIdNodeIdx(1, 2); - assertThat(false, equalTo(alarm.containNode(2, 2))); - } - - @Test - public void testContainNode_ContainLinkNoIdx() throws Exception { - alarm.addLinkIdNodeIdx(1, 2); - assertFalse(alarm.containNode(1, 3)); - } - - @Test - public void testContainNode_ContainLinkAndIdx() throws Exception { - alarm.addLinkIdNodeIdx(1, 2); - assertTrue(alarm.containNode(1, 2)); - } - - @Test - public void testGetDataType() throws Exception { - assertThat(Alarm.APLUS_EVENT, equalTo(alarm.getDataType())); - } - - @Test - public void testToString() throws Exception { - Alarm alarmTempA = new Alarm(); - Alarm alarmTempB = new Alarm(); - Date date = new Date(); - alarmTempA.setClearedTime(date); - alarmTempA.setRaisedTime(date); - alarmTempA.setRaisedServerTime(date); - alarmTempB.setClearedTime(date); - alarmTempB.setRaisedTime(date); - alarmTempB.setRaisedServerTime(date); - assertThat(alarmTempA.toString(),equalTo(alarmTempB.toString())); - } - - @Test - public void testHashCode() throws Exception { - final Alarm alarmTemp = new Alarm(); - final String alarmKey = "alarmKey"; - alarm.setAlarmKey(alarmKey); - alarmTemp.setAlarmKey(alarmKey); - assertThat(alarm.hashCode(), equalTo(alarmTemp.hashCode())); - } - - @Test - public void testEqualsAnd_NotNull() throws Exception { - final Alarm alarmTemp = new Alarm(); - final String alarmKey = "alarmKey"; - alarm.setAlarmKey(alarmKey); - alarmTemp.setAlarmKey(alarmKey); - assertTrue(alarm.equals(alarmTemp)); - } - - @Test - public void testEqualsAndH_isNull() throws Exception { - assertFalse(alarm.equals(null)); - } - - @Test - public void testClone() throws Exception { - alarm.setAlarmKey("alarmKey"); - Alarm alarmTemp = (Alarm) alarm.clone(); - assertTrue(alarm.equals(alarmTemp)); - assertFalse(alarm == alarmTemp); - } - - @Test - public void testGetObjectId() throws Exception { - alarm.setId(11); - assertThat("11", equalTo(alarm.getObjectId())); - } - - @Test - public void testAddLinkIds() throws Exception { - final int linkId = 11; - alarm.addLinkIds(linkId); - assertTrue(alarm.getLinkIds().contains(linkId)); - } - - @Test - public void testContainsPriority_true() throws Exception { - String ruleId = "ruleId"; - alarm.getPriorityMap().put(ruleId, 2); - assertTrue(alarm.containsPriority(ruleId)); - } - - @Test - public void testContainsPriority_false() throws Exception { - final String ruleId = "ruleId"; - assertFalse(alarm.containsPriority(ruleId)); - } - - @Test - public void testGetPriority_isNull() throws Exception { - final String ruleId = "ruleId"; - alarm.getPriorityMap().put(ruleId, null); - assertThat(0, equalTo(alarm.getPriority(ruleId))); - } - - @Test - public void testGetPriority_notNull() throws Exception { - final String ruleId = "ruleId"; - final int priority = 2; - alarm.getPriorityMap().put(ruleId, priority); - assertThat(priority, equalTo(alarm.getPriority(ruleId))); - } - - @Test - public void testGetAlarmTypeRuleId_isNull() throws Exception { - final String ruleId = "ruleId"; - alarm.getRootAlarmTypeMap().put(ruleId, null); - assertThat(-1, equalTo(alarm.getRootAlarmType(ruleId))); - } - - @Test - public void testGetAlarmTypeRuleId_notNull() throws Exception { - final String ruleId = "ruleId"; - final int rootAlarmType = 2; - alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmType); - assertThat(rootAlarmType, equalTo(alarm.getRootAlarmType(ruleId))); - } - - @Test - public void getterAndSetter4CenterType() throws Exception { - final int centerType = 1; - alarm.setCenterType(centerType); - assertThat(centerType, equalTo(alarm.getCenterType())); - } - - @Test - public void valueOf_exception() { - thrown.expect(Exception.class); - String xmlString = ""; - Alarm.valueOf(xmlString); - } - - @Test - public void valueOf_normal() { - String xmlString = alarm.toString(); - Alarm alarmValue = Alarm.valueOf(xmlString); - assertThat(alarmValue, equalTo(alarm)); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.java deleted file mode 100644 index bb79c8a..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/config/MQConfigTest.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.common.config; - -import org.junit.Test; -import org.junit.Before; -import org.junit.After; - -public class MQConfigTest { - @Test - public void testNewClass() { - MQConfig mqConfig= new MQConfig(); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java deleted file mode 100644 index 7ec7fe6..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java +++ /dev/null @@ -1,39 +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.common.config; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class MicroServiceConfigTest { - - @Test - public void getMsbServerAddrTest() { - System.setProperty("MSB_ADDR", "test"); - assertThat("http://test", equalTo(MicroServiceConfig.getMsbServerAddr())); - System.clearProperty("MSB_ADDR"); - } - - @Test - public void getServiceIpTest() { - System.setProperty("SERVICE_IP", "test"); - assertThat("test", equalTo(MicroServiceConfig.getServiceIp())); - System.clearProperty("SERVICE_IP"); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.java deleted file mode 100644 index bca63b2..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/exception/CorrelationExceptionTest.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.common.exception; - -import org.junit.Test; -import org.junit.Before; -import org.junit.After; - -public class CorrelationExceptionTest { - @Test - public void testConstructors() throws Exception { - CorrelationException ce1 = new CorrelationException("msg", new Exception()); - CorrelationException ce2 = new CorrelationException("msg"); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java deleted file mode 100644 index 1390b77..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/producer/MQProducerTest.java +++ /dev/null @@ -1,173 +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.common.producer; - -import static org.easymock.EasyMock.anyBoolean; -import static org.easymock.EasyMock.anyInt; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Session; -import javax.jms.Topic; -import org.glassfish.hk2.api.IterableProvider; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openo.holmes.common.api.entity.CorrelationResult; -import org.openo.holmes.common.api.stat.Alarm; -import org.openo.holmes.common.config.MQConfig; -import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.rule.PowerMockRule; -import org.powermock.reflect.Whitebox; - -public class MQProducerTest { - - @Rule - public PowerMockRule powerMockRule = new PowerMockRule(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private IterableProvider mqConfigProvider; - - private ConnectionFactory connectionFactory; - - private MQProducer mqProducer; - - @Before - public void before() throws Exception { - mqProducer = new MQProducer(); - - mqConfigProvider = PowerMock.createMock(IterableProvider.class); - connectionFactory = PowerMock.createMock(ConnectionFactory.class); - - Whitebox.setInternalState(mqProducer, "mqConfigProvider", mqConfigProvider); - Whitebox.setInternalState(mqProducer, "connectionFactory", connectionFactory); - PowerMock.resetAll(); - } - - @Test - public void init() { - MQConfig mqConfig = new MQConfig(); - mqConfig.brokerIp = "127.0.0.1"; - mqConfig.brokerPort = 61616; - mqConfig.brokerPassword = "admin"; - mqConfig.brokerUsername = "admin"; - expect(mqConfigProvider.get()).andReturn(mqConfig).anyTimes(); - - PowerMock.replayAll(); - - mqProducer.init(); - - PowerMock.verifyAll(); - } - - @Test - public void sendAlarmMQTopicMsg() throws Exception { - Alarm alarm = new Alarm(); - Connection connection = PowerMock.createMock(Connection.class); - Session session = PowerMock.createMock(Session.class); - Destination destination = PowerMock.createMock(Topic.class); - MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); - ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); - - expect(connectionFactory.createConnection()).andReturn(connection); - connection.start(); - expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); - expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); - expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); - - expect(session.createObjectMessage(anyObject(Alarm.class))).andReturn(objMessage); - messageProducer.send(objMessage); - session.commit(); - connection.close(); - - PowerMock.replayAll(); - - mqProducer.sendAlarmMQTopicMsg(alarm); - - PowerMock.verifyAll(); - - } - - @Test - public void sendAlarmMQTopicMsg_exception() throws Exception { - thrown.expect(JMSException.class); - Alarm alarm = new Alarm(); - - expect(connectionFactory.createConnection()).andThrow(new JMSException("")); - - PowerMock.replayAll(); - - mqProducer.sendAlarmMQTopicMsg(alarm); - - PowerMock.verifyAll(); - } - - @Test - public void sendCorrelationMQTopicMsg() throws Exception { - - Connection connection = PowerMock.createMock(Connection.class); - Session session = PowerMock.createMock(Session.class); - Destination destination = PowerMock.createMock(Topic.class); - MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); - ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); - - expect(connectionFactory.createConnection()).andReturn(connection); - connection.start(); - expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); - expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); - expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); - - expect(session.createObjectMessage(anyObject(CorrelationResult.class))) - .andReturn(objMessage); - messageProducer.send(objMessage); - session.commit(); - connection.close(); - - PowerMock.replayAll(); - - Alarm parentAlarm = new Alarm(); - Alarm childAlarm = new Alarm(); - mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); - - PowerMock.verifyAll(); - - } - - @Test - public void sendCorrelationMQTopicMsg_exception() throws Exception { - thrown.expect(JMSException.class); - - expect(connectionFactory.createConnection()).andThrow(new JMSException("")); - - PowerMock.replayAll(); - - Alarm parentAlarm = new Alarm(); - Alarm childAlarm = new Alarm(); - mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); - - PowerMock.verifyAll(); - - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java deleted file mode 100644 index 18c774e..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java +++ /dev/null @@ -1,188 +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.common.utils; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import io.dropwizard.db.DataSourceFactory; -import io.dropwizard.jdbi.DBIFactory; -import io.dropwizard.setup.Environment; -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.rule.PowerMockRule; -import org.powermock.reflect.Whitebox; -import org.skife.jdbi.v2.DBI; -import org.skife.jdbi.v2.Handle; - -public class DbDaoUtilTest { - - @Rule - public PowerMockRule powerMockRule = new PowerMockRule(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private DBI jdbi; - - private Environment environmentProvider; - - private DataSourceFactory dataSourceFactoryProvider; - - private DbDaoUtil dbDaoUtil; - - private DBIFactory factory; - - @Before - public void before() throws Exception { - dbDaoUtil = new DbDaoUtil(); - - jdbi = PowerMock.createMock(DBI.class); - environmentProvider = PowerMock.createMock(Environment.class); - dataSourceFactoryProvider = PowerMock.createMock(DataSourceFactory.class); - factory = PowerMock.createMock(DBIFactory.class); - - Whitebox.setInternalState(dbDaoUtil, "environmentProvider", environmentProvider); - Whitebox.setInternalState(dbDaoUtil, "dataSourceFactoryProvider", - dataSourceFactoryProvider); - Whitebox.setInternalState(dbDaoUtil, "factory", factory); - - PowerMock.resetAll(); - } - - @Test - public void init() throws Exception { - DBI jdbi = PowerMock.createMock(DBI.class); - - expect(factory.build(anyObject(Environment.class), anyObject(DataSourceFactory.class), - anyObject(String.class))).andReturn(jdbi); - - PowerMock.replayAll(); - - dbDaoUtil.init(); - - PowerMock.verifyAll(); - } - - @Test - public void getDao_normal() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); - - PowerMock.replayAll(); - - dbDaoUtil.getDao(String.class); - - PowerMock.verifyAll(); - } - - @Test - public void getDao_exception() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - - expect(jdbi.open(anyObject(Class.class))).andThrow(new RuntimeException("")); - - PowerMock.replayAll(); - - Object o = dbDaoUtil.getDao(String.class); - - PowerMock.verifyAll(); - - assertThat(o, equalTo(null)); - } - - @Test - public void getHandle_normal() throws Exception { - Handle handle = PowerMock.createMock(Handle.class); - - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open()).andReturn(handle); - - PowerMock.replayAll(); - - dbDaoUtil.getHandle(); - - PowerMock.verifyAll(); - } - @Test - public void getHandle_exception() throws Exception { - Handle handle = PowerMock.createMock(Handle.class); - - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open()).andThrow(new RuntimeException("")); - - PowerMock.replayAll(); - - Handle handle1 = dbDaoUtil.getHandle(); - - PowerMock.verifyAll(); - - assertThat(handle1, equalTo(null)); - } - - @Test - public void close_normal() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - jdbi.close(anyObject()); - - PowerMock.replayAll(); - - dbDaoUtil.close(new Object()); - - PowerMock.verifyAll(); - } - - @Test - public void close_exception() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - jdbi.close(anyObject()); - EasyMock.expectLastCall().andThrow(new RuntimeException("")); - PowerMock.replayAll(); - - dbDaoUtil.close(new Object()); - - PowerMock.verifyAll(); - } - @Test - public void testGetJdbiDaoByOnDemand() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.onDemand(anyObject(Class.class))).andReturn(Class.class); - - PowerMock.replayAll(); - - dbDaoUtil.getJdbiDaoByOnDemand(String.class); - - PowerMock.verifyAll(); - } - - @Test - public void testGetJdbiDaoByOpen() throws Exception { - Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); - expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); - - PowerMock.replayAll(); - - dbDaoUtil.getJdbiDaoByOpen(String.class); - - PowerMock.verifyAll(); - } -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.java deleted file mode 100644 index caa45e3..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/ExceptionUtilTest.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.common.utils; - -import static org.openo.holmes.common.utils.ExceptionUtil.buildExceptionResponse; - -import org.junit.Test; - -public class ExceptionUtilTest { - - @Test - public void testBuildExceptionResponse() throws Exception { - buildExceptionResponse("test"); - } - - -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java deleted file mode 100644 index c3631ac..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright 2016 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.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Locale; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; - -public class I18nProxyTest { - - private I18nProxy i18nProxy; - - @Before - public void setUp() { - i18nProxy = I18nProxy.getInstance(); - } - - @Test - public void getValue_locale_and_key() { - String result = i18nProxy.getValue(new Locale("zh"), "test"); - assertThat(result, equalTo(null)); - } - @Test - public void getValueByArgs(){ - String result = i18nProxy.getValueByArgs(new Locale("zh"), "test",new String[]{"1"}); - assertThat(result,equalTo(null)); - } - @Test - public void getValue_by_key(){ - Map result = i18nProxy.getValue("test"); - assertThat(result, equalTo(null)); - } - @Test - public void jsonI18n(){ - String result = i18nProxy.jsonI18n("test"); - assertThat(result,equalTo(null)); - } - @Test - public void i18nWithArgs(){ - String result = i18nProxy.i18nWithArgs("test",new String[]{}); - assertThat(result,equalTo("null")); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java deleted file mode 100644 index 22d628e..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JacksonUtilTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2016 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.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import org.junit.Test; -import org.openo.holmes.common.utils.bean.TestBean; - -public class JacksonUtilTest { - - @Test - public void testBeanToJson() throws Exception { - TestBean o = new TestBean(); - o.setId("id"); - String result = JacksonUtil.beanToJson(o); - assertThat("{\"id\":\"id\"}", equalTo(result)); - } - - @Test - public void jsonToBean_json_null() throws Exception { - String jsonNull = null; - TestBean testBean = JacksonUtil.jsonToBean(jsonNull, TestBean.class); - assertThat(testBean.getId(), equalTo(null)); - } - - @Test - public void jsonToBean_json_normal() throws Exception { - String json = "{\"id\":\"id\"}"; - TestBean testBean = JacksonUtil.jsonToBean(json, TestBean.class); - assertThat(testBean.getId(), equalTo("id")); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java deleted file mode 100644 index a2a0542..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2016 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.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.List; -import org.junit.Test; - -public class JudgeNullUtilTest { - - @Test - public void isEmpty_array_length_zero() { - boolean resultShorts = JudgeNullUtil.isEmpty(new short[]{}); - boolean resultInts = JudgeNullUtil.isEmpty(new int[]{}); - boolean resultLongs = JudgeNullUtil.isEmpty(new long[]{}); - boolean resultObjects = JudgeNullUtil.isEmpty(new Object[]{}); - boolean resultStrings = JudgeNullUtil.isEmpty(new String[]{}); - boolean resultLists = JudgeNullUtil.isEmpty(new List[]{}); - assertThat(true, equalTo(resultShorts)); - assertThat(true, equalTo(resultInts)); - assertThat(true, equalTo(resultLongs)); - assertThat(true, equalTo(resultObjects)); - assertThat(true, equalTo(resultStrings)); - assertThat(true, equalTo(resultLists)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java deleted file mode 100644 index d688a35..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/LanguageUtilTest.java +++ /dev/null @@ -1,118 +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.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.Locale; -import javax.servlet.http.HttpServletRequest; -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Test; -import org.openo.holmes.common.constant.AlarmConst; -import org.powermock.api.easymock.PowerMock; - - -public class LanguageUtilTest { - - private HttpServletRequest request; - - @Before - public void setUp() { - request = PowerMock.createMock(HttpServletRequest.class); - } - - @Test - public void getLanguage_header_language_empty() { - EasyMock.expect(request.getHeader("language-option")).andReturn(""); - - PowerMock.replayAll(); - - String language = LanguageUtil.getLanguage(request); - - PowerMock.verifyAll(); - - assertThat(AlarmConst.I18N_EN, equalTo(language)); - } - - @Test - public void getLanguage_zh() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); - - PowerMock.replayAll(); - - String language = LanguageUtil.getLanguage(request); - - PowerMock.verifyAll(); - - assertThat(AlarmConst.I18N_ZH, equalTo(language)); - } - - @Test - public void getLanguage_en() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); - - PowerMock.replayAll(); - - String language = LanguageUtil.getLanguage(request); - - PowerMock.verifyAll(); - - assertThat(AlarmConst.I18N_EN, equalTo(language)); - } - - @Test - public void getLocale_header_language_empty() { - EasyMock.expect(request.getHeader("language-option")).andReturn(""); - - PowerMock.replayAll(); - - Locale locale = LanguageUtil.getLocale(request); - - PowerMock.verifyAll(); - - assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); - } - - @Test - public void getLocale_zh() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_ZH); - - PowerMock.replayAll(); - - Locale locale = LanguageUtil.getLocale(request); - - PowerMock.verifyAll(); - - assertThat(new Locale(AlarmConst.I18N_ZH), equalTo(locale)); - } - - @Test - public void getLocale_en() { - EasyMock.expect(request.getHeader("language-option")).andReturn(AlarmConst.I18N_EN); - - PowerMock.replayAll(); - - Locale locale = LanguageUtil.getLocale(request); - - PowerMock.verifyAll(); - - assertThat(new Locale(AlarmConst.I18N_EN), equalTo(locale)); - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java deleted file mode 100644 index 5d04c1a..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java +++ /dev/null @@ -1,72 +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.common.utils; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; -import javax.ws.rs.QueryParam; -import org.easymock.EasyMock; -import org.junit.Rule; -import org.junit.Test; -import org.openo.holmes.common.api.entity.ServiceRegisterEntity; -import org.openo.holmes.common.config.MicroServiceConfig; -import org.openo.holmes.common.msb.MicroserviceBusRest; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.rule.PowerMockRule; - -@PrepareForTest(ConsumerFactory.class) -public class MSBRegisterUtilTest { - - @Rule - public PowerMockRule powerMockRule = new PowerMockRule(); - private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil(); - private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy(); - - @Test - public void registerTest() throws Exception { - ServiceRegisterEntity entity = initServiceEntity(); - PowerMock.mockStatic(ConsumerFactory.class); - EasyMock.expect(ConsumerFactory - .createConsumer(EasyMock.anyObject(String.class), EasyMock.anyObject(Class.class))) - .andReturn(microserviceBusRest); - PowerMock.replayAll(); - - msbRegisterUtil.register(initServiceEntity()); - - PowerMock.verifyAll(); - } - - 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; - } - - class MicroserviceBusRestProxy implements MicroserviceBusRest { - - @Override - public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate, - ServiceRegisterEntity entity) { - return null; - } - } -} \ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java deleted file mode 100644 index d81c919..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/UserUtilTest.java +++ /dev/null @@ -1,67 +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.common.utils; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -import javax.servlet.http.HttpServletRequest; -import org.easymock.EasyMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; -public class UserUtilTest { - - private HttpServletRequest request; - - @Before - public void before() throws Exception { - request = PowerMock.createMock(HttpServletRequest.class); - } - - @After - public void after() throws Exception { - } - - @Test - public void getUserName_header_name_empty() throws Exception { - EasyMock.expect(request.getHeader("username")).andReturn(null); - - PowerMock.replayAll(); - - String userName = UserUtil.getUserName(request); - - PowerMock.verifyAll(); - - assertThat("admin", equalTo(userName)); - } - - @Test - public void getUserName_normal() throws Exception { - EasyMock.expect(request.getHeader("username")).andReturn("name1"); - - PowerMock.replayAll(); - - String userName = UserUtil.getUserName(request); - - PowerMock.verifyAll(); - - assertThat("name1", equalTo(userName)); - } - -} diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java deleted file mode 100644 index fab78c2..0000000 --- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/bean/TestBean.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2016 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.common.utils.bean; - -import java.io.Serializable; - -public class TestBean implements Serializable { - String id; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index a5c3293..a978c81 100644 --- a/pom.xml +++ b/pom.xml @@ -11,15 +11,16 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.openo.oparent - oparent - 1.1.0-SNAPSHOT - ../oparent + org.onap.oparent + version + 1.0.0-SNAPSHOT + ../../oparent - org.openo.holmes.actions + org.onap.holmes.actions holmes-actions-parent pom + 1.0.0-SNAPSHOT holmes-actions-parent holmes-actions @@ -89,17 +90,6 @@ stringtemplate ${stringtemplate.version} - - - org.openo.common-services.common-utilities - dropwizard-ioc-container - ${project.version} - - - org.openo.common-services.common-utilities - baseservice-i18n - ${project.version} - org.quartz-scheduler quartz -- cgit 1.2.3-korg