b23d882c852d792dc3313ccd93a0bf946ccb2d0c
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data.entity;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Optional;
31 import javax.annotation.Nonnull;
32 import org.eclipse.jdt.annotation.NonNull;
33 import org.eclipse.jdt.annotation.Nullable;
34 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
35 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.BoolQueryBuilder;
36 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
37 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
38 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.RangeQueryBuilder;
39 import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
40 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2;
41 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.ArchiveCleanProvider;
42 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataInconsistencyException;
43 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
44 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
45 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionLogStatus;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentEntity;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughEntity;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInputBuilder;
69 import org.opendaylight.yangtools.yang.common.Uint32;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
72
73 /**
74  * Event service, writing all events into the database into the appropriate index.
75  *
76  * @author herbert
77  */
78 public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvider {
79     private static final Logger LOG = LoggerFactory.getLogger(HtDatabaseEventsService.class);
80
81     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();
82
83     private HtDatabaseClient client;
84     private EsDataObjectReaderWriter2<EventlogEntity> eventRWEventLogDevicemanager;
85     private EsDataObjectReaderWriter2<InventoryEntity> eventRWEquipment;
86     private EsDataObjectReaderWriter2<FaultcurrentEntity> eventRWFaultCurrentDB;
87     private EsDataObjectReaderWriter2<FaultlogEntity> eventRWFaultLogDB;
88     private EsDataObjectReaderWriter2<ConnectionlogEntity> eventRWConnectionLogDB;
89     private final EsDataObjectReaderWriter2<NetworkElementConnectionEntity> networkelementConnectionDB;
90     private final EsDataObjectReaderWriter2<GuicutthroughEntity> guiCutThroughDB;
91     private final EsDataObjectReaderWriter2<PmdataEntity> pmData15mDB;
92     private final EsDataObjectReaderWriter2<PmdataEntity> pmData24hDB;
93
94     @SuppressWarnings("unused")
95     private final ElasticSearchDataProvider dataProvider;
96     // --- Construct and initialize
97
98
99     public HtDatabaseEventsService(HtDatabaseClient client, ElasticSearchDataProvider elasticSearchDataProvider)
100             throws Exception {
101
102         LOG.info("Create {} start", HtDatabaseEventsService.class);
103         this.dataProvider = elasticSearchDataProvider;
104
105         try {
106             // Create control structure
107             this.client = client;
108
109             eventRWEventLogDevicemanager = new EsDataObjectReaderWriter2<>(client, Entity.Eventlog,
110                     EventlogEntity.class, EventlogBuilder.class);
111
112             eventRWEquipment = new EsDataObjectReaderWriter2<>(client, Entity.Inventoryequipment, InventoryEntity.class,
113                     InventoryBuilder.class);
114
115             eventRWFaultCurrentDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultcurrent,
116                     FaultcurrentEntity.class, FaultcurrentBuilder.class);
117
118             eventRWFaultLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultlog, FaultlogEntity.class,
119                     FaultlogBuilder.class);
120
121             eventRWConnectionLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Connectionlog,
122                     ConnectionlogEntity.class, ConnectionlogBuilder.class);
123
124             networkelementConnectionDB = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection,
125                     NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true)
126                             .setEsIdAttributeName("_id");
127
128             guiCutThroughDB = new EsDataObjectReaderWriter2<>(client, Entity.Guicutthrough, GuicutthroughEntity.class,
129                     GuicutthroughBuilder.class);
130
131             pmData15mDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, PmdataEntity.class,
132                     PmdataEntityBuilder.class);
133
134             pmData24hDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance24h, PmdataEntity.class,
135                     PmdataEntityBuilder.class);
136
137         } catch (Exception e) {
138             LOG.error("Can not start database client. Exception: {}", e);
139             throw new Exception("Can not start database client. Exception: {}", e);
140         }
141         LOG.info("Create {} finished. DB Service {} started.", HtDatabaseEventsService.class,
142                 client != null ? "sucessfully" : "not");
143     }
144
145     // --- Function
146
147     // -- Connection log
148     @Override
149     public void writeConnectionLog(ConnectionlogEntity event) {
150         if (assertIfClientNull(event)) {
151             return;
152         }
153         LOG.debug("Write event: {}", event);
154         eventRWConnectionLogDB.write(event, null);
155
156     }
157
158     // -- Event log
159     @Override
160     public void writeEventLog(EventlogEntity event) {
161         if (assertIfClientNull("No client to write {}", event)) {
162             return;
163         }
164
165         LOG.debug("Write event: {}", event.toString());
166         eventRWEventLogDevicemanager.write(event, null);
167     }
168
169
170     // -- Fault log
171
172     @Override
173     public void writeFaultLog(FaultlogEntity fault) {
174         if (assertIfClientNull(fault)) {
175             return;
176         }
177
178         LOG.debug("Write fault to faultlog: {}", fault.toString());
179         eventRWFaultLogDB.write(fault, null);
180     }
181
182     // -- Fault current
183
184     @Override
185     public void updateFaultCurrent(FaultcurrentEntity fault) {
186         if (assertIfClientNull(fault)) {
187             return;
188         }
189
190         if (FaultEntityManager.isManagedAsCurrentProblem(fault)) {
191             if (FaultEntityManager.isNoAlarmIndication(fault)) {
192                 LOG.debug("Remove from currentFaults: {}", fault.toString());
193                 eventRWFaultCurrentDB.remove(FaultEntityManager.genSpecificEsId(fault));
194             } else {
195                 LOG.debug("Write to currentFaults: {}", fault.toString());
196                 eventRWFaultCurrentDB.write(fault, FaultEntityManager.genSpecificEsId(fault));
197             }
198         } else {
199             LOG.debug("Ingnore for currentFaults: {}", fault.toString());
200         }
201     }
202
203     /**
204      * Remove all entries for one node
205      *
206      * @param nodeName contains the mountpointname
207      * @return number of deleted entries
208      */
209     @Override
210     public int clearFaultsCurrentOfNode(String nodeName) {
211         if (assertIfClientNullForNodeName(nodeName)) {
212             return -1;
213         }
214
215         LOG.debug("Remove from currentFaults all faults for node: {}", nodeName);
216         return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNode(nodeName));
217     }
218
219     /**
220      * Remove all entries for one node
221      *
222      * @param nodeName contains the mountpointname
223      * @param objectId of element to be deleted
224      * @return number of deleted entries
225      */
226     @Override
227     public int clearFaultsCurrentOfNodeWithObjectId(String nodeName, String objectId) {
228         if (assertIfClientNullForNodeName(nodeName)) {
229             return -1;
230         }
231
232         LOG.debug("Remove from currentFaults all faults for node/objectId: {}/{}", nodeName, objectId);
233         return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNodeAndObjectId(nodeName, objectId));
234     }
235
236     /**
237      * Deliver list with all mountpoint/node-names in the database.
238      *
239      * @return List of all mountpoint/node-names the had active alarms.
240      */
241     @Override
242     public @Nonnull List<String> getAllNodesWithCurrentAlarms() {
243         if (assertIfClientNull("No DB, can not delete for all nodes", null)) {
244             return new ArrayList<>();
245         }
246
247         LOG.debug("Remove from currentFaults faults for all node");
248         List<String> nodeNames = new ArrayList<>();
249
250         for (FaultcurrentEntity fault : eventRWFaultCurrentDB.doReadAll().getHits()) {
251             String nodeName = fault.getNodeId();
252             if (!nodeNames.contains(nodeName)) {
253                 // this.clearFaultsCurrentOfNode(nodeName); -> Function shifted
254                 nodeNames.add(nodeName);
255             }
256         }
257         return nodeNames;
258     }
259
260     // -- Inventory and equipment current
261
262     /**
263      * write internal equipment to database
264      *
265      * @param internalEquipment with mandatory fields.
266      */
267
268     private void writeInventory(Inventory internalEquipment) {
269
270         if (internalEquipment.getManufacturerIdentifier() == null) {
271             internalEquipment = new InventoryBuilder(internalEquipment).setManufacturerIdentifier("").build();
272         }
273         if (internalEquipment.getDate() == null) {
274             internalEquipment = new InventoryBuilder(internalEquipment).setDate("").build();
275         }
276         eventRWEquipment.write(internalEquipment, internalEquipment.getNodeId() + "/" + internalEquipment.getUuid());
277     }
278
279     /**
280      * write internal equipment to database
281      *
282      * @param nodeId
283      * @param list
284      */
285     @Override
286     public void writeInventory(String nodeId, List<Inventory> list) {
287
288         try {
289             checkConsistency(nodeId, list);
290         } catch (DataInconsistencyException e) {
291             LOG.warn("inventory list for node {} is not consistent", nodeId, e);
292             list = e.getRepairedList();
293         }
294
295         for (Inventory internalEquipment : list) {
296             this.writeInventory(internalEquipment);
297         }
298     }
299
300     private static void checkConsistency(String nodeId, List<Inventory> list) throws DataInconsistencyException {
301         final String UNBOUND_INVENTORY_UUID = "unbound";
302         List<String> failures = new ArrayList<>();
303         long treeLevel;
304         int failCounter = 0;
305         Map<String, Inventory> repairList = new HashMap<>();
306         InventoryBuilder repairedItem;
307         InventoryBuilder unboundItem = new InventoryBuilder().setNodeId(nodeId).setUuid(UNBOUND_INVENTORY_UUID)
308                 .setTreeLevel(Uint32.valueOf(0));;
309         for (Inventory item : list) {
310             repairedItem = new InventoryBuilder(item);
311             //check missing tree-level
312             if (!nodeId.equals(item.getNodeId())) {
313                 failures.add(String.format("missing node-id for equipment(uuid=%s)", item.getUuid()));
314                 repairedItem.setNodeId(nodeId);
315                 failCounter++;
316             }
317             if (item.getTreeLevel() == null) {
318                 failures.add(String.format("missing tree-level for equipment(uuid=%s)", item.getUuid()));
319                 repairedItem.setTreeLevel(Uint32.valueOf(1));
320                 failCounter++;
321
322             } else {
323                 treeLevel = item.getTreeLevel().longValue();
324                 if (treeLevel > 0) {
325                     //check non root elem and missing parent
326                     if (item.getParentUuid() == null) {
327                         failures.add(String.format("Non root level element (uuid=%s) has to have a parent element",
328                                 item.getUuid()));
329                         failCounter++;
330                         repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
331                         repairList.put(unboundItem.getUuid(), unboundItem.build());
332                     }
333                     //check that parent exists in list and is tree-level -1
334                     else {
335                         Optional<Inventory> parent =
336                                 list.stream().filter(e -> item.getParentUuid().equals(e.getUuid())).findFirst();
337                         if (parent.isEmpty()) {
338                             failures.add(String.format("no parent found for uuid=%s with parent-uuid=%s",
339                                     item.getUuid(), item.getParentUuid()));
340                             repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
341                             failCounter++;
342                         }
343                     }
344                 }
345                 //check for duplicated uui
346                 Optional<Inventory> duplicate = list
347                         .stream().filter(e -> !item.equals(e) && item.getUuid() != null
348                                 && item.getUuid().equals(e.getUuid()) && repairList.containsKey(e.getUuid()))
349                         .findFirst();
350                 if (duplicate.isPresent()) {
351                     failures.add(String.format("found duplicate uuid=%s", item.getUuid()));
352                     failCounter++;
353                     continue;
354
355                 }
356                 if (failCounter > 0) {
357                     repairList.put(repairedItem.getUuid(), repairedItem.build());
358                 } else {
359                     repairList.put(item.getUuid(), item);
360                 }
361             }
362         }
363
364         if (!failures.isEmpty()) {
365             throw new DataInconsistencyException(new ArrayList<>(repairList.values()),
366                     "inventory list is not consistent;\n" + String.join("\n", failures));
367         }
368     }
369
370     // -- Networkelement
371
372
373     /**
374      * join base with parameters of toJoin (only non null values)
375      *
376      * @param base base object
377      * @param toJoin object with new property values
378      * @return new joined object
379      */
380     @SuppressWarnings("unused")
381     private NetworkElementConnectionEntity joinNe(NetworkElementConnectionEntity base,
382             NetworkElementConnectionEntity toJoin) {
383         if (base == null) {
384             return toJoin;
385         }
386         NetworkElementConnectionBuilder builder = new NetworkElementConnectionBuilder(base);
387         if (toJoin != null) {
388             if (toJoin.isIsRequired() != null) {
389                 builder.setIsRequired(toJoin.isIsRequired());
390             }
391             if (toJoin.getCoreModelCapability() != null) {
392                 builder.setCoreModelCapability(toJoin.getCoreModelCapability());
393             }
394             if (toJoin.getDeviceType() != null) {
395                 builder.setDeviceType(toJoin.getDeviceType());
396             }
397             if (toJoin.getHost() != null) {
398                 builder.setHost(toJoin.getHost());
399             }
400             if (toJoin.getNodeDetails() != null) {
401                 builder.setNodeDetails(toJoin.getNodeDetails());
402             }
403             if (toJoin.getPassword() != null) {
404                 builder.setPassword(toJoin.getPassword());
405             }
406             if (toJoin.getPort() != null) {
407                 builder.setPort(toJoin.getPort());
408             }
409             if (toJoin.getStatus() != null) {
410                 builder.setStatus(toJoin.getStatus());
411             }
412             if (toJoin.getUsername() != null) {
413                 builder.setUsername(toJoin.getUsername());
414             }
415         }
416         return builder.build();
417     }
418
419     /**
420      *
421      * @param networkElementConnectionEntitiy to wirte to DB
422      * @param nodeId Id for this DB element
423      */
424     @Override
425     public boolean updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy,
426             String nodeId) {
427         return this.networkelementConnectionDB.update(networkElementConnectionEntitiy, nodeId) != null;
428         //              NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
429         //              this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId);
430     }
431
432     /**
433      * Update after new mountpoint registration
434      *
435      * @param networkElementConnectionEntitiy data
436      * @param nodeId of device (mountpoint name)
437      */
438     @Override
439     public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy,
440             String nodeId) {
441         LOG.info("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy);
442         return this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId,
443                 Arrays.asList("is-required", "username", "password")) != null;
444         //              NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
445         //              this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId);
446
447     }
448
449     /* please do not remove */
450     //    public void cleanNetworkElementConnections() {
451     //        this.networkelementConnectionDB.remove(QueryBuilders.matchQuery("is-required", false));
452     //        CreateNetworkElementConnectionInput x = new CreateNetworkElementConnectionInputBuilder().setStatus(ConnectionLogStatus.Disconnected).build();
453     //        this.networkelementConnectionDB.update(x,QueryBuilders.matchAllQuery());
454     //    }
455
456     @Override
457     public void removeNetworkConnection(String nodeId) {
458         Boolean isRequired;
459         NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
460         if (e != null && (isRequired = e.isIsRequired()) != null) {
461             if (isRequired) {
462                 LOG.debug("updating connection status for {} of required ne to disconnected", nodeId);
463                 this.networkelementConnectionDB.update(new UpdateNetworkElementConnectionInputBuilder()
464                         .setStatus(ConnectionLogStatus.Disconnected).build(), nodeId);
465             } else {
466                 LOG.debug("remove networkelement-connection for {} entry because of non-required", nodeId);
467                 this.networkelementConnectionDB.remove(nodeId);
468             }
469         } else {
470             LOG.warn("Unable to update connection-status. dbentry for {} not found in networkelement-connection",
471                     nodeId);
472         }
473     }
474
475     // -- Multiple areas
476
477     @Override
478     public int doIndexClean(Date olderAreOutdated) {
479
480         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
481         int removed = 0;
482
483         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
484         removed += eventRWEventLogDevicemanager.remove(queryEventBase);
485
486         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
487         removed += eventRWFaultLogDB.remove(queryFaultLog);
488         return removed;
489     }
490
491     @Override
492     public int getNumberOfOldObjects(Date olderAreOutdated) {
493
494         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
495         int numberOfElements = 0;
496
497         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
498         numberOfElements += eventRWEventLogDevicemanager.doReadAll(queryEventBase).getTotal();
499
500         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
501         numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal();
502
503         return numberOfElements;
504     }
505
506     // -- Helper
507
508     /**
509      * Verify status of client
510      *
511      * @param event that is printed with message
512      * @return true if client is null
513      */
514     private boolean assertIfClientNull(Object event) {
515         return assertIfClientNull("No DB, can not write: {}", event);
516     }
517
518     private boolean assertIfClientNullForNodeName(Object object) {
519         return assertIfClientNull("No DB, can not handle node: {}", object);
520     }
521
522     /**
523      * Verify status of client
524      *
525      * @param message to print including {} for object printout.
526      * @return true if client is null
527      */
528     private boolean assertIfClientNull(String message, Object object) {
529         if (client == null) {
530             LOG.debug(message, object);
531             return true;
532         }
533         return false;
534     }
535
536     // ### sub classes
537
538
539     private static class EsEventBase {
540         /**
541          * Query to get older Elements
542          *
543          * @param netconfTimeStamp to identify older Elements
544          * @return QueryBuilder for older elements related to timestamp
545          */
546         private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
547             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
548         }
549     }
550     private static class EsFaultLogDevicemanager {
551         /**
552          * Get older Elements
553          *
554          * @param netconfTimeStamp to identify query elements older than this timestamp.
555          * @return QueryBuilder for related elements
556          */
557         public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
558             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
559         }
560     }
561     public static class EsFaultCurrent {
562         /**
563          * @param nodeName name of the node
564          * @return query builder
565          */
566         public static QueryBuilder getQueryForOneNode(String nodeName) {
567             return QueryBuilders.matchQuery("node-id", nodeName);
568         }
569
570         public static QueryBuilder getQueryForOneNodeAndObjectId(String nodeName, String objectId) {
571             BoolQueryBuilder bq = QueryBuilders.boolQuery();
572             bq.must(QueryBuilders.matchQuery("node-id", nodeName));
573             bq.must(QueryBuilders.matchQuery("object-id", objectId));
574             return bq;
575         }
576     }
577
578     @Override
579     public List<NetworkElementConnectionEntity> getNetworkElementConnections() {
580         return this.networkelementConnectionDB.doReadAll().getHits();
581     }
582
583     @Override
584     public void doWritePerformanceData(List<PmdataEntity> list) {
585
586         list.forEach(elem -> {
587             GranularityPeriodType granularityPeriod = nnGetGranularityPeriodType(elem.getGranularityPeriod());
588             //_id": "Sim12600/LP-MWPS-TTP-01/2017-07-04T15:15:00.0+00:00"
589             StringBuffer id = new StringBuffer();
590             DateAndTime date = elem.getTimeStamp();
591             id.append(elem.getNodeName());
592             id.append("/");
593             id.append(elem.getUuidInterface());
594             id.append("/");
595             id.append(date != null ? date.getValue() : "null");
596
597             switch (granularityPeriod) {
598                 case Period15Min:
599                     pmData15mDB.write(elem, id.toString());
600                     break;
601                 case Period24Hours:
602                     pmData24hDB.write(elem, id.toString());
603                     break;
604                 case Unknown:
605                 default:
606                     LOG.debug("Unknown granularity {} id {}", granularityPeriod, id);
607                     break;
608             }
609         });
610
611     }
612
613     @NonNull
614     GranularityPeriodType nnGetGranularityPeriodType(@Nullable GranularityPeriodType granularityPeriod) {
615         return granularityPeriod != null ? granularityPeriod : GranularityPeriodType.Unknown;
616     }
617
618     @Override
619     public HtDatabaseClient getRawClient() {
620         return this.client;
621     }
622
623     @Override
624     public void writeGuiCutThroughData(Guicutthrough gcData, String nodeId) {
625         guiCutThroughDB.write(gcData, nodeId);
626     }
627
628 }