ONOS-2091 Installing app when already installed will now raise an error

Change-Id: I4dacd63bf4a99244b23b932d35dd9cbd088548c1
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 78fd0b9..1b1c23b 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
@@ -50,6 +50,7 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
+import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.io.ByteStreams.toByteArray;
 import static com.google.common.io.Files.createParentDirs;
 import static com.google.common.io.Files.write;
@@ -108,7 +109,7 @@
      *
      * @return top-level directory path
      */
-    protected String getRootPath() {
+    public String getRootPath() {
         return root.getPath();
     }
 
@@ -179,6 +180,8 @@
             boolean plainXml = isPlainXml(cache);
             ApplicationDescription desc = plainXml ?
                     parsePlainAppDescription(bis) : parseZippedAppDescription(bis);
+            checkState(!appFile(desc.name(), APP_XML).exists(),
+                       "Application %s already installed", desc.name());
 
             if (plainXml) {
                 expandPlainApplication(cache, desc);
@@ -309,6 +312,7 @@
     private void expandPlainApplication(byte[] stream, ApplicationDescription desc)
             throws IOException {
         File file = appFile(desc.name(), APP_XML);
+        checkState(!file.getParentFile().exists(), "Application already installed");
         createParentDirs(file);
         write(stream, file);
     }