3ee0c91adedf669d1d6483e95d3f9a0978eda655
[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.base.netconf.wrapperc;
19
20 import java.lang.reflect.Constructor;
21 import java.lang.reflect.InvocationTargetException;
22 import java.util.ArrayList;
23 import java.util.List;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElementCoreData;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
31 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
32 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
33 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.CurrentProblemTypeG;
34 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.EquipmentPac;
35 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.EquipmentPacKey;
36 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.equipment.pac.EquipmentCurrentProblems;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.common.QName;
39
40 public class WrapperEquipmentPacRev170402 implements OnfInterfacePac {
41
42     private static final Logger LOG = LoggerFactory.getLogger(WrapperEquipmentPacRev170402.class);
43     public static final QName QNAME = EquipmentPac.QNAME;
44
45     ONFCoreNetworkElementCoreData coreData;
46
47     public WrapperEquipmentPacRev170402(ONFCoreNetworkElementCoreData coreData) {
48         this.coreData = coreData;
49     }
50
51     /**
52      * Read problems of specific interfaces. TODO Goal for future implementation without usage of
53      * explicit new. Key is generated by newInstance() function here to verify this approach.
54      *
55      * @param interfacePacUuid Universal index of onf interface-pac
56      * @param resultList list to add, or null for new list.
57      * @return list of alarms
58      */
59     @Override
60     public List<ProblemNotificationXml> readTheFaults(UniversalId interfacePacUuid,
61             List<ProblemNotificationXml> resultList) {
62
63         final Class<EquipmentPac> clazzPac = EquipmentPac.class;
64         final Class<EquipmentPacKey> clazzPacKey = EquipmentPacKey.class;
65         final Class<EquipmentCurrentProblems> clazzProblems = EquipmentCurrentProblems.class;
66         // final Class<ContainerCurrentProblemTypeG> clazzProblem =
67         // ContainerCurrentProblemTypeG.class;
68
69         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
70                 coreData.getMountpoint(), interfacePacUuid.getValue());
71
72         try {
73             if (resultList == null) {
74                 resultList = new ArrayList<>();
75             }
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 = GenericTransactionUtils.readData(coreData.getDataBroker(),
83                     LogicalDatastoreType.OPERATIONAL, interfaceIID);
84             if (problems == null) {
85                 LOG.debug("DBRead Id {} no {}", interfacePacUuid, clazzProblems, clazzProblems.getName());
86             } else if (problems.getCurrentProblemList() == null) {
87                 LOG.debug("DBRead Id {} no list {}", interfacePacUuid, clazzProblems.getName());
88             } else {
89                 // -- Specific part 3
90                 for (CurrentProblemTypeG problem : problems.getCurrentProblemList()) {
91                     resultList.add(new ProblemNotificationXml(coreData.getMountpoint(), interfacePacUuid.getValue(),
92                             problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
93                             problem.getSequenceNumber().toString(),
94                             InternalDateAndTime.valueOf(problem.getTimeStamp())));
95                 }
96             }
97         } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
98                 | IllegalArgumentException | InvocationTargetException e) {
99             LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
100         }
101         return resultList;
102     }
103
104 }