1 /*******************************************************************************
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==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf;
20 import java.util.ArrayList;
21 import java.util.List;
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InventoryInformation;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.ValueNameList;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.OnfInterfacePac;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperEquipmentPacRev170402;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types.equipment.ExtendedEquipment;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
32 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
33 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
34 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.EquipmentKey;
35 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
36 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
37 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ContainedHolder;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.EquipmentType;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.ManufacturerProperties;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
45 * Contains equipment related information of ONFCore Network Element
47 public class ONFCoreNetworkElement12Equipment {
49 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Equipment.class);
51 private static final UniversalId EQUIPMENTROOT = new UniversalId("network-element");
52 private static final int EQUIPMENTROOTLEVEL = 0;
53 private static final OnfInterfacePac EMPTYEQUIPMENTPAC = (interfacePacUuid, resultList) -> { return(resultList); };
55 private final ONFCoreNetworkElementCoreData coreData;
56 private final OnfInterfacePac equipmentPac;
58 private final ValueNameList extensionList;
59 private final List<UniversalId> topLevelEqUuidList;
60 private final List<ProblemNotificationXml> globalProblemList;
61 private final List<ExtendedEquipment> globalEquipmentList;
63 public ONFCoreNetworkElement12Equipment(ONFCoreNetworkElementCoreData coreData, Capabilities capabilities) {
64 LOG.debug("Initialize " + ONFCoreNetworkElement12Equipment.class.getName());
65 this.coreData = coreData;
66 if (capabilities.isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
67 this.equipmentPac = new WrapperEquipmentPacRev170402(coreData);
68 LOG.debug("Equipment pac supported {}", WrapperEquipmentPacRev170402.QNAME);
70 this.equipmentPac = EMPTYEQUIPMENTPAC;
71 LOG.debug("Equipment pac not supported {}", WrapperEquipmentPacRev170402.QNAME);
74 extensionList = new ValueNameList();
75 topLevelEqUuidList = new ArrayList<>();
76 globalProblemList = new ArrayList<>();
77 globalEquipmentList = new ArrayList<>();
82 public void addProblemsofNode(List<ProblemNotificationXml> resultList) {
83 resultList.addAll(globalProblemList);
86 public List<ProblemNotificationXml> addProblemsofNodeObject(String uuidString) {
87 List<ProblemNotificationXml> res = new ArrayList<>();
89 if (this.equipmentPac != null) {
90 this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
95 public @Nonnull InventoryInformation getInventoryInformation(List<String> uuids) {
96 return getInventoryInformation(this.extensionList, uuids);
99 protected void readNetworkElementEquipment() {
100 doSyncNetworkElementEquipmentToClassVars();
103 public String getMountpoint() {
104 return coreData.getMountpoint();
107 public OnfInterfacePac getEquipmentPac() {
111 public List<UniversalId> getTopLevelEqUuidList() {
112 return topLevelEqUuidList;
115 public List<ExtendedEquipment> getEquipmentList() {
116 return globalEquipmentList;
119 public List<Equipment> getEquipmentAll() {
120 List<Equipment> equipmentListAll = new ArrayList<>();
122 Equipment equipment = readEquipmentAll();
123 equipmentListAll.add(equipment);
125 return equipmentListAll;
130 * --------------------------------------------------------------------------------- private
134 private void initClassVars() {
135 this.globalProblemList.clear();
136 this.globalEquipmentList.clear();
137 this.extensionList.clear();
138 this.topLevelEqUuidList.clear();
141 private void doSyncNetworkElementEquipmentToClassVars() {
143 NetworkElement optionalNe = coreData.getOptionalNetworkElement();
146 if (optionalNe != null) {
148 extensionList.put(optionalNe.getExtension());
150 if (!extensionList.isEmpty()) {
153 * Loop through network element extension to get "top-level-equipment" <extension>
154 * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
157 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
159 // If top-level-equipment exists get further information
160 if (topLevelEqUuidList.isEmpty()) {
161 LOG.debug("no top level equipment found");
163 // Read equipment and problems
164 for (UniversalId uuid : topLevelEqUuidList) {
165 recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, EQUIPMENTROOTLEVEL, globalProblemList,
166 globalEquipmentList);
170 LOG.debug("extension list is null");
175 private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, int treeLevel,
176 List<ProblemNotificationXml> problemList, List<ExtendedEquipment> equipmentList) {
180 Equipment equipment = this.readEquipment(uuid);
182 if (equipment != null) {
183 equipmentList.add(new ExtendedEquipment(parentUuid.getValue(), equipment, treeLevel));
185 this.equipmentPac.readTheFaults(uuid, problemList);
186 List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
187 if (containedHolderListe != null) {
188 for (ContainedHolder containedHolder : containedHolderListe) {
189 recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid, treeLevel + 1,
190 problemList, equipmentList);
197 private @Nonnull InventoryInformation getInventoryInformation(ValueNameList extensions, List<String> uuids) {
199 InventoryInformation inventoryInformation = new InventoryInformation();
202 inventoryInformation.setInterfaceUuidList(uuids);
204 if (!extensions.isEmpty()) {
206 inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
208 // If top-level-equipment exists get further information
209 if (topLevelEqUuidList.isEmpty()) {
210 LOG.debug("no top level equipment found");
213 if (!globalEquipmentList.isEmpty()) {
214 Equipment e = globalEquipmentList.get(0).getEquipment();
215 if (e.getManufacturedThing() != null) {
217 if ((et = e.getManufacturedThing().getEquipmentType()) != null) {
218 inventoryInformation.setType(et.getTypeName());
219 inventoryInformation.setModel(et.getModelIdentifier());
221 ManufacturerProperties em;
222 if ((em = e.getManufacturedThing().getManufacturerProperties()) != null) {
223 inventoryInformation.setVendor(em.getManufacturerIdentifier());
229 LOG.debug("extension list is null");
232 LOG.debug("Inventory: {}", inventoryInformation);
233 return inventoryInformation;
239 * Read equipment information
241 * @param interfacePacUuid uuid as key for Equipment.
242 * @return Equipment or null
244 private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
246 final Class<?> clazzPac = Equipment.class;
248 LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
249 coreData.getMountpoint(), interfacePacUuid.getValue());
251 InstanceIdentifier<Equipment> equipmentIID =
252 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
254 Equipment res = GenericTransactionUtils.readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
261 * Read equipment information
263 * @param interfacePacUuid uuid as key for Equipment.
264 * @return Equipment or null
266 private @Nullable Equipment readEquipmentAll() {
268 final Class<?> clazzPac = Equipment.class;
270 LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
271 coreData.getMountpoint());
273 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
275 Equipment res = GenericTransactionUtils.readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
282 * specific toString()
285 public String toString() {
286 return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
287 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
288 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";