aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-onap/onf14/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/impl/interfaces/Onf14AirInterfaceNotificationListener.java
blob: 1f3f30927b2098b573bbe3286b28241de263839b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * ============LICENSE_START=======================================================
 * ONAP : ccsdk feature sdnr wt
 * ================================================================================
 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
 * All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 *
 */
package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.AirInterface20Listener;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.AttributeValueChangedNotification;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectCreationNotification;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectDeletionNotification;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ProblemNotification;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPE;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPECRITICAL;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEMAJOR;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEMINOR;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPENONALARMED;
import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEWARNING;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Onf14AirInterfaceNotificationListener implements AirInterface20Listener, DOMNotificationListener {

    private static final Logger log = LoggerFactory.getLogger(Onf14AirInterfaceNotificationListener.class);

    private final NetconfAccessor netconfAccessor;
    private final DeviceManagerServiceProvider serviceProvider;

    private static final Map<Class<? extends SEVERITYTYPE>,SeverityType> severityMap = initSeverityMap();

    public Onf14AirInterfaceNotificationListener(NetconfAccessor netconfAccessor,
            DeviceManagerServiceProvider serviceProvider) {
        this.netconfAccessor = netconfAccessor;
        this.serviceProvider = serviceProvider;
    }

    private static Map<Class<? extends SEVERITYTYPE>, SeverityType> initSeverityMap() {
        Map<Class<? extends SEVERITYTYPE>, SeverityType> map = new HashMap<>();
        map.put(SEVERITYTYPECRITICAL.class,SeverityType.Critical);
        map.put(SEVERITYTYPEMAJOR.class,SeverityType.Major);
        map.put(SEVERITYTYPEMINOR.class,SeverityType.Minor);
        map.put(SEVERITYTYPEWARNING.class,SeverityType.Warning);
        map.put(SEVERITYTYPENONALARMED.class,SeverityType.NonAlarmed);
        return map;
    }

    @Override
    public void onObjectDeletionNotification(ObjectDeletionNotification notification) {
        log.debug("Got event of type :: {}", ObjectDeletionNotification.class.getSimpleName());

        EventlogBuilder eventlogBuilder = new EventlogBuilder();
        eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue()).setAttributeName("")
                .setCounter(notification.getCounter()).setNewValue("deleted")
                .setObjectId(notification.getObjectIdRef().getValue()).setSourceType(SourceType.Netconf)
                .setTimestamp(notification.getTimestamp());
        serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
        serviceProvider.getWebsocketService().sendNotification(notification, netconfAccessor.getNodeId(),
                ObjectDeletionNotification.QNAME, notification.getTimestamp());

        log.debug("onObjectDeletionNotification log entry written");
    }

    @Override
    public void onProblemNotification(ProblemNotification notification) {
        log.debug("Got event of type :: {}", ProblemNotification.class.getSimpleName());
        FaultlogEntity faultAlarm = new FaultlogBuilder().setObjectId(notification.getObjectIdRef().getValue())
                .setProblem(notification.getProblem()).setSourceType(SourceType.Netconf)
                .setTimestamp(notification.getTimestamp())
                .setNodeId(this.netconfAccessor.getNodeId().getValue())
                .setSeverity(mapSeverity(notification.getSeverity())).setCounter(notification.getCounter())
                .build();
        serviceProvider.getFaultService().faultNotification(faultAlarm);
        serviceProvider.getWebsocketService().sendNotification(notification, netconfAccessor.getNodeId(),
                ProblemNotification.QNAME, notification.getTimestamp());

    }

    private SeverityType mapSeverity(@Nullable Class<? extends SEVERITYTYPE> severity) {
        return severityMap.getOrDefault(severity,SeverityType.NonAlarmed);
    }

    @Override
    public void onAttributeValueChangedNotification(AttributeValueChangedNotification notification) {
        log.debug("Got event of type :: {}", AttributeValueChangedNotification.class.getSimpleName());

        EventlogBuilder eventlogBuilder = new EventlogBuilder();
        eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue())
                .setAttributeName(notification.getAttributeName()).setCounter(notification.getCounter())
                .setNewValue(notification.getNewValue()).setObjectId(notification.getObjectIdRef().getValue())
                .setSourceType(SourceType.Netconf).setTimestamp(notification.getTimestamp());
        serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
        serviceProvider.getWebsocketService().sendNotification(notification, netconfAccessor.getNodeId(),
                AttributeValueChangedNotification.QNAME, notification.getTimestamp());
        log.debug("onAttributeValueChangedNotification log entry written");
    }

    @Override
    public void onObjectCreationNotification(ObjectCreationNotification notification) {
        log.debug("Got event of type :: {}", ObjectCreationNotification.class.getSimpleName());

        EventlogBuilder eventlogBuilder = new EventlogBuilder();
        eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue()).setAttributeName(notification.getObjectType())
                .setCounter(notification.getCounter()).setNewValue("created")
                .setObjectId(notification.getObjectIdRef().getValue()).setSourceType(SourceType.Netconf)
                .setTimestamp(notification.getTimestamp());
        serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
        serviceProvider.getWebsocketService().sendNotification(notification, netconfAccessor.getNodeId(),
                ObjectCreationNotification.QNAME, notification.getTimestamp());
        log.debug("onObjectCreationNotification log entry written");
    }

    @Override
    public void onNotification(@NonNull DOMNotification notification) {

    }

}