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 --- .../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 -- 57 files changed, 2157 insertions(+), 1475 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 (limited to 'holmes-actions/src/main') 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; - } -} -- cgit 1.2.3-korg