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