f680edddfae4e87a766e9e0a5e347537dd0e3d99
[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     @Override
269     public void writeInventory(Inventory internalEquipment) {
270
271         if (internalEquipment.getManufacturerIdentifier() == null) {
272             internalEquipment = new InventoryBuilder(internalEquipment).setManufacturerIdentifier("").build();
273         }
274         if (internalEquipment.getDate() == null) {
275             internalEquipment = new InventoryBuilder(internalEquipment).setDate("").build();
276         }
277         eventRWEquipment.write(internalEquipment, internalEquipment.getNodeId() + "/" + internalEquipment.getUuid());
278     }
279
280     /**
281      * write internal equipment to database
282      *
283      * @param nodeId
284      * @param list
285      */
286     @Override
287     public void writeInventory(String nodeId, List<Inventory> list) {
288
289         try {
290             checkConsistency(nodeId, list);
291         } catch (DataInconsistencyException e) {
292             LOG.warn("inventory list for node {} is not consistent", nodeId, e);
293             list = e.getRepairedList();
294         }
295
296         for (Inventory internalEquipment : list) {
297             this.writeInventory(internalEquipment);
298         }
299     }
300
301     private static void checkConsistency(String nodeId, List<Inventory> list) throws DataInconsistencyException {
302         final String UNBOUND_INVENTORY_UUID = "unbound";
303         List<String> failures = new ArrayList<>();
304         long treeLevel;
305         int failCounter = 0;
306         Map<String, Inventory> repairList = new HashMap<>();
307         InventoryBuilder repairedItem;
308         InventoryBuilder unboundItem = new InventoryBuilder().setNodeId(nodeId).setUuid(UNBOUND_INVENTORY_UUID)
309                 .setTreeLevel(Uint32.valueOf(0));;
310         for (Inventory item : list) {
311             repairedItem = new InventoryBuilder(item);
312             //check missing tree-level
313             if (!nodeId.equals(item.getNodeId())) {
314                 failures.add(String.format("missing node-id for equipment(uuid=%s)", item.getUuid()));
315                 repairedItem.setNodeId(nodeId);
316                 failCounter++;
317             }
318             if (item.getTreeLevel() == null) {
319                 failures.add(String.format("missing tree-level for equipment(uuid=%s)", item.getUuid()));
320                 repairedItem.setTreeLevel(Uint32.valueOf(1));
321                 failCounter++;
322
323             } else {
324                 treeLevel = item.getTreeLevel().longValue();
325                 if (treeLevel > 0) {
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     /**
375      * join base with parameters of toJoin (only non null values)
376      *
377      * @param base base object
378      * @param toJoin object with new property values
379      * @return new joined object
380      */
381     @SuppressWarnings("unused")
382     private NetworkElementConnectionEntity joinNe(NetworkElementConnectionEntity base,
383             NetworkElementConnectionEntity toJoin) {
384         if (base == null) {
385             return toJoin;
386         }
387         NetworkElementConnectionBuilder builder = new NetworkElementConnectionBuilder(base);
388         if (toJoin != null) {
389             if (toJoin.isIsRequired() != null) {
390                 builder.setIsRequired(toJoin.isIsRequired());
391             }
392             if (toJoin.getCoreModelCapability() != null) {
393                 builder.setCoreModelCapability(toJoin.getCoreModelCapability());
394             }
395             if (toJoin.getDeviceType() != null) {
396                 builder.setDeviceType(toJoin.getDeviceType());
397             }
398             if (toJoin.getHost() != null) {
399                 builder.setHost(toJoin.getHost());
400             }
401             if (toJoin.getNodeDetails() != null) {
402                 builder.setNodeDetails(toJoin.getNodeDetails());
403             }
404             if (toJoin.getPassword() != null) {
405                 builder.setPassword(toJoin.getPassword());
406             }
407             if (toJoin.getPort() != null) {
408                 builder.setPort(toJoin.getPort());
409             }
410             if (toJoin.getStatus() != null) {
411                 builder.setStatus(toJoin.getStatus());
412             }
413             if (toJoin.getUsername() != null) {
414                 builder.setUsername(toJoin.getUsername());
415             }
416         }
417         return builder.build();
418     }
419
420     /**
421      *
422      * @param networkElementConnectionEntitiy to wirte to DB
423      * @param nodeId Id for this DB element
424      */
425     @Override
426     public boolean updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy,
427             String nodeId) {
428         return this.networkelementConnectionDB.update(networkElementConnectionEntitiy, nodeId) != null;
429         //              NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
430         //              this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId);
431     }
432
433     /**
434      * Update after new mountpoint registration
435      *
436      * @param networkElementConnectionEntitiy data
437      * @param nodeId of device (mountpoint name)
438      */
439     @Override
440     public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy,
441             String nodeId) {
442         LOG.info("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy);
443         return this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId,
444                 Arrays.asList("is-required", "username", "password")) != null;
445         //              NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
446         //              this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId);
447
448     }
449
450     /* please do not remove */
451     //    public void cleanNetworkElementConnections() {
452     //        this.networkelementConnectionDB.remove(QueryBuilders.matchQuery("is-required", false));
453     //        CreateNetworkElementConnectionInput x = new CreateNetworkElementConnectionInputBuilder().setStatus(ConnectionLogStatus.Disconnected).build();
454     //        this.networkelementConnectionDB.update(x,QueryBuilders.matchAllQuery());
455     //    }
456
457     @Override
458     public void removeNetworkConnection(String nodeId) {
459         Boolean isRequired;
460         NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId);
461         if (e != null && (isRequired = e.isIsRequired()) != null) {
462             if (isRequired) {
463                 LOG.debug("updating connection status for {} of required ne to disconnected", nodeId);
464                 this.networkelementConnectionDB.update(new UpdateNetworkElementConnectionInputBuilder()
465                         .setStatus(ConnectionLogStatus.Disconnected).build(), nodeId);
466             } else {
467                 LOG.debug("remove networkelement-connection for {} entry because of non-required", nodeId);
468                 this.networkelementConnectionDB.remove(nodeId);
469             }
470         } else {
471             LOG.warn("Unable to update connection-status. dbentry for {} not found in networkelement-connection",
472                     nodeId);
473         }
474     }
475
476     // -- Multiple areas
477
478     @Override
479     public int doIndexClean(Date olderAreOutdated) {
480
481         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
482         int removed = 0;
483
484         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
485         removed += eventRWEventLogDevicemanager.remove(queryEventBase);
486
487         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
488         removed += eventRWFaultLogDB.remove(queryFaultLog);
489         return removed;
490     }
491
492     @Override
493     public int getNumberOfOldObjects(Date olderAreOutdated) {
494
495         String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated);
496         int numberOfElements = 0;
497
498         QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp);
499         numberOfElements += eventRWEventLogDevicemanager.doReadAll(queryEventBase).getTotal();
500
501         QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp);
502         numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal();
503
504         return numberOfElements;
505     }
506
507     // -- Helper
508
509     /**
510      * Verify status of client
511      *
512      * @param event that is printed with message
513      * @return true if client is null
514      */
515     private boolean assertIfClientNull(Object event) {
516         return assertIfClientNull("No DB, can not write: {}", event);
517     }
518
519     private boolean assertIfClientNullForNodeName(Object object) {
520         return assertIfClientNull("No DB, can not handle node: {}", object);
521     }
522
523     /**
524      * Verify status of client
525      *
526      * @param message to print including {} for object printout.
527      * @return true if client is null
528      */
529     private boolean assertIfClientNull(String message, Object object) {
530         if (client == null) {
531             LOG.debug(message, object);
532             return true;
533         }
534         return false;
535     }
536
537     // ### sub classes
538
539
540     private static class EsEventBase {
541         /**
542          * Query to get older Elements
543          *
544          * @param netconfTimeStamp to identify older Elements
545          * @return QueryBuilder for older elements related to timestamp
546          */
547         private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
548             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
549         }
550     }
551     private static class EsFaultLogDevicemanager {
552         /**
553          * Get older Elements
554          *
555          * @param netconfTimeStamp to identify query elements older than this timestamp.
556          * @return QueryBuilder for related elements
557          */
558         public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
559             return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
560         }
561     }
562     public static class EsFaultCurrent {
563         /**
564          * @param nodeName name of the node
565          * @return query builder
566          */
567         public static QueryBuilder getQueryForOneNode(String nodeName) {
568             return QueryBuilders.matchQuery("node-id", nodeName);
569         }
570
571         public static QueryBuilder getQueryForOneNodeAndObjectId(String nodeName, String objectId) {
572             BoolQueryBuilder bq = QueryBuilders.boolQuery();
573             bq.must(QueryBuilders.matchQuery("node-id", nodeName));
574             bq.must(QueryBuilders.matchQuery("object-id", objectId));
575             return bq;
576         }
577     }
578
579     @Override
580     public List<NetworkElementConnectionEntity> getNetworkElementConnections() {
581         return this.networkelementConnectionDB.doReadAll().getHits();
582     }
583
584     @Override
585     public void doWritePerformanceData(List<PmdataEntity> list) {
586
587         list.forEach(elem -> {
588             GranularityPeriodType granularityPeriod = nnGetGranularityPeriodType(elem.getGranularityPeriod());
589             //_id": "Sim12600/LP-MWPS-TTP-01/2017-07-04T15:15:00.0+00:00"
590             StringBuffer id = new StringBuffer();
591             DateAndTime date = elem.getTimeStamp();
592             id.append(elem.getNodeName());
593             id.append("/");
594             id.append(elem.getUuidInterface());
595             id.append("/");
596             id.append(date != null ? date.getValue() : "null");
597
598             switch (granularityPeriod) {
599                 case Period15Min:
600                     pmData15mDB.write(elem, id.toString());
601                     break;
602                 case Period24Hours:
603                     pmData24hDB.write(elem, id.toString());
604                     break;
605                 case Unknown:
606                 default:
607                     LOG.debug("Unknown granularity {} id {}", granularityPeriod, id);
608                     break;
609             }
610         });
611
612     }
613
614     @NonNull
615     GranularityPeriodType nnGetGranularityPeriodType(@Nullable GranularityPeriodType granularityPeriod) {
616         return granularityPeriod != null ? granularityPeriod : GranularityPeriodType.Unknown;
617     }
618
619     @Override
620     public HtDatabaseClient getRawClient() {
621         return this.client;
622     }
623
624     @Override
625     public void writeGuiCutThroughData(Guicutthrough gcData, String nodeId) {
626         guiCutThroughDB.write(gcData, nodeId);
627     }
628
629 }