2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 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.dom;
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 java.util.Objects;
30 import org.eclipse.jdt.annotation.NonNull;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public class ORanDOMNotifToVESEventAssembly {
40 private static final Logger log = LoggerFactory.getLogger(ORanDOMNotifToVESEventAssembly.class);
41 private static final String VES_EVENT_DOMAIN = "notification";
42 private static final String VES_EVENTTYPE = "ORAN_notification";
43 private static final String VES_EVENT_PRIORITY = "Normal";
44 private NetconfDomAccessor netconfDomAccessor;
45 private VESCollectorService vesProvider;
47 public ORanDOMNotifToVESEventAssembly(@NonNull NetconfDomAccessor netconfDomAccessor,
48 @NonNull VESCollectorService vesCollectorService) {
49 this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor);
50 this.vesProvider = Objects.requireNonNull(vesCollectorService);
53 // VES CommonEventHeader fields
54 public VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName,
56 VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO();
57 vesCEH.setDomain(VES_EVENT_DOMAIN);
58 vesCEH.setEventName(notificationTypeName);
59 vesCEH.setEventType(VES_EVENTTYPE);
60 vesCEH.setPriority(VES_EVENT_PRIORITY);
64 eventId = notificationTypeName + "-" + Long.toUnsignedString(sequenceNo);
66 vesCEH.setEventId(eventId);
67 vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 1000);
68 vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 1000);
69 vesCEH.setNfVendorName("ORAN");
70 vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName());
71 vesCEH.setSequence(sequenceNo);
72 vesCEH.setSourceId("ORAN");
73 vesCEH.setSourceName(netconfDomAccessor.getNodeId().getValue());
77 // Notification fields
78 public VESNotificationFieldsPOJO createVESNotificationFields(HashMap<String, String> xPathFields,
79 String notificationTypeName) {
80 VESNotificationFieldsPOJO vesNotifFields = new VESNotificationFieldsPOJO();
82 vesNotifFields.setChangeType(notificationTypeName);
83 vesNotifFields.setChangeIdentifier(netconfDomAccessor.getNodeId().getValue());
85 StringBuffer buf = new StringBuffer();
86 Iterator<Entry<String, String>> it = xPathFields.entrySet().iterator();
87 while (it.hasNext()) {
88 Entry<String, String> pair = it.next();
89 buf.append("\n" + pair.getKey() + " = " + pair.getValue());
91 log.info("Resultlist({}):{}", xPathFields.size(), buf.toString());
93 ArrayList<HashMap<String, Object>> arrayOfNamedHashMap = new ArrayList<HashMap<String, Object>>();
94 HashMap<String, Object> namedHashMap = new HashMap<String, Object>();
95 namedHashMap.put("hashMap", xPathFields);
96 namedHashMap.put("name", notificationTypeName);
97 arrayOfNamedHashMap.add(namedHashMap);
98 vesNotifFields.setArrayOfNamedHashMap(arrayOfNamedHashMap);
99 return vesNotifFields;