diff options
author | Dan Timoney <dtimoney@att.com> | 2019-03-29 13:00:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-29 13:00:18 +0000 |
commit | d693378eaecbe21675c89688ef89353949254350 (patch) | |
tree | 91a8396c355055c97ab1b55f40c5348d60e4c8c3 /sdnr/wt | |
parent | e6f319474636b5a7834eb6c74d02609da3d8a411 (diff) | |
parent | 4186aae5531a82c9f0227181866682bdd1d9cb93 (diff) |
Merge "SDN-R add historical alarm viewer"
Diffstat (limited to 'sdnr/wt')
32 files changed, 920 insertions, 198 deletions
diff --git a/sdnr/wt/devicemanager/feature/pom.xml b/sdnr/wt/devicemanager/feature/pom.xml index a5efb1f78..d99f071fe 100644 --- a/sdnr/wt/devicemanager/feature/pom.xml +++ b/sdnr/wt/devicemanager/feature/pom.xml @@ -21,7 +21,9 @@ * ============LICENSE_END========================================================= --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.onap.ccsdk.features.sdnr.wt</groupId> @@ -34,7 +36,7 @@ <groupId>org.onap.ccsdk.parent</groupId> <artifactId>single-feature-parent</artifactId> <version>1.2.2-SNAPSHOT</version> - <relativePath/> + <relativePath /> </parent> <dependencyManagement> diff --git a/sdnr/wt/devicemanager/installer/pom.xml b/sdnr/wt/devicemanager/installer/pom.xml index c41cfa497..08464f538 100755 --- a/sdnr/wt/devicemanager/installer/pom.xml +++ b/sdnr/wt/devicemanager/installer/pom.xml @@ -21,14 +21,16 @@ * ============LICENSE_END========================================================= --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> <version>1.2.2-SNAPSHOT</version> - <relativePath/> + <relativePath /> </parent> <groupId>org.onap.ccsdk.features.sdnr.wt</groupId> diff --git a/sdnr/wt/devicemanager/model/pom.xml b/sdnr/wt/devicemanager/model/pom.xml index 8b2c1488d..c2e59e623 100644 --- a/sdnr/wt/devicemanager/model/pom.xml +++ b/sdnr/wt/devicemanager/model/pom.xml @@ -21,7 +21,9 @@ * ============LICENSE_END========================================================= --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.onap.ccsdk.features.sdnr.wt</groupId> <artifactId>sdnr-wt-devicemanager-model</artifactId> @@ -33,7 +35,7 @@ <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> <version>1.2.2-SNAPSHOT</version> - <relativePath/> + <relativePath /> </parent> <properties> @@ -66,3 +68,4 @@ </plugins> </build> </project> + diff --git a/sdnr/wt/devicemanager/provider/pom.xml b/sdnr/wt/devicemanager/provider/pom.xml index 566001b03..f29859fb2 100644 --- a/sdnr/wt/devicemanager/provider/pom.xml +++ b/sdnr/wt/devicemanager/provider/pom.xml @@ -15,7 +15,9 @@ language governing permissions and limitations under the License. ============LICENSE_END========================================================= --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.onap.ccsdk.features.sdnr.wt</groupId> @@ -28,7 +30,7 @@ <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> <version>1.2.2-SNAPSHOT</version> - <relativePath/> + <relativePath></relativePath> </parent> <properties> @@ -95,6 +97,11 @@ <artifactId>sal-netconf-connector</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.opendaylight.mdsal</groupId> + <artifactId>mdsal-singleton-common-api</artifactId> + <scope>provided</scope> + </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> @@ -367,6 +374,7 @@ org.opendaylight.controller.md.sal.binding.api;version="[1.6,2)", org.opendaylight.controller.md.sal.common.api.data;version="[1.6,2)", org.opendaylight.controller.sal.binding.api;version="[1.6,2)", + org.opendaylight.mdsal.singleton.common.api;version="[2.0,3)", org.opendaylight.yangtools.concepts;version="[2.0,3)", org.opendaylight.yangtools.yang.binding;version="[0.12,1)", org.opendaylight.yangtools.yang.common;version="[2.0,3)", @@ -486,3 +494,4 @@ </plugins> </build> </project> + diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/archiveservice/ArchiveCleanProvider.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/archiveservice/ArchiveCleanProvider.java new file mode 100644 index 000000000..44fae6d61 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/archiveservice/ArchiveCleanProvider.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============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.devicemanager.archiveservice; + +import java.util.Date; + +public interface ArchiveCleanProvider { + + /** + * Remove all index data older, than specified + * @param olderAreOutdated time to specify older elements + * @return number of removed elements + */ + int doIndexClean(Date olderAreOutdated); + + /** + * Get number of elements older then + * @param olderAreOutdated date to compare with and specify older elements + * @return number of elements + */ + public int getNumberOfOldObjects(Date olderAreOutdated); + + +} diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/archiveservice/ArchiveCleanService.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/archiveservice/ArchiveCleanService.java new file mode 100644 index 000000000..eb48b87c4 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/archiveservice/ArchiveCleanService.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * ============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.devicemanager.archiveservice; + +import java.util.Date; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.HtDevicemanagerConfiguration; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.IConfigChangedListener; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.EsConfig; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; +import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + +public class ArchiveCleanService implements AutoCloseable, IConfigChangedListener, Runnable,ClusterSingletonService { + + private static final Logger LOG = LoggerFactory.getLogger(ArchiveCleanService.class); + private static final ServiceGroupIdentifier IDENT = ServiceGroupIdentifier.create("ElasticSearchArchiveCleanService"); + + private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + private final ArchiveCleanProvider[] indexCleanList; + private final HtDevicemanagerConfiguration htconfig; + private final Runnable doClean; + + private EsConfig config; + private Future<?> taskReference; + private boolean isMaster; + + public ArchiveCleanService(HtDevicemanagerConfiguration config, ArchiveCleanProvider... indexCleanList) { + this.config = config.getEs(); + this.htconfig = config; + this.htconfig.registerConfigChangedListener(this); + this.indexCleanList = indexCleanList; + this.doClean = this; + this.taskReference = null; + + this.reinit(); + } + + private void reinit() { + + if (taskReference != null) { + taskReference.cancel(false); + } + if(this.isMaster) { + if (this.config.getArchiveCheckIntervalSeconds() > 0) { + LOG.info("DBCleanService is turned on for entries older than {} seconds", + this.config.getArchiveLifetimeSeconds()); + taskReference = this.scheduler.scheduleAtFixedRate(doClean, 0, + this.config.getArchiveCheckIntervalSeconds(), TimeUnit.SECONDS); + } else { + LOG.info("DBCleanService is turned off"); + } + } + else { + LOG.info("service is inactive on this node. active on another node."); + } + } + + public Date getDateForOldElements() { + return new Date(System.currentTimeMillis() - config.getArchiveLifetimeSeconds() * 1000); + } + + public int countOldEntries() { + int cnt = 0; + Date olderAreOutdated = getDateForOldElements(); + for (ArchiveCleanProvider indexCleanElement : indexCleanList) { + if (indexCleanElement != null) { + indexCleanElement.getNumberOfOldObjects(olderAreOutdated); + } + } + return cnt; + } + + @Override + public void run() { + + try { + int removed = 0; + Date olderElementToBeRemoved = getDateForOldElements(); + LOG.trace("cleaning logs from entries older than {}", olderElementToBeRemoved); + + for (ArchiveCleanProvider indexCleanElement : indexCleanList) { + if (indexCleanElement != null) { + removed += indexCleanElement.doIndexClean(olderElementToBeRemoved); + } + } + if (removed > 0) { + LOG.trace("Removed elements: {}",removed); + } + } catch (Exception e) { + LOG.warn("problem executing dbclean", e); + } + } + + @Override + public void onConfigChanged() { + LOG.debug("config changed. reninit timer"); + ArchiveCleanService.this.config = EsConfig.reload(); + ArchiveCleanService.this.reinit(); + }; + + @Override + public void close() throws Exception { + this.htconfig.unregisterConfigChangedListener(this); + this.scheduler.shutdown(); + } + + @Override + public String toString() { + return "ArchivCleanService [ArchiveCheckIntervalSeconds=" + config.getArchiveCheckIntervalSeconds() + + "ArchiveLifetimeSeconds=" + config.getArchiveLifetimeSeconds() + "]"; + } + + @Override + public ServiceGroupIdentifier getIdentifier() { + return IDENT; + } + + @Override + public void instantiateServiceInstance() { + LOG.info("We take Leadership"); + this.isMaster=true; + this.reinit(); + } + + @Override + public ListenableFuture<? extends Object> closeServiceInstance() { + LOG.info("We lost Leadership"); + this.isMaster=false; + this.reinit(); + return Futures.immediateFuture(null); + } +} diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDataBaseReaderAndWriter.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDataBaseReaderAndWriter.java index f13b1066f..a742a94b0 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDataBaseReaderAndWriter.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDataBaseReaderAndWriter.java @@ -54,7 +54,12 @@ public class HtDataBaseReaderAndWriter<T extends IsEsObject> { this.mapper = new HtMapper<>( clazz ); } - + /** + * @return dataTypeName + */ + public String getDataTypeName() { + return this.dataTypeName; + } /** * Remove Object from database * @param object Object with content @@ -201,23 +206,33 @@ public class HtDataBaseReaderAndWriter<T extends IsEsObject> { } return res; } - - + /** + * Get all elements of related type + * @return all Elements + */ + public List<T> doReadAll() { + return doReadAll(null); + } /** * Read all existing objects of a type + * @param query for the elements * @return the list of all objects */ - public List<T> doReadAll() { + public List<T> doReadAll(QueryBuilder query) { List<T> res = new ArrayList<>(); int idx = 0; //Idx for getAll int iterateLength = 100; //Step width for iterate SearchHit hits[]; - - do { - hits = db.doReadAllJsonData(idx, iterateLength, dataTypeName); + if(query!=null) { + log.trace("read data in {} {} with query {}",db.getNetworkIndex(),dataTypeName,query); + hits=db.doReadByQueryJsonData(0, 99999, dataTypeName, query); + } + else { + hits = db.doReadAllJsonData(idx, iterateLength, dataTypeName); + } log.debug("Read: {} elements: {} Failures: {}",dataTypeName,hits.length, mapper.getMappingFailures()); T object; diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDatabaseWebAPIClient.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDatabaseWebAPIClient.java index 25930791a..ed09d34cd 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDatabaseWebAPIClient.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/database/HtDatabaseWebAPIClient.java @@ -95,4 +95,8 @@ public class HtDatabaseWebAPIClient { return sresponse; } + + public void insertEntry(String index, String type, JSONObject data) throws IOException { + this.sendRequest(String.format("/%s/%s/", index,type), "POST", data); + } } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/internalTypes/Resources.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/internalTypes/Resources.java index 330ff8df0..3a899f884 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/internalTypes/Resources.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/internalTypes/Resources.java @@ -255,7 +255,7 @@ public class Resources { } private static Enumeration<URL> getResourceFolderFiles(String folder) { - LOG.info("Get ressource: {}", folder); + LOG.debug("Get resource: {}", folder); URL url = getUrlForRessource(folder); String path = url.getPath(); File[] files = new File(path).listFiles(); diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/ONFCoreNetworkElementFactory.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/ONFCoreNetworkElementFactory.java index bda77f223..2ed02c18c 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/ONFCoreNetworkElementFactory.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/ONFCoreNetworkElementFactory.java @@ -18,7 +18,6 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf; import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities; @@ -50,7 +49,6 @@ public class ONFCoreNetworkElementFactory { private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementFactory.class); - @SuppressWarnings("deprecation") public static @Nonnull ONFCoreNetworkElementRepresentation create(String mountPointNodeName, DataBroker dataBroker, WebSocketServiceClient webSocketService, HtDatabaseEventsService databaseService, InstanceIdentifier<Node> instanceIdentifier, DataBroker mountpointDataBroker, ProviderClient dcaeProvider, @@ -59,7 +57,6 @@ public class ONFCoreNetworkElementFactory { ONFCoreNetworkElementRepresentation res = null; try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();){ - CheckedFuture<Optional<Node>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier); Optional<Node> nodeOption = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet(); if (nodeOption.isPresent()) { Node node = nodeOption.get(); diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/util/NetconfTimeStamp.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/util/NetconfTimeStamp.java index a9e451a39..0dc6f0304 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/util/NetconfTimeStamp.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/util/NetconfTimeStamp.java @@ -101,10 +101,18 @@ public class NetconfTimeStamp { * @return String with Date in NETCONF/YANG Format Version 1.0. */ public String getTimeStampAsNetconfString() { - return getRightFormattedDate(new Date().getTime()); + return this.getRightFormattedDate(new Date().getTime()); } /** + * Get actual timestamp as NETCONF specific type NETCONF/YANG 1.0 Format + + * @return String with Date in NETCONF/YANG Format Version 1.0. + */ + public String getTimeStampAsNetconfString(Date date) { + return getRightFormattedDate(date.getTime()); + } + /** * Get actual timestamp as NETCONF specific type NETCONF/YANG 1.0 Format in GMT * * @return DateAndTime Type 1.0. Date in NETCONF/YANG Format Version 1.0. @@ -113,6 +121,15 @@ public class NetconfTimeStamp { return DateAndTime.getDefaultInstance(getTimeStampAsNetconfString()); } + /** + * Get time from date as NETCONF specific type NETCONF/YANG 1.0 Format in GMT + * @param date specifying the date and time + * @return DateAndTime Type 1.0. Date in NETCONF/YANG Format Version 1.0. + */ + public DateAndTime getTimeStamp(Date date) { + return DateAndTime.getDefaultInstance(getTimeStampAsNetconfString(date)); + } + /** * Return the String with a NETCONF time converted to long @@ -252,4 +269,6 @@ public class NetconfTimeStamp { } } + + } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/AkkaConfig.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/AkkaConfig.java index 55d5b9a11..eeccf601f 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/AkkaConfig.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/AkkaConfig.java @@ -59,6 +59,10 @@ public class AkkaConfig { return this.cluserConfig != null ? this.cluserConfig.isCluster() : false; } + public boolean isClusterAndFirstNode() { + return isSingleNode() || isCluster() && getClusterConfig().getRoleMemberIndex() == 1; + } + public static AkkaConfig load() throws Exception { return load(DEFAULT_FILENAME); } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/EsConfig.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/EsConfig.java index 958a0dfd3..bdfbf655d 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/EsConfig.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/config/impl/EsConfig.java @@ -29,13 +29,29 @@ public class EsConfig extends BaseSubConfig { public static final String ESDATATYPENAME = "database"; private static final String EMPTY = "empty"; private static final String PROPERTY_KEY_CLUSTER = "esCluster"; + private static final String PROPERTY_KEY_ARCHIVE_INTERVAL = "esArchiveCheckIntervalSeconds"; + private static final String PROPERTY_KEY_ARCHIVE_LIMIT = "esArchiveLifetimeSeconds"; + private static final String DEFAULT_VALUE_CLUSTER = ""; + /** + * check db data in this interval [in seconds] + * 0 deactivated + */ + private static final long DEFAULT_ARCHIVE_INTERVAL_SEC = 0; + /** + * keep data for this time [in seconds] + * 30 days + */ + private static final long DEFAULT_ARCHIVE_LIMIT_SEC = 60 * 60 * 24 * 30; + private static EsConfig esConfig; private String cluster; private String host; private String node; private String index; + private long archiveCheckIntervalSeconds; + private long archiveLifetimeSeconds; private EsConfig() { super(); @@ -43,6 +59,8 @@ public class EsConfig extends BaseSubConfig { this.node = EMPTY; this.index = EMPTY; this.cluster = DEFAULT_VALUE_CLUSTER; + this.archiveCheckIntervalSeconds = DEFAULT_ARCHIVE_INTERVAL_SEC; + this.archiveLifetimeSeconds = DEFAULT_ARCHIVE_LIMIT_SEC; } public EsConfig cloneWithIndex(String _index) { @@ -51,6 +69,8 @@ public class EsConfig extends BaseSubConfig { c.host = this.host; c.node = this.node; c.cluster = this.cluster; + c.archiveCheckIntervalSeconds = this.archiveCheckIntervalSeconds; + c.archiveLifetimeSeconds = this.archiveLifetimeSeconds; return c; } @@ -90,6 +110,22 @@ public class EsConfig extends BaseSubConfig { this.index = index; } + public long getArchiveCheckIntervalSeconds() { + return this.archiveCheckIntervalSeconds; + } + + public void setArchiveCheckIntervalSeconds(long x) { + this.archiveCheckIntervalSeconds = x; + } + + public long getArchiveLifetimeSeconds() { + return this.archiveLifetimeSeconds; + } + + public void setArchiveLimit(long x) { + this.archiveLifetimeSeconds = x; + } + @Override public String toString() { return "EsConfig [cluster=" + cluster + ", host=" + host + ", node=" + node + ", index=" + index + "]"; @@ -112,9 +148,13 @@ public class EsConfig extends BaseSubConfig { this.cluster = c; this.node = String.format("%s%s", this.cluster, "n1"); this.host = "localhost"; + this.archiveCheckIntervalSeconds = this.getLong(PROPERTY_KEY_ARCHIVE_INTERVAL, DEFAULT_ARCHIVE_INTERVAL_SEC); + this.archiveLifetimeSeconds = this.getLong(PROPERTY_KEY_ARCHIVE_LIMIT, DEFAULT_ARCHIVE_LIMIT_SEC); if (save) { config.setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_CLUSTER, this.cluster); + config.setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_ARCHIVE_INTERVAL, this.archiveCheckIntervalSeconds); + config.setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_ARCHIVE_LIMIT, this.archiveLifetimeSeconds); this.save(); } } @@ -170,15 +210,21 @@ public class EsConfig extends BaseSubConfig { } else if (!node.equals(other.node)) { return false; } + if (archiveCheckIntervalSeconds != other.archiveCheckIntervalSeconds) { + return false; + } + if (archiveLifetimeSeconds != other.archiveLifetimeSeconds) { + return false; + } return true; } @Override - public void save() - { + public void save() { this.getConfig().setProperty(SECTION_MARKER_ES + "." + PROPERTY_KEY_CLUSTER, this.cluster); super.save(); } + public static boolean isInstantiated() { return esConfig != null; } @@ -213,7 +259,7 @@ public class EsConfig extends BaseSubConfig { } public static void clear() { - esConfig=null; + esConfig = null; } } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/devicemonitor/impl/DeviceMonitorImpl.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/devicemonitor/impl/DeviceMonitorImpl.java index 0141b2663..89ee376da 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/devicemonitor/impl/DeviceMonitorImpl.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/devicemonitor/impl/DeviceMonitorImpl.java @@ -6,9 +6,9 @@ * ================================================================================================= * 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 @@ -61,6 +61,7 @@ import org.slf4j.LoggerFactory; * @author herbert */ +@SuppressWarnings("deprecation") public class DeviceMonitorImpl implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DeviceMonitorImpl.class); diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java index f0efe7aa4..97595ddac 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java @@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.AaiProviderClient; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseNode; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElementFactory; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElementRepresentation; @@ -71,6 +72,8 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; @SuppressWarnings("deprecation") public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, ResyncNetworkElementsListener { @@ -92,6 +95,7 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R private RpcProviderRegistry rpcProviderRegistry = null; @SuppressWarnings("unused") private NotificationPublishService notificationPublishService = null; + private ClusterSingletonServiceProvider clusterSingletonServiceProvider; private final ConcurrentHashMap<String, ONFCoreNetworkElementRepresentation> networkElementRepresentations = new ConcurrentHashMap<>(); @@ -116,6 +120,9 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R private Thread threadDoClearCurrentFaultByNodename = null; private int refreshCounter = 0; private AkkaConfig akkaConfig; + private ArchiveCleanService archiveCleanService; + @SuppressWarnings("unused") + private ClusterSingletonServiceRegistration cssRegistration; // Blueprint 1 public DeviceManagerImpl() { @@ -137,7 +144,9 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R public void setMountPointService(MountPointService mountPointService) { this.mountPointService = mountPointService; } - + public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) { + this.clusterSingletonServiceProvider = clusterSingletonService; + } public void init() { LOG.info("Session Initiated start {}", APPLICATION_NAME); @@ -146,11 +155,11 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry); // Get configuration HtDevicemanagerConfiguration config = HtDevicemanagerConfiguration.getConfiguration(); - this.akkaConfig = null; try { this.akkaConfig = AkkaConfig.load(); LOG.debug("akka.conf loaded: " + akkaConfig.toString()); } catch (Exception e1) { + this.akkaConfig = null; LOG.warn("problem loading akka.conf: " + e1.getMessage()); } GeoConfig geoConfig = null; @@ -180,8 +189,7 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R LOG.error("Can only run with local database. Stop initialization of devicemanager."); } else { // init Database Values only if singleNode or clusterMember=1 - if (akkaConfig == null || akkaConfig.isSingleNode() || akkaConfig != null && akkaConfig.isCluster() - && akkaConfig.getClusterConfig().getRoleMemberIndex() == 1) { + if (akkaConfig == null || akkaConfig.isClusterAndFirstNode()) { // Create DB index if not existing and if database is running try { this.configService = new IndexConfigService(htDatabase); @@ -192,6 +200,7 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R } // start service for device maintenance service this.maintenanceService = new MaintenanceServiceImpl(htDatabase); + // Websockets try { this.webSocketService = new WebSocketServiceClientImpl2(rpcProviderRegistry); @@ -210,14 +219,17 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R LOG.warn("No configuration available. Don't start event manager"); } else { this.databaseClientEvents = new HtDatabaseEventsService(htDatabase); + //Make sure to start for one cluster node only + if (akkaConfig == null || akkaConfig.isClusterAndFirstNode() || akkaConfig.isSingleNode()) { + } String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + dbConfig.getCluster(); - this.odlEventListener = new ODLEventListener(myDbKeyNameExtended, webSocketService, databaseClientEvents, dcaeProviderClient, aotsMProvider, maintenanceService); } - + this.archiveCleanService = new ArchiveCleanService(config, databaseClientEvents, mwtnService); + this.cssRegistration = this.clusterSingletonServiceProvider.registerClusterSingletonService(this.archiveCleanService); // PM PmConfig configurationPM = config.getPm(); LOG.info("Performance manager configuration: {}", configurationPM); @@ -275,7 +287,7 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R close(maintenanceService); close(rpcApiService); close(notificationDelayService); - + close(archiveCleanService); LOG.info("DeviceManagerImpl closing done"); } @@ -300,8 +312,11 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R /** * For each mounted device a mountpoint is created and this listener is called. + * Mountpoint was created or existing. Managed device is now fully connected to node/mountpoint. + * @param action provide action + * @param nNodeId id of the mountpoint + * @param nNode mountpoint contents */ - @Override public void startListenerOnNodeForConnectedState(Action action, NodeId nNodeId, NetconfNode nNode) { String mountPointNodeName = nNodeId.getValue(); @@ -384,7 +399,8 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R ne.initSynchronizationExtension(); // Setup Service that monitors registration/ deregistration of session - odlEventListener.registration(mountPointNodeName); + ConnectionStatus csts = nNode.getConnectionStatus(); + sendCreateOrUpdateNotification(mountPointNodeName, action, csts); if (aaiProviderClient != null) { aaiProviderClient.onDeviceRegistered(mountPointNodeName); @@ -399,52 +415,121 @@ public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, R LOG.info("Starting Event listener on Netconf device :: Name : {} finished", mountPointNodeName); } - @Override - public void enterNonConnectedState(NodeId nNodeId, NetconfNode nNode) { + /** + * Mountpoint created or existing. Managed device is actually disconnected from node/ mountpoint. + * Origin state: Connecting, Connected + * Target state: are UnableToConnect or Connecting + * @param action create or update + * @param nNodeId id of the mountpoint + * @param nNode mountpoint contents + */ + public void enterNonConnectedState(Action action, NodeId nNodeId, NetconfNode nNode) { + String mountPointNodeName = nNodeId.getValue(); + ConnectionStatus csts = nNode.getConnectionStatus(); + + sendCreateOrUpdateNotification(mountPointNodeName, action, csts); + + // Handling if mountpoint exist. connected -> connecting/UnableToConnect + stopListenerOnNodeForConnectedState(mountPointNodeName); + + if (deviceMonitor != null) { + deviceMonitor.deviceDisconnectIndication(mountPointNodeName); + } + + } + + /** + * Mountpoint removed indication. + * @param nNodeId id of the mountpoint + */ + public void removeMountpointState(NodeId nNodeId) { String mountPointNodeName = nNodeId.getValue(); - LOG.info("enter Non ConnectedState for device :: Name : {}", mountPointNodeName); + LOG.info("mountpointNodeRemoved {}", nNodeId.getValue()); + stopListenerOnNodeForConnectedState(mountPointNodeName); + deviceMonitor.removeMountpointIndication(mountPointNodeName); + if (odlEventListener != null) { + odlEventListener.deRegistration(mountPointNodeName); + } + } + + /** + * Do all tasks necessary to move from mountpoint state connected -> connecting + * @param mountPointNodeName provided + * @param ne representing the device connected to mountpoint + */ + private void stopListenerOnNodeForConnectedState( String mountPointNodeName) { ONFCoreNetworkElementRepresentation ne = networkElementRepresentations.remove(mountPointNodeName); if (ne != null) { - // Handling transition mountpoint connected -> connecting this.maintenanceService.deleteIfNotRequired(mountPointNodeName); int problems = ne.removeAllCurrentProblemsOfNode(); LOG.debug("Removed all {} problems from database at deregistration for {}", problems, mountPointNodeName); - if (odlEventListener != null) { - odlEventListener.deRegistration(mountPointNodeName); - } if (performanceManager != null) { performanceManager.deRegistration(mountPointNodeName); } if (aaiProviderClient != null) { aaiProviderClient.onDeviceUnregistered(mountPointNodeName); } - } else { - // Handling -> create not connected mountpoint, or change other beside connected. - ConnectionStatus csts = nNode.getConnectionStatus(); - if (csts != null) { - odlEventListener.updateRegistration(mountPointNodeName, csts.getClass().getSimpleName(), csts.getName()); - } else { - LOG.info("Unknown connection status"); - } - } - if (deviceMonitor != null) { - deviceMonitor.deviceDisconnectIndication(mountPointNodeName); } + } + private void sendCreateOrUpdateNotification(String mountPointNodeName, Action action, ConnectionStatus csts) { + LOG.info("enter Non ConnectedState for device :: Name : {} Action {} ConnectionStatus {}", mountPointNodeName, action, csts); + if (action == Action.CREATE) { + odlEventListener.registration(mountPointNodeName); + } else { + odlEventListener.updateRegistration(mountPointNodeName, ConnectionStatus.class.getSimpleName(), csts != null ? csts.getName() : "null"); + } } + /** + * Handle netconf/mountpoint changes + */ @Override - public void removeMountpointState(NodeId nNodeId) { - String mountPointNodeName = nNodeId.getValue(); - LOG.info("mountpointNodeRemoved {}", nNodeId.getValue()); - deviceMonitor.removeMountpointIndication(mountPointNodeName); + public void netconfChangeHandler(Action action, @Nullable ConnectionStatus csts, NodeId nodeId, NetconfNode nnode) { + switch (action) { + case REMOVE: + removeMountpointState(nodeId); // Stop Monitor + //deviceManagerService.enterNonConnectedState(nodeId, nnode); // Remove Mountpoint handler + break; + + case UPDATE: + case CREATE: + if (csts != null) { + switch (csts) { + case Connected: { + startListenerOnNodeForConnectedState(action, nodeId, nnode); + break; + } + case UnableToConnect: + case Connecting: { + enterNonConnectedState(action, nodeId, nnode); + break; + } + } + } else { + LOG.debug("NETCONF Node handled with null status for action", action); + } + break; + } } /*------------------------------------------------------------------------------------------- * Functions */ + public ArchiveCleanService getArchiveCleanService() { + return this.archiveCleanService; + } + + public HtDatabaseEventsService getDatabaseClientEvents() { + return databaseClientEvents; + } + + public IndexMwtnService getMwtnService() { + return mwtnService; + } + /** * Async RPC Interface implementation */ diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerService.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerService.java index 13fbc644e..ce34401d8 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerService.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerService.java @@ -16,8 +16,9 @@ * ============LICENSE_END========================================================================== ******************************************************************************/ package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl; -import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; public interface DeviceManagerService { @@ -28,23 +29,11 @@ public interface DeviceManagerService { UPDATE } /** - * Mountpoint was created or existing. Managed device is now fully connected to node/mountpoint. - * @param action provide action - * @param nNodeId id of the mountpoint - * @param nNode mountpoint contents + * MountpointChangeHandler, called to indicate change to DeviceManager + * @param action provided + * @param csts provided + * @param nodeId provided + * @param nnode provided */ - void startListenerOnNodeForConnectedState(@Nonnull Action action, @Nonnull NodeId nNodeId, @Nonnull NetconfNode nNode); - - /** - * Mountpoint created or existing. Managed device is actually disconnected from node/ mountpoint. - * @param nNodeId id of the mountpoint - * @param nNode mountpoint contents - */ - void enterNonConnectedState(@Nonnull NodeId nNodeId, @Nonnull NetconfNode nNode); - - /** - * Mountpoint removed indication. - * @param nNodeId id of the mountpoint - */ - void removeMountpointState(@Nonnull NodeId nNodeId); + void netconfChangeHandler(Action action, @Nullable ConnectionStatus csts, NodeId nodeId, NetconfNode nnode); } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/service/HtDatabaseEventsService.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/service/HtDatabaseEventsService.java index 90b07999c..0a38e0f60 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/service/HtDatabaseEventsService.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/service/HtDatabaseEventsService.java @@ -18,23 +18,24 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service; import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.annotation.Nonnull; +import org.elasticsearch.index.query.QueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanProvider; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDataBaseReaderAndWriter; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseClientAbstract; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseNode; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.IndexClientBuilder; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElement12Equipment; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.NetconfTimeStamp; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types.EsEventBase; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types.EsFaultCurrent; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types.EsFaultLog; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types.equipment.EsEquipment; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types.equipment.EsToplevelEquipment; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types.equipment.ExtendedEquipment; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.MwtNotificationBase; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectDeletionNotificationXml; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,9 +45,11 @@ import org.slf4j.LoggerFactory; * * @author herbert */ -public class HtDatabaseEventsService { +public class HtDatabaseEventsService implements ArchiveCleanProvider { private static final Logger LOG = LoggerFactory.getLogger(HtDatabaseEventsService.class); + private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter(); + ///** Filename in the resources with maven initialized version information */ //private static final String RESOURCENAME = "version.properties"; // could also be a constant ///** Index name to be used */ @@ -88,19 +91,7 @@ public class HtDatabaseEventsService { // --- Function - public void writeEventLog(ObjectCreationNotificationXml event) { - writeEventGeneric(event); - } - - public void writeEventLog(ObjectDeletionNotificationXml event) { - writeEventGeneric(event); - } - - public void writeEventLog(AttributeValueChangedNotificationXml event) { - writeEventGeneric(event); - } - - private void writeEventGeneric(MwtNotificationBase event) { + public void writeEventLog(MwtNotificationBase event) { if (client == null) { LOG.debug("No DB, can not write: {}",event.toString()); return; @@ -224,5 +215,33 @@ public class HtDatabaseEventsService { } } + @Override + public int doIndexClean(Date olderAreOutdated) { + + String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); + int removed = 0; + + QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp); + removed += eventRWEventLog.doRemoveByQuery(queryEventBase); + + QueryBuilder queryFaultLog = EsFaultLog.getQueryForTimeStamp(netconfTimeStamp); + removed += eventRWFaultLog.doRemoveByQuery(queryFaultLog); + return removed; + } + + @Override + public int getNumberOfOldObjects(Date olderAreOutdated) { + + String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); + int numberOfElements = 0; + + QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp); + numberOfElements += eventRWEventLog.doReadAll(queryEventBase).size(); + + QueryBuilder queryFaultLog = EsFaultLog.getQueryForTimeStamp(netconfTimeStamp); + numberOfElements += eventRWFaultLog.doReadAll(queryFaultLog).size(); + + return numberOfElements; + } } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsEventBase.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsEventBase.java index bcd2849d2..568e01f88 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsEventBase.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsEventBase.java @@ -17,6 +17,8 @@ ******************************************************************************/ package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.RangeQueryBuilder; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.EsObject; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.MwtNotificationBase; @@ -30,6 +32,9 @@ public class EsEventBase extends EsObject { public static final String ESDATATYPENAME = "eventlog"; + private static final String EVENTLOG_FIELD_TIMESTAMP = "event.timeStamp"; + + private MwtNotificationBase event; public MwtNotificationBase getProblem() { @@ -40,4 +45,13 @@ public class EsEventBase extends EsObject { this.event = event; } + /** + * Query to get older Elements + * @param netconfTimeStamp to identify older Elements + * @return QueryBuilder for older elements related to timestamp + */ + public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { + return new RangeQueryBuilder(EVENTLOG_FIELD_TIMESTAMP).lt(netconfTimeStamp); + } + } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsFaultLog.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsFaultLog.java index 06a893ad7..e15aba5b2 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsFaultLog.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/database/types/EsFaultLog.java @@ -17,6 +17,8 @@ ******************************************************************************/ package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.types; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.RangeQueryBuilder; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.EsObject; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml; @@ -30,6 +32,8 @@ public class EsFaultLog extends EsObject { public static final String ESDATATYPENAME = "faultlog"; + private static final String FAULTLOG_FIELD_TIMESTAMP = "fault.timeStamp"; + private ProblemNotificationXml fault; public ProblemNotificationXml getProblem() { @@ -40,4 +44,13 @@ public class EsFaultLog extends EsObject { this.fault = fault; } + /** + * Get older Elements + * @param netconfTimeStamp to identify query elements older than this timestamp. + * @return QueryBuilder for related elements + */ + public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { + return new RangeQueryBuilder(FAULTLOG_FIELD_TIMESTAMP).lt(netconfTimeStamp); + } + } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/NetconfChangeListener.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/NetconfChangeListener.java index fc5607557..a521bb94c 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/NetconfChangeListener.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/NetconfChangeListener.java @@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory; // 07.09.18 Switched to DataTreeChangeListener from ClusteredDataTreeChangeListener -> DM Service is // running at all nodes // This is not correct +@SuppressWarnings("deprecation") public class NetconfChangeListener implements ClusteredDataTreeChangeListener<Node>, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(NetconfChangeListener.class); @@ -156,33 +157,8 @@ public class NetconfChangeListener implements ClusteredDataTreeChangeListener<No if (nodeIdString.equals(CONTROLLER)) { LOG.debug("Stop processing for [{}]", nodeIdString); } else { - // Action related to mountpoint status - switch (action) { - case REMOVE: - deviceManagerService.removeMountpointState(nodeId); // Stop Monitor - deviceManagerService.enterNonConnectedState(nodeId, nnode); // Remove Mountpoint handler - break; - - case UPDATE: - case CREATE: - if (csts != null) { - switch (csts) { - case Connected: { - deviceManagerService.startListenerOnNodeForConnectedState(action, nodeId, - nnode); - break; - } - case UnableToConnect: - case Connecting: { - deviceManagerService.enterNonConnectedState(nodeId, nnode); - break; - } - } - } else { - LOG.debug("NETCONF Node handled with null status for action", action); - } - break; - } + // Action forwarded to devicehandler + deviceManagerService.netconfChangeHandler(action, csts, nodeId, nnode); } } } catch (NullPointerException e) { diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/ODLEventListener.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/ODLEventListener.java index ecaf06b55..4b87b5828 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/ODLEventListener.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/listener/ODLEventListener.java @@ -47,17 +47,18 @@ import org.slf4j.LoggerFactory; public class ODLEventListener { private static final Logger LOG = LoggerFactory.getLogger(ODLEventListener.class); - private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter(); + private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter(); private final String ownKeyName; - private final WebSocketServiceClient webSocketService; private final HtDatabaseEventsService databaseService; private final ProviderClient dcaeProvider; private final ProviderClient aotsMProvider; - private int eventNumber; private final MaintenanceService maintenanceService; + + private int eventNumber; + /*--------------------------------------------------------------- * Construct */ diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/xml/WebSocketServiceClientImpl2.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/xml/WebSocketServiceClientImpl2.java index 6ca7a5c18..c8f769677 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/xml/WebSocketServiceClientImpl2.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/xml/WebSocketServiceClientImpl2.java @@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory; * Wrapper for forwarding web-socket notifications to the web-socket service, that is running as * bundle. */ +@SuppressWarnings("deprecation") public class WebSocketServiceClientImpl2 implements WebSocketServiceClient { private static final Logger LOG = LoggerFactory.getLogger(ODLEventListener.class); diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/index/database/types/EsEventOdluxLog.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/index/database/types/EsEventOdluxLog.java new file mode 100644 index 000000000..14f7d2447 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/index/database/types/EsEventOdluxLog.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * ============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.devicemanager.index.database.types; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.RangeQueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.EsObject; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime; + +/** + * Event log, used by Odlux client. + * Not used for writing any data by devicemanager. + * Type introduced to implement IndexCleanService + */ + +public class EsEventOdluxLog extends EsObject { + + public static final String ESDATATYPENAME = "log"; + + private static final String LOG_FIELD_TIMESTAMP = "timestamp"; + + private String type; + private String component; + private String message; + private String timestamp; + + /** + * For jackson + */ + protected EsEventOdluxLog() { + } + /** + * Constructor + * @param type string + * @param component string + * @param message string + * @param timestamp string with netconf format string + */ + public EsEventOdluxLog(String type, String component, String message, InternalDateAndTime timestamp) { + super(); + this.type = type; + this.component = component; + this.message = message; + this.timestamp = timestamp.getValue(); + } + + @JsonProperty("type") + public String getType() { + return type; + } + + @JsonProperty("component") + public String getComponent() { + return component; + } + + @JsonProperty("message") + public String getMessage() { + return message; + } + + @JsonProperty(LOG_FIELD_TIMESTAMP) + public String getTimestamp() { + return timestamp; + } + + /** + * Query to get older Elements + * @param netconfTimeStamp to identify older Elements + * @return QueryBuilder for older elements related to timestamp + */ + public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { + return new RangeQueryBuilder(LOG_FIELD_TIMESTAMP).lt(netconfTimeStamp); + } + + } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/index/impl/IndexMwtnService.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/index/impl/IndexMwtnService.java index e175515ae..0e6b03291 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/index/impl/IndexMwtnService.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/index/impl/IndexMwtnService.java @@ -17,9 +17,15 @@ ******************************************************************************/ package org.onap.ccsdk.features.sdnr.wt.devicemanager.index.impl; +import java.util.Date; +import org.elasticsearch.index.query.QueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDataBaseReaderAndWriter; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseClientAbstract; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseNode; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.IndexClientBuilder; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.index.database.types.EsEventOdluxLog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,9 +34,10 @@ import org.slf4j.LoggerFactory; * @author herbert * */ -public class IndexMwtnService implements AutoCloseable { +public class IndexMwtnService implements AutoCloseable, ArchiveCleanProvider { private static final Logger LOG = LoggerFactory.getLogger(IndexMwtnService.class); + private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter(); /** Index name to be used */ public static final String INDEX = "mwtn"; @@ -39,6 +46,9 @@ public class IndexMwtnService implements AutoCloseable { /** Location of configuration data **/ private static final String MODELDATA = "elasticsearch/index/mwtn/modelDescription"; + private final HtDataBaseReaderAndWriter<EsEventOdluxLog> eventRWOdluxLog; + + private final HtDatabaseClientAbstract client; // --- Construct and initialize @@ -46,11 +56,15 @@ public class IndexMwtnService implements AutoCloseable { public IndexMwtnService(HtDatabaseNode database) throws Exception { LOG.info("Create {} start", this.getClass().getSimpleName()); + IndexClientBuilder clientBuilder = IndexClientBuilder.getBuilder(INDEX) .setMappingSettingJsonFileName(MAPPING) .setModelDataDirectory(MODELDATA); client = clientBuilder.create(database); clientBuilder.close(); + + eventRWOdluxLog = new HtDataBaseReaderAndWriter<>(client, EsEventOdluxLog.ESDATATYPENAME, EsEventOdluxLog.class); + LOG.info("Create {} finished. DB Service sucessfully started.", this.getClass().getSimpleName()); } @@ -62,10 +76,42 @@ public class IndexMwtnService implements AutoCloseable { return client; } + /** + * Write into Odlux log, used by client + * @param logEntry as test data + */ + public void writeOdluxEventForTestpurpose(EsEventOdluxLog logEntry) { + eventRWOdluxLog.doWrite(logEntry); + } @Override public void close() throws Exception { - client.close(); + if (client != null) { + client.close(); + } + } + + @Override + public int doIndexClean(Date olderAreOutdated) { + + String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); + + QueryBuilder queryOdluxLog = EsEventOdluxLog.getQueryForTimeStamp(netconfTimeStamp); + int removed = eventRWOdluxLog.doRemoveByQuery(queryOdluxLog); + return removed; + + } + + @Override + public int getNumberOfOldObjects(Date olderAreOutdated) { + + String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); + int numberOfElements = 0; + + QueryBuilder queryOdluxLog = EsEventOdluxLog.getQueryForTimeStamp(netconfTimeStamp); + numberOfElements += eventRWOdluxLog.doReadAll(queryOdluxLog).size(); + + return numberOfElements; } } diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/index/mwtn/modelDescription/maintenancemode.json b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/index/mwtn/modelDescription/maintenancemode.json index 3d0a41424..9e26dfeeb 100644 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/index/mwtn/modelDescription/maintenancemode.json +++ b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/index/mwtn/modelDescription/maintenancemode.json @@ -1,22 +1 @@ -{ - "maintenancemode": { - "DragonWave-Z3":{ - "node":"DragonWave-Z3", - "filter": [{ - "definition":{}, - "description":"", - "start":"2018-01-01T10:00+00:00", - "end":"2018-10-10T10:00+00:00" - }] - }, - "MaintenanceMode":{ - "node":"MaintenanceMode", - "filter": [{ - "definition":{}, - "description":"", - "start":"2018-01-01T10:00+00:00", - "end":"2018-10-10T10:00+00:00" - }] - } - } -}
\ No newline at end of file +{}
\ No newline at end of file diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/devicemanager/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index a9a4e18ec..b946e1035 100644 --- a/sdnr/wt/devicemanager/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/sdnr/wt/devicemanager/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -36,13 +36,16 @@ limitations under the License. <reference id="rpcProviderRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry" odl:type="default" /> - + + <reference id="clusterSingletonService" + interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/> <bean id="provider" class="org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl" init-method="init" destroy-method="close"> <property name="dataBroker" ref="dataBroker"/> <property name="rpcProviderRegistry" ref="rpcProviderRegistry" /> <property name="notificationPublishService" ref="notificationPublishService" /> <property name="mountPointService" ref="mountPointService" /> + <property name="clusterSingletonService" ref="clusterSingletonService" /> </bean> diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDevMgrPropertiesFile.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDevMgrPropertiesFile.java index 74d2d2263..1f488b2e9 100644 --- a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDevMgrPropertiesFile.java +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDevMgrPropertiesFile.java @@ -163,14 +163,14 @@ public class TestDevMgrPropertiesFile { } - private void sleep(int milliseconds) { + private static void sleep(int milliseconds) { try { Thread.sleep(milliseconds); } catch (InterruptedException e) { } } - private void writeFile(File f, String content) { + public static void writeFile(File f, String content) { try { Files.asCharSink(f, StandardCharsets.UTF_8).write(content); } catch (IOException e) { diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDeviceManagerWithDatabase.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDeviceManagerWithDatabase.java index 661194c38..435e8e151 100644 --- a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDeviceManagerWithDatabase.java +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestDeviceManagerWithDatabase.java @@ -1,22 +1,17 @@ /******************************************************************************* - * ============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 + * ============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 + * 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========================================================= + * 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.devicemanager.test; @@ -30,27 +25,35 @@ import java.io.StringWriter; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; import org.json.JSONException; import org.json.JSONObject; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseWebAPIClient; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources; import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerService.Action; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.ClusterSingletonServiceProviderMock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.DataBrokerNetconfMock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointMock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointServiceMock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.NotificationPublishServiceMock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.RpcProviderRegistryMock; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.DBCleanServiceHelper; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.ReadOnlyTransactionMountpoint1211Mock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.ReadOnlyTransactionMountpoint1211pMock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.ReadOnlyTransactionMountpoint12Mock; import org.opendaylight.controller.md.sal.binding.api.MountPointService; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.slf4j.Logger; @@ -63,7 +66,7 @@ public class TestDeviceManagerWithDatabase { private static Path KARAF_ETC = Paths.get("etc"); private static DeviceManagerImpl deviceManager; - private static MountPointMock mountPoint; + private static MountPointMock mountPoint; private static DataBrokerNetconfMock dataBrokerNetconf; private static final Logger LOG = LoggerFactory.getLogger(TestDeviceManagerWithDatabase.class); @@ -73,25 +76,26 @@ public class TestDeviceManagerWithDatabase { @BeforeClass public static void before() throws InterruptedException, IOException { - System.out.println("Logger: "+LOG.getClass().getName() + " " + LOG.getName()); + System.out.println("Logger: " + LOG.getClass().getName() + " " + LOG.getName()); // Call System property to get the classpath value Path etc = KARAF_ETC; delete(etc); - System.out.println("Create empty:"+etc.toString()); + System.out.println("Create empty:" + etc.toString()); Files.createDirectories(etc); - //Create mocks + // Create mocks ReadOnlyTransactionMountpoint12Mock readOnlyTransaction = new ReadOnlyTransactionMountpoint12Mock(); dataBrokerNetconf = new DataBrokerNetconfMock(); dataBrokerNetconf.setReadOnlyTransaction(readOnlyTransaction); mountPoint = new MountPointMock(); mountPoint.setReadOnlyTransaction(readOnlyTransaction); - MountPointService mountPointService = new MountPointServiceMock(mountPoint); + ClusterSingletonServiceProvider clusterSingletonService = new ClusterSingletonServiceProviderMock(); + MountPointService mountPointService = new MountPointServiceMock(mountPoint); NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); RpcProviderRegistry rpcProviderRegistry = new RpcProviderRegistryMock(); - //start using blueprint interface + // start using blueprint interface String msg = ""; try { deviceManager = new DeviceManagerImpl(); @@ -100,7 +104,7 @@ public class TestDeviceManagerWithDatabase { deviceManager.setMountPointService(mountPointService); deviceManager.setNotificationPublishService(notificationPublishService); deviceManager.setRpcProviderRegistry(rpcProviderRegistry); - + deviceManager.setClusterSingletonService(clusterSingletonService); deviceManager.init(); } catch (Exception e) { StringWriter sw = new StringWriter(); @@ -110,17 +114,17 @@ public class TestDeviceManagerWithDatabase { e.printStackTrace(); } readOnlyTransaction.close(); - System.out.println("Initialization status: "+deviceManager.isDevicemanagerInitializationOk()); - assertTrue("Devicemanager not initialized: "+msg, deviceManager.isDevicemanagerInitializationOk()); + System.out.println("Initialization status: " + deviceManager.isDevicemanagerInitializationOk()); + assertTrue("Devicemanager not initialized: " + msg, deviceManager.isDevicemanagerInitializationOk()); System.out.println("Initialization done"); - + waitfordatabase(); } @AfterClass public static void after() throws InterruptedException, IOException { System.out.println("Start shutdown"); - //close using blueprint interface + // close using blueprint interface try { deviceManager.close(); } catch (Exception e) { @@ -143,18 +147,6 @@ public class TestDeviceManagerWithDatabase { } @Test - public void test1() throws InterruptedException { - - System.out.println("Test1: Wait for database"); - int timeout = DATABASETIMEOUTSECONDS; - while ( !deviceManager.isDatabaseInitializationFinished() && timeout-- > 0) { - System.out.println("Test1: "+timeout); - Thread.sleep(1000); //On second - } - System.out.println("Test1: database initialized"); - } - - @Test public void test2() { System.out.println("Test2: slave mountpoint"); @@ -190,7 +182,7 @@ public class TestDeviceManagerWithDatabase { NodeId nodeId = new NodeId("mountpointTest3"); Capabilities capabilities = Capabilities.getAvailableCapabilities(nNode); - System.out.println("Node capabilites: "+capabilities); + System.out.println("Node capabilites: " + capabilities); try { deviceManager.startListenerOnNodeForConnectedState(Action.CREATE, nodeId, nNode); @@ -223,7 +215,7 @@ public class TestDeviceManagerWithDatabase { NodeId nodeId = new NodeId("mountpointTest4"); Capabilities capabilities = Capabilities.getAvailableCapabilities(nNode); - System.out.println("Node capabilites: "+capabilities); + System.out.println("Node capabilites: " + capabilities); try { deviceManager.startListenerOnNodeForConnectedState(Action.CREATE, nodeId, nNode); @@ -257,7 +249,7 @@ public class TestDeviceManagerWithDatabase { NodeId nodeId = new NodeId("mountpointTest5"); Capabilities capabilities = Capabilities.getAvailableCapabilities(nNode); - System.out.println("Node capabilites: "+capabilities); + System.out.println("Node capabilites: " + capabilities); try { deviceManager.startListenerOnNodeForConnectedState(Action.CREATE, nodeId, nNode); @@ -283,9 +275,9 @@ public class TestDeviceManagerWithDatabase { System.out.println("Test6: Write zip data file file"); File testFile = new File("etc/elasticsearch_update.zip"); Resources.extractFileTo("elasticsearch_update.zip", testFile); - int wait=130; - while ( testFile.exists() && wait-- > 0) { - System.out.println("Waiting "+wait); + int wait = 130; + while (testFile.exists() && wait-- > 0) { + System.out.println("Waiting " + wait); try { Thread.sleep(1000); } catch (InterruptedException e) { @@ -298,11 +290,92 @@ public class TestDeviceManagerWithDatabase { } - //********************* Private + @Test + public void test7() throws Exception { + final int NUM = 5; + final int ARCHIVE_DAYS = 30; + final long ARCHIVE_LIMIT_SEC = TimeUnit.SECONDS.convert(ARCHIVE_DAYS, TimeUnit.DAYS); + final long ARCHIVE_INTERVAL_SEC = 10; + File propFile = KARAF_ETC.resolve("devicemanager.properties").toFile(); + + ArchiveCleanService service = deviceManager.getArchiveCleanService(); + DBCleanServiceHelper helper = new DBCleanServiceHelper(deviceManager); + + // setEsConfg + TestDevMgrPropertiesFile.writeFile(propFile, getContent(ARCHIVE_LIMIT_SEC, ARCHIVE_INTERVAL_SEC)); + //give time to read file + sleep(5); + System.out.println("Archive clean service configuration "+service); + System.out.println("To delete elements older: "+service.getDateForOldElements()); + System.out.println("Status of elements is: "+service.countOldEntries()); + + // create old data and check if the will be cleaned completely + int elements = helper.writeDataToLogs(NUM, ARCHIVE_DAYS+5, 0 /*Hours*/); + System.out.println("Written elements are: "+elements); + + waitForDeletion(service, 2 * ARCHIVE_INTERVAL_SEC, elements, "Entries are not cleared completely as expected"); + + // create partial old and newer data and check that only half of all data are cleaned + // New data are not counted as "old" .. + int elementsToRemove = elements = helper.writeDataToLogs(NUM, ARCHIVE_DAYS+5, 0); + elements += helper.writeDataToLogs(NUM, ARCHIVE_DAYS-5, 0); + waitForDeletion(service, 2 * ARCHIVE_INTERVAL_SEC, elementsToRemove, "Entries are not cleared exactly half as expected"); + + // create only newer data and check that nothing is cleaned + elements = helper.writeDataToLogs(NUM, ARCHIVE_DAYS+2, 0); + waitForDeletion(service, 2 * ARCHIVE_INTERVAL_SEC, elements, "Some entries were removed, but shouldn't."); + + service.close(); + } + + // ********************* Private + + private void waitForDeletion(ArchiveCleanService service, long timeout, long numberAtBeginning, String faultMessage) { + int numberEntries = 0; + while (timeout-- > 0) { + sleep(1000); + numberEntries = service.countOldEntries(); + if (numberEntries <= 0) { + break; + } + } + if (timeout == 0) { + fail(faultMessage + " Timeout at:" + timeout + " Entries at beginning " + numberAtBeginning + + " remaining" + numberEntries); + } + } + + + private static void waitfordatabase() throws InterruptedException { + + System.out.println("Test1: Wait for database"); + int timeout = DATABASETIMEOUTSECONDS; + while (!deviceManager.isDatabaseInitializationFinished() && timeout-- > 0) { + System.out.println("Test1: " + timeout); + Thread.sleep(1000); // On second + } + System.out.println("Ddatabase initialized"); + } + + private static void sleep(int millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + LOG.warn(e.getMessage()); + Thread.interrupted(); + } + } + + private static void waitEnter() { + Scanner sc = new Scanner(System.in); + System.out.println("Enter"); + sc.next(); + sc.close(); + } private static void delete(Path etc) throws IOException { if (Files.exists(etc)) { - System.out.println("Found and remove:"+etc.toString()); + System.out.println("Found and remove:" + etc.toString()); delete(etc.toFile()); } } @@ -318,5 +391,21 @@ public class TestDeviceManagerWithDatabase { } } + private String getContent(long archiveLimitSeconds, long esArchiveCheckIntervalSeconds) { + return "[dcae]\n" + "dcaeUserCredentials=admin:admin\n" + "dcaeUrl=http://localhost:45/abc\n" + + "dcaeHeartbeatPeriodSeconds=120\n" + "dcaeTestCollector=no\n" + "\n" + "[aots]\n" + + "userPassword=passwd\n" + "soapurladd=off\n" + "soapaddtimeout=10\n" + "soapinqtimeout=20\n" + + "userName=user\n" + "inqtemplate=inqreq.tmpl.xml\n" + "assignedto=userid\n" + + "addtemplate=addreq.tmpl.xml\n" + "severitypassthrough=critical,major,minor,warning\n" + + "systemuser=user\n" + "prt-offset=1200\n" + "soapurlinq=off\n" + "#smtpHost=\n" + "#smtpPort=\n" + + "#smtpUsername=\n" + "#smtpPassword=\n" + "#smtpSender=\n" + "#smtpReceivers=\n" + "\n" + "[es]\n" + + "esCluster=sendateodl5\n" + "esArchiveLifetimeSeconds=" + archiveLimitSeconds + "\n" + "esArchiveCheckIntervalSeconds=" + + esArchiveCheckIntervalSeconds + "\n" + "\n" + "[aai]\n" + "#keep comment\n" + + "aaiHeaders=[\"X-TransactionId: 9999\"]\n" + "aaiUrl=off\n" + "aaiUserCredentials=AAI:AAI\n" + + "aaiDeleteOnMountpointRemove=true\n" + "aaiTrustAllCerts=false\n" + "aaiApiVersion=aai/v13\n" + + "aaiPropertiesFile=aaiclient.properties\n" + "\n" + "[pm]\n" + "pmCluster=sendateodl5\n" + + "pmEnabled=true\n" + "[toggleAlarmFilter]\n" + "taEnabled=false\n" + "taDelay=5555\n" + ""; + } + } diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/ClusterSingletonServiceProviderMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/ClusterSingletonServiceProviderMock.java new file mode 100644 index 000000000..30b64817a --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/ClusterSingletonServiceProviderMock.java @@ -0,0 +1,19 @@ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; + +public class ClusterSingletonServiceProviderMock implements ClusterSingletonServiceProvider { + + @Override + public void close() throws Exception { + + } + + @Override + public ClusterSingletonServiceRegistration registerClusterSingletonService(ClusterSingletonService service) { + return null; + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/util/DBCleanServiceHelper.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/util/DBCleanServiceHelper.java new file mode 100644 index 000000000..4e46e1800 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/util/DBCleanServiceHelper.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * ============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.devicemanager.test.util; + +import java.util.Date; +import java.util.concurrent.TimeUnit; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.index.database.types.EsEventOdluxLog; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.index.impl.IndexMwtnService; + +public class DBCleanServiceHelper { + + private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter(); + + private final HtDatabaseEventsService databaseEventService; + private final IndexMwtnService mwtnService; + + /** + * Helper to fill data into the database + * @param deviceManager devicemanger to get services + */ + public DBCleanServiceHelper(DeviceManagerImpl deviceManager) { + this.databaseEventService = deviceManager.getDatabaseClientEvents(); + this.mwtnService = deviceManager.getMwtnService(); + } + + /** + * Write data into database with specific date and content profile. + * @param number of data to be written for each log + * @param days starting day, relative to actual date + * @param hours starting hour ... increased by one hour for each write + * @return integer with the amount of written data + */ + public int writeDataToLogs(int number, int days, int hours) { + int res = 0; + for (Integer t=0; t < number; t++) { //Test "sdnevents", "eventlog" + ObjectCreationNotificationXml notificationXml = new ObjectCreationNotificationXml( + "Testpoint"+t, t.toString(), getInternalDateAndTime(days, hours+t), "ObjectId"+t); + databaseEventService.writeEventLog(notificationXml); + res++; + } + + for (Integer t=0; t < number; t++) { //Test "sdnevents", "faultlog" + ProblemNotificationXml fault = new ProblemNotificationXml( + "ProblemNode"+t, "Problemuuid", "Problemname", InternalSeverity.Major, t.toString(), getInternalDateAndTime(days, hours+t)); + databaseEventService.writeFaultLog(fault); + res++; + } + + for (Integer t=0; t < number; t++) { //Test "mwtn", "log" + EsEventOdluxLog odluxEvent = new EsEventOdluxLog("Odluxevent"+t, "Problemuuid", "Message", getInternalDateAndTime(days, hours+t)); + mwtnService.writeOdluxEventForTestpurpose(odluxEvent); + res++; + } + + return res; + } + + /************************************************************** + * Private section + */ + + private InternalDateAndTime getInternalDateAndTime(int days, int hours) { + Date actual = new Date(new Date().getTime() - TimeUnit.MILLISECONDS.convert(days, TimeUnit.DAYS) - TimeUnit.MILLISECONDS.convert(hours, TimeUnit.HOURS)); + InternalDateAndTime timeStamp = InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp(actual)); + return timeStamp; + } + + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/resources/simplelogger.properties b/sdnr/wt/devicemanager/provider/src/test/resources/simplelogger.properties index 5a8d43145..eec5d3a4c 100644 --- a/sdnr/wt/devicemanager/provider/src/test/resources/simplelogger.properties +++ b/sdnr/wt/devicemanager/provider/src/test/resources/simplelogger.properties @@ -10,9 +10,10 @@ org.slf4j.simpleLogger.defaultLogLevel=info # Must be one of ("trace", "debug", "info", "warn", or "error"). # If not specified, the default logging detail level is used. # org.slf4j.simpleLogger.log.xxx.yyy=debug -org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager=debug +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager=info +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice=debug org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources=info -org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container=trace +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container=info # Set to true if you want the current date and time to be included in output messages. # Default is false, and will output the number of milliseconds elapsed since startup. diff --git a/sdnr/wt/devicemanager/provider/src/test/resources/test.properties b/sdnr/wt/devicemanager/provider/src/test/resources/test.properties index 943c25bd9..de49c5893 100644 --- a/sdnr/wt/devicemanager/provider/src/test/resources/test.properties +++ b/sdnr/wt/devicemanager/provider/src/test/resources/test.properties @@ -26,6 +26,14 @@ soapurlinq=off [es] esCluster=sendateodl5 +#time limit to keep increasing data in database [in seconds] +#60*60*24*30 (30days) +esArchiveLimit=2592000 +#folder where removed data will be stored +esArchiveFolder=./backup +#interval to archive database [in seconds] +#60*60*24 (1day) +esArchiveInterval=86400 [aai] #keep comment |