2  * ============LICENSE_START========================================================================
 
   3  * ONAP : ccsdk feature sdnr wt
 
   4  * =================================================================================================
 
   5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
 
   6  * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
 
   7  * =================================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 
   9  * in compliance with the License. You may obtain a copy of the License at
 
  11  * http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software distributed under the License
 
  14  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 
  15  * or implied. See the License for the specific language governing permissions and limitations under
 
  17  * ============LICENSE_END==========================================================================
 
  20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
 
  22 import com.fasterxml.jackson.databind.JsonNode;
 
  23 import com.fasterxml.jackson.databind.ObjectMapper;
 
  24 import java.io.IOException;
 
  25 import java.time.Instant;
 
  26 import java.time.ZoneId;
 
  28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
 
  29 import org.slf4j.Logger;
 
  30 import org.slf4j.LoggerFactory;
 
  32 public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
 
  34     private static final Logger LOG = LoggerFactory.getLogger(DMaaPFaultVESMsgConsumer.class);
 
  36     public DMaaPFaultVESMsgConsumer(GeneralConfig generalConfig) {
 
  41     public void processMsg(String msg) throws Exception {
 
  43         String faultOccurrenceTime;
 
  49         String reportingEntityName;
 
  50         ObjectMapper oMapper = new ObjectMapper();
 
  51         JsonNode dmaapMessageRootNode;
 
  53         LOG.info("Fault VES Message is - {}", msg);
 
  55             dmaapMessageRootNode = oMapper.readTree(msg);
 
  56             reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue();
 
  57             if (reportingEntityName.equals("ONAP SDN-R")) {
 
  59                         "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message");
 
  63             vesDomain = dmaapMessageRootNode.at("/event/commonEventHeader/domain").textValue();
 
  64             if (!vesDomain.equalsIgnoreCase("fault")) {
 
  65                 LOG.warn("Received {} domain VES Message in DMaaP Fault topic, ignoring it", vesDomain);
 
  68             faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
 
  69             faultOccurrenceTime = Instant
 
  71                             dmaapMessageRootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000)
 
  72                     .atZone(ZoneId.of("Z")).toString();
 
  73             faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue();
 
  74             faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue();
 
  75             faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue();
 
  76             faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue();
 
  78             if (faultSeverity.equalsIgnoreCase("critical")) {
 
  79                 faultSeverity = SeverityType.Critical.toString();
 
  80             } else if (faultSeverity.equalsIgnoreCase("major")) {
 
  81                 faultSeverity = SeverityType.Major.toString();
 
  82             } else if (faultSeverity.equalsIgnoreCase("minor")) {
 
  83                 faultSeverity = SeverityType.Minor.toString();
 
  84             } else if (faultSeverity.equalsIgnoreCase("warning")) {
 
  85                 faultSeverity = SeverityType.Warning.toString();
 
  86             } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) {
 
  87                 faultSeverity = SeverityType.NonAlarmed.toString();
 
  89                 faultSeverity = SeverityType.NonAlarmed.toString();
 
  92             String baseUrl = getBaseUrl();
 
  93             String sdnrUser = getSDNRUser();
 
  94             String sdnrPasswd = getSDNRPasswd();
 
  96             Map<String, String> payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId,
 
  97                     Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity);
 
  99             FaultNotificationClient faultClient = new FaultNotificationClient(baseUrl);
 
 100             LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
 
 101             faultClient.setAuthorization(sdnrUser, sdnrPasswd);
 
 102             String message = faultClient.prepareMessageFromPayloadMap(payloadMapMessage);
 
 103             faultClient.sendNotification(message);
 
 105         } catch (IOException e) {
 
 106             LOG.info("Cannot parse json object ");
 
 107             throw new Exception("Cannot parse json object", e);