aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-onap/onf14/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/dom/notifications/Onf14DomEthernetContainerNotificationListener.java
blob: 3f2b95e938a59f6effdf8d787d6765e06f58c3d8 (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
147
148
149
150
151
package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.notifications;

import org.eclipse.jdt.annotation.NonNull;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.dataprovider.InternalDataModelSeverity;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DevicemanagerQNames;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
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.SourceType;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Onf14DomEthernetContainerNotificationListener implements DOMNotificationListener {

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

    private final NetconfDomAccessor netconfDomAccessor;
    private final DeviceManagerServiceProvider serviceProvider;

    public Onf14DomEthernetContainerNotificationListener(NetconfDomAccessor netconfDomAccessor,
            DeviceManagerServiceProvider serviceProvider) {
        this.netconfDomAccessor = netconfDomAccessor;
        this.serviceProvider = serviceProvider;
    }

    @Override
    public void onNotification(@NonNull DOMNotification domNotification) {
        log.debug("Got event of type :: {}", domNotification.getType());
        if (domNotification.getType()
                .equals(Absolute.of(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION))) {
            onObjectCreationNotification(domNotification);
        } else if (domNotification.getType()
                .equals(Absolute.of(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION))) {
            onAttributeValueChangedNotification(domNotification);
        } else if (domNotification.getType()
                .equals(Absolute.of(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION))) {
            onProblemNotification(domNotification);
        } else if (domNotification.getType()
                .equals(Absolute.of(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION))) {
            onObjectDeletionNotification(domNotification);
        }
    }

    public void onObjectDeletionNotification(DOMNotification notification) {

        ContainerNode cn = notification.getBody();
        EventlogBuilder eventlogBuilder = new EventlogBuilder();
        eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue()).setAttributeName("")
                .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_COUNTER)))
                .setNewValue("deleted")
                .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_OBJECT_ID_REF))

                .setSourceType(SourceType.Netconf).setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_TIMESTAMP)));
        serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
        serviceProvider.getNotificationService().deletionNotification(netconfDomAccessor.getNodeId(),
                Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_COUNTER)),
                new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_TIMESTAMP)),
                Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_OBJECT_ID_REF));

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

    public void onProblemNotification(DOMNotification notification) {

        ContainerNode cn = notification.getBody();
        FaultlogEntity faultAlarm = new FaultlogBuilder()
                .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_OBJECT_ID_REF))
                .setProblem(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_PROBLEM))
                .setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_TIMESTAMP)))
                .setNodeId(this.netconfDomAccessor.getNodeId().getValue()).setSourceType(SourceType.Netconf)
                .setSeverity(InternalDataModelSeverity.mapSeverity(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_SEVERITY)))
                .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_COUNTER)))
                .build();
        serviceProvider.getFaultService().faultNotification(faultAlarm);
        serviceProvider.getWebsocketService()
                .sendNotification(notification, netconfDomAccessor.getNodeId(),
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_OBJECT_ID_REF,
                        new DateAndTime(cn.childByArg(new NodeIdentifier(
                                Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_TIMESTAMP))
                                .body().toString()));
        log.debug("onProblemNotification log entry written");
    }

    public void onAttributeValueChangedNotification(DOMNotification notification) {

        ContainerNode cn = notification.getBody();
        EventlogBuilder eventlogBuilder = new EventlogBuilder();
        eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue())
                .setAttributeName(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_ATTRIBUTE_NAME))
                .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_COUNTER)))
                .setNewValue(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_NEW_VALUE))
                .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_OBJECT_ID_REF))
                .setSourceType(SourceType.Netconf).setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_TIMESTAMP)));
        serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
        serviceProvider.getWebsocketService().sendNotification(notification, netconfDomAccessor.getNodeId(),
                Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION,
                new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_TIMESTAMP)));

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

    public void onObjectCreationNotification(DOMNotification notification) {

        ContainerNode cn = notification.getBody();
        EventlogBuilder eventlogBuilder = new EventlogBuilder();
        eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue())
                .setAttributeName(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_OBJECT_ID_REF))
                .setCounter(Integer.parseInt(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_COUNTER)))
                .setNewValue("created")
                .setObjectId(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_OBJECT_ID_REF))

                .setSourceType(SourceType.Netconf).setTimestamp(new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_TIMESTAMP)));
        serviceProvider.getDataProvider().writeEventLog(eventlogBuilder.build());
        serviceProvider.getWebsocketService().sendNotification(notification, netconfDomAccessor.getNodeId(),
                Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION,
                new DateAndTime(Onf14DMDOMUtility.getLeafValue(cn,
                        Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_TIMESTAMP)));

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