2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
20 import java.time.Instant;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.Optional;
26 import org.eclipse.jdt.annotation.Nullable;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.HardwareClass;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
31 import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.Alarm.FaultSeverity;
32 import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif;
33 import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
43 import org.opendaylight.yangtools.yang.binding.CodeHelpers;
44 import org.opendaylight.yangtools.yang.common.Uint32;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Convert data to data-provider model and perform consistency checks.<br>
50 * <b>Component list characteristics:</b><br>
52 * <li>component list is a flat list tree structure specified
53 * <li>via "component.getParent()":
55 * <li>If null we have a root element
56 * <li>if not null it is a child element with generated child level<br>
59 * Example of List:<br>
63 public class ORanToInternalDataModel {
65 private static final Logger log = LoggerFactory.getLogger(ORanToInternalDataModel.class);
67 public static List<Inventory> getInventoryList(NodeId nodeId, Collection<Component> componentList) {
69 List<Inventory> inventoryResultList = new ArrayList<Inventory>();
70 for (Component component : getRootComponents(componentList)) {
71 inventoryResultList = recurseGetInventory(nodeId, component, componentList, 0, inventoryResultList);
73 // Verify if result is complete
74 if (componentList.size() != inventoryResultList.size()) {
76 "Not all data were written to the Inventory. Potential entries with missing "
77 + "contained-child. Node Id = {}, Components Found = {}, Entries written to Database = {}",
78 nodeId.getValue(), componentList.size(), inventoryResultList.size());
80 return inventoryResultList;
83 private static List<Inventory> recurseGetInventory(NodeId nodeId, Component component,
84 Collection<Component> componentList, int treeLevel, List<Inventory> inventoryResultList) {
86 //Add element to list, if conversion successfull
87 Optional<Inventory> oInventory = getInternalEquipment(nodeId, component, treeLevel);
88 if (oInventory.isPresent()) {
89 inventoryResultList.add(oInventory.get());
91 //Walk trough list of child keys and add to list
92 for (String childUuid : CodeHelpers.nonnull(component.getContainsChild())) {
93 for (Component c : getComponentsByName(childUuid, componentList)) {
94 inventoryResultList = recurseGetInventory(nodeId, c, componentList, treeLevel + 1, inventoryResultList);
97 return inventoryResultList;
100 public static List<Component> getRootComponents(Collection<Component> componentList) {
101 List<Component> resultList = new ArrayList<>();
102 for (Component c : componentList) {
103 if (c.getParent() == null) { // Root elements do not have a parent
110 private static List<Component> getComponentsByName(String name, Collection<Component> componentList) {
111 List<Component> resultList = new ArrayList<>();
112 for (Component c : componentList) {
113 if (name.equals(c.getName())) { // <-- Component list is flat search for child's of name
121 * Convert equipment into Inventory. Decide if inventory can by created from content or not. Public for test case.
123 * @param nodeId of node (Similar to mountpointId)
124 * @param component to handle
125 * @param treeLevel of components
126 * @return Inventory if possible to be created.
128 public static Optional<Inventory> getInternalEquipment(NodeId nodeId, Component component, int treeLevel) {
130 // Make sure that expected data are not null
131 Objects.requireNonNull(nodeId);
132 Objects.requireNonNull(component);
134 // Read manadatory data
137 String nodeIdString = nodeId.getValue();
139 String uuid = component.getName();
141 String idParent = component.getParent();
143 String uuidParent = idParent != null ? idParent : uuid; //<- Passt nicht
145 // do consistency check if all mandatory parameters are there
146 if (treeLevel >= 0 && nodeIdString != null && uuid != null && uuidParent != null) {
150 InventoryBuilder inventoryBuilder = new InventoryBuilder();
152 // General assumed as mandatory
153 inventoryBuilder.setNodeId(nodeIdString);
154 inventoryBuilder.setUuid(uuid);
155 inventoryBuilder.setParentUuid(uuidParent);
156 inventoryBuilder.setTreeLevel(Uint32.valueOf(treeLevel));
158 // -- String list with ids of holders (optional)
159 inventoryBuilder.setContainedHolder(CodeHelpers.nonnull(component.getContainsChild()));
161 // -- Manufacturer related things (optional)
163 String mfgName = component.getMfgName();
164 inventoryBuilder.setManufacturerName(mfgName);
165 inventoryBuilder.setManufacturerIdentifier(mfgName);
167 // Equipment type (optional)
168 inventoryBuilder.setDescription(component.getDescription());
169 inventoryBuilder.setModelIdentifier(component.getModelName());
171 Class<? extends HardwareClass> xmlClass = component.getXmlClass();
172 if (xmlClass != null) {
173 inventoryBuilder.setPartTypeId(xmlClass.getName());
175 inventoryBuilder.setTypeName(component.getName());
176 inventoryBuilder.setVersion(component.getHardwareRev());
178 // Equipment instance (optional)
180 DateAndTime mfgDate = component.getMfgDate();
181 if (mfgDate != null) {
182 inventoryBuilder.setDate(mfgDate.getValue());
184 inventoryBuilder.setSerial(component.getSerialNum());
186 return Optional.of(inventoryBuilder.build());
188 return Optional.empty();
192 * If system data is available convert
197 public static Optional<Guicutthrough> getGuicutthrough(@Nullable System1 sys) {
199 String name = sys.getName();
201 Uri uri = sys.getWebUi();
203 GuicutthroughBuilder gcBuilder = new GuicutthroughBuilder();
205 gcBuilder.setName(name);
207 gcBuilder.setWeburi(uri.getValue());
208 return Optional.of(gcBuilder.build());
210 log.warn("Uri not set to invoke a Gui cut through session to the device. Please set the Uri in the device");
212 log.warn("Retrieving augmented System details failed. Gui cut through information not available");
213 return Optional.empty();
217 * Convert netconf time into Instant
219 * @param eventTime with netconf time
220 * @return Instant with converted time. If not convertable provide Instant.Min
222 public static Instant getInstantTime(@Nullable DateAndTime eventTime) {
223 return eventTime != null ? Instant.parse(eventTime.getValue()) : Instant.MIN;
227 * Convert fault notification into data-provider FaultLogEntity
229 * @param notification with O-RAN notification
230 * @param nodeId of node to handle
231 * @param counter to be integrated into data
232 * @return FaultlogEntity with data
234 public static FaultlogEntity getFaultLog(AlarmNotif notification, NodeId nodeId, Integer counter) {
235 FaultlogBuilder faultAlarm = new FaultlogBuilder();
236 faultAlarm.setNodeId(nodeId.getValue());
237 faultAlarm.setObjectId(notification.getFaultSource());
238 faultAlarm.setProblem(notification.getFaultText());
239 faultAlarm.setSeverity(getSeverityType(notification.getFaultSeverity(), notification.getIsCleared()));
240 faultAlarm.setCounter(counter);
241 faultAlarm.setId(String.valueOf(notification.getFaultId()));
242 faultAlarm.setSourceType(SourceType.Netconf);
243 faultAlarm.setTimestamp(notification.getEventTime());
244 return faultAlarm.build();
248 * Convert O-RAN specific severity into data-provider severity
250 * @param faultSeverity O-RAN severity
251 * @param isCleared clear indicator
252 * @return data-provider severity type
253 * @throws IllegalArgumentException if conversion not possible.
255 public static SeverityType getSeverityType(@Nullable FaultSeverity faultSeverity, @Nullable Boolean isCleared)
256 throws IllegalArgumentException {
257 if (isCleared != null && isCleared) {
258 return SeverityType.NonAlarmed;
260 if (faultSeverity != null) {
261 switch (faultSeverity) {
263 return SeverityType.Critical;
265 return SeverityType.Major;
267 return SeverityType.Minor;
269 return SeverityType.Warning;
272 throw new IllegalArgumentException("Unknown Alarm state represent as Critical. isCleared=" + isCleared
273 + " faultSeverity=" + faultSeverity);