03e830e5a4c5ae6461dbbc2d018b6fd9efbca4a7
[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 javax.annotation.Nullable;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCOreNetworkElementCoreData;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
32 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
33 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
34 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.CurrentProblemTypeG;
35 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.EquipmentPac;
36 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.EquipmentPacKey;
37 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.equipment.pac.EquipmentCurrentProblems;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.opendaylight.yangtools.yang.common.QName;
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     ONFCOreNetworkElementCoreData coreData;
47
48     public WrapperEquipmentPacRev170402(ONFCOreNetworkElementCoreData coreData) {
49         this.coreData = coreData;
50     }
51
52     /**
53      * Read problems of specific interfaces. TODO Goal for future implementation without usage of
54      * explicit new. Key is generated by newInstance() function here to verify this approach.
55      *
56      * @param interfacePacUuid Universal index of onf interface-pac
57      * @param resultList list to add, or null for new list.
58      * @return list of alarms
59      */
60     @Override
61     public List<ProblemNotificationXml> readTheFaults(UniversalId interfacePacUuid,
62             List<ProblemNotificationXml> resultList) {
63
64         final Class<EquipmentPac> clazzPac = EquipmentPac.class;
65         final Class<EquipmentPacKey> clazzPacKey = EquipmentPacKey.class;
66         final Class<EquipmentCurrentProblems> clazzProblems = EquipmentCurrentProblems.class;
67         // final Class<ContainerCurrentProblemTypeG> clazzProblem =
68         // ContainerCurrentProblemTypeG.class;
69
70         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
71                 coreData.getMountpoint(), interfacePacUuid.getValue());
72
73         try {
74             if (resultList == null) {
75                 resultList = new ArrayList<>();
76             }
77             // -- Specific part 1
78             Constructor<EquipmentPacKey> cons = clazzPacKey.getConstructor(UniversalId.class); // Avoid new()
79             InstanceIdentifier<EquipmentCurrentProblems> interfaceIID = InstanceIdentifier
80                     .builder(clazzPac, cons.newInstance(interfacePacUuid)).child(clazzProblems).build();
81
82             // -- Specific part 2
83             EquipmentCurrentProblems problems = GenericTransactionUtils.readData(coreData.getDataBroker(),
84                     LogicalDatastoreType.OPERATIONAL, interfaceIID);
85             if (problems == null) {
86                 LOG.debug("DBRead Id {} no {}", interfacePacUuid, clazzProblems, clazzProblems.getName());
87             } else if (problems.getCurrentProblemList() == null) {
88                 LOG.debug("DBRead Id {} no list {}", interfacePacUuid, clazzProblems.getName());
89             } else {
90                 // -- Specific part 3
91                 for (CurrentProblemTypeG problem : problems.getCurrentProblemList()) {
92                     resultList.add(new ProblemNotificationXml(coreData.getMountpoint(), interfacePacUuid.getValue(),
93                             problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
94                             problem.getSequenceNumber().toString(),
95                             InternalDateAndTime.valueOf(problem.getTimeStamp())));
96                 }
97             }
98         } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
99                 | IllegalArgumentException | InvocationTargetException e) {
100             LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
101         }
102         return resultList;
103     }
104
105     /**
106      * Read problems of specific interfaces
107      *
108      * @param interfacePacUuid Universal index of Equipmentpac
109      * @return EquipmentPac or null
110      */
111     public @Nullable EquipmentPac readEquipmentPac(UniversalId interfacePacUuid) {
112
113         final Class<?> clazzPac = EquipmentPac.class;
114
115         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
116                 coreData.getMountpoint(), interfacePacUuid.getValue());
117
118         InstanceIdentifier<EquipmentPac> equipmentIID =
119                 InstanceIdentifier.builder(EquipmentPac.class, new EquipmentPacKey(interfacePacUuid)).build();
120
121         EquipmentPac res = GenericTransactionUtils.readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
122                 equipmentIID);
123
124         return res;
125     }
126
127 }