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.Collection;
22 import java.util.List;
23 import java.util.Optional;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.NetworkElementCoreData;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.OnfInterfacePac;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.EquipmentData;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.InventoryInformationDcae;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
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 @Nullable OnfInterfacePac equipmentPac;
59 private final NetconfAccessor acessor;
61 private final ValueNameList extensionList;
62 private final @NonNull List<UniversalId> topLevelEqUuidList;
63 private final @NonNull FaultData globalProblemList;
64 private final @NonNull List<ExtendedEquipment> globalEquipmentList;
66 public ONFCoreNetworkElement12Equipment(NetconfAccessor acessor, NetworkElementCoreData coreData) {
67 this(acessor, coreData, false);
70 public ONFCoreNetworkElement12Equipment(NetconfAccessor acessor, NetworkElementCoreData coreData,
72 LOG.debug("Initialize class: {} " + ONFCoreNetworkElement12Equipment.class.getName());
73 this.acessor = acessor;
74 this.coreData = coreData;
77 this.equipmentPac = null;
79 } else if (acessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
80 this.equipmentPac = new WrapperEquipmentPacRev170402(acessor);
81 reason = "WrapperEquipmentPacRev170402.QNAME";
83 this.equipmentPac = null;
84 reason = "unsupported";
86 LOG.debug("Equipement pac initialization '{}'", reason);
88 globalEquipmentList = new ArrayList<>();
90 extensionList = new ValueNameList();
91 topLevelEqUuidList = new ArrayList<>();
92 globalProblemList = new FaultData();
96 public void addProblemsofNode(FaultData resultList) {
97 resultList.addAll(globalProblemList);
100 public FaultData addProblemsofNodeObject(String uuidString) {
101 FaultData res = new FaultData();
103 if (this.equipmentPac != null) {
104 this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
109 public @NonNull InventoryInformationDcae getInventoryInformation(List<String> uuids) {
110 return getInventoryInformationDcae(this.extensionList, uuids);
113 public void readNetworkElementEquipment() {
114 doSyncNetworkElementEquipmentToClassVars();
117 public String getMountpoint() {
118 return coreData.getMountpoint();
121 public OnfInterfacePac getEquipmentPac() {
125 public List<UniversalId> getTopLevelEqUuidList() {
126 return topLevelEqUuidList;
129 public @NonNull EquipmentData getEquipmentData() {
130 EquipmentData res = new EquipmentData();
131 globalEquipmentList.forEach(extEquipment -> res.add(extEquipment.getCreateInventoryInput()));
135 public List<Equipment> getEquipmentAll() {
136 List<Equipment> equipmentListAll = new ArrayList<>();
138 Equipment equipment = readEquipmentAll();
139 equipmentListAll.add(equipment);
141 return equipmentListAll;
144 TransactionUtils getGenericTransactionUtils() {
145 return acessor.getTransactionUtils();
149 * --------------------------------------------------------------------------------- private
153 private void initClassVars() {
154 this.globalProblemList.clear();
155 this.extensionList.clear();
156 this.topLevelEqUuidList.clear();
159 private void doSyncNetworkElementEquipmentToClassVars() {
161 Optional<NetworkElement> optionalNe = coreData.getOptionalNetworkElement();
164 if (optionalNe.isPresent()) {
167 extensionList.put(YangHelper.getList(optionalNe.get().getExtension()));
169 if (!extensionList.isEmpty()) {
172 * Loop through network element extension to get "top-level-equipment" <extension>
173 * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
176 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
178 // If top-level-equipment exists get further information
179 if (topLevelEqUuidList.isEmpty()) {
180 LOG.debug("no top level equipment found");
182 // Read equipment and problems
183 for (UniversalId uuid : topLevelEqUuidList) {
184 recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, coreData.getMountpoint(), EQUIPMENTROOTLEVEL,
185 globalProblemList, globalEquipmentList);
189 LOG.debug("extension list is null");
194 private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, String path, int treeLevel,
195 @NonNull FaultData problemList, @NonNull List<ExtendedEquipment> equipmentList) {
199 Equipment equipment = this.readEquipment(uuid);
201 if (equipment != null) {
203 new ExtendedEquipment(this.getMountpoint(), parentUuid.getValue(), equipment, path, treeLevel));
205 if (equipmentPac != null) {
206 equipmentPac.readTheFaults(uuid, problemList);
208 Collection<ContainedHolder> containedHolderListe = YangHelper.getCollection(equipment.getContainedHolder());
209 if (containedHolderListe != null) {
210 for (ContainedHolder containedHolder : containedHolderListe) {
211 recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid,
212 path + "/" + uuid.getValue(), treeLevel + 1, problemList, equipmentList);
220 private @NonNull InventoryInformationDcae getInventoryInformationDcae(ValueNameList extensions,
221 List<String> uuids) {
223 InventoryInformationDcae inventoryInformation = new InventoryInformationDcae();
226 inventoryInformation.setInterfaceUuidList(uuids);
228 if (!extensions.isEmpty()) {
230 inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
232 // If top-level-equipment exists get further information
233 if (topLevelEqUuidList.isEmpty()) {
234 LOG.debug("no top level equipment found");
236 if (!globalEquipmentList.isEmpty()) {
237 Equipment e = globalEquipmentList.get(0).getEquipment();
239 ManufacturedThing manufacturedThing = e.getManufacturedThing();
240 if (manufacturedThing != null) {
242 if ((et = manufacturedThing.getEquipmentType()) != null) {
243 inventoryInformation.setType(et.getTypeName());
244 inventoryInformation.setModel(et.getModelIdentifier());
246 ManufacturerProperties em;
247 if ((em = manufacturedThing.getManufacturerProperties()) != null) {
248 inventoryInformation.setVendor(em.getManufacturerIdentifier());
255 LOG.debug("extension list is null");
258 LOG.debug("Inventory: {}", inventoryInformation);
259 return inventoryInformation;
265 * Read equipment information
267 * @param interfacePacUuid uuid as key for Equipment.
268 * @return Equipment or null
270 private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
272 final Class<?> clazzPac = Equipment.class;
274 LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
275 coreData.getMountpoint(), interfacePacUuid.getValue());
277 InstanceIdentifier<Equipment> equipmentIID =
278 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
280 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
286 * Read equipment information
288 * @param interfacePacUuid uuid as key for Equipment.
289 * @return Equipment or null
291 private @Nullable Equipment readEquipmentAll() {
293 final Class<?> clazzPac = Equipment.class;
295 LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
296 coreData.getMountpoint());
298 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
300 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
306 * specific toString()
309 public String toString() {
310 return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
311 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
312 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";