2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21 import com.fasterxml.jackson.databind.JsonNode;
22 import com.fasterxml.jackson.databind.ObjectMapper;
23 import java.io.IOException;
24 import java.time.Instant;
25 import java.time.ZoneId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
32 private static final Logger LOG = LoggerFactory.getLogger(DMaaPFaultVESMsgConsumer.class);
34 private static final String DEFAULT_SDNRUSER = "admin";
35 private static final String DEFAULT_SDNRPASSWD = "admin";
37 private final GeneralConfig generalConfig;
39 public DMaaPFaultVESMsgConsumer(GeneralConfig generalConfig) {
40 this.generalConfig = generalConfig;
44 public void processMsg(String msg) throws Exception {
46 String faultOccurrenceTime;
52 String reportingEntityName;
53 ObjectMapper oMapper = new ObjectMapper();
54 JsonNode dmaapMessageRootNode;
56 LOG.info("Fault VES Message is - {}", msg);
58 dmaapMessageRootNode = oMapper.readTree(msg);
59 reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue();
60 if (reportingEntityName.equals("ONAP SDN-R")) {
62 "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message");
66 vesDomain = dmaapMessageRootNode.at("/event/commonEventHeader/domain").textValue();
67 if (!vesDomain.equalsIgnoreCase("fault")) {
68 LOG.warn("Received {} domain VES Message in DMaaP Fault topic, ignoring it", vesDomain);
71 faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
72 faultOccurrenceTime = Instant
74 dmaapMessageRootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000)
75 .atZone(ZoneId.of("Z")).toString();
76 faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue();
77 faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue();
78 faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue();
79 faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue();
81 if (faultSeverity.equalsIgnoreCase("critical")) {
82 faultSeverity = SeverityType.Critical.toString();
83 } else if (faultSeverity.equalsIgnoreCase("major")) {
84 faultSeverity = SeverityType.Major.toString();
85 } else if (faultSeverity.equalsIgnoreCase("minor")) {
86 faultSeverity = SeverityType.Minor.toString();
87 } else if (faultSeverity.equalsIgnoreCase("warning")) {
88 faultSeverity = SeverityType.Warning.toString();
89 } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) {
90 faultSeverity = SeverityType.NonAlarmed.toString();
92 faultSeverity = SeverityType.NonAlarmed.toString();
95 String baseUrl = getBaseUrl();
96 String sdnrUser = getSDNRUser();
97 String sdnrPasswd = getSDNRPasswd();
99 FaultNotificationClient faultClient = getFaultNotificationClient(baseUrl);
100 faultClient.setAuthorization(sdnrUser, sdnrPasswd);
101 faultClient.sendFaultNotification(faultNodeId, Integer.toString(faultSequence), faultOccurrenceTime,
102 faultObjectId, faultReason, faultSeverity);
104 } catch (IOException e) {
105 LOG.info("Cannot parse json object ");
106 throw new Exception("Cannot parse json object", e);
110 public String getBaseUrl() {
111 return generalConfig.getBaseUrl();
114 public String getSDNRUser() {
115 return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
118 public String getSDNRPasswd() {
119 return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
122 public FaultNotificationClient getFaultNotificationClient(String baseUrl) {
123 return new FaultNotificationClient(baseUrl);