Add uptimes to device and cluster REST APIs

Change-Id: I0ccdf4e33135be4bcfd1674a76ff4b39e992268b
diff --git a/core/api/src/main/java/org/onosproject/cluster/ClusterService.java b/core/api/src/main/java/org/onosproject/cluster/ClusterService.java
index 1a75e5f..54f23cd 100644
--- a/core/api/src/main/java/org/onosproject/cluster/ClusterService.java
+++ b/core/api/src/main/java/org/onosproject/cluster/ClusterService.java
@@ -20,6 +20,7 @@
 import java.util.Set;
 
 import org.joda.time.DateTime;
+import org.onlab.util.Tools;
 import org.onosproject.core.Version;
 import org.onosproject.event.ListenerService;
 
@@ -82,6 +83,21 @@
     }
 
     /**
+     * Returns a human readable form of the system time when the availability state was last updated.
+     *
+     * @param nodeId controller node identifier
+     * @return human readable string for system time when the availability state was last updated.
+     */
+    default String localStatus(NodeId nodeId) {
+        Instant lastUpdated = getLastUpdatedInstant(nodeId);
+        String timeAgo = "Never";
+        if (lastUpdated != null) {
+            timeAgo = Tools.timeAgo(lastUpdated.toEpochMilli());
+        }
+        return timeAgo;
+    }
+
+    /**
      * Returns the system time when the availability state was last updated.
      *
      * @param nodeId controller node identifier
diff --git a/core/api/src/main/java/org/onosproject/net/device/DeviceService.java b/core/api/src/main/java/org/onosproject/net/device/DeviceService.java
index 232809b..f86a98a 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DeviceService.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DeviceService.java
@@ -185,4 +185,14 @@
      */
     String localStatus(DeviceId deviceId);
 
+
+    /**
+     * Indicates how long ago the device connected or disconnected from this
+     * controller instance as a time offset.
+     *
+     * @param deviceId device identifier
+     * @return time offset in miliseconds
+     */
+    long getLastUpdatedInstant(DeviceId deviceId);
+
 }
diff --git a/core/api/src/main/java/org/onosproject/net/device/DeviceServiceAdapter.java b/core/api/src/main/java/org/onosproject/net/device/DeviceServiceAdapter.java
index 125cbcc..f85d198 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DeviceServiceAdapter.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DeviceServiceAdapter.java
@@ -142,4 +142,9 @@
         return null;
     }
 
+    @Override
+    public long getLastUpdatedInstant(DeviceId deviceId) {
+        return 0;
+    }
+
 }
diff --git a/core/api/src/main/java/org/onosproject/net/utils/ForwardingDeviceService.java b/core/api/src/main/java/org/onosproject/net/utils/ForwardingDeviceService.java
index acca07f..3a3eea2 100644
--- a/core/api/src/main/java/org/onosproject/net/utils/ForwardingDeviceService.java
+++ b/core/api/src/main/java/org/onosproject/net/utils/ForwardingDeviceService.java
@@ -127,4 +127,9 @@
         return delegate.localStatus(deviceId);
     }
 
+    @Override
+    public long getLastUpdatedInstant(DeviceId deviceId) {
+        return delegate.getLastUpdatedInstant(deviceId);
+    }
+
 }