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.NetconfBindingAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
35 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
36 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
37 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.EquipmentKey;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ContainedHolder;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ManufacturedThing;
42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.EquipmentType;
43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.ManufacturerProperties;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Contains equipment related information of ONFCore Network Element
51 public class ONFCoreNetworkElement12Equipment {
53 private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Equipment.class);
55 private static final UniversalId EQUIPMENTROOT = new UniversalId("network-element");
56 private static final int EQUIPMENTROOTLEVEL = 0;
58 private final NetworkElementCoreData coreData;
59 private final @Nullable OnfInterfacePac equipmentPac;
60 private final NetconfBindingAccessor acessor;
62 private final ValueNameList extensionList;
63 private final @NonNull List<UniversalId> topLevelEqUuidList;
64 private final @NonNull FaultData globalProblemList;
65 private final @NonNull List<ExtendedEquipment> globalEquipmentList;
67 public ONFCoreNetworkElement12Equipment(NetconfBindingAccessor acessor, NetworkElementCoreData coreData) {
68 this(acessor, coreData, false);
71 public ONFCoreNetworkElement12Equipment(NetconfBindingAccessor acessor, NetworkElementCoreData coreData,
73 LOG.debug("Initialize class: {} " + ONFCoreNetworkElement12Equipment.class.getName());
74 this.acessor = acessor;
75 this.coreData = coreData;
78 this.equipmentPac = null;
80 } else if (acessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
81 this.equipmentPac = new WrapperEquipmentPacRev170402(acessor);
82 reason = "WrapperEquipmentPacRev170402.QNAME";
84 this.equipmentPac = null;
85 reason = "unsupported";
87 LOG.debug("Equipement pac initialization '{}'", reason);
89 globalEquipmentList = new ArrayList<>();
91 extensionList = new ValueNameList();
92 topLevelEqUuidList = new ArrayList<>();
93 globalProblemList = new FaultData();
97 public void addProblemsofNode(FaultData resultList) {
98 resultList.addAll(globalProblemList);
101 public FaultData addProblemsofNodeObject(String uuidString) {
102 FaultData res = new FaultData();
104 if (this.equipmentPac != null) {
105 this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
110 public @NonNull InventoryInformationDcae getInventoryInformation(List<String> uuids) {
111 return getInventoryInformationDcae(this.extensionList, uuids);
114 public void readNetworkElementEquipment() {
115 doSyncNetworkElementEquipmentToClassVars();
118 public String getMountpoint() {
119 return coreData.getMountpoint();
122 public OnfInterfacePac getEquipmentPac() {
126 public List<UniversalId> getTopLevelEqUuidList() {
127 return topLevelEqUuidList;
130 public @NonNull EquipmentData getEquipmentData() {
131 EquipmentData res = new EquipmentData();
132 globalEquipmentList.forEach(extEquipment -> res.add(extEquipment.getCreateInventoryInput()));
136 public List<Equipment> getEquipmentAll() {
137 List<Equipment> equipmentListAll = new ArrayList<>();
139 Equipment equipment = readEquipmentAll();
140 equipmentListAll.add(equipment);
142 return equipmentListAll;
145 TransactionUtils getGenericTransactionUtils() {
146 return acessor.getTransactionUtils();
150 * --------------------------------------------------------------------------------- private
154 private void initClassVars() {
155 this.globalProblemList.clear();
156 this.extensionList.clear();
157 this.topLevelEqUuidList.clear();
160 private void doSyncNetworkElementEquipmentToClassVars() {
162 Optional<NetworkElement> optionalNe = coreData.getOptionalNetworkElement();
165 if (optionalNe.isPresent()) {
168 extensionList.put(YangHelper.getList(optionalNe.get().getExtension()));
170 if (!extensionList.isEmpty()) {
173 * Loop through network element extension to get "top-level-equipment" <extension>
174 * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
177 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
179 // If top-level-equipment exists get further information
180 if (topLevelEqUuidList.isEmpty()) {
181 LOG.debug("no top level equipment found");
183 // Read equipment and problems
184 for (UniversalId uuid : topLevelEqUuidList) {
185 recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, coreData.getMountpoint(), EQUIPMENTROOTLEVEL,
186 globalProblemList, globalEquipmentList);
190 LOG.debug("extension list is null");
195 private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, String path, int treeLevel,
196 @NonNull FaultData problemList, @NonNull List<ExtendedEquipment> equipmentList) {
200 Equipment equipment = this.readEquipment(uuid);
202 if (equipment != null) {
204 new ExtendedEquipment(this.getMountpoint(), parentUuid.getValue(), equipment, path, treeLevel));
206 if (equipmentPac != null) {
207 equipmentPac.readTheFaults(uuid, problemList);
209 Collection<ContainedHolder> containedHolderListe = YangHelper.getCollection(equipment.getContainedHolder());
210 if (containedHolderListe != null) {
211 for (ContainedHolder containedHolder : containedHolderListe) {
212 recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid,
213 path + "/" + uuid.getValue(), treeLevel + 1, problemList, equipmentList);
221 private @NonNull InventoryInformationDcae getInventoryInformationDcae(ValueNameList extensions,
222 List<String> uuids) {
224 InventoryInformationDcae inventoryInformation = new InventoryInformationDcae();
227 inventoryInformation.setInterfaceUuidList(uuids);
229 if (!extensions.isEmpty()) {
231 inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
233 // If top-level-equipment exists get further information
234 if (topLevelEqUuidList.isEmpty()) {
235 LOG.debug("no top level equipment found");
237 if (!globalEquipmentList.isEmpty()) {
238 Equipment e = globalEquipmentList.get(0).getEquipment();
240 ManufacturedThing manufacturedThing = e.getManufacturedThing();
241 if (manufacturedThing != null) {
243 if ((et = manufacturedThing.getEquipmentType()) != null) {
244 inventoryInformation.setType(et.getTypeName());
245 inventoryInformation.setModel(et.getModelIdentifier());
247 ManufacturerProperties em;
248 if ((em = manufacturedThing.getManufacturerProperties()) != null) {
249 inventoryInformation.setVendor(em.getManufacturerIdentifier());
256 LOG.debug("extension list is null");
259 LOG.debug("Inventory: {}", inventoryInformation);
260 return inventoryInformation;
266 * Read equipment information
268 * @param interfacePacUuid uuid as key for Equipment.
269 * @return Equipment or null
271 private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
273 final Class<?> clazzPac = Equipment.class;
275 LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
276 coreData.getMountpoint(), interfacePacUuid.getValue());
278 InstanceIdentifier<Equipment> equipmentIID =
279 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
281 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
287 * Read equipment information
289 * @param interfacePacUuid uuid as key for Equipment.
290 * @return Equipment or null
292 private @Nullable Equipment readEquipmentAll() {
294 final Class<?> clazzPac = Equipment.class;
296 LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
297 coreData.getMountpoint());
299 InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
301 return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
307 * specific toString()
310 public String toString() {
311 return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
312 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
313 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";