2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
30 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.entity.PerformanceData;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.entity.PerformanceDataBuilder;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
48 * Reading Openroadm PM data and returning as PmDataEntitiy data
50 public class PmDataBuilderOpenRoadm {
52 private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElement.class);
53 private PmdataEntityBuilder pmDataBuilder;
57 public PmDataBuilderOpenRoadm(NetconfAccessor accessor) {
58 this.pmDataBuilder = new PmdataEntityBuilder();
59 this.pmDataBuilder.setNodeName(accessor.getNodeId().getValue());
62 // end of constructors
65 public HistoricalPmList getPmData(NetconfAccessor accessor) {
66 final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
67 log.info("Get PM data for element {}", accessor.getNodeId().getValue());
68 InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build();
69 return accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
74 // Build PM entity for writing into the database
75 public List<PmdataEntity> buildPmDataEntity(HistoricalPmList historicalPmEnitityList) {
76 List<PmdataEntity> pmEntitiyList = new ArrayList<>();
77 Collection<HistoricalPmEntry> pmDataEntryList = YangHelper.getCollection(historicalPmEnitityList.getHistoricalPmEntry());
78 for (HistoricalPmEntry pmDataEntry : pmDataEntryList) {
79 pmDataBuilder.setUuidInterface(pmDataEntry.getPmResourceType().getName());
80 Collection<HistoricalPm> historicalPmList = YangHelper.getCollection(pmDataEntry.getHistoricalPm());
81 for (HistoricalPm historicalPm : historicalPmList) {
82 log.info("PmName:{}", historicalPm.getType());
83 this.pmDataBuilder.setScannerId(historicalPm.getType().getName());
84 writeperformanceData(historicalPm);
85 log.info("NodeName: {}, Scanner Id:{}, Period: {}", this.pmDataBuilder.getNodeName(),
86 this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getGranularityPeriod().getName());
87 pmEntitiyList.add(this.pmDataBuilder.build());
88 log.info("PmListSize before db writing: {}", pmEntitiyList.size());
90 log.info("PmListSize before db writing: {}", pmEntitiyList.size());
94 // end of public methods
97 private void writeperformanceData(HistoricalPm historicalPm) {
98 Collection<Measurement> measurementList = YangHelper.getCollection(historicalPm.getMeasurement());
100 for (Measurement measurementData : measurementList) {
101 this.pmDataBuilder.setGranularityPeriod(mapGranularityPeriod(measurementData.getGranularity()))
102 .setPerformanceData(getPerformancedata(measurementData))
103 .setTimeStamp(measurementData.getCompletionTime());
104 if (measurementData.getValidity().getName().equals("suspect")) {
105 this.pmDataBuilder.setSuspectIntervalFlag(true);
107 log.info("Time:d{}, \n Scannerid: {}, \n UUID: {}", this.pmDataBuilder.getGranularityPeriod().getName(),
108 this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getUuidInterface());
112 //Map Performance data of PmDataEntity with MeasurmentData-HistoricalPm
113 private PerformanceData getPerformancedata(Measurement measurementData) {
114 PerformanceData performanceData;
115 PerformanceDataBuilder performanceDataBuilder = new PerformanceDataBuilder();
116 performanceData = performanceDataBuilder.setCses(YangHelper2.getInteger(measurementData.getBinNumber()))
117 .setSes(measurementData.getPmParameterValue().getUint64().intValue()).build();
118 return performanceData;
121 // Mapping Granularity period of PmDataEntity with PmGranularity of MeasurmentData-HistoricalPm
122 private GranularityPeriodType mapGranularityPeriod(PmGranularity pmGranularity) {
124 GranularityPeriodType granPeriod = null;
125 switch (pmGranularity.getName()) {
126 case ("notApplicable"):
127 granPeriod = GranularityPeriodType.Unknown;
130 granPeriod = GranularityPeriodType.Period15Min;
133 granPeriod = GranularityPeriodType.Period24Hours;
136 granPeriod = GranularityPeriodType.Period15Min;
141 // end of private methods