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.NetconfAccessor;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
32 import org.opendaylight.mdsal.common.api.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.equipment.g.ManufacturedThing;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.EquipmentType;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.ManufacturerProperties;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * Contains equipment related information of ONFCore Network Element
48 public class ONFCoreNetworkElement12Equipment {
50 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Equipment.class);
52 private static final UniversalId EQUIPMENTROOT = new UniversalId("network-element");
53 private static final int EQUIPMENTROOTLEVEL = 0;
55 private final NetworkElementCoreData coreData;
56 private final @Nullable OnfInterfacePac equipmentPac;
57 private final NetconfAccessor acessor;
59 private final ValueNameList extensionList;
60 private final @NonNull List<UniversalId> topLevelEqUuidList;
61 private final @NonNull FaultData globalProblemList;
62 private final @NonNull List<ExtendedEquipment> globalEquipmentList;
64 public ONFCoreNetworkElement12Equipment(NetconfAccessor acessor, NetworkElementCoreData coreData) {
65 this(acessor, coreData, false);
68 public ONFCoreNetworkElement12Equipment(NetconfAccessor acessor, NetworkElementCoreData coreData,
70 LOG.debug("Initialize class: {} " + ONFCoreNetworkElement12Equipment.class.getName());
71 this.acessor = acessor;
72 this.coreData = coreData;
75 this.equipmentPac = null;
77 } else if (acessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
78 this.equipmentPac = new WrapperEquipmentPacRev170402(acessor);
79 reason = "WrapperEquipmentPacRev170402.QNAME";
81 this.equipmentPac = null;
82 reason = "unsupported";
84 LOG.debug("Equipement pac initialization '{}'", reason);
86 globalEquipmentList = new ArrayList<>();
88 extensionList = new ValueNameList();
89 topLevelEqUuidList = new ArrayList<>();
90 globalProblemList = new FaultData();
94 public void addProblemsofNode(FaultData resultList) {
95 resultList.addAll(globalProblemList);
98 public FaultData addProblemsofNodeObject(String uuidString) {
99 FaultData res = new FaultData();
101 if (this.equipmentPac != null) {
102 this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
107 public @NonNull InventoryInformationDcae getInventoryInformation(List<String> uuids) {
108 return getInventoryInformationDcae(this.extensionList, uuids);
111 public void readNetworkElementEquipment() {
112 doSyncNetworkElementEquipmentToClassVars();
115 public String getMountpoint() {
116 return coreData.getMountpoint();
119 public OnfInterfacePac getEquipmentPac() {
123 public List<UniversalId> getTopLevelEqUuidList() {
124 return topLevelEqUuidList;
127 public @NonNull EquipmentData getEquipmentData() {
128 EquipmentData res = new EquipmentData();
129 globalEquipmentList.forEach(extEquipment -> res.add(extEquipment.getCreateInventoryInput()));
133 public List<Equipment> getEquipmentAll() {
134 List<Equipment> equipmentListAll = new ArrayList<>();
136 Equipment equipment = readEquipmentAll();
137 equipmentListAll.add(equipment);
139 return equipmentListAll;
142 TransactionUtils getGenericTransactionUtils() {
143 return acessor.getTransactionUtils();
147 * --------------------------------------------------------------------------------- private
151 private void initClassVars() {
152 this.globalProblemList.clear();
153 this.extensionList.clear();
154 this.topLevelEqUuidList.clear();
157 private void doSyncNetworkElementEquipmentToClassVars() {
159 Optional<NetworkElement> optionalNe = coreData.getOptionalNetworkElement();
162 if (optionalNe.isPresent()) {
165 extensionList.put(optionalNe.get().getExtension());
167 if (!extensionList.isEmpty()) {
170 * Loop through network element extension to get "top-level-equipment" <extension>
171 * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
174 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
176 // If top-level-equipment exists get further information
177 if (topLevelEqUuidList.isEmpty()) {
178 LOG.debug("no top level equipment found");
180 // Read equipment and problems
181 for (UniversalId uuid : topLevelEqUuidList) {
182 recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, coreData.getMountpoint(), EQUIPMENTROOTLEVEL,
183 globalProblemList, globalEquipmentList);
187 LOG.debug("extension list is null");
192 private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, String path, int treeLevel,
193 @NonNull FaultData problemList, @NonNull List<ExtendedEquipment> equipmentList) {
197 Equipment equipment = this.readEquipment(uuid);
199 if (equipment != null) {
201 new ExtendedEquipment(this.getMountpoint(), parentUuid.getValue(), equipment, path, treeLevel));
203 if (equipmentPac != null) {
204 equipmentPac.readTheFaults(uuid, problemList);
206 List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
207 if (containedHolderListe != null) {
208 for (ContainedHolder containedHolder : containedHolderListe) {
209 recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid,
210 path + "/" + uuid.getValue(), treeLevel + 1, problemList, equipmentList);
218 private @NonNull InventoryInformationDcae getInventoryInformationDcae(ValueNameList extensions,
219 List<String> uuids) {
221 InventoryInformationDcae inventoryInformation = new InventoryInformationDcae();
224 inventoryInformation.setInterfaceUuidList(uuids);
226 if (!extensions.isEmpty()) {
228 inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
230 // If top-level-equipment exists get further information
231 if (topLevelEqUuidList.isEmpty()) {
232 LOG.debug("no top level equipment found");
234 if (!globalEquipmentList.isEmpty()) {
235 Equipment e = globalEquipmentList.get(0).getEquipment();
237 ManufacturedThing manufacturedThing = e.getManufacturedThing();
238 if (manufacturedThing != null) {
240 if ((et = manufacturedThing.getEquipmentType()) != null) {
241 inventoryInformation.setType(et.getTypeName());
242 inventoryInformation.setModel(et.getModelIdentifier());
244 ManufacturerProperties em;
245 if ((em = manufacturedThing.getManufacturerProperties()) != null) {
246 inventoryInformation.setVendor(em.getManufacturerIdentifier());
253 LOG.debug("extension list is null");
256 LOG.debug("Inventory: {}", inventoryInformation);
257 return inventoryInformation;
263 * Read equipment information
265 * @param interfacePacUuid uuid as key for Equipment.
266 * @return Equipment or null
268 private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
270 final Class<?> clazzPac = Equipment.class;
272 LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
273 coreData.getMountpoint(), interfacePacUuid.getValue());
275 InstanceIdentifier<Equipment> equipmentIID =
276 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
278 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
284 * Read equipment information
286 * @param interfacePacUuid uuid as key for Equipment.
287 * @return Equipment or null
289 private @Nullable Equipment readEquipmentAll() {
291 final Class<?> clazzPac = Equipment.class;
293 LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
294 coreData.getMountpoint());
296 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
298 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
304 * specific toString()
307 public String toString() {
308 return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
309 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
310 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";