c97449d69dac9096da6b193dc8b6a7b1fef9b51b
[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 com.google.common.collect.Sets;
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.Optional;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.dataprovider.InternalDataModelSeverity;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.interfaces.TechnologySpecificPacKeys;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.qnames.Onf14DevicemanagerQNames;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Debug;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
38 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
40 import org.opendaylight.yangtools.yang.common.QNameModule;
41 import org.opendaylight.yangtools.yang.common.Revision;
42 import org.opendaylight.yangtools.yang.common.XMLNamespace;
43 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
44 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
45 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
46 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
47 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
48 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
49 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
50 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 public class WireInterface20 extends YangModule {
55
56     private static final Logger LOG = LoggerFactory.getLogger(WireInterface20.class);
57
58     private static String NAMESPACE = "urn:onf:yang:wire-interface-2-0";
59     private static final List<QNameModule> MODULES =
60             Arrays.asList(QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2020-01-23")));
61
62     private final CoreModel14 coreModel14;
63
64     private WireInterface20(NetconfDomAccessor netconfDomAccessor, QNameModule module, CoreModel14 coreModel14) {
65         super(netconfDomAccessor, module);
66         this.coreModel14 = coreModel14;
67     }
68
69     private FaultData readWireInterfaceCurrentProblemForLtp(String ltpUuid, String localId, FaultData resultList) {
70
71         LOG.debug("DBRead Get current problems for Wire Interface from mountpoint {} for LTP uuid {} and local-id {}",
72                 netconfDomAccessor.getNodeId().getValue(), ltpUuid, localId);
73
74         // constructing the IID needs the augmentation exposed by the wire-interface-2-0
75         // model
76         YangInstanceIdentifier layerProtocolIID = coreModel14.getLayerProtocolIId(ltpUuid, localId);
77
78         @NonNull
79         AugmentationIdentifier wireInterfacePacIID = YangInstanceIdentifier.AugmentationIdentifier
80                 .create(Sets.newHashSet(Onf14DevicemanagerQNames.WIRE_INTERFACE_PAC));
81
82         InstanceIdentifierBuilder augmentedWireInterfaceConfigurationIID =
83                 YangInstanceIdentifier.builder(layerProtocolIID).node(wireInterfacePacIID);
84
85         // reading all the current-problems list for this specific LTP and LP
86         Optional<NormalizedNode> wireInterfaceConfigurationOpt = netconfDomAccessor
87                 .readDataNode(LogicalDatastoreType.OPERATIONAL, augmentedWireInterfaceConfigurationIID.build());
88
89         if (wireInterfaceConfigurationOpt.isPresent()) {
90             AugmentationNode wireInterfaceConfiguration = (AugmentationNode) wireInterfaceConfigurationOpt.get();
91             MapNode wireInterfaceCurrentProblemsList = (MapNode) wireInterfaceConfiguration
92                     .childByArg(new NodeIdentifier(Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_LIST));
93             if (wireInterfaceCurrentProblemsList != null) {
94                 Collection<MapEntryNode> wireInterfaceProblemsCollection = wireInterfaceCurrentProblemsList.body();
95                 for (MapEntryNode wireInterfaceProblem : wireInterfaceProblemsCollection) {
96                     resultList.add(netconfDomAccessor.getNodeId(),
97                             Integer.parseInt(Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
98                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_SEQ_NO)),
99                             new DateAndTime(Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
100                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_TIMESTAMP)),
101                             ltpUuid,
102                             Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
103                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_PROBLEM_NAME),
104                             InternalDataModelSeverity.mapSeverity(Onf14DMDOMUtility.getLeafValue(wireInterfaceProblem,
105                                     Onf14DevicemanagerQNames.WIRE_INTERFACE_CURRENT_PROBLEMS_PROBLEM_SEVERITY)));
106                 }
107             } else {
108                 LOG.debug("DBRead Id {} empty CurrentProblemList", ltpUuid);
109             }
110         }
111         return resultList;
112     }
113
114     public FaultData readAllCurrentProblems(FaultData resultList,
115             List<TechnologySpecificPacKeys> wireInterfaceList) {
116
117         int idxStart; // Start index for debug messages
118
119         for (TechnologySpecificPacKeys key : wireInterfaceList) {
120             idxStart = resultList.size();
121
122             resultList = readWireInterfaceCurrentProblemForLtp(key.getLtpUuid(), key.getLocalId(), resultList);
123             Debug.debugResultList(key.getLtpUuid(), resultList, idxStart);
124         }
125         return resultList;
126     }
127
128     /**
129      * Get specific module for device, depending on capabilities
130      */
131     public static Optional<WireInterface20> getModule(NetconfDomAccessor netconfDomAccessor, CoreModel14 coreModel14) {
132
133         Capabilities capabilities = netconfDomAccessor.getCapabilites();
134         for (QNameModule module : MODULES) {
135
136             if (capabilities.isSupportingNamespaceAndRevision(module)) {
137                 return Optional.of(new WireInterface20(netconfDomAccessor, module, coreModel14));
138             }
139         }
140         return Optional.empty();
141     }
142 }