ea3296acb9205b0221f40a63eaa93dd67579ca39
[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 static final int ROOT_TREE_LEVEL = 0;
84
85     private HtDatabaseClient client;
86     private EsDataObjectReaderWriter2<EventlogEntity> eventRWEventLogDevicemanager;
87     private EsDataObjectReaderWriter2<InventoryEntity> eventRWEquipment;
88     private EsDataObjectReaderWriter2<FaultcurrentEntity> eventRWFaultCurrentDB;
89     private EsDataObjectReaderWriter2<FaultlogEntity> eventRWFaultLogDB;
90     private EsDataObjectReaderWriter2<ConnectionlogEntity> eventRWConnectionLogDB;
91     private final EsDataObjectReaderWriter2<NetworkElementConnectionEntity> networkelementConnectionDB;
92     private final EsDataObjectReaderWriter2<GuicutthroughEntity> guiCutThroughDB;
93     private final EsDataObjectReaderWriter2<PmdataEntity> pmData15mDB;
94     private final EsDataObjectReaderWriter2<PmdataEntity> pmData24hDB;
95
96     @SuppressWarnings("unused")
97     private final DatabaseDataProvider dataProvider;
98     // --- Construct and initialize
99
100     public HtDatabaseEventsService(HtDatabaseClient client, DatabaseDataProvider elasticSearchDataProvider)
101             throws Exception {
102
103         LOG.info("Create {} start", HtDatabaseEventsService.class);
104         this.dataProvider = elasticSearchDataProvider;
105
106         try {
107             // Create control structure
108             this.client = client;
109
110             eventRWEventLogDevicemanager = new EsDataObjectReaderWriter2<>(client, Entity.Eventlog,
111                     EventlogEntity.class, EventlogBuilder.class);
112
113             eventRWEquipment = new EsDataObjectReaderWriter2<>(client, Entity.Inventoryequipment, InventoryEntity.class,
114                     InventoryBuilder.class);
115
116             eventRWFaultCurrentDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultcurrent,
117                     FaultcurrentEntity.class, FaultcurrentBuilder.class);
118
119             eventRWFaultLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultlog, FaultlogEntity.class,
120                     FaultlogBuilder.class);
121
122             eventRWConnectionLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Connectionlog,
123                     ConnectionlogEntity.class, ConnectionlogBuilder.class);
124
125             networkelementConnectionDB = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection,
126                     NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true)
127                             .setEsIdAttributeName("_id");
128
129             guiCutThroughDB = new EsDataObjectReaderWriter2<>(client, Entity.Guicutthrough, GuicutthroughEntity.class,
130                     GuicutthroughBuilder.class);
131
132             pmData15mDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, PmdataEntity.class,
133                     PmdataEntityBuilder.class);
134
135             pmData24hDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance24h, PmdataEntity.class,
136                     PmdataEntityBuilder.class);
137
138         } catch (Exception e) {
139             LOG.error("Can not start database client. Exception: {}", e);
140             throw new Exception("Can not start database client. Exception: {}", e);
141         }
142         LOG.info("Create {} finished. DB Service {} started.", HtDatabaseEventsService.class,
143                 client != null ? "sucessfully" : "not");
144     }
145
146     // --- Function
147
148     // -- Connection log
149     @Override
150     public void writeConnectionLog(ConnectionlogEntity event) {
151         if (assertIfClientNull(event)) {
152             return;
153         }
154         LOG.debug("Write event: {}", event);
155         eventRWConnectionLogDB.write(event, null);
156
157     }
158
159     // -- Event log
160     @Override
161     public void writeEventLog(EventlogEntity event) {
162         if (assertIfClientNull("No client to write {}", event)) {
163             return;
164         }
165
166         LOG.debug("Write event: {}", event.toString());
167         eventRWEventLogDevicemanager.write(event, null);
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 for bad node-id
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             // check missing tree-level
318             if (item.getTreeLevel() == null) {
319                 failures.add(String.format("missing tree-level for equipment(uuid=%s)", item.getUuid()));
320                 repairedItem.setTreeLevel(Uint32.valueOf(ROOT_TREE_LEVEL));
321                 failCounter++;
322
323             } else {
324                 treeLevel = item.getTreeLevel().longValue();
325                 if (treeLevel > ROOT_TREE_LEVEL) {
326                     // check non root elem and missing parent
327                     if (item.getParentUuid() == null) {
328                         failures.add(String.format("Non root level element (uuid=%s) has to have a parent element",
329                                 item.getUuid()));
330                         failCounter++;
331                         repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
332                         repairList.put(unboundItem.getUuid(), unboundItem.build());
333                     }
334                     // check that parent exists in list and is tree-level -1
335                     else {
336                         Optional<Inventory> parent =
337                                 list.stream().filter(e -> item.getParentUuid().equals(e.getUuid())).findFirst();
338                         if (parent.isEmpty()) {
339                             failures.add(String.format("no parent found for uuid=%s with parent-uuid=%s",
340                                     item.getUuid(), item.getParentUuid()));
341                             repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
342                             failCounter++;
343                         }
344                     }
345                 }
346                 // check for duplicated uui
347                 Optional<Inventory> duplicate = list
348                         .stream().filter(e -> !item.equals(e) && item.getUuid() != null
349                                 && item.getUuid().equals(e.getUuid()) && repairList.containsKey(e.getUuid()))
350                         .findFirst();
351                 if (duplicate.isPresent()) {
352                     failures.add(String.format("found duplicate uuid=%s", item.getUuid()));
353                     failCounter++;
354                     continue;
355
356                 }
357                 if (failCounter > 0) {
358                     repairList.put(repairedItem.getUuid(), repairedItem.build());
359                 } else {
360                     repairList.put(item.getUuid(), item);
361                 }
362             }
363         }
364
365         if (failures.size() > 0) {
366             throw new DataInconsistencyException(new ArrayList<>(repairList.values()),
367                     "inventory list is not consistent;\n" + String.join("\n", failures));
368         }
369     }
370
371     // -- Networkelement
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 =
429         // this.networkelementConnectionDB.read(nodeId);
430         // this.networkelementConnectionDB.write(this.joinNe(e,
431         // networkElementConnectionEntitiy), nodeId);
432     }
433
434     /**
435      * Update after new mountpoint registration
436      *
437      * @param networkElementConnectionEntitiy data
438      * @param nodeId of device (mountpoint name)
439      */
440     @Override
441     public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy,
442             String nodeId) {
443         LOG.info("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy);
444         return this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId,
445                 Arrays.asList("is-required", "username", "password")) != null;
446         // NetworkElementConnectionEntity e =
447         // this.networkelementConnectionDB.read(nodeId);
448         // this.networkelementConnectionDB.write(this.joinNe(e,
449         // networkElementConnectionEntitiy), nodeId);
450
451     }
452
453     /* please do not remove */
454     // public void cleanNetworkElementConnections() {
455     // this.networkelementConnectionDB.remove(QueryBuilders.matchQuery("is-required",
456     // false));
457     // CreateNetworkElementConnectionInput x = new
458     // CreateNetworkElementConnectionInputBuilder().setStatus(ConnectionLogStatus.Disconnected).build();
459     // this.networkelementConnectionDB.update(x,QueryBuilders.matchAllQuery());
460     // }
461
462     @Override
463     public void removeNetworkConnection(String nodeId) {
464         Boolean isRequired;
465         NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
466         if (e != null && (isRequired = e.isIsRequired()) != null) {
467             if (isRequired) {
468                 LOG.debug("updating connection status for {} of required ne to disconnected", nodeId);
469                 this.networkelementConnectionDB.update(new UpdateNetworkElementConnectionInputBuilder()
470                         .setStatus(ConnectionLogStatus.Disconnected).build(), nodeId);
471             } else {
472                 LOG.debug("remove networkelement-connection for {} entry because of non-required", nodeId);
473                 this.networkelementConnectionDB.remove(nodeId);
474             }
475         } else {
476             LOG.warn("Unable to update connection-status. dbentry for {} not found in networkelement-connection",
477                     nodeId);
478         }
479     }
480
481     // -- Multiple areas
482
483     @Override
484     public int doIndexClean(Date olderAreOutdated) {
485
486         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
487         int removed = 0;
488
489         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
490         removed += eventRWEventLogDevicemanager.remove(queryEventBase);
491
492         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
493         removed += eventRWFaultLogDB.remove(queryFaultLog);
494         return removed;
495     }
496
497     @Override
498     public long getNumberOfOldObjects(Date olderAreOutdated) {
499
500         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
501         int numberOfElements = 0;
502
503         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
504         numberOfElements += eventRWEventLogDevicemanager.doReadAll(queryEventBase).getTotal();
505
506         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
507         numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal();
508
509         return numberOfElements;
510     }
511
512     // -- Helper
513
514     /**
515      * Verify status of client
516      *
517      * @param event that is printed with message
518      * @return true if client is null
519      */
520     private boolean assertIfClientNull(Object event) {
521         return assertIfClientNull("No DB, can not write: {}", event);
522     }
523
524     private boolean assertIfClientNullForNodeName(Object object) {
525         return assertIfClientNull("No DB, can not handle node: {}", object);
526     }
527
528     /**
529      * Verify status of client
530      *
531      * @param message to print including {} for object printout.
532      * @return true if client is null
533      */
534     private boolean assertIfClientNull(String message, Object object) {
535         if (client == null) {
536             LOG.debug(message, object);
537             return true;
538         }
539         return false;
540     }
541
542     // ### sub classes
543
544     private static class EsEventBase {
545         /**
546          * Query to get older Elements
547          *
548          * @param netconfTimeStamp to identify older Elements
549          * @return QueryBuilder for older elements related to timestamp
550          */
551         private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
552             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
553         }
554     }
555
556     private static class EsFaultLogDevicemanager {
557         /**
558          * Get older Elements
559          *
560          * @param netconfTimeStamp to identify query elements older than this timestamp.
561          * @return QueryBuilder for related elements
562          */
563         public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
564             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
565         }
566     }
567
568     public static class EsFaultCurrent {
569         /**
570          * @param nodeName name of the node
571          * @return query builder
572          */
573         public static QueryBuilder getQueryForOneNode(String nodeName) {
574             return QueryBuilders.matchQuery("node-id", nodeName);
575         }
576
577         public static QueryBuilder getQueryForOneNodeAndObjectId(String nodeName, String objectId) {
578             BoolQueryBuilder bq = QueryBuilders.boolQuery();
579             bq.must(QueryBuilders.matchQuery("node-id", nodeName));
580             bq.must(QueryBuilders.matchQuery("object-id", objectId));
581             return bq;
582         }
583     }
584
585     @Override
586     public List<NetworkElementConnectionEntity> getNetworkElementConnections() {
587         return this.networkelementConnectionDB.doReadAll().getHits();
588     }
589
590     @Override
591     public void doWritePerformanceData(List<PmdataEntity> list) {
592
593         list.forEach(elem -> {
594             GranularityPeriodType granularityPeriod = nnGetGranularityPeriodType(elem.getGranularityPeriod());
595             // _id": "Sim12600/LP-MWPS-TTP-01/2017-07-04T15:15:00.0+00:00"
596             StringBuffer id = new StringBuffer();
597             DateAndTime date = elem.getTimeStamp();
598             id.append(elem.getNodeName());
599             id.append("/");
600             id.append(elem.getUuidInterface());
601             id.append("/");
602             id.append(date != null ? date.getValue() : "null");
603
604             switch (granularityPeriod) {
605                 case Period15Min:
606                     pmData15mDB.write(elem, id.toString());
607                     break;
608                 case Period24Hours:
609                     pmData24hDB.write(elem, id.toString());
610                     break;
611                 case Unknown:
612                 default:
613                     LOG.debug("Unknown granularity {} id {}", granularityPeriod, id);
614                     break;
615             }
616         });
617
618     }
619
620     @NonNull
621     GranularityPeriodType nnGetGranularityPeriodType(@Nullable GranularityPeriodType granularityPeriod) {
622         return granularityPeriod != null ? granularityPeriod : GranularityPeriodType.Unknown;
623     }
624
625     @Override
626     public HtDatabaseClient getRawClient() {
627         return this.client;
628     }
629
630     @Override
631     public void writeGuiCutThroughData(Guicutthrough gcData, String nodeId) {
632         guiCutThroughDB.write(gcData, nodeId);
633     }
634
635     @Override
636     public int clearGuiCutThroughEntriesOfNode(String nodeName) {
637         guiCutThroughDB.remove(nodeName);
638         return 0;
639     }
640
641 }