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.oran.impl;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import java.time.Instant;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.Map.Entry;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.VESCommonEventHeaderPOJO;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.VESEvent;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.VESNotificationFieldsPOJO;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
36 import org.opendaylight.yangtools.yang.binding.DataObject;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class ORanNotifToVESEventAssembly {
42 private static final Logger log = LoggerFactory.getLogger(ORanNotifToVESEventAssembly.class);
43 private static final String VES_EVENT_DOMAIN = "notification";
44 private static final String VES_EVENTTYPE = "ORAN_notification";
45 private static final String VES_EVENT_PRIORITY = "Normal";
46 private NetconfAccessor netconfAccessor;
47 private VESCollectorService vesProvider;
49 public ORanNotifToVESEventAssembly(NetconfAccessor netconfAccessor, VESCollectorService vesProvider) {
50 this.netconfAccessor = netconfAccessor;
51 this.vesProvider = vesProvider;
54 public String performAssembly(HashMap<String, String> xPathFieldsMap, Instant instant, String notificationTypeName,
56 VESEvent data = assembleVESEventMsg(xPathFieldsMap, instant, notificationTypeName, sequenceNo);
57 return createVESEventJSON(data);
60 public VESEvent assembleVESEventMsg(HashMap<String, String> xPathFieldsMap, Instant instant,
61 String notificationTypeName, long sequenceNo) {
62 VESCommonEventHeaderPOJO vesCEH = createVESCommonEventHeader(instant, notificationTypeName, sequenceNo);
63 VESNotificationFieldsPOJO vesNotifFields = createVESNotificationFields(xPathFieldsMap, notificationTypeName);
65 VESEvent vesEvent = new VESEvent();
66 vesEvent.addEventObjects(vesCEH);
67 vesEvent.addEventObjects(vesNotifFields);
72 public String createVESEventJSON(VESEvent vesEvent) {
73 String oranVESMsg = "";
75 ObjectMapper objMapper = new ObjectMapper();
76 oranVESMsg = objMapper.writeValueAsString(vesEvent);
77 } catch (JsonProcessingException e) {
80 log.debug("VES Message generated from ORAN Netconf Notification is - {}", oranVESMsg);
84 // VES CommonEventHeader fields
85 private VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName,
87 VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
88 vesCEH.setDomain(VES_EVENT_DOMAIN);
89 vesCEH.setEventName(notificationTypeName);
90 vesCEH.setEventType(VES_EVENTTYPE);
91 vesCEH.setPriority(VES_EVENT_PRIORITY);
95 eventId = notificationTypeName + "-" + Long.toUnsignedString(sequenceNo);
97 vesCEH.setEventId(eventId);
98 vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 100);
99 vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 100);
100 vesCEH.setNfVendorName("ORAN");
101 vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
102 vesCEH.setSequence(sequenceNo);
103 vesCEH.setSourceId("ORAN");
104 vesCEH.setSourceName(netconfAccessor.getNodeId().getValue());
108 // Notification fields
109 private VESNotificationFieldsPOJO createVESNotificationFields(HashMap<String, String> xPathFields,
110 String notificationTypeName) {
111 VESNotificationFieldsPOJO vesNotifFields = new VESNotificationFieldsPOJO();
113 vesNotifFields.setChangeType(notificationTypeName);
114 vesNotifFields.setChangeIdentifier(netconfAccessor.getNodeId().getValue());
116 StringBuffer buf = new StringBuffer();
117 Iterator<Entry<String, String>> it = xPathFields.entrySet().iterator();
118 while (it.hasNext()) {
119 Entry<String, String> pair = it.next();
120 buf.append("\n" + pair.getKey() + " = " + pair.getValue());
122 log.info("Resultlist({}):{}", xPathFields.size(), buf.toString());
124 ArrayList<HashMap<String, Object>> arrayOfNamedHashMap = new ArrayList<HashMap<String, Object>>();
125 HashMap<String, Object> namedHashMap = new HashMap<String, Object>();
126 namedHashMap.put("hashMap", xPathFields);
127 namedHashMap.put("name", notificationTypeName);
128 arrayOfNamedHashMap.add(namedHashMap);
129 vesNotifFields.setArrayOfNamedHashMap(arrayOfNamedHashMap);
130 return vesNotifFields;