2 * Copyright © 2020 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.nbinotifications.utils;
10 import java.io.IOException;
11 import java.io.InputStream;
13 import java.util.Properties;
14 import java.util.function.Function;
15 import java.util.stream.Collectors;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiServiceBuilder;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishTapiNotificationService;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.AdditionalInfo;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.AdditionalInfoBuilder;
21 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.AdditionalInfoKey;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.ChangedAttributes;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.ChangedAttributesBuilder;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.ChangedAttributesKey;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.TargetObjectName;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.TargetObjectNameBuilder;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.tapi.service.TargetObjectNameKey;
28 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name;
29 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameKey;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public final class NbiNotificationsUtils {
35 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsUtils.class);
37 private NbiNotificationsUtils() {
40 public static Properties loadProperties(String propertyFileName) {
41 Properties props = new Properties();
42 InputStream inputStream = NbiNotificationsUtils.class.getClassLoader().getResourceAsStream(propertyFileName);
44 if (inputStream != null) {
45 props.load(inputStream);
47 LOG.warn("Kafka property file '{}' is empty", propertyFileName);
49 } catch (IOException e) {
50 LOG.error("Kafka property file '{}' was not found in the classpath", propertyFileName, e);
55 public static NotificationTapiService transformTapiNotification(PublishTapiNotificationService notification) {
56 Map<AdditionalInfoKey, AdditionalInfo> addInfoMap = notification.nonnullAdditionalInfo().values().stream()
57 .collect(Collectors.toMap(
58 e -> new AdditionalInfoKey(e.getValueName()),
59 e -> new AdditionalInfoBuilder(e).build()));
60 Map<ChangedAttributesKey, ChangedAttributes> changedAttMap = notification.nonnullChangedAttributes().values()
61 .stream().collect(Collectors.toMap(
62 e -> new ChangedAttributesKey(e.getValueName()),
63 e -> new ChangedAttributesBuilder(e).build()));
64 Map<NameKey, Name> nameMap = notification.nonnullName().values().stream()
65 .collect(Collectors.toMap(Name::key, Function.identity()));
66 Map<TargetObjectNameKey, TargetObjectName> targetObjNameMap = notification.nonnullTargetObjectName().values()
67 .stream().collect(Collectors.toMap(
68 e -> new TargetObjectNameKey(e.getValueName()),
69 e -> new TargetObjectNameBuilder(e).build()));
70 LOG.info("Notification uuid = {}", notification.getUuid());
72 return new NotificationTapiServiceBuilder()
73 .setAlarmInfo(notification.getAlarmInfo())
74 .setAdditionalText(notification.getAdditionalText())
75 .setAdditionalInfo(addInfoMap)
76 .setNotificationType(notification.getNotificationType())
77 .setChangedAttributes(changedAttMap)
78 .setEventTimeStamp(notification.getEventTimeStamp())
79 .setLayerProtocolName(notification.getLayerProtocolName())
81 .setSequenceNumber(notification.getSequenceNumber())
82 .setSourceIndicator(notification.getSourceIndicator())
83 .setTargetObjectIdentifier(notification.getTargetObjectIdentifier())
84 .setTargetObjectName(targetObjNameMap)
85 .setTargetObjectType(notification.getTargetObjectType())
86 .setTcaInfo(notification.getTcaInfo())
87 .setUuid(notification.getUuid())