ONOS-1418 Fix for intermittent issue with app store.

Change-Id: I94cb818550825984ec5e70a82a772a6f3bae5b0d
diff --git a/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java b/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java
index 880a31b..ff3ad1d 100644
--- a/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java
+++ b/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java
@@ -346,7 +346,7 @@
      * @param appName application name
      * @return true if the app descriptor was updated
      */
-    private boolean updateTime(String appName) {
+    protected boolean updateTime(String appName) {
         return appFile(appName, APP_XML).setLastModified(System.currentTimeMillis());
     }
 
diff --git a/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java b/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java
index 1279c0e..03b5b5e 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java
@@ -172,9 +172,9 @@
      */
     private void loadFromDisk() {
         for (String name : getApplicationNames()) {
-            Application app = create(getApplicationDescription(name));
+            Application app = create(getApplicationDescription(name), false);
             if (app != null && isActive(app.id().name())) {
-                activate(app.id());
+                activate(app.id(), false);
                 // load app permissions
             }
         }
@@ -224,11 +224,14 @@
     @Override
     public Application create(InputStream appDescStream) {
         ApplicationDescription appDesc = saveApplication(appDescStream);
-        return create(appDesc);
+        return create(appDesc, true);
     }
 
-    private Application create(ApplicationDescription appDesc) {
+    private Application create(ApplicationDescription appDesc, boolean updateTime) {
         Application app = registerApp(appDesc);
+        if (updateTime) {
+            updateTime(app.id().name());
+        }
         apps.put(app.id(), app);
         states.put(app, INSTALLED);
         return app;
@@ -246,8 +249,15 @@
 
     @Override
     public void activate(ApplicationId appId) {
+        activate(appId, true);
+    }
+
+    private void activate(ApplicationId appId, boolean updateTime) {
         Application app = apps.get(appId);
         if (app != null) {
+            if (updateTime) {
+                updateTime(appId.name());
+            }
             states.put(app, ACTIVATED);
         }
     }
@@ -256,6 +266,7 @@
     public void deactivate(ApplicationId appId) {
         Application app = apps.get(appId);
         if (app != null) {
+            updateTime(appId.name());
             states.put(app, DEACTIVATED);
         }
     }