Fix ONOS CI by removing the usage of getRegisteredApps

getRegisteredApps is deprecated and it has been discontinued

This patch partially reverts:
- https://gerrit.onosproject.org/c/onos/+/22325
- https://gerrit.onosproject.org/c/onos/+/22362
- https://gerrit.onosproject.org/c/onos/+/22382

Change-Id: I652d814a006709bd40a673699697ba229955b0e4
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
index 67bd6ba..0571fb2 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
@@ -21,19 +21,13 @@
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onosproject.app.ApplicationAdminService;
-import org.onosproject.app.ApplicationService;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.core.Application;
 import org.onosproject.core.ApplicationId;
-import org.onosproject.core.VersionService;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
 
 import java.io.IOException;
 import java.net.URL;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -49,12 +43,8 @@
     static final String ACTIVATE = "activate";
     static final String DEACTIVATE = "deactivate";
     static final String DOWNLOAD = "download";
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY)
-    protected VersionService versionService;
-
     @Argument(index = 0, name = "command",
-            description = "Command name (install|activate|deactivate|uninstall|download|installreg)",
+            description = "Command name (install|activate|deactivate|uninstall|download)",
             required = true)
     @Completion(ApplicationCommandCompleter.class)
     String command = null;
@@ -90,31 +80,11 @@
 
     // Installs the application from input of the specified URL
     private boolean installApp(ApplicationAdminService service, String url) {
-
         try {
             if ("-".equals(url)) {
                 service.install(System.in);
-            } else if (url.contains("oar")) {
-                service.install(new URL(url).openStream());
             } else {
-                Set<Application> app = get(ApplicationService.class)
-                        .getRegisteredApplications();
-                if (app.isEmpty()) {
-                    System.out.println("Could Not Install " + url);
-                    return false;
-                }
-                Iterator<Application> iterator = app.iterator();
-                Application recent = null;
-                while (iterator.hasNext()) {
-                    Application application = iterator.next();
-                    if (recent == null && application.id().name().equals(url)) {
-                        recent = application;
-                    } else if (application.version().compareTo(recent.version()) > 0 &&
-                            application.id().name().equals(url)) {
-                        recent = application;
-                    }
-                }
-                service.install(recent.imageUrl().openStream());
+                service.install(new URL(url).openStream());
             }
         } catch (IOException e) {
             error("Unable to get URL: %s", url);
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java
index 03409d0..5984603 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java
@@ -58,20 +58,13 @@
         ApplicationService service = get(ApplicationService.class);
         Iterator<Application> it = service.getApplications().iterator();
         SortedSet<String> strings = delegate.getStrings();
-        if ("install".equals(cmd)) {
-            it = service.getRegisteredApplications().iterator();
-            while (it.hasNext()) {
-                strings.add(it.next().id().name());
-            }
-        } else {
-            while (it.hasNext()) {
-                Application app = it.next();
-                ApplicationState state = service.getState(app.id());
-                if ("uninstall".equals(cmd) || "download".equals(cmd) ||
-                        ("activate".equals(cmd) && state == INSTALLED) ||
-                        ("deactivate".equals(cmd) && state == ACTIVE)) {
-                    strings.add(app.id().name());
-                }
+        while (it.hasNext()) {
+            Application app = it.next();
+            ApplicationState state = service.getState(app.id());
+            if ("uninstall".equals(cmd) || "download".equals(cmd) ||
+                    ("activate".equals(cmd) && state == INSTALLED) ||
+                    ("deactivate".equals(cmd) && state == ACTIVE)) {
+                strings.add(app.id().name());
             }
         }
 
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..0832f8c 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
@@ -61,24 +61,16 @@
     @Option(name = "-n", aliases = "--name", description = "Sort by application ID name")
     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/app/ApplicationService.java b/core/api/src/main/java/org/onosproject/app/ApplicationService.java
index 0f2d155..aa6b8e6 100644
--- a/core/api/src/main/java/org/onosproject/app/ApplicationService.java
+++ b/core/api/src/main/java/org/onosproject/app/ApplicationService.java
@@ -91,7 +91,10 @@
      * Returns the set of all installed applications.
      *
      * @return set of apps putside the build/core environment
+     *
+     * @deprecated since onos-2.5
      */
+    @Deprecated
     default Set<Application> getRegisteredApplications() {
         return ImmutableSet.of();
     }
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 6b18a04..8ebfa4c 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,14 +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;
@@ -37,9 +32,6 @@
 import org.onosproject.app.ApplicationStoreDelegate;
 import org.onosproject.core.Application;
 import org.onosproject.core.ApplicationId;
-import org.onosproject.core.DefaultApplication;
-import org.onosproject.core.DefaultApplicationId;
-import org.onosproject.core.Version;
 import org.onosproject.core.VersionService;
 import org.onosproject.event.AbstractListenerManager;
 import org.onosproject.security.Permission;
@@ -51,19 +43,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.Iterator;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 
 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,8 +68,6 @@
 
     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();
@@ -336,67 +324,7 @@
 
     @Override
     public Set<Application> getRegisteredApplications() {
-        ImmutableSet.Builder<Application> builder = ImmutableSet.builder();
-        ObjectMapper mapper = new ObjectMapper();
-        String vers = versionService.version().toString();
-        vers = vers.substring(0, vers.lastIndexOf(".") + 2);
-        // Get input stream from the URL
-        try {
-            URL serverUrl = new URL(APP_REGISTRY_URL + "?onosVersion=" + vers);
-            HttpURLConnection serverHttp = (HttpURLConnection) serverUrl.openConnection();
-            InputStream githubStream = serverHttp.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 + "?onosVersion=" + vers, e);
-        } catch (IOException e) {
-            throw new IllegalStateException("Unable to fetch URL: " + APP_REGISTRY_URL + "?onosVersion=" + vers, e);
-        }
+        return ImmutableSet.of();
     }
 
-    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 203abb7..8c835c1 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
@@ -85,14 +85,6 @@
         assertEquals("incorrect features", FEATURES, app.features());
     }
 
-    @Test
-    public void testGetRegisteredApps() {
-        mgr.versionService = new TestVersionService();
-        Set<Application> apps = mgr.getRegisteredApplications();
-        System.out.println(apps);
-        assertFalse("SET contains less Apps than it should", apps.size() < 158);
-    }
-
     private static class TestVersionService extends VersionServiceAdapter {
 
         @Override