Revert "Corrections to getRegisteredApplications and CLI implementation"

ApplicationService is not available. For example, when using the ONOS CLI:

onos> apps -s -a
Service org.onosproject.app.ApplicationService not found

The issue seems to be a circular dependency, as ApplicationManager depends on CoreService, but CoreManager depends on ApplicationService.

Reverting for now.

This reverts commit 35ef3d3000f8b19608531dfd06f8e78482c45b32.

Change-Id: I298c3c7844df7f2395e092fbb89a8e9264883094
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
index 806449e..24b2da1 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
@@ -62,23 +62,16 @@
     private boolean sortByName = false;
 
 
-    @Option(name = "-r", aliases = "--regapps", description = "Get Registered Apps for Runtime Version")
-    private boolean getRegisteredApps = false;
-
     @Override
     protected void doExecute() {
         ApplicationService service = get(ApplicationService.class);
-        List<Application> apps;
-        if (getRegisteredApps) {
-            apps = newArrayList(service.getRegisteredApplications());
-        } else {
-            apps = newArrayList(service.getApplications());
-        }
+        List<Application> apps = newArrayList(service.getApplications());
         if (sortByName) {
             apps.sort(Comparator.comparing(app -> app.id().name()));
         } else {
             Collections.sort(apps, Comparators.APP_COMPARATOR);
         }
+
         if (outputJson()) {
             print("%s", json(service, apps));
         } else {
diff --git a/core/api/src/main/java/org/onosproject/core/Application.java b/core/api/src/main/java/org/onosproject/core/Application.java
index 84279dc..b898cb6 100644
--- a/core/api/src/main/java/org/onosproject/core/Application.java
+++ b/core/api/src/main/java/org/onosproject/core/Application.java
@@ -21,7 +21,6 @@
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
-import java.net.URL;
 
 /**
  * Abstraction of a network control/management application.
@@ -133,11 +132,4 @@
      * @return list of application names
      */
     List<String> requiredApps();
-
-    /**
-     * Returns binary image URL.
-     *
-     * @return URL of binary image
-     */
-    URL imageUrl();
-}
\ No newline at end of file
+}
diff --git a/core/api/src/main/java/org/onosproject/core/DefaultApplication.java b/core/api/src/main/java/org/onosproject/core/DefaultApplication.java
index 793ab70..2df2f8f 100644
--- a/core/api/src/main/java/org/onosproject/core/DefaultApplication.java
+++ b/core/api/src/main/java/org/onosproject/core/DefaultApplication.java
@@ -26,7 +26,6 @@
 import java.util.Optional;
 import java.util.List;
 import java.util.Objects;
-import java.net.URL;
 
 import static com.google.common.base.MoreObjects.toStringHelper;
 import static com.google.common.base.Preconditions.checkArgument;
@@ -51,7 +50,7 @@
     private final Optional<URI> featuresRepo;
     private final List<String> features;
     private final List<String> requiredApps;
-    private final URL imageUrl;
+
     /**
      * Default constructor is hidden to prevent calls to new.
      */
@@ -70,7 +69,6 @@
         featuresRepo = Optional.empty();
         features = ImmutableList.of();
         requiredApps = ImmutableList.of();
-        imageUrl = null;
     }
 
     /**
@@ -90,14 +88,13 @@
      * @param featuresRepo optional features repo URI
      * @param features     application features
      * @param requiredApps list of required application names
-     * @param imageUrl     url of oar file
      */
-    public DefaultApplication(ApplicationId appId, Version version, String title,
+    private DefaultApplication(ApplicationId appId, Version version, String title,
                               String description, String origin, String category,
                               String url, String readme, byte[] icon,
                               ApplicationRole role, Set<Permission> permissions,
                               Optional<URI> featuresRepo, List<String> features,
-                              List<String> requiredApps, URL imageUrl) {
+                              List<String> requiredApps) {
         this.appId = appId;
         this.version = version;
         this.title = title;
@@ -112,8 +109,8 @@
         this.featuresRepo = featuresRepo;
         this.features = ImmutableList.copyOf(features);
         this.requiredApps = ImmutableList.copyOf(requiredApps);
-        this.imageUrl = imageUrl;
     }
+
     @Override
     public ApplicationId id() {
         return appId;
@@ -185,11 +182,6 @@
     }
 
     @Override
-    public URL imageUrl() {
-        return imageUrl;
-    }
-
-    @Override
     public int hashCode() {
         return Objects.hash(appId, version, title, description, origin, category, url,
                             readme, role, permissions, featuresRepo, features, requiredApps);
@@ -238,7 +230,6 @@
                 .add("featuresRepo", featuresRepo)
                 .add("features", features)
                 .add("requiredApps", requiredApps)
-                .add("imageURL", imageUrl)
                 .toString();
     }
 
@@ -286,6 +277,7 @@
      * Default application builder.
      */
     public static final class Builder {
+
         private ApplicationId appId;
         private Version version;
         private String title;
@@ -293,14 +285,13 @@
         private String category;
         private String url;
         private String readme;
-        private byte[] icon = new byte[0];
+        private byte[] icon;
         private String origin;
-        private ApplicationRole role = ApplicationRole.ADMIN;
-        private Set<Permission> permissions = ImmutableSet.of();
-        private Optional<URI> featuresRepo = Optional.empty();
-        private List<String> features = ImmutableList.of();
-        private List<String> requiredApps = ImmutableList.of();
-        private URL imageUrl;
+        private ApplicationRole role;
+        private Set<Permission> permissions;
+        private Optional<URI> featuresRepo;
+        private List<String> features;
+        private List<String> requiredApps;
 
         /**
          * Default constructor for the builder.
@@ -527,17 +518,6 @@
         }
 
         /**
-         * Adds a Binary Image URL.
-         *
-         * @param imageUrl url of oar file
-         * @return builder
-         */
-        public Builder withImageUrl(URL imageUrl) {
-            this.imageUrl = imageUrl;
-            return this;
-        }
-
-        /**
          * Builds a default application object from the gathered parameters.
          *
          * @return new default application
@@ -562,7 +542,7 @@
                                           url, readme, icon,
                                           role, permissions,
                                           featuresRepo, features,
-                                          requiredApps, imageUrl);
+                                          requiredApps);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java b/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java
index 98dccec..b523126 100644
--- a/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java
+++ b/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java
@@ -49,20 +49,20 @@
 
     public static final ApplicationId APP_ID = new DefaultApplicationId(2, APP_NAME);
     private Builder baseBuilder = DefaultApplication.builder()
-            .withAppId(APP_ID)
-            .withVersion(VER)
-            .withTitle(TITLE)
-            .withDescription(DESC)
-            .withOrigin(ORIGIN)
-            .withCategory(CATEGORY)
-            .withUrl(URL)
-            .withReadme(README)
-            .withIcon(ICON)
-            .withRole(ROLE)
-            .withPermissions(PERMS)
-            .withFeaturesRepo(Optional.of(FURL))
-            .withFeatures(FEATURES)
-            .withRequiredApps(APPS);
+                .withAppId(APP_ID)
+                .withVersion(VER)
+                .withTitle(TITLE)
+                .withDescription(DESC)
+                .withOrigin(ORIGIN)
+                .withCategory(CATEGORY)
+                .withUrl(URL)
+                .withReadme(README)
+                .withIcon(ICON)
+                .withRole(ROLE)
+                .withPermissions(PERMS)
+                .withFeaturesRepo(Optional.of(FURL))
+                .withFeatures(FEATURES)
+                .withRequiredApps(APPS);
 
     @Test
     public void basics() {
@@ -77,8 +77,8 @@
         assertEquals("incorrect URL", URL, app.url());
         assertEquals("incorrect readme", README, app.readme());
         assertArrayEquals("incorrect icon", ICON, app.icon());
-        assertEquals("incorrect permissions", PERMS, app.permissions());
         assertEquals("incorrect role", ROLE, app.role());
+        assertEquals("incorrect permissions", PERMS, app.permissions());
         assertEquals("incorrect features repo", FURL, app.featuresRepo().get());
         assertEquals("incorrect features", FEATURES, app.features());
         assertEquals("incorrect apps", APPS, app.requiredApps());
@@ -88,7 +88,7 @@
     @Test
     public void testEquality() {
         Application a1 = baseBuilder.build();
-         Application a2 = DefaultApplication.builder(a1)
+        Application a2 = DefaultApplication.builder(a1)
                 .build();
         Application a3 = DefaultApplication.builder(baseBuilder)
                 .withFeaturesRepo(Optional.empty())
@@ -227,4 +227,4 @@
         assertNotNull("null icon", icon);
         assertEquals("unexpected size", 0, icon.length);
     }
-}
\ No newline at end of file
+}
diff --git a/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java b/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java
index 2f78d3a..2bb9c11 100644
--- a/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java
+++ b/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java
@@ -15,15 +15,9 @@
  */
 package org.onosproject.app.impl;
 
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Multimap;
 import com.google.common.util.concurrent.Uninterruptibles;
 import org.apache.karaf.features.Feature;
@@ -37,10 +31,6 @@
 import org.onosproject.app.ApplicationStoreDelegate;
 import org.onosproject.core.Application;
 import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.DefaultApplication;
-import org.onosproject.core.DefaultApplicationId;
-import org.onosproject.core.Version;
 import org.onosproject.event.AbstractListenerManager;
 import org.onosproject.security.Permission;
 import org.onosproject.security.SecurityUtil;
@@ -51,19 +41,17 @@
 import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.slf4j.Logger;
 
-import java.io.IOException;
 import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
-import java.util.Iterator;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.app.ApplicationEvent.Type.*;
+import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED;
+import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED;
+import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED;
+import static org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED;
 import static org.onosproject.security.AppGuard.checkPermission;
 import static org.onosproject.security.AppPermission.Type.APP_READ;
 import static org.slf4j.LoggerFactory.getLogger;
@@ -78,10 +66,9 @@
 
     private final Logger log = getLogger(getClass());
 
-    private static final String APP_REGISTRY_URL = "http://api.onosproject.org:8080/api/applications";
-
     private static final String APP_ID_NULL = "Application ID cannot be null";
     private static final long DEFAULT_OPERATION_TIMEOUT_MILLIS = 2000;
+
     private final ApplicationStoreDelegate delegate = new InternalStoreDelegate();
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
@@ -90,15 +77,12 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     protected FeaturesService featuresService;
 
-    @Reference(cardinality = ReferenceCardinality.MANDATORY)
-    protected CoreService coreService;
-
     // Application supplied hooks for pre-activation processing.
     private final Multimap<String, Runnable> deactivateHooks = HashMultimap.create();
     private final Cache<ApplicationId, CountDownLatch> pendingOperations =
             CacheBuilder.newBuilder()
-                    .expireAfterWrite(DEFAULT_OPERATION_TIMEOUT_MILLIS * 2, TimeUnit.MILLISECONDS)
-                    .build();
+                        .expireAfterWrite(DEFAULT_OPERATION_TIMEOUT_MILLIS * 2, TimeUnit.MILLISECONDS)
+                        .build();
 
     @Activate
     public void activate() {
@@ -319,8 +303,7 @@
     }
 
     // Invokes the specified function, if not null.
-    @java.lang.SuppressWarnings("squid:S1217")
-    // We really do mean to call run()
+    @java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run()
     private void invokeHook(Runnable hook, ApplicationId appId) {
         if (hook != null) {
             try {
@@ -332,68 +315,4 @@
         }
     }
 
-    @Override
-    public Set<Application> getRegisteredApplications() {
-        ImmutableSet.Builder<Application> builder = ImmutableSet.builder();
-        ObjectMapper mapper = new ObjectMapper();
-
-        // Get input stream from the URL
-        try {
-            URL githubUrl = new URL(APP_REGISTRY_URL + "?onosVersion=" + coreService.version().toString());
-            HttpURLConnection githubHttp = (HttpURLConnection) githubUrl.openConnection();
-            InputStream githubStream = githubHttp.getInputStream();
-
-            // Read input stream into an ArrayNode
-            ArrayNode rootTree = (ArrayNode) mapper.readTree(githubStream);
-
-            // Iterate over the array node for each object add each version as application object to the set
-            rootTree.forEach(n -> {
-                mapObject(builder, (ObjectNode) n);
-            });
-
-            //Iterate through Builder to remove unnecessary apps
-            Set<Application> apps = builder.build();
-
-            return apps;
-        } catch (MalformedURLException e) {
-            throw new IllegalStateException("Bad URL " + APP_REGISTRY_URL, e);
-        } catch (IOException e) {
-            throw new IllegalStateException("Unable to fetch URL " + APP_REGISTRY_URL, e);
-        }
-    }
-
-    private void mapObject(ImmutableSet.Builder<Application> apps, ObjectNode node) {
-        String appIDs = node.get("id").asText();
-        ApplicationId appID = new DefaultApplicationId(1, appIDs);
-        String title = node.get("title").asText();
-        String readme = node.get("readme").asText();
-        String category = node.get("category").asText();
-        String url = node.get("url").asText();
-        String origin = node.get("maintainer").asText();
-        JsonNode it = node.get("versions");
-        Iterator iterate = it.iterator();
-        while (iterate.hasNext()) {
-            DefaultApplication.Builder app = new DefaultApplication.Builder();
-            JsonNode jsonNode = (JsonNode) iterate.next();
-            URL imageUrl = null;
-            try {
-                imageUrl = new URL(jsonNode.get("oarURL").asText());
-            } catch (MalformedURLException e) {
-                e.printStackTrace();
-            }
-            Version version1 = Version.version(jsonNode.get("onosVersion").asText());
-            app.withImageUrl(imageUrl)
-                    .withAppId(new DefaultApplicationId(1, node.get("id").asText()))
-                    .withVersion(version1)
-                    .withAppId(appID)
-                    .withReadme(readme)
-                    .withDescription(readme)
-                    .withTitle(title)
-                    .withFeatures(ImmutableList.of("none"))
-                    .withCategory(category)
-                    .withUrl(url)
-                    .withOrigin(origin);
-            apps.add(app.build());
-        }
-    }
-}
\ No newline at end of file
+}
diff --git a/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java b/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java
index f8c7eed..5528f26 100644
--- a/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java
@@ -27,10 +27,8 @@
 import org.onosproject.common.event.impl.TestEventDispatcher;
 import org.onosproject.core.Application;
 import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreServiceAdapter;
 import org.onosproject.core.DefaultApplication;
 import org.onosproject.core.DefaultApplicationId;
-import org.onosproject.core.Version;
 
 import java.io.InputStream;
 import java.net.URI;
@@ -51,13 +49,10 @@
 public class ApplicationManagerTest {
 
     public static final DefaultApplicationId APP_ID = new DefaultApplicationId(1, APP_NAME);
-    private static final Version CORE_VERSION = Version.version(2, 1, "0", "");
 
     private ApplicationManager mgr = new ApplicationManager();
     private ApplicationListener listener = new TestListener();
 
-
-
     private boolean deactivated = false;
 
     @Before
@@ -86,22 +81,6 @@
     }
 
     @Test
-    public void testGetRegisteredApps() {
-        mgr.coreService = new TestCoreService();
-        Set<Application> apps = mgr.getRegisteredApplications();
-        System.out.println(apps);
-        assertFalse("SET contains less Apps than it should", apps.size() < 158);
-    }
-
-    private static class TestCoreService extends CoreServiceAdapter {
-
-        @Override
-        public Version version() {
-            return CORE_VERSION;
-        }
-    }
-
-    @Test
     public void install() {
         InputStream stream = ApplicationArchive.class.getResourceAsStream("app.zip");
         Application app = mgr.install(stream);
@@ -244,4 +223,4 @@
         }
     }
 
-}
\ No newline at end of file
+}