diff options
Diffstat (limited to 'sdnr/wt/data-provider')
14 files changed, 692 insertions, 103 deletions
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java index 63d92b64d..1192950e6 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java @@ -371,7 +371,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid * @return QueryBuilder for older elements related to timestamp */ private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { - return new RangeQueryBuilder("event.timeStamp").lte(netconfTimeStamp); + return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp); } } private static class EsFaultLogDevicemanager { diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java index bc61e81e5..9e576857b 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java @@ -61,32 +61,35 @@ public class MediatorServerDataProvider implements AutoCloseable { @Override public void run() { isRunning = true; - SearchResult<Data> result = MediatorServerDataProvider.this.mediatorserverRW.doReadAll(); - List<Data> data = result.getHits(); - for (Data item : data) { - MediatorServerDataProvider.this.entries.put(item.getId(), item); - } + runIt(); isRunning = false; } }; + private void runIt() { + SearchResult<Data> result = MediatorServerDataProvider.this.mediatorserverRW.doReadAll(); + List<Data> data = result.getHits(); + for (Data item : data) { + MediatorServerDataProvider.this.entries.put(item.getId(), item); + } + } + + /** + * + * @param dbServerId + * @return url or null if not exists + */ public String getHostUrl(String dbServerId) { Data info = this.entries.getOrDefault(dbServerId, null); return info == null ? null : info.getUrl(); } public boolean triggerReloadSync() { - new Thread(onTick).start(); - int i = 20; - while (isRunning && i-- > 0) { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + if (!isRunning) { + runIt(); } - return i > 0; + return true; } @Override diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java index 2b3ebd86e..fbdc9d825 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java @@ -163,43 +163,43 @@ public class SystemInfo { printValue(sb, "Garbage collector", maxNameLen, val); } - if (showMemoryPools) { - List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans(); - sb.append("Memory Pools\n"); - printValue(sb, "Total Memory Pools", maxNameLen, printLong(memoryPools.size())); - String spaces4 = " "; - for (MemoryPoolMXBean pool : memoryPools) { - String name = pool.getName(); - MemoryType type = pool.getType(); - printValue(sb, spaces4 + "Pool (" + type + ")", maxNameLen, name); - - // PeakUsage/CurrentUsage - MemoryUsage peakUsage = pool.getPeakUsage(); - MemoryUsage usage = pool.getUsage(); - - if (usage != null && peakUsage != null) { - long init = peakUsage.getInit(); - long used = peakUsage.getUsed(); - long committed = peakUsage.getCommitted(); - long max = peakUsage.getMax(); - sb.append(spaces4 + spaces4 + "Peak Usage\n"); - printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); - printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); - printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); - printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); - - init = usage.getInit(); - used = usage.getUsed(); - committed = usage.getCommitted(); - max = usage.getMax(); - sb.append(spaces4 + spaces4 + "Current Usage\n"); - printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); - printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); - printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); - printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); - } - } - } +// if (showMemoryPools) { +// List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans(); +// sb.append("Memory Pools\n"); +// printValue(sb, "Total Memory Pools", maxNameLen, printLong(memoryPools.size())); +// String spaces4 = " "; +// for (MemoryPoolMXBean pool : memoryPools) { +// String name = pool.getName(); +// MemoryType type = pool.getType(); +// printValue(sb, spaces4 + "Pool (" + type + ")", maxNameLen, name); +// +// // PeakUsage/CurrentUsage +// MemoryUsage peakUsage = pool.getPeakUsage(); +// MemoryUsage usage = pool.getUsage(); +// +// if (usage != null && peakUsage != null) { +// long init = peakUsage.getInit(); +// long used = peakUsage.getUsed(); +// long committed = peakUsage.getCommitted(); +// long max = peakUsage.getMax(); +// sb.append(spaces4 + spaces4 + "Peak Usage\n"); +// printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); +// printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); +// printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); +// printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); +// +// init = usage.getInit(); +// used = usage.getUsed(); +// committed = usage.getCommitted(); +// max = usage.getMax(); +// sb.append(spaces4 + spaces4 + "Current Usage\n"); +// printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); +// printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); +// printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); +// printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); +// } +// } +// } sb.append("Classes\n"); printValue(sb, "Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount())); diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java index b119b80d4..3fd74b09d 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java @@ -190,7 +190,7 @@ public class EsDataObjectReaderWriter<T extends DataObject> { * @param esId * @return String with esId or null */ - public @Nullable <S extends DataObject> String update(S object, QueryBuilder query) { + public @Nullable <S extends DataObject> boolean update(S object, QueryBuilder query) { if (writeInterfaceClazz.isInstance(object)) { try { String json = yangtoolsMapper.writeValueAsString(object); @@ -202,7 +202,7 @@ public class EsDataObjectReaderWriter<T extends DataObject> { LOG.error("Type {} does not provide interface {}", object!=null?object.getClass().getName():"null", writeInterfaceClazz.getName()); } - return null; + return false; } /** * Write/ update partial child object to database with specific id Write if not diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java index d097d8284..d3d9dbf25 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java @@ -204,7 +204,7 @@ public class EsDataObjectReaderWriter2<T extends DataObject> { * @param query for write of specific attributes * @return json string with new Object */ - public @Nullable <S extends DataObject> String update(S object, QueryBuilder query) { + public @Nullable <S extends DataObject> boolean update(S object, QueryBuilder query) { if (object != null && writeInterfaceClazz.isInstance(object)) { try { String json = yangtoolsMapper.writeValueAsString(object); @@ -216,7 +216,7 @@ public class EsDataObjectReaderWriter2<T extends DataObject> { LOG.error("Type {} does not provide interface {}", object!=null?object.getClass().getName():"null", writeInterfaceClazz.getName()); } - return null; + return false; } /** * Write/ update partial child object to database with specific id Write if not diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java index cdcbb4912..6a42d0f21 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java @@ -39,9 +39,9 @@ public class MsServlet extends BaseServlet { private static final long serialVersionUID = -5361461082028405171L; private static final String OFFLINE_RESPONSE_MESSAGE = "MediatorServer interface is offline"; private static boolean trustAll = false; - private MediatorServerDataProvider entryProvider; + private static MediatorServerDataProvider entryProvider; public MsServlet() { - super(false); + super(); } @Override @@ -59,7 +59,7 @@ public class MsServlet extends BaseServlet { public void triggerReloadDatabaseEntries() { LOG.debug("external reload triggered"); - this.entryProvider.triggerReloadSync(); + entryProvider.triggerReloadSync(); } @Override @@ -85,7 +85,7 @@ public class MsServlet extends BaseServlet { } protected String getBaseUrl(String dbServerId) { - return this.entryProvider.getHostUrl(dbServerId); + return entryProvider.getHostUrl(dbServerId); } @Override protected boolean doTrustAll() { @@ -97,6 +97,16 @@ public class MsServlet extends BaseServlet { } public void setDataProvider(MediatorServerDataProvider mediatorServerDataProvider) { - this.entryProvider = mediatorServerDataProvider; + entryProvider = mediatorServerDataProvider; + } + + @Override + protected boolean trustInsecure() { + return trustAll; + } + + @Override + protected boolean isCorsEnabled() { + return false; } } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java index fc9ae5085..a846cd8f3 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java @@ -98,7 +98,7 @@ public class EsConfig implements Configuration, IEsConfig { public boolean hasBasicAuthCredentials() { return this.getBasicAuthUsername()!=null && this.getBasicAuthPassword()!=null && - this.getBasicAuthUsername()!="" && this.getBasicAuthPassword()!="" ; + !this.getBasicAuthUsername().isEmpty() && !this.getBasicAuthPassword().isEmpty() ; } public String getBasicAuthUsername() { return this.configuration.getProperty(SECTION_MARKER_ES, PROPERTY_KEY_AUTH_USERNAME); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java index 748ad51c6..d898644c9 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java @@ -114,7 +114,7 @@ public class TestCRUDforDatabase { private static ElasticSearchDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; - private static HostInfo[] hosts = new HostInfo[] { new HostInfo("localhost", Integer + public static HostInfo[] hosts = new HostInfo[] { new HostInfo("localhost", Integer .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200")) }; @BeforeClass @@ -125,7 +125,7 @@ public class TestCRUDforDatabase { dbRawProvider = new HtDatabaseClient(hosts); } - private static void trySleep(long ms) { + public static void trySleep(long ms) { try { Thread.sleep(ms); } catch (Exception e) { @@ -133,7 +133,7 @@ public class TestCRUDforDatabase { } } - private static void trySleep() { + public static void trySleep() { trySleep(0); } @@ -1183,8 +1183,8 @@ public class TestCRUDforDatabase { // == UPDATE ============================== - String shouldbeEmpty = dbRawProvider.doUpdate(Entity.Historicalperformance24h.getName(), "{'uuid-interface':'LTP-TEST-MWP-097'}", QueryBuilders.termQuery("_id", aDbId)); - assertEquals("",shouldbeEmpty); + boolean success = dbRawProvider.doUpdate(Entity.Historicalperformance24h.getName(), "{'uuid-interface':'LTP-TEST-MWP-097'}", QueryBuilders.termQuery("_id", aDbId)); + assertTrue("update dbentry not succeeded",success); try { readltpResult = dbProvider.readPmdata24hLtpList(readLtp); } catch (Exception e) { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java new file mode 100644 index 000000000..850d80e1a --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java @@ -0,0 +1,316 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + ******************************************************************************/ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; +import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionLogStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.GranularityPeriodType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntityBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType; + +/** + * @author Michael Dürre + * + */ +public class TestEventService { + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static HtDatabaseEventsService service = null; + + private static final String NODEID = "node1"; + private static final String NODEID2 = "node2"; + private static final String OBJECTREFID1 = "objid1"; + private static final String OBJECTREFID2 = "objid2"; + + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + + try { + service = new HtDatabaseEventsService(dbRawProvider, dbProvider); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testClearFaultsCurrent() { + + service.clearFaultsCurrentOfNode(NODEID); + service.clearFaultsCurrentOfNode(NODEID2); + + List<String> nodeIds = service.getAllNodesWithCurrentAlarms(); + if (nodeIds.size() > 0) { + for (String nodeId : nodeIds) { + service.clearFaultsCurrentOfNode(nodeId); + } + } + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abc", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abcde", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID2, OBJECTREFID2, "abcde", SeverityType.Major)); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 2); + service.clearFaultsCurrentOfNodeWithObjectId(NODEID, OBJECTREFID1); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 2); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.NonAlarmed)); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 1); + } + + private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, + SeverityType severity) { + return createFault(nodeId, objectRefId, problem, severity, NetconfTimeStampImpl.getConverter().getTimeStamp()); + } + + /** + * @param nODENAME + * @param problem + * @param ts + * @param severity + * @return + */ + private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, + SeverityType severity, DateAndTime ts) { + return new FaultcurrentBuilder().setNodeId(nodeId).setObjectId(objectRefId).setTimestamp(ts) + .setSeverity(severity).setProblem(problem).build(); + } + + @Test + public void testIndexClean() { + Date now = new Date(); + service.doIndexClean(now); + clearDbEntity(Entity.Eventlog); + clearDbEntity(Entity.Faultlog); + TestCRUDforDatabase.trySleep(1000); + service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "abc", 1)); + service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "avasvas", 2)); + + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 1)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 2)); + service.writeFaultLog(createFaultLog(NODEID2, OBJECTREFID2, "problem", SeverityType.Major, 1)); + TestCRUDforDatabase.trySleep(100); + now = new Date(); + int numOlds = service.getNumberOfOldObjects(now); + assertEquals(5, numOlds); + TestCRUDforDatabase.trySleep(100); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 3)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 5)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 6)); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(5, numOlds); + now = new Date(); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(8, numOlds); + service.doIndexClean(now); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(0, numOlds); + + } + + @Test + public void testPm() { + final String IFNAME1 = "if1"; + final String SCNID1 = "scn1"; + List<PmdataEntity> list = Arrays.asList(createPmData(NODEID, IFNAME1, SCNID1), + createPmData(NODEID, IFNAME1, SCNID1), createPmData(NODEID, IFNAME1, SCNID1), + createPmData(NODEID, IFNAME1, SCNID1) + + ); + service.doWritePerformanceData(list); + } + + /** + * @param ifname + * @param ifUuid + * @param scannerId + * @param nodename3 + * @return + */ + private static PmdataEntity createPmData(String nodeId, String ifUuid, String scannerId) { + return new PmdataEntityBuilder().setNodeName(nodeId).setGranularityPeriod(GranularityPeriodType.Period15Min) + .setUuidInterface(ifUuid).setScannerId(scannerId).setLayerProtocolName("NETCONF") + .setPerformanceData(null).setSuspectIntervalFlag(true) + .setTimeStamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).build(); + } + + @Test + public void testNeConnection() { + service.removeNetworkConnection(NODEID); + service.removeNetworkConnection(NODEID2); + + clearDbEntity(Entity.NetworkelementConnection); + List<NetworkElementConnectionEntity> nes = service.getNetworkElementConnections(); + assertEquals(0, nes.size()); + service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID); + service.updateNetworkConnection22(createNeConnection(NODEID2, NetworkElementDeviceType.ORAN), NODEID2); + nes = service.getNetworkElementConnections(); + assertEquals(2, nes.size()); + service.updateNetworkConnectionDeviceType(createNeConnection(NODEID, NetworkElementDeviceType.Wireless), + NODEID); + nes = service.getNetworkElementConnections(); + assertEquals(2, nes.size()); + boolean found = false; + for (NetworkElementConnectionEntity ne : nes) { + if (NODEID.equals(ne.getNodeId()) && ne.getDeviceType() == NetworkElementDeviceType.Wireless) { + found = true; + } + } + assertTrue(found); + + } + + @Test + public void testConnectionLog() { + clearDbEntity(Entity.Connectionlog); + service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); + service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); + assertEquals(2, getDbEntityEntries(Entity.Connectionlog).getTotal()); + } + + /** + * @param nodeId + * @param status + * @return + */ + private static ConnectionlogEntity createConnectionLog(String nodeId, ConnectionLogStatus status) { + return new ConnectionlogBuilder().setNodeId(nodeId) + .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setStatus(status).build(); + } + + @Test + public void testInventory() { + clearDbEntity(Entity.Inventoryequipment); + service.writeInventory(createEquipment(NODEID, "uuid1")); + service.writeInventory(createEquipment(NODEID, "uuid2")); + service.writeInventory(createEquipment(NODEID2, "uuid3")); + service.writeInventory(createEquipment(NODEID2, "uuid4")); + service.writeInventory(createEquipment(NODEID2, "uuid5")); + assertEquals(5, getDbEntityEntries(Entity.Inventoryequipment).getTotal()); + } + + private static SearchResult<SearchHit> getDbEntityEntries(Entity entity) { + return dbRawProvider.doReadAllJsonData(entity.getName()); + } + + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } + + /** + * @param nodeId + * @param uuid + * @return + */ + private Inventory createEquipment(String nodeId, String uuid) { + return new InventoryBuilder().setNodeId(nodeId).setParentUuid("").setDescription("desc") + .setManufacturerName("manu").setUuid(uuid).build(); + } + + /** + * @param devType + * @param nodename3 + * @return + */ + private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) { + return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(1234L) + .setCoreModelCapability("123").setStatus(ConnectionLogStatus.Connected).setDeviceType(devType) + .setIsRequired(true).build(); + } + + /** + * @param nodeId + * @param objectId + * @param problem + * @param severity + * @param counter + * @return + */ + private static FaultlogEntity createFaultLog(String nodeId, String objectId, String problem, SeverityType severity, + int counter) { + return new FaultlogBuilder().setNodeId(nodeId).setObjectId(objectId).setProblem(problem).setSeverity(severity) + .setCounter(counter).setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()) + .setSourceType(SourceType.Netconf).build(); + } + + /** + * @param nodeId + * @param objectId + * @param attributeName + * @param newValue + * @param counter + * @return + */ + private static EventlogEntity createEventLog(String nodeId, String objectId, String attributeName, String newValue, + int counter) { + return new EventlogBuilder().setNodeId(nodeId).setObjectId(objectId).setAttributeName(attributeName) + .setNewValue(newValue).setCounter(counter) + .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setSourceType(SourceType.Netconf) + .build(); + } +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java index 94381b6a3..5ce8fcc0b 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java @@ -17,23 +17,47 @@ ******************************************************************************/ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Arrays; import java.util.List; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.QueryByFilter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SortOrder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.FilterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Sortorder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.SortorderBuilder; public class TestFilterConversion { private static final String PROPERTY = "node-id"; + private static final String PROPERTY2 = "_id"; + private static final String PROPERTY3 = "timestamp"; @Test public void testQuestionMark() { - List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); - QueryBuilder query = QueryByFilter.fromFilter(filters ); + List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); + QueryBuilder query = QueryByFilter.fromFilter(filters); + System.out.println(query.toJSON()); + assertTrue(query.toJSON().contains("{1,1}")); + assertNotNull(QueryByFilter.getFilter(filters, PROPERTY)); + assertNull(QueryByFilter.getFilter(filters, PROPERTY2)); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + new FilterBuilder().setProperty(PROPERTY2).setFiltervalue("abc").build()); + query = QueryByFilter.fromFilter(filters); System.out.println(query.toJSON()); + assertNotNull(QueryByFilter.getFilter(filters, PROPERTY2)); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + new FilterBuilder().setProperty(PROPERTY3).setFiltervalue("<2019-06-13T15:00:12.0Z").build()); + query = QueryByFilter.fromFilter(filters); + List<Sortorder> sortorder = Arrays + .asList(new SortorderBuilder().setProperty(PROPERTY).setSortorder(SortOrder.Ascending).build()); + QueryByFilter.setSortOrder(query, sortorder); + assertNotNull(QueryByFilter.getSortOrder(sortorder, PROPERTY)); } } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java new file mode 100644 index 000000000..eae301a34 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + ******************************************************************************/ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; + +import static org.junit.Assert.fail; + +import java.util.Set; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DataProviderService; +import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.RpcService; + +import net.bytebuddy.implementation.bytecode.StackSize; + +/** + * @author Michael Dürre + * + */ +public class TestImplementation { + + @Test + public void test() { + DataProviderImpl impl = new DataProviderImpl(); + impl.setRpcProviderService(new RpcProviderService() { + + @Override + public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, + T implementation, Set<InstanceIdentifier<?>> paths) { + // TODO Auto-generated method stub + return null; + } + + @Override + public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, + T implementation) { + // TODO Auto-generated method stub + return null; + } + }); + impl.setMediatorServerServlet(new MsServlet()); + impl.setAboutServlet(new AboutHttpServlet()); + try { + impl.init(); + } catch (Exception e) { + e.printStackTrace(); + fail("failed to init impl: "+e.getMessage()); + } + + impl.setStatus(StatusKey.CLUSTER_SIZE, "3"); + impl.setReadyStatus(true); + try { + impl.close(); + } catch (Exception e) { + e.printStackTrace(); + fail("failed to close impl: "+e.getMessage()); + } + } + +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInitalMaintenanceObjectInDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInitalMaintenanceObjectInDatabase.java deleted file mode 100644 index 633912579..000000000 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInitalMaintenanceObjectInDatabase.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - ******************************************************************************/ -package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; - -import static org.junit.Assert.*; - -import org.junit.Test; - -/** - * - Handling of inital values for Maintenance mode. - */ -public class TestInitalMaintenanceObjectInDatabase { - - //@Test - public void test() { - fail("Not yet implemented"); - } - -} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceService.java new file mode 100644 index 000000000..bd91219c8 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceService.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + ******************************************************************************/ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtDatabaseMaintenanceService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceEntity; + +/** + * - Handling of inital values for Maintenance mode. + */ +public class TestMaintenanceService { + + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static HtDatabaseMaintenance service = null; + + private static final String NODEID = "node1"; + private static final String NODEID2 = "node2"; + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + service = dbProvider.getHtDatabaseMaintenance(); + } + @Test + public void test() { + clearDbEntity(Entity.Maintenancemode); + MaintenanceEntity obj = service.createIfNotExists(NODEID); + assertNotNull(obj); + obj = service.createIfNotExists(NODEID2); + assertNotNull(obj); + obj = service.getMaintenance(NODEID); + assertNotNull(obj); + List<MaintenanceEntity> list = service.getAll(); + assertEquals(2,list.size()); + service.deleteIfNotRequired(NODEID); + obj = service.getMaintenance(NODEID); + assertNull(obj); + + + obj = service.setMaintenance(createMaintenance(NODEID,true)); + + + } + /** + * @param nodeId + * @param active + * @return + */ + private static MaintenanceEntity createMaintenance(String nodeId, Boolean active) { + return new MaintenanceBuilder().setNodeId(nodeId).setActive(active).setProblem("problem").setObjectIdRef("idref").build(); + } + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } + +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java new file mode 100644 index 000000000..20c0da596 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + ******************************************************************************/ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.MediatorServerDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; + +/** + * @author Michael Dürre + * + */ +public class TestMediatorServerService { + private static final String SERVERID = null; + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static MediatorServerDataProvider service = null; + + + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + service = new MediatorServerDataProvider(TestCRUDforDatabase.hosts); + + + } + @Test + public void test() { + clearDbEntity(Entity.MediatorServer); + System.out.println(service.triggerReloadSync()); + String dbServerId="abc"; + String host = service.getHostUrl(dbServerId); + assertNull(host); + final String NAME="ms1"; + final String HOST = "http://10.20.30.40:7070"; + CreateMediatorServerOutputBuilder output = null; + try { + output = dbProvider.createMediatorServer(new CreateMediatorServerInputBuilder().setName(NAME).setUrl(HOST).build()); + } catch (IOException e) { + e.printStackTrace(); + fail("unable to create ms entry: "+e.getMessage()); + } + System.out.println(service.triggerReloadSync()); + host = service.getHostUrl(output.getId()); + assertEquals(HOST, host); + + } + + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } +} |