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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc;
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;
41 public class WrapperEquipmentPacRev170402 implements OnfInterfacePac {
43 private static final Logger LOG = LoggerFactory.getLogger(WrapperEquipmentPacRev170402.class);
44 public static final QName QNAME = EquipmentPac.QNAME;
46 ONFCOreNetworkElementCoreData coreData;
48 public WrapperEquipmentPacRev170402(ONFCOreNetworkElementCoreData coreData) {
49 this.coreData = coreData;
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.
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
61 public List<ProblemNotificationXml> readTheFaults(UniversalId interfacePacUuid,
62 List<ProblemNotificationXml> resultList) {
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;
70 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
71 coreData.getMountpoint(), interfacePacUuid.getValue());
74 if (resultList == null) {
75 resultList = new ArrayList<>();
78 Constructor<EquipmentPacKey> cons = clazzPacKey.getConstructor(UniversalId.class); // Avoid new()
79 InstanceIdentifier<EquipmentCurrentProblems> interfaceIID = InstanceIdentifier
80 .builder(clazzPac, cons.newInstance(interfacePacUuid)).child(clazzProblems).build();
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());
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())));
98 } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
99 | IllegalArgumentException | InvocationTargetException e) {
100 LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
106 * Read problems of specific interfaces
108 * @param interfacePacUuid Universal index of Equipmentpac
109 * @return EquipmentPac or null
111 public @Nullable EquipmentPac readEquipmentPac(UniversalId interfacePacUuid) {
113 final Class<?> clazzPac = EquipmentPac.class;
115 LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
116 coreData.getMountpoint(), interfacePacUuid.getValue());
118 InstanceIdentifier<EquipmentPac> equipmentIID =
119 InstanceIdentifier.builder(EquipmentPac.class, new EquipmentPacKey(interfacePacUuid)).build();
121 EquipmentPac res = GenericTransactionUtils.readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,