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 ObjectMapper oMapper = new ObjectMapper();
53 JsonNode dmaapMessageRootNode;
55 LOG.info("Fault VES Message is - {}", msg);
57 dmaapMessageRootNode = oMapper.readTree(msg);
58 vesDomain = dmaapMessageRootNode.at("/event/commonEventHeader/domain").textValue();
59 if (!vesDomain.equalsIgnoreCase("fault")) {
60 LOG.warn("Received {} domain VES Message in DMaaP Fault topic, ignoring it", vesDomain);
63 faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
64 faultOccurrenceTime = Instant.ofEpochMilli(dmaapMessageRootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue()/1000)
65 .atZone(ZoneId.of("Z")).toString();
66 faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue();
67 faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue();
68 faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue();
69 faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue();
71 if (faultSeverity.equalsIgnoreCase("critical")) {
72 faultSeverity = SeverityType.Critical.toString();
73 } else if (faultSeverity.equalsIgnoreCase("major")) {
74 faultSeverity = SeverityType.Major.toString();
75 } else if (faultSeverity.equalsIgnoreCase("minor")) {
76 faultSeverity = SeverityType.Minor.toString();
77 } else if (faultSeverity.equalsIgnoreCase("warning")) {
78 faultSeverity = SeverityType.Warning.toString();
79 } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) {
80 faultSeverity = SeverityType.NonAlarmed.toString();
82 faultSeverity = SeverityType.NonAlarmed.toString();
85 String baseUrl = getBaseUrl();
86 String sdnrUser = getSDNRUser();
87 String sdnrPasswd = getSDNRPasswd();
89 FaultNotificationClient faultClient = getFaultNotificationClient(baseUrl);
90 faultClient.setAuthorization(sdnrUser, sdnrPasswd);
91 faultClient.sendFaultNotification(faultNodeId, Integer.toString(faultSequence), faultOccurrenceTime,
92 faultObjectId, faultReason, faultSeverity);
94 } catch (IOException e) {
95 LOG.info("Cannot parse json object ");
96 throw new Exception("Cannot parse json object", e);
100 public String getBaseUrl() {
101 return generalConfig.getBaseUrl();
104 public String getSDNRUser() {
105 return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
108 public String getSDNRPasswd() {
109 return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
112 public FaultNotificationClient getFaultNotificationClient(String baseUrl) {
113 return new FaultNotificationClient(baseUrl);