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.onf.ifpac.equipment;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Optional;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.NetworkElementCoreData;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.OnfInterfacePac;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.EquipmentData;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.InventoryInformationDcae;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
33 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
34 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
35 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.EquipmentKey;
36 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
37 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ContainedHolder;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ManufacturedThing;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.EquipmentType;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.ManufacturerProperties;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * Contains equipment related information of ONFCore Network Element
49 public class ONFCoreNetworkElement12Equipment {
51 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Equipment.class);
53 private static final UniversalId EQUIPMENTROOT = new UniversalId("network-element");
54 private static final int EQUIPMENTROOTLEVEL = 0;
56 private final NetworkElementCoreData coreData;
57 private final OnfInterfacePac equipmentPac;
58 private final NetconfAccessor acessor;
60 private final ValueNameList extensionList;
61 private final List<UniversalId> topLevelEqUuidList;
62 private final @NonNull FaultData globalProblemList;
63 private final @NonNull List<ExtendedEquipment> globalEquipmentList;
65 public ONFCoreNetworkElement12Equipment(NetconfAccessor acessor, NetworkElementCoreData coreData,
66 Capabilities capabilities) {
67 LOG.debug("Initialize class: {} " + ONFCoreNetworkElement12Equipment.class.getName());
68 this.acessor = acessor;
69 this.coreData = coreData;
70 if (capabilities.isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
71 this.equipmentPac = new WrapperEquipmentPacRev170402(acessor);
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 globalEquipmentList = new ArrayList<>();
81 globalProblemList = new FaultData();
86 public void addProblemsofNode(FaultData resultList) {
87 resultList.addAll(globalProblemList);
90 public FaultData addProblemsofNodeObject(String uuidString) {
91 FaultData res = new FaultData();
93 if (this.equipmentPac != null) {
94 this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
99 public @NonNull InventoryInformationDcae getInventoryInformation(List<String> uuids) {
100 return getInventoryInformationDcae(this.extensionList, uuids);
103 public 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 @NonNull EquipmentData getEquipmentData() {
120 EquipmentData res = new EquipmentData();
121 globalEquipmentList.forEach(extEquipment -> res.add(extEquipment.getCreateInventoryInput()));
125 public List<Equipment> getEquipmentAll() {
126 List<Equipment> equipmentListAll = new ArrayList<>();
128 Equipment equipment = readEquipmentAll();
129 equipmentListAll.add(equipment);
131 return equipmentListAll;
134 TransactionUtils getGenericTransactionUtils() {
135 return acessor.getTransactionUtils();
139 * --------------------------------------------------------------------------------- private
143 private void initClassVars() {
144 this.globalProblemList.clear();
145 this.extensionList.clear();
146 this.topLevelEqUuidList.clear();
149 private void doSyncNetworkElementEquipmentToClassVars() {
151 Optional<NetworkElement> optionalNe = coreData.getOptionalNetworkElement();
154 if (optionalNe.isPresent()) {
157 extensionList.put(optionalNe.get().getExtension());
159 if (!extensionList.isEmpty()) {
162 * Loop through network element extension to get "top-level-equipment" <extension>
163 * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
166 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
168 // If top-level-equipment exists get further information
169 if (topLevelEqUuidList.isEmpty()) {
170 LOG.debug("no top level equipment found");
172 // Read equipment and problems
173 for (UniversalId uuid : topLevelEqUuidList) {
174 recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, coreData.getMountpoint(), EQUIPMENTROOTLEVEL,
175 globalProblemList, globalEquipmentList);
179 LOG.debug("extension list is null");
184 private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, String path, int treeLevel,
185 @NonNull FaultData problemList, @NonNull List<ExtendedEquipment> equipmentList) {
189 Equipment equipment = this.readEquipment(uuid);
191 if (equipment != null) {
193 new ExtendedEquipment(this.getMountpoint(), parentUuid.getValue(), equipment, path, treeLevel));
195 if (this.equipmentPac != null) {
196 this.equipmentPac.readTheFaults(uuid, problemList);
198 List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
199 if (containedHolderListe != null) {
200 for (ContainedHolder containedHolder : containedHolderListe) {
201 recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid,
202 path + "/" + uuid.getValue(), treeLevel + 1, problemList, equipmentList);
210 private @NonNull InventoryInformationDcae getInventoryInformationDcae(ValueNameList extensions,
211 List<String> uuids) {
213 InventoryInformationDcae inventoryInformation = new InventoryInformationDcae();
216 inventoryInformation.setInterfaceUuidList(uuids);
218 if (!extensions.isEmpty()) {
220 inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
222 // If top-level-equipment exists get further information
223 if (topLevelEqUuidList.isEmpty()) {
224 LOG.debug("no top level equipment found");
226 if (!globalEquipmentList.isEmpty()) {
227 Equipment e = globalEquipmentList.get(0).getEquipment();
229 ManufacturedThing manufacturedThing = e.getManufacturedThing();
230 if (manufacturedThing != null) {
232 if ((et = manufacturedThing.getEquipmentType()) != null) {
233 inventoryInformation.setType(et.getTypeName());
234 inventoryInformation.setModel(et.getModelIdentifier());
236 ManufacturerProperties em;
237 if ((em = manufacturedThing.getManufacturerProperties()) != null) {
238 inventoryInformation.setVendor(em.getManufacturerIdentifier());
245 LOG.debug("extension list is null");
248 LOG.debug("Inventory: {}", inventoryInformation);
249 return inventoryInformation;
255 * Read equipment information
257 * @param interfacePacUuid uuid as key for Equipment.
258 * @return Equipment or null
260 private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
262 final Class<?> clazzPac = Equipment.class;
264 LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
265 coreData.getMountpoint(), interfacePacUuid.getValue());
267 InstanceIdentifier<Equipment> equipmentIID =
268 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
270 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
276 * Read equipment information
278 * @param interfacePacUuid uuid as key for Equipment.
279 * @return Equipment or null
281 private @Nullable Equipment readEquipmentAll() {
283 final Class<?> clazzPac = Equipment.class;
285 LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
286 coreData.getMountpoint());
288 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
290 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
296 * specific toString()
299 public String toString() {
300 return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
301 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
302 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";