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, Capabilities capabilities) {
 
  66         LOG.debug("Initialize class: {} " + ONFCoreNetworkElement12Equipment.class.getName());
 
  67         this.acessor = acessor;
 
  68         this.coreData = coreData;
 
  69         if (capabilities.isSupportingNamespaceAndRevision(WrapperEquipmentPacRev170402.QNAME)) {
 
  70             this.equipmentPac = new WrapperEquipmentPacRev170402(acessor);
 
  71             LOG.debug("Equipement pac supported {}", WrapperEquipmentPacRev170402.QNAME);
 
  73             this.equipmentPac = null;
 
  74             LOG.debug("Equipement pac not supported {}", WrapperEquipmentPacRev170402.QNAME);
 
  77         extensionList = new ValueNameList();
 
  78         topLevelEqUuidList = new ArrayList<>();
 
  79         globalEquipmentList = new ArrayList<>();
 
  80         globalProblemList = new FaultData();
 
  85     public void addProblemsofNode(FaultData resultList) {
 
  86         resultList.addAll(globalProblemList);
 
  89     public FaultData addProblemsofNodeObject(String uuidString) {
 
  90         FaultData res = new FaultData();
 
  92         if (this.equipmentPac != null) {
 
  93             this.equipmentPac.readTheFaults(new UniversalId(uuidString), res);
 
  98     public @NonNull InventoryInformationDcae getInventoryInformation(List<String> uuids) {
 
  99         return getInventoryInformationDcae(this.extensionList, uuids);
 
 102     public void readNetworkElementEquipment() {
 
 103         doSyncNetworkElementEquipmentToClassVars();
 
 106     public String getMountpoint() {
 
 107         return coreData.getMountpoint();
 
 110     public OnfInterfacePac getEquipmentPac() {
 
 114     public List<UniversalId> getTopLevelEqUuidList() {
 
 115         return topLevelEqUuidList;
 
 118     public @NonNull EquipmentData getEquipmentData() {
 
 119         EquipmentData res = new EquipmentData();
 
 120         globalEquipmentList.forEach(extEquipment -> res.add(extEquipment.getCreateInventoryInput()));
 
 124     public List<Equipment> getEquipmentAll() {
 
 125         List<Equipment> equipmentListAll = new ArrayList<>();
 
 127         Equipment equipment = readEquipmentAll();
 
 128         equipmentListAll.add(equipment);
 
 130         return equipmentListAll;
 
 133     TransactionUtils getGenericTransactionUtils() {
 
 134         return acessor.getTransactionUtils();
 
 138      * --------------------------------------------------------------------------------- private
 
 142     private void initClassVars() {
 
 143         this.globalProblemList.clear();
 
 144         this.extensionList.clear();
 
 145         this.topLevelEqUuidList.clear();
 
 148     private void doSyncNetworkElementEquipmentToClassVars() {
 
 150         Optional<NetworkElement> optionalNe = coreData.getOptionalNetworkElement();
 
 153         if (optionalNe.isPresent()) {
 
 156             extensionList.put(optionalNe.get().getExtension());
 
 158             if (!extensionList.isEmpty()) {
 
 161                  * Loop through network element extension to get "top-level-equipment" <extension>
 
 162                  * <value-name>top-level-equipment</value-name> <value>1.0.BKP,1.0.WCS</value> </extension> "ipv4"
 
 165                 extensionList.getAsUniversalIdList("top-level-equipment", topLevelEqUuidList);
 
 167                 // If top-level-equipment exists get further information
 
 168                 if (topLevelEqUuidList.isEmpty()) {
 
 169                     LOG.debug("no top level equipment found");
 
 171                     // Read equipment and problems
 
 172                     for (UniversalId uuid : topLevelEqUuidList) {
 
 173                         recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, coreData.getMountpoint(), EQUIPMENTROOTLEVEL,
 
 174                                 globalProblemList, globalEquipmentList);
 
 178                 LOG.debug("extension list is null");
 
 183     private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, String path, int treeLevel,
 
 184             @NonNull FaultData problemList, @NonNull List<ExtendedEquipment> equipmentList) {
 
 188             Equipment equipment = this.readEquipment(uuid);
 
 190             if (equipment != null) {
 
 191                 equipmentList.add(new ExtendedEquipment(this.getMountpoint(),parentUuid.getValue(), equipment, path, treeLevel));
 
 193                 if (this.equipmentPac != null) {
 
 194                     this.equipmentPac.readTheFaults(uuid, problemList);
 
 196                     List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
 
 197                     if (containedHolderListe != null) {
 
 198                         for (ContainedHolder containedHolder : containedHolderListe) {
 
 199                             recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid, path+"/"+uuid.getValue(), treeLevel + 1,
 
 200                                     problemList, equipmentList);
 
 208     private @NonNull InventoryInformationDcae getInventoryInformationDcae(ValueNameList extensions, List<String> uuids) {
 
 210         InventoryInformationDcae inventoryInformation = new InventoryInformationDcae();
 
 213         inventoryInformation.setInterfaceUuidList(uuids);
 
 215         if (!extensions.isEmpty()) {
 
 217             inventoryInformation.setDeviceIpv4(extensions.getOrNull("neIpAddress"));
 
 219             // If top-level-equipment exists get further information
 
 220             if (topLevelEqUuidList.isEmpty()) {
 
 221                 LOG.debug("no top level equipment found");
 
 223                 if (!globalEquipmentList.isEmpty()) {
 
 224                     Equipment e = globalEquipmentList.get(0).getEquipment();
 
 226                         ManufacturedThing manufacturedThing = e.getManufacturedThing();
 
 227                         if (manufacturedThing != null) {
 
 229                             if ((et = manufacturedThing.getEquipmentType()) != null) {
 
 230                                 inventoryInformation.setType(et.getTypeName());
 
 231                                 inventoryInformation.setModel(et.getModelIdentifier());
 
 233                             ManufacturerProperties em;
 
 234                             if ((em = manufacturedThing.getManufacturerProperties()) != null) {
 
 235                                 inventoryInformation.setVendor(em.getManufacturerIdentifier());
 
 242             LOG.debug("extension list is null");
 
 245         LOG.debug("Inventory: {}", inventoryInformation);
 
 246         return inventoryInformation;
 
 252      * Read equipment information
 
 254      * @param interfacePacUuid uuid as key for Equipment.
 
 255      * @return Equipment or null
 
 257     private @Nullable Equipment readEquipment(UniversalId interfacePacUuid) {
 
 259         final Class<?> clazzPac = Equipment.class;
 
 261         LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
 
 262                 coreData.getMountpoint(), interfacePacUuid.getValue());
 
 264         InstanceIdentifier<Equipment> equipmentIID =
 
 265                 InstanceIdentifier.builder(Equipment.class, new EquipmentKey(interfacePacUuid)).build();
 
 267         return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
 
 273      * Read equipment information
 
 275      * @param interfacePacUuid uuid as key for Equipment.
 
 276      * @return Equipment or null
 
 278     private @Nullable Equipment readEquipmentAll() {
 
 280         final Class<?> clazzPac = Equipment.class;
 
 282         LOG.info("DBRead Get all equipment for class {} from mountpoint {}", clazzPac.getSimpleName(),
 
 283                 coreData.getMountpoint());
 
 285         InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();
 
 287         return getGenericTransactionUtils().readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
 
 293      * specific toString()
 
 296     public String toString() {
 
 297         return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
 
 298                 + ", extensions=" + extensionList + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
 
 299                 + globalProblemList + ", equipmentList=" + globalEquipmentList + "]";