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.List;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
27 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.GranularityPeriodType;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntityBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.pmdata.entity.PerformanceData;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.pmdata.entity.PerformanceDataBuilder;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
45 * Reading Openroadm PM data and returning as PmDataEntitiy data
47 public class PmDataBuilderOpenRoadm {
49 private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElement.class);
50 private PmdataEntityBuilder pmDataBuilder;
54 public PmDataBuilderOpenRoadm(NetconfAccessor accessor) {
55 this.pmDataBuilder = new PmdataEntityBuilder();
56 this.pmDataBuilder.setNodeName(accessor.getNodeId().getValue());
59 // end of constructors
62 public HistoricalPmList getPmData(NetconfAccessor accessor) {
63 final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
64 log.info("Get PM data for element {}", accessor.getNodeId().getValue());
65 InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build();
66 return accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
71 // Build PM entity for writing into the database
72 public List<PmdataEntity> buildPmDataEntity(HistoricalPmList historicalPmEnitityList) {
73 List<PmdataEntity> pmEntitiyList = new ArrayList<>();
74 List<HistoricalPmEntry> pmDataEntryList = historicalPmEnitityList.getHistoricalPmEntry();
75 for (HistoricalPmEntry pmDataEntry : pmDataEntryList) {
76 pmDataBuilder.setUuidInterface(pmDataEntry.getPmResourceType().getName());
77 List<HistoricalPm> historicalPmList = pmDataEntry.getHistoricalPm();
78 for (HistoricalPm historicalPm : historicalPmList) {
79 log.info("PmName:{}", historicalPm.getType());
80 this.pmDataBuilder.setScannerId(historicalPm.getType().getName());
81 writeperformanceData(historicalPm);
82 log.info("NodeName: {}, Scanner Id:{}, Period: {}", this.pmDataBuilder.getNodeName(),
83 this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getGranularityPeriod().getName());
84 pmEntitiyList.add(this.pmDataBuilder.build());
85 log.info("PmListSize before db writing: {}", pmEntitiyList.size());
87 log.info("PmListSize before db writing: {}", pmEntitiyList.size());
91 // end of public methods
94 private void writeperformanceData(HistoricalPm historicalPm) {
95 List<Measurement> measurementList = historicalPm.getMeasurement();
97 for (Measurement measurementData : measurementList) {
98 this.pmDataBuilder.setGranularityPeriod(mapGranularityPeriod(measurementData.getGranularity()))
99 .setPerformanceData(getPerformancedata(measurementData))
100 .setTimeStamp(measurementData.getCompletionTime());
101 if (measurementData.getValidity().getName().equals("suspect")) {
102 this.pmDataBuilder.setSuspectIntervalFlag(true);
104 log.info("Time:d{}, \n Scannerid: {}, \n UUID: {}", this.pmDataBuilder.getGranularityPeriod().getName(),
105 this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getUuidInterface());
109 //Map Performance data of PmDataEntity with MeasurmentData-HistoricalPm
110 private PerformanceData getPerformancedata(Measurement measurementData) {
111 PerformanceData performanceData;
112 PerformanceDataBuilder performanceDataBuilder = new PerformanceDataBuilder();
113 performanceData = performanceDataBuilder.setCses(measurementData.getBinNumber())
114 .setSes(measurementData.getPmParameterValue().getUint64().intValue()).build();
115 return performanceData;
118 // Mapping Granularity period of PmDataEntity with PmGranularity of MeasurmentData-HistoricalPm
119 private GranularityPeriodType mapGranularityPeriod(PmGranularity pmGranularity) {
121 GranularityPeriodType granPeriod = null;
122 switch (pmGranularity.getName()) {
123 case ("notApplicable"):
124 granPeriod = GranularityPeriodType.Unknown;
127 granPeriod = GranularityPeriodType.Period15Min;
130 granPeriod = GranularityPeriodType.Period24Hours;
133 granPeriod = GranularityPeriodType.Period15Min;
138 // end of private methods