2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.service;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import java.time.Instant;
27 import java.util.HashMap;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
34 import org.opendaylight.yangtools.yang.binding.Notification;
37 * Interface for mapping ODL notification to VES event fields grouped by event type.
38 * Also includes the commonEventHeader which is applicable for all events.
39 * Ex: fault event, notification event.
41 * No base implementation exists for this interface. Clients that need to map their data into VES formats must implement this interface.
44 public abstract class VESEventMapper<N extends Notification,F extends Notification,T extends Notification> {
47 * Creates VESEvent mapping
49 public abstract String createMapping(NetconfBindingAccessor netconfAccessor,
50 VESCollectorService vesCollectorService, Notification notification, String notifName, int sequenceNo,
54 * Returns VES commonEventHeader fields
56 public abstract VESCommonEventHeaderPOJO mapCommonEventHeader(N notification);
59 * Returns VES faultFields
61 public abstract VESFaultFieldsPOJO mapFaultFields(F notification);
64 * Returns VES Notification Fields
66 public abstract VESNotificationFieldsPOJO mapNotificationFields(T notification);
69 * Returns VES pnfRegistration domain fields
73 public abstract VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields();
76 * Generates VES Event JSON containing commonEventHeader and notificationFields fields
78 * @param commonEventHeader
80 * @return String - representing the VESEvent JSON
82 String generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESNotificationFieldsPOJO notifFields) {
83 Map<String, Object> innerEvent = new HashMap<String, Object>();
84 innerEvent.put("commonEventHeader", commonEventHeader);
85 innerEvent.put("notificationFields", notifFields);
87 Map<String, Object> outerEvent = new HashMap<String, Object>();
88 outerEvent.put("event", innerEvent);
90 ObjectMapper objMapper = new ObjectMapper();
91 return objMapper.writeValueAsString(outerEvent);
92 } catch (JsonProcessingException e) {
99 * Generates VES Event JSON containing commonEventHeader and faultFields fields
101 * @param commonEventHeader
103 * @return String - representing the VES Event JSON
105 String generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESFaultFieldsPOJO faultFields) {
106 Map<String, Object> innerEvent = new HashMap<String, Object>();
107 innerEvent.put("commonEventHeader", commonEventHeader);
108 innerEvent.put("faultFields", faultFields);
110 Map<String, Object> outerEvent = new HashMap<String, Object>();
111 outerEvent.put("event", innerEvent);
113 ObjectMapper objMapper = new ObjectMapper();
114 return objMapper.writeValueAsString(outerEvent);
115 } catch (JsonProcessingException e) {