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;
54 private final ONFCOreNetworkElementCoreData coreData;
55 private final OnfInterfacePac equipmentPac;
57 private final ValueNameList extensionList;
58 private final List<UniversalId> topLevelEqUuidList;
59 private final List<ProblemNotificationXml> globalProblemList;
60 private final List<ExtendedEquipment> globalEquipmentList;
62 public ONFCoreNetworkElement12Equipment(ONFCOreNetworkElementCoreData coreData, Capabilities capabilities) {
63 LOG.debug("Initialize " + ONFCoreNetworkElement12Equipment.class.getName());
64 this.coreData = coreData;
65 if (capabilities.isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
66 this.equipmentPac = new WrapperEquipmentPacRev170402(coreData);
67 LOG.debug("Equipement pac supported {}", WrapperEquipmentPacRev170402.QNAME);
69 this.equipmentPac = null;
70 LOG.debug("Equipement pac not supported {}", WrapperEquipmentPacRev170402.QNAME);
73 extensionList = new ValueNameList();
74 topLevelEqUuidList = new ArrayList<>();
75 globalProblemList = new ArrayList<>();
76 globalEquipmentList = new ArrayList<>();
81 public void addProblemsofNode(List<ProblemNotificationXml> resultList) {
82 resultList.addAll(globalProblemList);
85 public List<ProblemNotificationXml> addProblemsofNodeObject(String uuidString) {
86 List<ProblemNotificationXml> res = new ArrayList<>();
88 if (this.equipmentPac != null) {
89 this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
94 public @Nonnull InventoryInformation getInventoryInformation(List<String> uuids) {
95 return getInventoryInformation(this.extensionList, uuids);
98 protected void readNetworkElementEquipment() {
99 doSyncNetworkElementEquipmentToClassVars();
102 public String getMountpoint() {
103 return coreData.getMountpoint();
106 public OnfInterfacePac getEquipmentPac() {
110 public List<UniversalId> getTopLevelEqUuidList() {
111 return topLevelEqUuidList;
114 public List<ExtendedEquipment> getEquipmentList() {
115 return globalEquipmentList;
118 public List<Equipment> getEquipmentAll() {
119 List<Equipment> equipmentListAll = new ArrayList<>();
121 Equipment equipment = readEquipmentAll();
122 equipmentListAll.add(equipment);
124 return equipmentListAll;
129 * --------------------------------------------------------------------------------- private
133 private void initClassVars() {
134 this.globalProblemList.clear();
135 this.globalEquipmentList.clear();
136 this.extensionList.clear();
137 this.topLevelEqUuidList.clear();
140 private void doSyncNetworkElementEquipmentToClassVars() {
142 NetworkElement optionalNe = coreData.getOptionalNetworkElement();
145 if (optionalNe != null) {
147 extensionList.put(optionalNe.getExtension());
149 if (!extensionList.isEmpty()) {
152 * Loop through network element extension to get "top-level-equipment" <extension>
153 * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
156 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
158 // If top-level-equipment exists get further information
159 if (topLevelEqUuidList.isEmpty()) {
160 LOG.debug("no top level equipment found");
162 // Read equipment and problems
163 for (UniversalId uuid : topLevelEqUuidList) {
164 recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, EQUIPMENTROOTLEVEL, globalProblemList,
165 globalEquipmentList);
169 LOG.debug("extension list is null");
174 private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, int treeLevel,
175 List<ProblemNotificationXml> problemList, List<ExtendedEquipment> equipmentList) {
179 Equipment equipment = this.readEquipment(uuid);
181 if (equipment != null) {
182 equipmentList.add(new ExtendedEquipment(parentUuid.getValue(), equipment, treeLevel));
184 if (this.equipmentPac != null) {
185 this.equipmentPac.readTheFaults(uuid, problemList);
187 List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
188 if (containedHolderListe != null) {
189 for (ContainedHolder containedHolder : containedHolderListe) {
190 recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid, treeLevel + 1,
191 problemList, equipmentList);
199 private @Nonnull InventoryInformation getInventoryInformation(ValueNameList extensions, List<String> uuids) {
201 InventoryInformation inventoryInformation = new InventoryInformation();
204 inventoryInformation.setInterfaceUuidList(uuids);
206 if (!extensions.isEmpty()) {
208 inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
210 // If top-level-equipment exists get further information
211 if (topLevelEqUuidList.isEmpty()) {
212 LOG.debug("no top level equipment found");
215 if (!globalEquipmentList.isEmpty()) {
216 Equipment e = globalEquipmentList.get(0).getEquipment();
217 if (e.getManufacturedThing() != null) {
219 if ((et = e.getManufacturedThing().getEquipmentType()) != null) {
220 inventoryInformation.setType(et.getTypeName());
221 inventoryInformation.setModel(et.getModelIdentifier());
223 ManufacturerProperties em;
224 if ((em = e.getManufacturedThing().getManufacturerProperties()) != null) {
225 inventoryInformation.setVendor(em.getManufacturerIdentifier());
231 LOG.debug("extension list is null");
234 LOG.debug("Inventory: {}", inventoryInformation);
235 return inventoryInformation;
241 * Read equipment information
243 * @param interfacePacUuid uuid as key for Equipment.
244 * @return Equipment or null
246 private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
248 final Class<?> clazzPac = Equipment.class;
250 LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
251 coreData.getMountpoint(), interfacePacUuid.getValue());
253 InstanceIdentifier<Equipment> equipmentIID =
254 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
256 Equipment res = GenericTransactionUtils.readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
263 * Read equipment information
265 * @param interfacePacUuid uuid as key for Equipment.
266 * @return Equipment or null
268 private @Nullable Equipment readEquipmentAll() {
270 final Class<?> clazzPac = Equipment.class;
272 LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
273 coreData.getMountpoint());
275 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
277 Equipment res = GenericTransactionUtils.readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
284 * specific toString()
287 public String toString() {
288 return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
289 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
290 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";