App mountpoint-registrar
[ccsdk/features.git] / sdnr / wt / mountpoint-registrar / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / mountpointregistrar / impl / DMaaPFaultVESMsgConsumer.java
1 /*******************************************************************************
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import com.fasterxml.jackson.databind.JsonNode;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26
27 import java.io.IOException;
28
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
30
31 public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
32
33         private static final Logger LOG = LoggerFactory.getLogger(DMaaPFaultVESMsgConsumer.class);
34         
35         //private static int faultCounter = 0;
36         private static final String DEFAULT_SDNRUSER = "admin";
37         private static final String DEFAULT_SDNRPASSWD = "admin";
38
39         @Override
40         public void processMsg(String msg) throws Exception {
41                 String faultNodeId;
42                 String faultOccurrenceTime;
43                 String faultObjectId;
44                 String faultReason;
45                 String faultSeverity;
46                 int faultSequence;
47                 ObjectMapper oMapper = new ObjectMapper();
48                 JsonNode dmaapMessageRootNode;
49
50                 LOG.info("Fault VES Message is - {}", msg);
51                 try {
52                         dmaapMessageRootNode = oMapper.readTree(msg);
53                         faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
54                         faultOccurrenceTime =  dmaapMessageRootNode.at("/event/faultFields/alarmAdditionalInformation/eventTime").textValue();
55                         faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue();
56                         faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue();
57                         faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue();
58                         faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue();
59                         //faultCounter++;
60
61                         if (faultSeverity.equalsIgnoreCase("critical")) {
62                                 faultSeverity = SeverityType.Critical.toString();
63                         } else if (faultSeverity.equalsIgnoreCase("major")) {
64                                 faultSeverity = SeverityType.Major.toString();
65                         } else if (faultSeverity.equalsIgnoreCase("minor")) {
66                                 faultSeverity = SeverityType.Minor.toString();
67                         } else if (faultSeverity.equalsIgnoreCase("warning")) {
68                                 faultSeverity = SeverityType.Warning.toString();
69                         } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) {
70                                 faultSeverity = SeverityType.NonAlarmed.toString();
71                         } else {
72                                 faultSeverity = SeverityType.NonAlarmed.toString();
73                         }
74
75                         String baseUrl = getBaseUrl();
76                         String sdnrUser = getSDNRUser();
77                         String sdnrPasswd = getSDNRPasswd();
78
79                         FaultNotificationClient faultClient = getFaultNotificationClient(baseUrl);
80                         faultClient.setAuthorization(sdnrUser, sdnrPasswd);
81                         faultClient.sendFaultNotification(faultNodeId, Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity);
82
83                 } catch (IOException e) {
84                         LOG.info("Cannot parse json object ");
85                         throw new Exception("Cannot parse json object", e);
86                 }
87         }
88
89         public String getBaseUrl() {
90                 return GeneralConfig.getBaseUrl();
91         }
92         
93         public String getSDNRUser() {
94                 return GeneralConfig.getSDNRUser()!= null?GeneralConfig.getSDNRUser():DEFAULT_SDNRUSER;
95         }
96         
97         public String getSDNRPasswd() {
98                 return GeneralConfig.getSDNRPasswd()!= null?GeneralConfig.getSDNRPasswd():DEFAULT_SDNRPASSWD;
99         }
100         
101         public FaultNotificationClient getFaultNotificationClient(String baseUrl) {
102                 return new FaultNotificationClient(baseUrl);
103         }
104 }