1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util;
20 import java.util.Date;
21 import java.util.concurrent.TimeUnit;
22 import org.onap.ccsdk.features.sdnr.wt.base.netconf.util.NetconfTimeStamp;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
31 public class DBCleanServiceHelper {
33 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
35 private final DataProvider databaseEventService;
38 * Helper to fill data into the database
39 * @param deviceManager devicemanger to get services
41 public DBCleanServiceHelper(DeviceManagerImpl deviceManager) {
42 this.databaseEventService = deviceManager.getDatabaseClientEvents();
46 * Write data into database with specific date and content profile.
47 * @param number of data to be written for each log
48 * @param days starting day, relative to actual date
49 * @param hours starting hour ... increased by one hour for each write
50 * @return integer with the amount of written data
52 public int writeDataToLogs(int number, int days, int hours) {
54 for (Integer t=0; t < number; t++) { //Test "sdnevents", "eventlog"
55 ObjectCreationNotificationXml notificationXml = new ObjectCreationNotificationXml(
56 "Testpoint"+t, t, getInternalDateAndTime(days, hours+t), "ObjectId"+t);
57 databaseEventService.writeConnectionLog(notificationXml.getConnectionlogEntity());
61 for (Integer t=0; t < number; t++) { //Test "sdnevents", "faultlog"
62 ProblemNotificationXml fault = new ProblemNotificationXml(
63 "ProblemNode"+t, "Problemuuid", "Problemname", InternalSeverity.Major, t, getInternalDateAndTime(days, hours+t));
64 databaseEventService.writeFaultLog(fault.getFaultlog(SourceType.Unknown));
71 /**************************************************************
75 private InternalDateAndTime getInternalDateAndTime(int days, int hours) {
76 Date actual = new Date(new Date().getTime() - TimeUnit.MILLISECONDS.convert(days, TimeUnit.DAYS) - TimeUnit.MILLISECONDS.convert(hours, TimeUnit.HOURS));
77 InternalDateAndTime timeStamp = InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp(actual));