diff options
author | 2020-08-31 12:50:44 +0000 | |
---|---|---|
committer | 2020-08-31 12:50:44 +0000 | |
commit | e76a3d93363d72d1f5c98f6f8f16d0d6c2992b91 (patch) | |
tree | 4f864d3c4e49029197b2f2926192aaf0dc131039 /sdnr/wt/data-provider/provider/src/main/java/org/onap | |
parent | a4ceb7aa23cab5d291d0784095492b001709981f (diff) | |
parent | 4cd4c471e9b56494b7ae1e4917e88fa9513082b9 (diff) |
Merge "add data-provider v2 for openroadm"
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/main/java/org/onap')
2 files changed, 54 insertions, 232 deletions
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java index 46475f02d..de6870571 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java @@ -25,9 +25,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; - import javax.annotation.Nonnull; - import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; @@ -83,6 +81,8 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid private final EsDataObjectReaderWriter2<NetworkElementConnectionEntity> networkelementConnectionDB; private final EsDataObjectReaderWriter2<PmdataEntity> pmData15mDB; private final EsDataObjectReaderWriter2<PmdataEntity> pmData24hDB; + private final EsDataObjectReaderWriter2<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.PmdataEntity> pmData15mDBv2; + private final EsDataObjectReaderWriter2<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.PmdataEntity> pmData24hDBv2; @SuppressWarnings("unused") private final ElasticSearchDataProvider dataProvider; @@ -124,6 +124,15 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid pmData24hDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance24h, PmdataEntity.class, PmdataEntityBuilder.class); + pmData15mDBv2 = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.PmdataEntity.class, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.PmdataEntityBuilder.class); + + pmData24hDBv2 = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance24h, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.PmdataEntity.class, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.PmdataEntityBuilder.class); + + } catch (Exception e) { LOG.error("Can not start database client. Exception: {}", e); throw new Exception("Can not start database client. Exception: {}", e); @@ -251,7 +260,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid /** * write internal equipment to database - * + * * @param internalEquipment with mandatory fields. */ @Override @@ -276,7 +285,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid /** * join base with parameters of toJoin (only non null values) - * + * * @param base base object * @param toJoin object with new property values * @return new joined object @@ -335,7 +344,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid /** * Update after new mountpoint registration - * + * * @param networkElementConnectionEntitiy data * @param nodeId of device (mountpoint name) */ @@ -411,7 +420,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid /** * Verify status of client - * + * * @param event that is printed with message * @return true if client is null */ @@ -425,7 +434,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid /** * Verify status of client - * + * * @param message to print including {} for object printout. * @return true if client is null */ @@ -443,7 +452,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid private static class EsEventBase { /** * Query to get older Elements - * + * * @param netconfTimeStamp to identify older Elements * @return QueryBuilder for older elements related to timestamp */ @@ -454,7 +463,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid private static class EsFaultLogDevicemanager { /** * Get older Elements - * + * * @param netconfTimeStamp to identify query elements older than this timestamp. * @return QueryBuilder for related elements */ @@ -513,15 +522,51 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid }); } + @Override + public void doWritePerformanceData2( + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.PmdataEntity> list) { + + list.forEach(elem -> { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.GranularityPeriodType + granularityPeriod = nnGetGranularityPeriodType2(elem.getGranularityPeriod()); + //_id": "Sim12600/LP-MWPS-TTP-01/2017-07-04T15:15:00.0+00:00" + StringBuffer id = new StringBuffer(); + DateAndTime date = elem.getTimeStamp(); + id.append(elem.getNodeName()); + id.append("/"); + id.append(elem.getUuidInterface()); + id.append("/"); + id.append(date != null ? date.getValue() : "null"); + switch (granularityPeriod) { + case Period15Min: + pmData15mDB.write(elem, id.toString()); + break; + case Period24Hours: + pmData24hDB.write(elem, id.toString()); + break; + case Unknown: + default: + LOG.debug("Unknown granularity {} id {}", granularityPeriod, id); + break; + } + }); + } @NonNull GranularityPeriodType nnGetGranularityPeriodType(@Nullable GranularityPeriodType granularityPeriod) { return granularityPeriod != null ? granularityPeriod : GranularityPeriodType.Unknown; } + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.GranularityPeriodType nnGetGranularityPeriodType2( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.@Nullable GranularityPeriodType granularityPeriod) { + return granularityPeriod != null ? granularityPeriod : + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.v2.rev200702.GranularityPeriodType.Unknown; + } @Override public HtDatabaseClient getRawClient() { return this.client; } + + } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsCloner.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsCloner.java deleted file mode 100644 index a9a658387..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsCloner.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - */ -package org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nullable; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class YangToolsCloner { - - private static YangToolsMapper yangtoolsMapper = new YangToolsMapper(); - private static final Logger LOG = LoggerFactory.getLogger(YangToolsCloner.class); - public static final int ACCESSOR_FIELD = 0; - public static final int ACCESSOR_METHOD = 1; - - - private final int accessor; - - private YangToolsCloner(int ac) { - this.accessor = ac; - } - - public static YangToolsCloner instance() { - return instance(ACCESSOR_METHOD); - } - - public static YangToolsCloner instance(int ac) { - return new YangToolsCloner(ac); - } - - /** - * - * @param source source object - * @param clazz Class of return object - * @return list of cloned object - * @return - */ - public <S extends DataObject, T extends DataObject> List<T> cloneList(List<S> source, Class<T> clazz) { - return cloneList(source, clazz, null); - } - - /** - * - * @param source source object - * @param clazz Class of return object - * @attrList filter for attribute Names to clone - * @return list of cloned object - */ - public <S extends DataObject, T extends DataObject> List<T> cloneList(List<S> source, Class<T> clazz, - @Nullable List<String> attrList) { - if (source == null) { - return null; - } - List<T> list = new ArrayList<>(); - for (S s : source) { - list.add(clone(s, clazz, attrList)); - } - return list; - } - - /** - * - * @param source source object - * @param clazz Class of return object - * @return cloned object - */ - public <S, T extends DataObject> T clone(S source, Class<T> clazz) { - return clone(source, clazz, null); - } - - /** - * - * @param source source object - * @param clazz Class of return object - * @attrList if empty copy all else list of attribute Names to clone - * @return cloned object - */ - public <S, T extends DataObject> T clone(S source, Class<T> clazz, @Nullable List<String> attrList) { - if (source == null) { - return (T) null; - } - Field[] attributeFields; - Field sourceField; - Method m; - Builder<T> builder = yangtoolsMapper.getBuilder(clazz); - T object = builder.build(); - attributeFields = object.getClass().getDeclaredFields(); - for (Field attributeField : attributeFields) { - // check if attr is in inclusion list - if (attrList != null && !attrList.contains(attributeField.getName())) { - continue; - } - // ignore QNAME - if (attributeField.getName().equals("QNAME")) { - continue; - } - - attributeField.setAccessible(true); - try { - if (accessor == ACCESSOR_FIELD) { - sourceField = source.getClass().getDeclaredField(attributeField.getName()); - sourceField.setAccessible(true); - if (attributeField.getType().equals(String.class) && !sourceField.getType().equals(String.class)) { - attributeField.set(object, String.valueOf(sourceField.get(source))); - } else { - attributeField.set(object, sourceField.get(source)); - } - } else if (accessor == ACCESSOR_METHOD) { - String getter = getter(attributeField.getName()); - System.out.println("getter=" + getter); - m = source.getClass().getDeclaredMethod(getter); - m.setAccessible(true); - if (attributeField.getType().equals(String.class) && !m.getReturnType().equals(String.class)) { - attributeField.set(object, String.valueOf(m.invoke(source))); - } else { - attributeField.set(object, m.invoke(source)); - } - } - - } catch (NoSuchMethodException | NoSuchFieldException e) { - // Convert to run-time exception - String msg = "no such field " + attributeField.getName() + " in class " + source.getClass().getName(); - LOG.debug(msg); - // throw new IllegalArgumentException(msg); - } catch (IllegalAccessException | SecurityException e) { - LOG.debug("Access problem " + attributeField.getName(), e); - } catch (IllegalArgumentException e) { - LOG.debug("argument problem " + attributeField.getName(), e); - } catch (InvocationTargetException e) { - LOG.debug("invocation problem " + attributeField.getName(), e); - } - } - - return object; - } - - private static String getter(String name) { - return String.format("%s%s%s", "get", name.substring(1, 2).toUpperCase(), name.substring(2)); - } - - public <S extends DataObject, T extends DataObject, B extends Builder<T>> B cloneToBuilder(S source, B builder) { - return cloneToBuilder(source, builder, null); - } - - public <S extends DataObject, T extends DataObject, B extends Builder<T>> B cloneToBuilder(S source, B builder, - @Nullable List<String> attrList) { - Field[] attributeFields; - Field sourceField; - Method m; - attributeFields = builder.getClass().getDeclaredFields(); - for (Field attributeField : attributeFields) { - // check if attr is in inclusion list - if (attrList != null && !attrList.contains(attributeField.getName())) { - continue; - } - // ignore QNAME - if (attributeField.getName().equals("QNAME")) { - continue; - } - - attributeField.setAccessible(true); - try { - if (accessor == ACCESSOR_FIELD) { - sourceField = source.getClass().getDeclaredField(attributeField.getName()); - sourceField.setAccessible(true); - if (attributeField.getType().equals(String.class) && !sourceField.getType().equals(String.class)) { - attributeField.set(builder, String.valueOf(sourceField.get(source))); - } else { - attributeField.set(builder, sourceField.get(source)); - } - } else if (accessor == ACCESSOR_METHOD) { - m = source.getClass().getDeclaredMethod(getter(attributeField.getName())); - m.setAccessible(true); - if (attributeField.getType().equals(String.class) && !m.getReturnType().equals(String.class)) { - attributeField.set(builder, String.valueOf(m.invoke(source))); - } else { - attributeField.set(builder, m.invoke(source)); - } - } - - } catch (NoSuchMethodException | NoSuchFieldException e) { - // Convert to run-time exception - String msg = "no such field " + attributeField.getName() + " in class " + source.getClass().getName(); - LOG.debug(msg); - // throw new IllegalArgumentException(msg); - } catch (IllegalAccessException | SecurityException e) { - LOG.debug("Access problem " + attributeField.getName(), e); - } catch (IllegalArgumentException e) { - LOG.debug("argument problem " + attributeField.getName(), e); - } catch (InvocationTargetException e) { - LOG.debug("invocation problem " + attributeField.getName(), e); - } - } - return builder; - } -} |