2  * ============LICENSE_START========================================================================
 
   3  * ONAP : ccsdk feature sdnr wt mountpoint-registrar
 
   4  * =================================================================================================
 
   5  * Copyright (C) 2022 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.vesdomain.stnddefined;
 
  21 import com.fasterxml.jackson.core.JsonProcessingException;
 
  22 import com.fasterxml.jackson.databind.JsonNode;
 
  23 import java.time.Instant;
 
  24 import java.time.ZoneId;
 
  26 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig;
 
  27 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException;
 
  28 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.StrimziKafkaVESMsgConsumerImpl;
 
  29 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault.FaultNotificationClient;
 
  30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
 
  31 import org.slf4j.Logger;
 
  32 import org.slf4j.LoggerFactory;
 
  34 public class StrimziKafkaStndDefinedFaultVESMsgConsumer extends StrimziKafkaVESMsgConsumerImpl {
 
  36     private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaStndDefinedFaultVESMsgConsumer.class);
 
  37     Map<String, String> payloadMapMessage = null;
 
  39     String notificationType;
 
  41     public StrimziKafkaStndDefinedFaultVESMsgConsumer(GeneralConfig generalConfig) {
 
  43         LOG.info("StrimziKafkaStndDefinedFaultVESMsgConsumer started successfully");
 
  47      * Supports processing of notifyNewAlarm and notifyClearedAlarm messages ONLY
 
  50     public void processMsg(String msg) throws InvalidMessageException, JsonProcessingException {
 
  51         LOG.debug("Processing StndDefined Fault message {}", msg);
 
  52         JsonNode rootNode = convertMessageToJsonNode(msg);
 
  55             faultNodeId = rootNode.at("/event/commonEventHeader/sourceName").textValue();
 
  56             notificationType = rootNode.at("/event/stndDefinedFields/data/notificationType").textValue();
 
  58             if (notificationType.equalsIgnoreCase("notifyNewAlarm")) {
 
  59                 LOG.info("Read stndDefined Fault message of type - {} with id {} from Kafka topic", notificationType,
 
  61                 processNewAlarm(rootNode);
 
  62             } else if (notificationType.equalsIgnoreCase("notifyClearedAlarm")) {
 
  63                 LOG.info("Read stdnDefined Fault message of type - {} with id {} from Kafka topic", notificationType,
 
  65                 processClearedAlarm(rootNode);
 
  68                         "Read stdnDefined Fault message of type - {} with id {} from Kafka topic. No suitable implementation for processing this message",
 
  69                         notificationType, faultNodeId);
 
  70                 throw new InvalidMessageException();
 
  72             // Send Fault Notification
 
  73             String baseUrl = getBaseUrl();
 
  74             String sdnrUser = getSDNRUser();
 
  75             String sdnrPasswd = getSDNRPasswd();
 
  77             FaultNotificationClient faultClient = new FaultNotificationClient(baseUrl);
 
  78             LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
 
  79             faultClient.setAuthorization(sdnrUser, sdnrPasswd);
 
  80             String message = faultClient.prepareMessageFromPayloadMap(payloadMapMessage);
 
  81             faultClient.sendNotification(message);
 
  82         } catch (NullPointerException e) {
 
  83             LOG.warn("Message is invalid, sending aborted, processing stopped because one of fields is missing");
 
  84             throw new InvalidMessageException("Missing field");
 
  89     private void processClearedAlarm(JsonNode rootNode) {
 
  90         String faultOccurrenceTime =
 
  91                 Instant.ofEpochMilli(rootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000)
 
  92                         .atZone(ZoneId.of("Z")).toString();
 
  93         int faultSequence = rootNode.at("/event/commonEventHeader/sequence").intValue();
 
  94         String faultObjectId = rootNode.at("/event/stndDefinedFields/data/alarmId").textValue();
 
  95         String faultReason = rootNode.at("/event/stndDefinedFields/data/probableCause").textValue();
 
  96         String faultSeverity = SeverityType.NonAlarmed.toString();
 
  98         payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId,
 
  99                 Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity);
 
 103     private void processNewAlarm(JsonNode rootNode) {
 
 104         String faultOccurrenceTime =
 
 105                 Instant.ofEpochMilli(rootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000)
 
 106                         .atZone(ZoneId.of("Z")).toString();
 
 107         int faultSequence = rootNode.at("/event/commonEventHeader/sequence").intValue();
 
 108         String faultObjectId = rootNode.at("/event/stndDefinedFields/data/alarmId").textValue();
 
 109         String faultReason = rootNode.at("/event/stndDefinedFields/data/probableCause").textValue();
 
 110         String faultSeverity =
 
 111                 getSDNRSeverityType(rootNode.at("/event/stndDefinedFields/data/perceivedSeverity").textValue());
 
 113         payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId,
 
 114                 Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity);
 
 119      * 3GPP Definition PerceivedSeverity: type: string enum: - INDETERMINATE -
 
 120      * CRITICAL - MAJOR - MINOR - WARNING - CLEARED
 
 123     private String getSDNRSeverityType(String faultSeverity) {
 
 124         if (faultSeverity.equalsIgnoreCase("critical")) {
 
 125             faultSeverity = SeverityType.Critical.toString();
 
 126         } else if (faultSeverity.equalsIgnoreCase("major")) {
 
 127             faultSeverity = SeverityType.Major.toString();
 
 128         } else if (faultSeverity.equalsIgnoreCase("minor")) {
 
 129             faultSeverity = SeverityType.Minor.toString();
 
 130         } else if (faultSeverity.equalsIgnoreCase("warning") || faultSeverity.equalsIgnoreCase("indeterminate")) {
 
 131             faultSeverity = SeverityType.Warning.toString();
 
 132         } else if (faultSeverity.equalsIgnoreCase("cleared")) {
 
 133             faultSeverity = SeverityType.NonAlarmed.toString();
 
 135             faultSeverity = SeverityType.NonAlarmed.toString();
 
 137         return faultSeverity;