2  * ============LICENSE_START=======================================================
 
   3  * ONAP : ccsdk features
 
   4  * ================================================================================
 
   5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
 
   7  * ================================================================================
 
   8  * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
 
   9  * =================================================================================================
 
  10  * Licensed under the Apache License, Version 2.0 (the "License");
 
  11  * you may not use this file except in compliance with the License.
 
  12  * You may obtain a copy of the License at
 
  14  *     http://www.apache.org/licenses/LICENSE-2.0
 
  16  * Unless required by applicable law or agreed to in writing, software
 
  17  * distributed under the License is distributed on an "AS IS" BASIS,
 
  18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  19  * See the License for the specific language governing permissions and
 
  20  * limitations under the License.
 
  21  * ============LICENSE_END=========================================================
 
  24 package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity;
 
  26 import java.util.ArrayList;
 
  27 import java.util.Arrays;
 
  28 import java.util.Date;
 
  29 import java.util.HashMap;
 
  30 import java.util.List;
 
  32 import java.util.Optional;
 
  33 import javax.annotation.Nonnull;
 
  34 import org.eclipse.jdt.annotation.NonNull;
 
  35 import org.eclipse.jdt.annotation.Nullable;
 
  36 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
 
  37 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.BoolQueryBuilder;
 
  38 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
 
  39 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
 
  40 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.RangeQueryBuilder;
 
  41 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider;
 
  42 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.EsDataObjectReaderWriter2;
 
  43 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.ArchiveCleanProvider;
 
  44 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataInconsistencyException;
 
  45 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
 
  46 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
 
  47 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
 
  48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
 
  49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogBuilder;
 
  50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogEntity;
 
  51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionLogStatus;
 
  52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogBuilder;
 
  53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity;
 
  54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
 
  55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
 
  56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
 
  57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder;
 
  58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentEntity;
 
  59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
 
  60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
 
  61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType;
 
  62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough;
 
  63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder;
 
  64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughEntity;
 
  65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
 
  66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder;
 
  67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity;
 
  68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
 
  69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity;
 
  70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
 
  71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder;
 
  72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInputBuilder;
 
  73 import org.opendaylight.yangtools.yang.common.Uint32;
 
  74 import org.slf4j.Logger;
 
  75 import org.slf4j.LoggerFactory;
 
  78  * Event service, writing all events into the database into the appropriate index.
 
  82 public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvider {
 
  83     private static final Logger LOG = LoggerFactory.getLogger(HtDatabaseEventsService.class);
 
  85     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();
 
  87     private static final int ROOT_TREE_LEVEL = 0;
 
  89     private HtDatabaseClient client;
 
  90     private EsDataObjectReaderWriter2<EventlogEntity> eventRWEventLogDevicemanager;
 
  91     private EsDataObjectReaderWriter2<InventoryEntity> eventRWEquipment;
 
  92     private EsDataObjectReaderWriter2<FaultcurrentEntity> eventRWFaultCurrentDB;
 
  93     private EsDataObjectReaderWriter2<FaultlogEntity> eventRWFaultLogDB;
 
  94     private EsDataObjectReaderWriter2<CmlogEntity> eventRWFCMLogDB;
 
  95     private EsDataObjectReaderWriter2<ConnectionlogEntity> eventRWConnectionLogDB;
 
  96     private final EsDataObjectReaderWriter2<NetworkElementConnectionEntity> networkelementConnectionDB;
 
  97     private final EsDataObjectReaderWriter2<GuicutthroughEntity> guiCutThroughDB;
 
  98     private final EsDataObjectReaderWriter2<PmdataEntity> pmData15mDB;
 
  99     private final EsDataObjectReaderWriter2<PmdataEntity> pmData24hDB;
 
 101     @SuppressWarnings("unused")
 
 102     private final DatabaseDataProvider dataProvider;
 
 103     // --- Construct and initialize
 
 105     public HtDatabaseEventsService(HtDatabaseClient client, DatabaseDataProvider elasticSearchDataProvider)
 
 108         LOG.info("Create {} start", HtDatabaseEventsService.class);
 
 109         this.dataProvider = elasticSearchDataProvider;
 
 112             // Create control structure
 
 113             this.client = client;
 
 115             eventRWEventLogDevicemanager = new EsDataObjectReaderWriter2<>(client, Entity.Eventlog,
 
 116                     EventlogEntity.class, EventlogBuilder.class);
 
 118             eventRWEquipment = new EsDataObjectReaderWriter2<>(client, Entity.Inventoryequipment, InventoryEntity.class,
 
 119                     InventoryBuilder.class);
 
 121             eventRWFaultCurrentDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultcurrent,
 
 122                     FaultcurrentEntity.class, FaultcurrentBuilder.class);
 
 124             eventRWFaultLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultlog, FaultlogEntity.class,
 
 125                     FaultlogBuilder.class);
 
 127             eventRWFCMLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Cmlog, CmlogEntity.class,
 
 130             eventRWConnectionLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Connectionlog,
 
 131                     ConnectionlogEntity.class, ConnectionlogBuilder.class);
 
 133             networkelementConnectionDB = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection,
 
 134                     NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true)
 
 135                             .setEsIdAttributeName("_id");
 
 137             guiCutThroughDB = new EsDataObjectReaderWriter2<>(client, Entity.Guicutthrough, GuicutthroughEntity.class,
 
 138                     GuicutthroughBuilder.class);
 
 140             pmData15mDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, PmdataEntity.class,
 
 141                     PmdataEntityBuilder.class);
 
 143             pmData24hDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance24h, PmdataEntity.class,
 
 144                     PmdataEntityBuilder.class);
 
 146         } catch (Exception e) {
 
 147             LOG.error("Can not start database client. Exception: {}", e);
 
 148             throw new Exception("Can not start database client. Exception: {}", e);
 
 150         LOG.info("Create {} finished. DB Service {} started.", HtDatabaseEventsService.class,
 
 151                 client != null ? "sucessfully" : "not");
 
 158     public void writeConnectionLog(ConnectionlogEntity event) {
 
 159         if (assertIfClientNull(event)) {
 
 162         LOG.debug("Write event: {}", event);
 
 163         eventRWConnectionLogDB.write(event, null);
 
 169     public void writeEventLog(EventlogEntity event) {
 
 170         if (assertIfClientNull("No client to write {}", event)) {
 
 174         LOG.debug("Write event: {}", event.toString());
 
 175         eventRWEventLogDevicemanager.write(event, null);
 
 181     public void writeFaultLog(FaultlogEntity fault) {
 
 182         if (assertIfClientNull(fault)) {
 
 186         LOG.debug("Write fault to faultlog: {}", fault.toString());
 
 187         eventRWFaultLogDB.write(fault, null);
 
 193     public void writeCMLog(CmlogEntity cm) {
 
 194         if (assertIfClientNull(cm)) {
 
 198         LOG.debug("Write CM to cmlog: {}", cm.toString());
 
 199         eventRWFCMLogDB.write(cm, null);
 
 205     public void updateFaultCurrent(FaultcurrentEntity fault) {
 
 206         if (assertIfClientNull(fault)) {
 
 210         if (FaultEntityManager.isManagedAsCurrentProblem(fault)) {
 
 211             if (FaultEntityManager.isNoAlarmIndication(fault)) {
 
 212                 LOG.debug("Remove from currentFaults: {}", fault.toString());
 
 213                 eventRWFaultCurrentDB.remove(FaultEntityManager.genSpecificEsId(fault));
 
 215                 LOG.debug("Write to currentFaults: {}", fault.toString());
 
 216                 eventRWFaultCurrentDB.write(fault, FaultEntityManager.genSpecificEsId(fault));
 
 219             LOG.debug("Ingnore for currentFaults: {}", fault.toString());
 
 224      * Remove all entries for one node
 
 226      * @param nodeName contains the mountpointname
 
 227      * @return number of deleted entries
 
 230     public int clearFaultsCurrentOfNode(String nodeName) {
 
 231         if (assertIfClientNullForNodeName(nodeName)) {
 
 235         LOG.debug("Remove from currentFaults all faults for node: {}", nodeName);
 
 236         return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNode(nodeName));
 
 240      * Remove all entries for one node
 
 242      * @param nodeName contains the mountpointname
 
 243      * @param objectId of element to be deleted
 
 244      * @return number of deleted entries
 
 247     public int clearFaultsCurrentOfNodeWithObjectId(String nodeName, String objectId) {
 
 248         if (assertIfClientNullForNodeName(nodeName)) {
 
 252         LOG.debug("Remove from currentFaults all faults for node/objectId: {}/{}", nodeName, objectId);
 
 253         return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNodeAndObjectId(nodeName, objectId));
 
 257      * Deliver list with all mountpoint/node-names in the database.
 
 259      * @return List of all mountpoint/node-names the had active alarms.
 
 262     public @Nonnull List<String> getAllNodesWithCurrentAlarms() {
 
 263         if (assertIfClientNull("No DB, can not delete for all nodes", null)) {
 
 264             return new ArrayList<>();
 
 267         LOG.debug("Remove from currentFaults faults for all node");
 
 268         List<String> nodeNames = new ArrayList<>();
 
 270         for (FaultcurrentEntity fault : eventRWFaultCurrentDB.doReadAll().getHits()) {
 
 271             String nodeName = fault.getNodeId();
 
 272             if (!nodeNames.contains(nodeName)) {
 
 273                 // this.clearFaultsCurrentOfNode(nodeName); -> Function shifted
 
 274                 nodeNames.add(nodeName);
 
 280     // -- Inventory and equipment current
 
 283      * write internal equipment to database
 
 285      * @param internalEquipment with mandatory fields.
 
 288     private void writeInventory(Inventory internalEquipment) {
 
 290         if (internalEquipment.getManufacturerIdentifier() == null) {
 
 291             internalEquipment = new InventoryBuilder(internalEquipment).setManufacturerIdentifier("").build();
 
 293         if (internalEquipment.getDate() == null) {
 
 294             internalEquipment = new InventoryBuilder(internalEquipment).setDate("").build();
 
 296         eventRWEquipment.write(internalEquipment, internalEquipment.getNodeId() + "/" + internalEquipment.getUuid());
 
 300      * write internal equipment to database
 
 306     public void writeInventory(String nodeId, List<Inventory> list) {
 
 309             checkConsistency(nodeId, list);
 
 310         } catch (DataInconsistencyException e) {
 
 311             LOG.warn("inventory list for node {} is not consistent", nodeId, e);
 
 312             list = e.getRepairedList();
 
 315         for (Inventory internalEquipment : list) {
 
 316             this.writeInventory(internalEquipment);
 
 320     private static void checkConsistency(String nodeId, List<Inventory> list) throws DataInconsistencyException {
 
 321         final String UNBOUND_INVENTORY_UUID = "unbound";
 
 322         List<String> failures = new ArrayList<>();
 
 325         Map<String, Inventory> repairList = new HashMap<>();
 
 326         InventoryBuilder repairedItem;
 
 327         InventoryBuilder unboundItem = new InventoryBuilder().setNodeId(nodeId).setUuid(UNBOUND_INVENTORY_UUID)
 
 328                 .setTreeLevel(Uint32.valueOf(0));;
 
 329         for (Inventory item : list) {
 
 330             repairedItem = new InventoryBuilder(item);
 
 331             // check for bad node-id
 
 332             if (!nodeId.equals(item.getNodeId())) {
 
 333                 failures.add(String.format("missing node-id for equipment(uuid=%s)", item.getUuid()));
 
 334                 repairedItem.setNodeId(nodeId);
 
 337             // check missing tree-level
 
 338             if (item.getTreeLevel() == null) {
 
 339                 failures.add(String.format("missing tree-level for equipment(uuid=%s)", item.getUuid()));
 
 340                 repairedItem.setTreeLevel(Uint32.valueOf(ROOT_TREE_LEVEL));
 
 344                 treeLevel = item.getTreeLevel().longValue();
 
 345                 if (treeLevel > ROOT_TREE_LEVEL) {
 
 346                     // check non root elem and missing parent
 
 347                     if (item.getParentUuid() == null) {
 
 348                         failures.add(String.format("Non root level element (uuid=%s) has to have a parent element",
 
 351                         repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
 
 352                         repairList.put(unboundItem.getUuid(), unboundItem.build());
 
 354                     // check that parent exists in list and is tree-level -1
 
 356                         Optional<Inventory> parent =
 
 357                                 list.stream().filter(e -> item.getParentUuid().equals(e.getUuid())).findFirst();
 
 358                         if (parent.isEmpty()) {
 
 359                             failures.add(String.format("no parent found for uuid=%s with parent-uuid=%s",
 
 360                                     item.getUuid(), item.getParentUuid()));
 
 361                             repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
 
 366                 // check for duplicated uui
 
 367                 Optional<Inventory> duplicate = list
 
 368                         .stream().filter(e -> !item.equals(e) && item.getUuid() != null
 
 369                                 && item.getUuid().equals(e.getUuid()) && repairList.containsKey(e.getUuid()))
 
 371                 if (duplicate.isPresent()) {
 
 372                     failures.add(String.format("found duplicate uuid=%s", item.getUuid()));
 
 377                 if (failCounter > 0) {
 
 378                     repairList.put(repairedItem.getUuid(), repairedItem.build());
 
 380                     repairList.put(item.getUuid(), item);
 
 385         if (failures.size() > 0) {
 
 386             throw new DataInconsistencyException(new ArrayList<>(repairList.values()),
 
 387                     "inventory list is not consistent;\n" + String.join("\n", failures));
 
 394      * join base with parameters of toJoin (only non null values)
 
 396      * @param base base object
 
 397      * @param toJoin object with new property values
 
 398      * @return new joined object
 
 400     @SuppressWarnings("unused")
 
 401     private NetworkElementConnectionEntity joinNe(NetworkElementConnectionEntity base,
 
 402             NetworkElementConnectionEntity toJoin) {
 
 406         NetworkElementConnectionBuilder builder = new NetworkElementConnectionBuilder(base);
 
 407         if (toJoin != null) {
 
 408             if (toJoin.requireIsRequired() != null) {
 
 409                 builder.setIsRequired(toJoin.requireIsRequired());
 
 411             if (toJoin.getCoreModelCapability() != null) {
 
 412                 builder.setCoreModelCapability(toJoin.getCoreModelCapability());
 
 414             if (toJoin.getDeviceType() != null) {
 
 415                 builder.setDeviceType(toJoin.getDeviceType());
 
 417             if (toJoin.getHost() != null) {
 
 418                 builder.setHost(toJoin.getHost());
 
 420             if (toJoin.getNodeDetails() != null) {
 
 421                 builder.setNodeDetails(toJoin.getNodeDetails());
 
 423             if (toJoin.getPassword() != null) {
 
 424                 builder.setPassword(toJoin.getPassword());
 
 426             if (toJoin.getPort() != null) {
 
 427                 builder.setPort(toJoin.getPort());
 
 429             if (toJoin.getStatus() != null) {
 
 430                 builder.setStatus(toJoin.getStatus());
 
 432             if (toJoin.getUsername() != null) {
 
 433                 builder.setUsername(toJoin.getUsername());
 
 436         return builder.build();
 
 441      * @param networkElementConnectionEntitiy to wirte to DB
 
 442      * @param nodeId Id for this DB element
 
 445     public boolean updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy,
 
 447         return this.networkelementConnectionDB.update(networkElementConnectionEntitiy, nodeId) != null;
 
 448         // NetworkElementConnectionEntity e =
 
 449         // this.networkelementConnectionDB.read(nodeId);
 
 450         // this.networkelementConnectionDB.write(this.joinNe(e,
 
 451         // networkElementConnectionEntitiy), nodeId);
 
 455      * Update after new mountpoint registration
 
 457      * @param networkElementConnectionEntitiy data
 
 458      * @param nodeId of device (mountpoint name)
 
 461     public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy,
 
 463         LOG.info("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy);
 
 464         return this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId,
 
 465                 Arrays.asList("is-required", "username", "password")) != null;
 
 466         // NetworkElementConnectionEntity e =
 
 467         // this.networkelementConnectionDB.read(nodeId);
 
 468         // this.networkelementConnectionDB.write(this.joinNe(e,
 
 469         // networkElementConnectionEntitiy), nodeId);
 
 473     /* please do not remove */
 
 474     // public void cleanNetworkElementConnections() {
 
 475     // this.networkelementConnectionDB.remove(QueryBuilders.matchQuery("is-required",
 
 477     // CreateNetworkElementConnectionInput x = new
 
 478     // CreateNetworkElementConnectionInputBuilder().setStatus(ConnectionLogStatus.Disconnected).build();
 
 479     // this.networkelementConnectionDB.update(x,QueryBuilders.matchAllQuery());
 
 483     public void removeNetworkConnection(String nodeId) {
 
 485         NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
 
 486         if (e != null && (isRequired = e.requireIsRequired()) != null) {
 
 488                 LOG.debug("updating connection status for {} of required ne to disconnected", nodeId);
 
 489                 this.networkelementConnectionDB.update(new UpdateNetworkElementConnectionInputBuilder()
 
 490                         .setStatus(ConnectionLogStatus.Disconnected).build(), nodeId);
 
 492                 LOG.debug("remove networkelement-connection for {} entry because of non-required", nodeId);
 
 493                 this.networkelementConnectionDB.remove(nodeId);
 
 496             LOG.warn("Unable to update connection-status. dbentry for {} not found in networkelement-connection",
 
 504     public int doIndexClean(Date olderAreOutdated) {
 
 506         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
 
 509         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
 
 510         removed += eventRWEventLogDevicemanager.remove(queryEventBase);
 
 512         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
 
 513         removed += eventRWFaultLogDB.remove(queryFaultLog);
 
 515         QueryBuilder queryCMLog = EsCMLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
 
 516         removed += eventRWFCMLogDB.remove(queryCMLog);
 
 522     public long getNumberOfOldObjects(Date olderAreOutdated) {
 
 524         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
 
 525         int numberOfElements = 0;
 
 527         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
 
 528         numberOfElements += eventRWEventLogDevicemanager.doReadAll(queryEventBase).getTotal();
 
 530         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
 
 531         numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal();
 
 533        QueryBuilder queryCMLog = EsCMLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
 
 534         numberOfElements += eventRWFCMLogDB.doReadAll(queryCMLog).getTotal();
 
 536         return numberOfElements;
 
 542      * Verify status of client
 
 544      * @param event that is printed with message
 
 545      * @return true if client is null
 
 547     private boolean assertIfClientNull(Object event) {
 
 548         return assertIfClientNull("No DB, can not write: {}", event);
 
 551     private boolean assertIfClientNullForNodeName(Object object) {
 
 552         return assertIfClientNull("No DB, can not handle node: {}", object);
 
 556      * Verify status of client
 
 558      * @param message to print including {} for object printout.
 
 559      * @return true if client is null
 
 561     private boolean assertIfClientNull(String message, Object object) {
 
 562         if (client == null) {
 
 563             LOG.debug(message, object);
 
 571     private static class EsEventBase {
 
 573          * Query to get older Elements
 
 575          * @param netconfTimeStamp to identify older Elements
 
 576          * @return QueryBuilder for older elements related to timestamp
 
 578         private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
 
 579             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
 
 583     private static class EsFaultLogDevicemanager {
 
 587          * @param netconfTimeStamp to identify query elements older than this timestamp.
 
 588          * @return QueryBuilder for related elements
 
 590         public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
 
 591             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
 
 595     private static class EsCMLogDevicemanager {
 
 599          * @param netconfTimeStamp to identify query elements older than this timestamp.
 
 600          * @return QueryBuilder for related elements
 
 602         public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
 
 603             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
 
 607     public static class EsFaultCurrent {
 
 609          * @param nodeName name of the node
 
 610          * @return query builder
 
 612         public static QueryBuilder getQueryForOneNode(String nodeName) {
 
 613             return QueryBuilders.matchQuery("node-id", nodeName);
 
 616         public static QueryBuilder getQueryForOneNodeAndObjectId(String nodeName, String objectId) {
 
 617             BoolQueryBuilder bq = QueryBuilders.boolQuery();
 
 618             bq.must(QueryBuilders.matchQuery("node-id", nodeName));
 
 619             bq.must(QueryBuilders.matchQuery("object-id", objectId));
 
 625     public List<NetworkElementConnectionEntity> getNetworkElementConnections() {
 
 626         return this.networkelementConnectionDB.doReadAll().getHits();
 
 630     public void doWritePerformanceData(List<PmdataEntity> list) {
 
 632         list.forEach(elem -> {
 
 633             GranularityPeriodType granularityPeriod = nnGetGranularityPeriodType(elem.getGranularityPeriod());
 
 634             // _id": "Sim12600/LP-MWPS-TTP-01/2017-07-04T15:15:00.0+00:00"
 
 635             StringBuffer id = new StringBuffer();
 
 636             DateAndTime date = elem.getTimeStamp();
 
 637             id.append(elem.getNodeName());
 
 639             id.append(elem.getUuidInterface());
 
 641             id.append(date != null ? date.getValue() : "null");
 
 643             switch (granularityPeriod) {
 
 645                     pmData15mDB.write(elem, id.toString());
 
 648                     pmData24hDB.write(elem, id.toString());
 
 652                     LOG.debug("Unknown granularity {} id {}", granularityPeriod, id);
 
 660     GranularityPeriodType nnGetGranularityPeriodType(@Nullable GranularityPeriodType granularityPeriod) {
 
 661         return granularityPeriod != null ? granularityPeriod : GranularityPeriodType.Unknown;
 
 665     public HtDatabaseClient getRawClient() {
 
 670     public void writeGuiCutThroughData(Guicutthrough gcData, String nodeId) {
 
 671         guiCutThroughDB.write(gcData, nodeId);
 
 675     public int clearGuiCutThroughEntriesOfNode(String nodeName) {
 
 676         guiCutThroughDB.remove(nodeName);