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.binding;
24 import java.time.Instant;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.Map.Entry;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class ORanNotifToVESEventAssembly {
38 private static final Logger log = LoggerFactory.getLogger(ORanNotifToVESEventAssembly.class);
39 private static final String VES_EVENT_DOMAIN = "notification";
40 private static final String VES_EVENTTYPE = "ORAN_notification";
41 private static final String VES_EVENT_PRIORITY = "Normal";
42 private NetconfBindingAccessor netconfAccessor;
43 private VESCollectorService vesProvider;
45 public ORanNotifToVESEventAssembly(NetconfBindingAccessor netconfAccessor, VESCollectorService vesProvider) {
46 this.netconfAccessor = netconfAccessor;
47 this.vesProvider = vesProvider;
50 // VES CommonEventHeader fields
51 public VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName,
53 VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
54 vesCEH.setDomain(VES_EVENT_DOMAIN);
55 vesCEH.setEventName(notificationTypeName);
56 vesCEH.setEventType(VES_EVENTTYPE);
57 vesCEH.setPriority(VES_EVENT_PRIORITY);
61 eventId = notificationTypeName + "-" + Long.toUnsignedString(sequenceNo);
63 vesCEH.setEventId(eventId);
64 vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 1000);
65 vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 1000);
66 vesCEH.setNfVendorName("ORAN");
67 vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
68 vesCEH.setSequence(sequenceNo);
69 vesCEH.setSourceId("ORAN");
70 vesCEH.setSourceName(netconfAccessor.getNodeId().getValue());
74 // Notification fields
75 public VESNotificationFieldsPOJO createVESNotificationFields(HashMap<String, String> xPathFields,
76 String notificationTypeName) {
77 VESNotificationFieldsPOJO vesNotifFields = new VESNotificationFieldsPOJO();
79 vesNotifFields.setChangeType(notificationTypeName);
80 vesNotifFields.setChangeIdentifier(netconfAccessor.getNodeId().getValue());
82 StringBuffer buf = new StringBuffer();
83 Iterator<Entry<String, String>> it = xPathFields.entrySet().iterator();
84 while (it.hasNext()) {
85 Entry<String, String> pair = it.next();
86 buf.append("\n" + pair.getKey() + " = " + pair.getValue());
88 log.info("Resultlist({}):{}", xPathFields.size(), buf.toString());
90 ArrayList<HashMap<String, Object>> arrayOfNamedHashMap = new ArrayList<HashMap<String, Object>>();
91 HashMap<String, Object> namedHashMap = new HashMap<String, Object>();
92 namedHashMap.put("hashMap", xPathFields);
93 namedHashMap.put("name", notificationTypeName);
94 arrayOfNamedHashMap.add(namedHashMap);
95 vesNotifFields.setArrayOfNamedHashMap(arrayOfNamedHashMap);
96 return vesNotifFields;