15a9cfd45fd35f8b11dfcc1739ce63dac4282e56
[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.onfcore.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
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.NetworkElementCoreData;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.INetconfAcessor;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
31 import org.opendaylight.mdsal.common.api.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 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 public class WrapperEquipmentPacRev170402 implements OnfInterfacePac {
43
44     private static final Logger LOG = LoggerFactory.getLogger(WrapperEquipmentPacRev170402.class);
45     public static final QName QNAME = EquipmentPac.QNAME;
46
47     private final NetworkElementCoreData coreData;
48     private final INetconfAcessor acessor;
49
50
51     public WrapperEquipmentPacRev170402(INetconfAcessor acessor, NetworkElementCoreData coreData) {
52         this.coreData = coreData;
53         this.acessor = acessor;
54     }
55
56     private TransactionUtils getGenericTransactionUtils() {
57         return acessor.getTransactionUtils();
58     }
59
60     /**
61      * Read problems of specific interfaces. TODO Goal for future implementation without usage of
62      * explicit new. Key is generated by newInstance() function here to verify this approach.
63      *
64      * @param interfacePacUuid Universal index of onf interface-pac
65      * @param resultList list to add, or null for new list.
66      * @return list of alarms
67      */
68     @Override
69     public List<ProblemNotificationXml> readTheFaults(UniversalId interfacePacUuid,
70             List<ProblemNotificationXml> resultList) {
71
72         final Class<EquipmentPac> clazzPac = EquipmentPac.class;
73         final Class<EquipmentPacKey> clazzPacKey = EquipmentPacKey.class;
74         final Class<EquipmentCurrentProblems> clazzProblems = EquipmentCurrentProblems.class;
75         // final Class<ContainerCurrentProblemTypeG> clazzProblem =
76         // ContainerCurrentProblemTypeG.class;
77
78         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
79                 coreData.getMountpoint(), interfacePacUuid.getValue());
80
81         try {
82             if (resultList == null) {
83                 resultList = new ArrayList<>();
84             }
85             // -- Specific part 1
86             Constructor<EquipmentPacKey> cons = clazzPacKey.getConstructor(UniversalId.class); // Avoid new()
87             InstanceIdentifier<EquipmentCurrentProblems> interfaceIID = InstanceIdentifier
88                     .builder(clazzPac, cons.newInstance(interfacePacUuid)).child(clazzProblems).build();
89
90             // -- Specific part 2
91             EquipmentCurrentProblems problems = getGenericTransactionUtils().readData(coreData.getDataBroker(),
92                     LogicalDatastoreType.OPERATIONAL, interfaceIID);
93             if (problems == null) {
94                 LOG.debug("DBRead Id {} no {}", interfacePacUuid, clazzProblems, clazzProblems.getName());
95              } else {
96                 // -- Specific part 3
97                 for (CurrentProblemTypeG problem : problems.nonnullCurrentProblemList()) {
98                     resultList.add(new ProblemNotificationXml(coreData.getMountpoint(), interfacePacUuid.getValue(),
99                             problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
100                             problem.getSequenceNumber(),
101                             InternalDateAndTime.valueOf(problem.getTimeStamp())));
102                 }
103             }
104         } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
105                 | IllegalArgumentException | InvocationTargetException e) {
106             LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
107         }
108         return resultList;
109     }
110
111 }