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.onfcore;
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.NetworkElementCoreData;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.INetconfAcessor;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.container.ExtendedEquipment;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.container.ValueNameList;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.wrapperc.OnfInterfacePac;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.wrapperc.WrapperEquipmentPacRev170402;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.legacy.InventoryInformation;
34 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
35 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
36 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.EquipmentKey;
37 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ContainedHolder;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ManufacturedThing;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.EquipmentType;
42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.ManufacturerProperties;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * Contains equipment related information of ONFCore Network Element
50 public class ONFCoreNetworkElement12Equipment {
52 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Equipment.class);
54 private static final UniversalId EQUIPMENTROOT = new UniversalId("network-element");
55 private static final int EQUIPMENTROOTLEVEL = 0;
57 private final NetworkElementCoreData coreData;
58 private final OnfInterfacePac equipmentPac;
59 private final INetconfAcessor acessor;
61 private final ValueNameList extensionList;
62 private final List<UniversalId> topLevelEqUuidList;
63 private final List<ProblemNotificationXml> globalProblemList;
64 private final List<ExtendedEquipment> globalEquipmentList;
66 public ONFCoreNetworkElement12Equipment(INetconfAcessor acessor, NetworkElementCoreData coreData, Capabilities capabilities) {
67 LOG.debug("Initialize " + ONFCoreNetworkElement12Equipment.class.getName());
68 this.acessor = acessor;
69 this.coreData = coreData;
70 if (capabilities.isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
71 this.equipmentPac = new WrapperEquipmentPacRev170402(acessor, coreData);
72 LOG.debug("Equipement pac supported {}", WrapperEquipmentPacRev170402.QNAME);
74 this.equipmentPac = null;
75 LOG.debug("Equipement pac not supported {}", WrapperEquipmentPacRev170402.QNAME);
78 extensionList = new ValueNameList();
79 topLevelEqUuidList = new ArrayList<>();
80 globalProblemList = new ArrayList<>();
81 globalEquipmentList = new ArrayList<>();
86 public void addProblemsofNode(List<ProblemNotificationXml> resultList) {
87 resultList.addAll(globalProblemList);
90 public List<ProblemNotificationXml> addProblemsofNodeObject(String uuidString) {
91 List<ProblemNotificationXml> res = new ArrayList<>();
93 if (this.equipmentPac != null) {
94 this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
99 public @NonNull InventoryInformation getInventoryInformation(List<String> uuids) {
100 return getInventoryInformation(this.extensionList, uuids);
103 protected void readNetworkElementEquipment() {
104 doSyncNetworkElementEquipmentToClassVars();
107 public String getMountpoint() {
108 return coreData.getMountpoint();
111 public OnfInterfacePac getEquipmentPac() {
115 public List<UniversalId> getTopLevelEqUuidList() {
116 return topLevelEqUuidList;
119 public List<ExtendedEquipment> getEquipmentList() {
120 return globalEquipmentList;
123 public List<Equipment> getEquipmentAll() {
124 List<Equipment> equipmentListAll = new ArrayList<>();
126 Equipment equipment = readEquipmentAll();
127 equipmentListAll.add(equipment);
129 return equipmentListAll;
132 TransactionUtils getGenericTransactionUtils() {
133 return acessor.getTransactionUtils();
137 * --------------------------------------------------------------------------------- private
141 private void initClassVars() {
142 this.globalProblemList.clear();
143 this.globalEquipmentList.clear();
144 this.extensionList.clear();
145 this.topLevelEqUuidList.clear();
148 private void doSyncNetworkElementEquipmentToClassVars() {
150 NetworkElement optionalNe = coreData.getOptionalNetworkElement();
153 if (optionalNe != null) {
155 extensionList.put(optionalNe.getExtension());
157 if (!extensionList.isEmpty()) {
160 * Loop through network element extension to get "top-level-equipment" <extension>
161 * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
164 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
166 // If top-level-equipment exists get further information
167 if (topLevelEqUuidList.isEmpty()) {
168 LOG.debug("no top level equipment found");
170 // Read equipment and problems
171 for (UniversalId uuid : topLevelEqUuidList) {
172 recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, coreData.getMountpoint(), EQUIPMENTROOTLEVEL, globalProblemList,
173 globalEquipmentList);
177 LOG.debug("extension list is null");
182 private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, String path, int treeLevel,
183 List<ProblemNotificationXml> problemList, List<ExtendedEquipment> equipmentList) {
187 Equipment equipment = this.readEquipment(uuid);
189 if (equipment != null) {
190 equipmentList.add(new ExtendedEquipment(this.getMountpoint(),parentUuid.getValue(), equipment, path, treeLevel));
192 if (this.equipmentPac != null) {
193 this.equipmentPac.readTheFaults(uuid, problemList);
195 List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
196 if (containedHolderListe != null) {
197 for (ContainedHolder containedHolder : containedHolderListe) {
198 recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid, path+"/"+uuid.getValue(), treeLevel + 1,
199 problemList, equipmentList);
207 private @NonNull InventoryInformation getInventoryInformation(ValueNameList extensions, List<String> uuids) {
209 InventoryInformation inventoryInformation = new InventoryInformation();
212 inventoryInformation.setInterfaceUuidList(uuids);
214 if (!extensions.isEmpty()) {
216 inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
218 // If top-level-equipment exists get further information
219 if (topLevelEqUuidList.isEmpty()) {
220 LOG.debug("no top level equipment found");
222 if (!globalEquipmentList.isEmpty()) {
223 Equipment e = globalEquipmentList.get(0).getEquipment();
225 ManufacturedThing manufacturedThing = e.getManufacturedThing();
226 if (manufacturedThing != null) {
228 if ((et = manufacturedThing.getEquipmentType()) != null) {
229 inventoryInformation.setType(et.getTypeName());
230 inventoryInformation.setModel(et.getModelIdentifier());
232 ManufacturerProperties em;
233 if ((em = manufacturedThing.getManufacturerProperties()) != null) {
234 inventoryInformation.setVendor(em.getManufacturerIdentifier());
241 LOG.debug("extension list is null");
244 LOG.debug("Inventory: {}", inventoryInformation);
245 return inventoryInformation;
251 * Read equipment information
253 * @param interfacePacUuid uuid as key for Equipment.
254 * @return Equipment or null
256 private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
258 final Class<?> clazzPac = Equipment.class;
260 LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
261 coreData.getMountpoint(), interfacePacUuid.getValue());
263 InstanceIdentifier<Equipment> equipmentIID =
264 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
266 Equipment res = getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
273 * Read equipment information
275 * @param interfacePacUuid uuid as key for Equipment.
276 * @return Equipment or null
278 private @Nullable Equipment readEquipmentAll() {
280 final Class<?> clazzPac = Equipment.class;
282 LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
283 coreData.getMountpoint());
285 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
287 Equipment res = getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
294 * specific toString()
297 public String toString() {
298 return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
299 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
300 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";