summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/model/src/main/java
diff options
context:
space:
mode:
authorherbert <herbert.eiselt@highstreet-technologies.com>2020-01-30 10:15:11 +0100
committerKAPIL SINGAL <ks220y@att.com>2020-01-31 19:42:37 +0000
commitd77d01bae41b5c8331a6de6eff1a64e08cd9e279 (patch)
treeb0863c9c34916a0fab99d044ad9f8925597bfbc3 /sdnr/wt/data-provider/model/src/main/java
parent913eea4f5e7bdb32f9fa42767ccbc9b1cf04f5ef (diff)
SDN-R add updated app
add updated data-provider Issue-ID: SDNC-1026 Signed-off-by: herbert <herbert.eiselt@highstreet-technologies.com> Change-Id: I641f8144955fcfb196d0cb19d57452c1d1a69a92 Signed-off-by: herbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/model/src/main/java')
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/ArchiveCleanProvider.java39
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java102
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtDatabaseMaintenance.java56
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java41
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEsConfig.java48
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/NetconfTimeStamp.java87
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/StatusChangedHandler.java29
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java215
8 files changed, 617 insertions, 0 deletions
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/ArchiveCleanProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/ArchiveCleanProvider.java
new file mode 100644
index 000000000..00ec2e60e
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/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.dataprovider.model;
+
+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/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java
new file mode 100644
index 000000000..fd25661e3
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java
@@ -0,0 +1,102 @@
+/**
+ * ============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.model;
+
+import java.util.Date;
+import java.util.List;
+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.EventlogEntity;
+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.FaultlogEntity;
+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.NetworkElementConnectionEntity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity;
+
+public interface DataProvider extends ArchiveCleanProvider {
+
+ // -- Connection log
+ void writeConnectionLog(ConnectionlogEntity event);
+
+ // -- Event log
+ void writeEventLog(EventlogEntity event);
+
+ void writeFaultLog(FaultlogEntity fault);
+
+ void updateFaultCurrent(FaultcurrentEntity fault);
+
+ /**
+ * Remove all entries for one node
+ *
+ * @param nodeName contains the mountpointname
+ * @return number of deleted entries
+ */
+ int clearFaultsCurrentOfNode(String nodeName);
+
+ /**
+ * Remove all entries for one node
+ *
+ * @param nodeName contains the mountpointname
+ * @param objectId of element to be deleted
+ * @return number of deleted entries
+ */
+ int clearFaultsCurrentOfNodeWithObjectId(String nodeName, String objectId);
+
+ /**
+ * Deliver list with all mountpoint/node-names in the database.
+ *
+ * @return List of all mountpoint/node-names the had active alarms.
+ */
+ List<String> getAllNodesWithCurrentAlarms();
+
+ /**
+ * write internal equipment to database
+ * @param internalEquipment with mandatory fields.
+ */
+ void writeInventory(Inventory internalEquipment);
+
+ /**
+ *
+ * @param networkElementConnectionEntitiy to wirte to DB
+ * @param nodeId Id for this DB element
+ */
+ void updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy,
+ String nodeId);
+
+ /**
+ * Update after new mountpoint registration
+ * @param networkElementConnectionEntitiy data
+ * @param nodeId of device (mountpoint name)
+ */
+ void updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId);
+
+ void removeNetworkConnection(String nodeId);
+
+ @Override
+ int doIndexClean(Date olderAreOutdated);
+
+ @Override
+ int getNumberOfOldObjects(Date olderAreOutdated);
+
+ List<NetworkElementConnectionEntity> getNetworkElementConnections();
+
+ /**
+ * @param list
+ */
+ void doWritePerformanceData(List<PmdataEntity> list);
+
+}
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtDatabaseMaintenance.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtDatabaseMaintenance.java
new file mode 100644
index 000000000..11681c05f
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtDatabaseMaintenance.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * ============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.model;
+
+import java.util.List;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceEntity;
+
+/**
+ * @author herbert
+ *
+ */
+public interface HtDatabaseMaintenance {
+
+ /**
+ * @param mountPointNodeName
+ */
+ MaintenanceEntity createIfNotExists(String mountPointNodeName);
+
+ /**
+ * @param mountPointNodeName
+ */
+ void deleteIfNotRequired(String mountPointNodeName);
+
+ /**
+ * @return
+ */
+ List<MaintenanceEntity> getAll();
+
+ /**
+ * @param mountpointName
+ * @return
+ */
+ MaintenanceEntity getMaintenance(@Nullable String mountpointName);
+
+ /**
+ * @param m
+ */
+ MaintenanceEntity setMaintenance(MaintenanceEntity m);
+
+}
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java
new file mode 100644
index 000000000..95ea0752b
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * ============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.model;
+
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey;
+
+public interface IEntityDataProvider {
+
+ /** Get provider for database read/write operations **/
+ public DataProvider getDataProvider();
+
+ /** Get provider to access read/write operations for maintenance **/
+ public HtDatabaseMaintenance getHtDatabaseMaintenance();
+
+ /** Set overall ready status from outside of this data-provider **/
+ public void setReadyStatus(boolean status);
+
+ /** Set some static status information after startup */
+ public void setStatus(StatusKey key,String value);
+
+ /** Database configuration information **/
+ public IEsConfig getEsConfig();
+
+ /** Provide NetconfTimeStamp handler **/
+ public NetconfTimeStamp getConverter();
+}
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEsConfig.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEsConfig.java
new file mode 100644
index 000000000..f41095db9
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEsConfig.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * ============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.model;
+
+import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
+
+public interface IEsConfig {
+
+ String getCluster();
+
+ /**
+ * @return seconds
+ */
+ long getArchiveCheckIntervalSeconds();
+
+ /**
+ * @return seconds
+ */
+ long getArchiveLifetimeSeconds();
+
+ /**
+ * @param archiveCleanService
+ */
+ void unregisterConfigChangedListener(IConfigChangedListener archiveCleanService);
+
+ /**
+ * @param archiveCleanService
+ */
+ void registerConfigChangedListener(IConfigChangedListener archiveCleanService);
+
+
+
+}
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/NetconfTimeStamp.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/NetconfTimeStamp.java
new file mode 100644
index 000000000..5bed9f7a3
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/NetconfTimeStamp.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * ============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.model;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+
+/**
+ * @author herbert
+ *
+ */
+public interface NetconfTimeStamp {
+
+ /**
+ * Get actual timestamp as NETCONF specific type NETCONF/YANG 1.0 Format
+ *
+ * @return String with Date in NETCONF/YANG Format Version 1.0.
+ */
+ String getTimeStampAsNetconfString();
+
+ /**
+ * Get actual timestamp as NETCONF specific type NETCONF/YANG 1.0 Format
+
+ * @return String with Date in NETCONF/YANG Format Version 1.0.
+ */
+ String getTimeStampAsNetconfString(Date date);
+
+ /**
+ * 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.
+ */
+ DateAndTime getTimeStamp();
+
+ /**
+ * 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.
+ */
+ DateAndTime getTimeStamp(Date date);
+
+ /**
+ * 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.
+ */
+ DateAndTime getTimeStamp(String date);
+
+ /**
+ * Return the String with a NETCONF time converted to long
+ *
+ * @param netconfTime as String according the formats given above
+ * @return Epoch milliseconds
+ * @throws IllegalArgumentException In case of no compliant time format definition for the string
+ */
+ long getTimeStampFromNetconfAsMilliseconds(String netconfTime) throws IllegalArgumentException;
+
+ /**
+ * Deliver String result.
+ *
+ * @param netconfTime as String according the formats given above
+ * @return If successful: String in ISO8601 Format for database and presentation. If "wrong formed
+ * input" the Input string with the prefix "Maleformed date" is delivered back.
+ */
+ String getTimeStampFromNetconf(String netconfTime);
+
+ Date getDateFromNetconf(String netconfTime);
+
+ String getTimeStampAsNetconfString(LocalDateTime dt);
+
+} \ No newline at end of file
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/StatusChangedHandler.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/StatusChangedHandler.java
new file mode 100644
index 000000000..fa64d4d3e
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/StatusChangedHandler.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * ============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.model;
+
+
+public interface StatusChangedHandler {
+
+ public enum StatusKey {
+ CLUSTER_SIZE,
+
+ }
+ public void onStatusChanged(StatusKey key,String newValue);
+
+}
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java
new file mode 100644
index 000000000..f5dd65269
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * ============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.model.types;
+
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.util.Date;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 2019/06/17 Redesign to ZonedDateTime because of sync problems.
+ *
+ * Function is handling the NETCONF and the format used by database and restconf communication.
+ *
+ * Input supported for the formats used in NETCONF messages:
+ *
+ * Format1 ISO 8601 2017-01-18T11:44:49.482-05:00
+ *
+ * Format2 NETCONF - pattern from ietf-yang-types "2013-07-15" Pattern:
+ * "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-](\d{2}):(\d{2}))"
+ *
+ * Format3 NETCONF DateAndTime CoreModel-CoreFoundationModule-TypeDefinitions vom
+ * 2016-07-01 Example1: 20170118114449.1Z Example2: 20170118114449.1-0500 Pattern:
+ * "\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}.\d+?(Z|[\+\-](\d{2})(\d{2}))" typedef DateAndTime { description
+ * "This primitive type defines the date and time according to the following structure:
+ * 'yyyyMMddhhmmss.s[Z|{+|-}HHMm]' where: yyyy '0000'..'9999' year MM '01'..'12' month dd '01'..'31'
+ * day hh '00'..'23' hour mm '00'..'59' minute ss '00'..'59' second s '.0'..'.9' tenth of second
+ * (set to '.0' if EMS or NE cannot support this granularity) Z 'Z' indicates UTC (rather than local
+ * time) {+|-} '+' or '-' delta from UTC HH '00'..'23' time zone difference in hours Mm '00'..'59'
+ * time zone difference in minutes."; type string; } Format4 E/// specific Example1:
+ * 2017-01-23T13:32:38-05:00 Example2: 2017-01-23T13:32-05:00
+ *
+ * Input formats netconfTime as String according the formats given above
+ *
+ * Return format is String in ISO8601 Format for database and presentation.
+ *
+ * Example formats:
+ * 1) ISO8601. Example 2017-01-18T11:44:49.482-05:00
+ * 2) Microwave ONF. Examples 20170118114449.1Z, 20170118114449.1-0500
+ * 3.1) Ericson. Example: 2017-01-23T13:32:38-05:00
+ * 3.2) Ericson. Example: 2017-01-23T13:32-05:00
+ * Always 10 Groups,
+ * 1:Year 2:Month 3:day 4:Hour 5:minute 6:optional sec 7:optional ms 8:optional Z or 9:offset
+ * signedhour 10:min
+ *
+ * Template:
+ * private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
+ */
+
+public class NetconfTimeStampImpl implements NetconfTimeStamp {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfTimeStamp.class);
+
+ private static final NetconfTimeStamp CONVERTER = new NetconfTimeStampImpl();
+
+ /**
+ * Specify the input format expected from netconf, and from specific devices.
+ */
+ private static DateTimeFormatter formatterInput = DateTimeFormatter.ofPattern(""
+ + "[yyyy-MM-dd'T'HH:mm[:ss][.SSS][.SS][.S][xxx][xx][X][Z]]"
+ + "[yyyyMMddHHmmss[.SSS][.SS][.S][xxx][xx][X][Z]]"
+ ).withZone(ZoneOffset.UTC);
+
+ /**
+ * Specify output format that is used internally
+ */
+ private static DateTimeFormatter formatterOutput = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.S'Z'")
+ .withZone(ZoneOffset.UTC);
+
+ /**
+ * Use static access
+ */
+ private NetconfTimeStampImpl() {
+ }
+
+ /*
+ * ------------------------------------ Public function
+ */
+
+ /**
+ * Use this function to get the converter
+ * @return global converter
+ */
+ public static NetconfTimeStamp getConverter() {
+ return CONVERTER;
+ }
+
+ /**
+ * Get actual timestamp as NETCONF specific type NETCONF/YANG 1.0 Format
+ *
+ * @return String with Date in NETCONF/YANG Format Version 1.0.
+ */
+ @Override
+ public String getTimeStampAsNetconfString() {
+ return ZonedDateTime.now(ZoneOffset.UTC).format(formatterOutput);
+ }
+
+ /**
+ * Get actual timestamp as NETCONF specific type NETCONF/YANG 1.0 Format
+
+ * @return String with Date in NETCONF/YANG Format Version 1.0.
+ */
+ @Override
+ public String getTimeStampAsNetconfString(Date date) {
+ return ZonedDateTime.ofInstant(date.toInstant(),ZoneOffset.UTC).format(formatterOutput);
+ }
+
+
+
+ /**
+ * 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.
+ */
+ @Override
+ public DateAndTime getTimeStamp() {
+ 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.
+ */
+ @Override
+ public DateAndTime getTimeStamp(Date date) {
+ return DateAndTime.getDefaultInstance(getTimeStampAsNetconfString(date));
+ }
+ /**
+ * 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.
+ */
+ @Override
+ public DateAndTime getTimeStamp(String date) {
+ return DateAndTime.getDefaultInstance(date);
+ }
+
+ /**
+ * Return the String with a NETCONF time converted to long
+ *
+ * @param netconfTime as String according the formats given above
+ * @return Epoch milliseconds
+ * @throws IllegalArgumentException In case of no compliant time format definition for the string
+ */
+ @Override
+ public long getTimeStampFromNetconfAsMilliseconds(String netconfTime) throws IllegalArgumentException {
+ try {
+ long utcMillis = doParse(netconfTime).toInstant().toEpochMilli();
+ return utcMillis;
+ } catch (DateTimeParseException e) {
+ throw new IllegalArgumentException(
+ "No pattern for NETCONF data string: " + netconfTime + " Msg:" + e.getMessage());
+ }
+ }
+
+ /**
+ * Deliver String result.
+ *
+ * @param netconfTime as String according the formats given above
+ * @return If successful: String in ISO8601 Format for database and presentation. If "wrong formed
+ * input" the Input string with the prefix "Maleformed date" is delivered back.
+ */
+ @Override
+ public String getTimeStampFromNetconf(String netconfTime) {
+ try {
+ String inputUTC = doParse(netconfTime).format(formatterOutput);
+ return inputUTC;
+ } catch (Exception e) {
+ LOG.info(e.getMessage());
+ }
+ LOG.debug("No pattern for NETCONF data string: {}", netconfTime);
+ return "Malformed date: " + netconfTime; // Error handling
+ }
+
+ /*----------------------------------------------------
+ * Private functions
+ */
+
+ private OffsetDateTime doParse(String netconfTime) {
+ return OffsetDateTime.parse(netconfTime, formatterInput);
+ }
+
+ @Override
+ public Date getDateFromNetconf(String netconfTime) {
+ return Date.from(LocalDateTime.parse(netconfTime, formatterInput).atZone(ZoneOffset.UTC).toInstant());
+ }
+
+ @Override
+ public String getTimeStampAsNetconfString(LocalDateTime dt) {
+ return formatterOutput.format(dt);
+ }
+
+}