977fdb19ca3dc9f3e40ab4ffbb0349f5ffc6a4cc
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs;
23
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Optional;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.dataprovider.InternalDataModelSeverity;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.interfaces.TechnologySpecificPacKeys;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.qnames.Onf14DevicemanagerQNames;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Debug;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
36 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
38 import org.opendaylight.yangtools.yang.common.QNameModule;
39 import org.opendaylight.yangtools.yang.common.Revision;
40 import org.opendaylight.yangtools.yang.common.XMLNamespace;
41 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
42 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
43 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
44 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
45 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
46 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
47 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51 public class WireInterface20 extends YangModule {
52
53     private static final Logger LOG = LoggerFactory.getLogger(WireInterface20.class);
54
55     private static String NAMESPACE = "urn:onf:yang:wire-interface-2-0";
56     private static final List<QNameModule> MODULES =
57             Arrays.asList(QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2020-01-23")));
58
59     private final CoreModel14 coreModel14;
60
61     private WireInterface20(NetconfDomAccessor netconfDomAccessor, QNameModule module, CoreModel14 coreModel14) {
62         super(netconfDomAccessor, module);
63         this.coreModel14 = coreModel14;
64     }
65
66     private FaultData readWireInterfaceCurrentProblemForLtp(String ltpUuid, String localId, FaultData resultList) {
67
68         LOG.debug("DBRead Get current problems for Wire Interface from mountpoint {} for LTP uuid {} and local-id {}",
69                 netconfDomAccessor.getNodeId().getValue(), ltpUuid, localId);
70
71         // constructing the IID needs the augmentation exposed by the wire-interface-2-0
72         // model
73         YangInstanceIdentifier layerProtocolIID = coreModel14.getLayerProtocolIId(ltpUuid, localId);
74         InstanceIdentifierBuilder wireInterfacePacIID =
75                 YangInstanceIdentifier.builder(layerProtocolIID).node(Onf14DevicemanagerQNames.WIRE_INTERFACE_PAC);
76         //        @NonNull
77         //        YangInstanceIdentifier wireInterfacePacIID =
78         //                YangInstanceIdentifier.of(Onf14DevicemanagerQNames.WIRE_INTERFACE_PAC);
79         //
80         //        InstanceIdentifierBuilder augmentedWireInterfaceConfigurationIID =
81         //                YangInstanceIdentifier.builder(layerProtocolIID).node(wireInterfacePacIID.getLastPathArgument());
82
83         // reading all the current-problems list for this specific LTP and LP
84         Optional<NormalizedNode> wireInterfaceConfigurationOpt =
85                 netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, wireInterfacePacIID.build());
86
87         if (wireInterfaceConfigurationOpt.isPresent()) {
88             ContainerNode wireInterfaceConfiguration = (ContainerNode) wireInterfaceConfigurationOpt.get();
89             MapNode wireInterfaceCurrentProblemsList = (MapNode) wireInterfaceConfiguration
90                     .childByArg(new NodeIdentifier(Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_LIST));
91             if (wireInterfaceCurrentProblemsList != null) {
92                 Collection<MapEntryNode> wireInterfaceProblemsCollection = wireInterfaceCurrentProblemsList.body();
93                 for (MapEntryNode wireInterfaceProblem : wireInterfaceProblemsCollection) {
94                     resultList.add(netconfDomAccessor.getNodeId(),
95                             Integer.parseInt(Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
96                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_SEQ_NO)),
97                             new DateAndTime(Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
98                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_TIMESTAMP)),
99                             ltpUuid,
100                             Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
101                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_PROBLEM_NAME),
102                             InternalDataModelSeverity.mapSeverity(Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
103                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_PROBLEM_SEVERITY)));
104                 }
105             } else {
106                 LOG.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
107             }
108         }
109         return resultList;
110     }
111
112     public FaultData readAllCurrentProblems(FaultData resultList, List<TechnologySpecificPacKeys> wireInterfaceList) {
113
114         int idxStart; // Start index for debug messages
115
116         for (TechnologySpecificPacKeys key : wireInterfaceList) {
117             idxStart = resultList.size();
118
119             resultList = readWireInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
120             Debug.debugResultList(key.getLtpUuid(), resultList, idxStart);
121         }
122         return resultList;
123     }
124
125     /**
126      * Get specific module for device, depending on capabilities
127      */
128     public static Optional<WireInterface20> getModule(NetconfDomAccessor netconfDomAccessor, CoreModel14 coreModel14) {
129
130         Capabilities capabilities = netconfDomAccessor.getCapabilites();
131         for (QNameModule module : MODULES) {
132
133             if (capabilities.isSupportingNamespaceAndRevision(module)) {
134                 return Optional.of(new WireInterface20(netconfDomAccessor, module, coreModel14));
135             }
136         }
137         return Optional.empty();
138     }
139 }