d0b4cc51a26c178e4b43bc287f5cdb7737dcd4e2
[ccsdk/features.git] /
1 /*
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.equipment;
19
20 import java.lang.reflect.Constructor;
21 import java.lang.reflect.InvocationTargetException;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.OnfInterfacePac;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.WrapperMicrowaveModelRev181010;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
28 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
30 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
31 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
32 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.CurrentProblemTypeG;
33 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.EquipmentPac;
34 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.EquipmentPacKey;
35 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.equipment.pac.EquipmentCurrentProblems;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.opendaylight.yangtools.yang.common.QName;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 public class WrapperEquipmentPacRev170402 implements OnfInterfacePac {
42
43     private static final Logger LOG = LoggerFactory.getLogger(WrapperEquipmentPacRev170402.class);
44     public static final QName QNAME = EquipmentPac.QNAME;
45
46     private final NetconfBindingAccessor acessor;
47
48
49     public WrapperEquipmentPacRev170402(NetconfBindingAccessor acessor) {
50         this.acessor = acessor;
51     }
52
53     private TransactionUtils getGenericTransactionUtils() {
54         return acessor.getTransactionUtils();
55     }
56
57     /**
58      * Read problems of specific interfaces. TODO Goal for future implementation without usage of explicit new. Key is
59      * generated by newInstance() function here to verify this approach.
60      *
61      * @param interfacePacUuid Universal index of onf interface-pac
62      * @param resultList list to add, or null for new list.
63      * @return list of alarms
64      */
65     @Override
66     public @NonNull FaultData readTheFaults(@NonNull UniversalId interfacePacUuid, @NonNull FaultData resultList) {
67
68         final Class<EquipmentPac> clazzPac = EquipmentPac.class;
69         final Class<EquipmentPacKey> clazzPacKey = EquipmentPacKey.class;
70         final Class<EquipmentCurrentProblems> clazzProblems = EquipmentCurrentProblems.class;
71
72         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
73                 acessor.getNodeId(), interfacePacUuid.getValue());
74
75         try {
76             // -- Specific part 1
77             Constructor<EquipmentPacKey> cons = clazzPacKey.getConstructor(UniversalId.class); // Avoid new()
78             InstanceIdentifier<EquipmentCurrentProblems> interfaceIID = InstanceIdentifier
79                     .builder(clazzPac, cons.newInstance(interfacePacUuid)).child(clazzProblems).build();
80
81             // -- Specific part 2
82             EquipmentCurrentProblems problems = getGenericTransactionUtils().readData(acessor.getDataBroker(),
83                     LogicalDatastoreType.OPERATIONAL, interfaceIID);
84             if (problems == null) {
85                 LOG.debug("DBRead Id {} no {} name {}", interfacePacUuid, clazzProblems, clazzProblems.getName());
86             } else {
87                 // -- Specific part 3
88                 for (CurrentProblemTypeG problem : YangHelper.getCollection(problems.nonnullCurrentProblemList())) {
89                     resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
90                             interfacePacUuid.getValue(), problem.getProblemName(),
91                             WrapperMicrowaveModelRev181010.mapSeverity(problem.getProblemSeverity()));
92                 }
93             }
94         } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
95                 | IllegalArgumentException | InvocationTargetException e) {
96             LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
97         }
98         return resultList;
99     }
100
101 }