Remove deprecated SNMP provider config

Change-Id: I7b3afecdb26762be9cd2d12b6feb50900ba2e303
diff --git a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java b/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java
index 5a78260..c4fdcd1 100644
--- a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java
+++ b/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java
@@ -15,7 +15,6 @@
  */
 package org.onosproject.provider.snmp.device.impl;
 
-import com.google.common.collect.ImmutableList;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -25,7 +24,6 @@
 import org.onlab.packet.ChassisId;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
-import org.onosproject.net.config.ConfigException;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.Device;
@@ -54,14 +52,12 @@
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 
-import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
 import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
@@ -106,16 +102,7 @@
     protected final NetworkConfigListener cfgLister = new InternalNetworkConfigListener();
 
 
-    protected final List<ConfigFactory> factories = ImmutableList.of(
-            new ConfigFactory<ApplicationId, SnmpProviderConfig>(APP_SUBJECT_FACTORY,
-                                                                 SnmpProviderConfig.class,
-                                                                 "snmp_devices",
-                                                                 true) {
-                @Override
-                public SnmpProviderConfig createConfig() {
-                    return new SnmpProviderConfig();
-                }
-            },
+    protected final ConfigFactory factory =
             new ConfigFactory<DeviceId, SnmpDeviceConfig>(SubjectFactories.DEVICE_SUBJECT_FACTORY,
                                                           SnmpDeviceConfig.class,
                                                           SCHEME) {
@@ -123,7 +110,7 @@
                 public SnmpDeviceConfig createConfig() {
                     return new SnmpDeviceConfig();
                 }
-            });
+            };
 
 
     /**
@@ -139,10 +126,9 @@
 
         providerService = providerRegistry.register(this);
         appId = coreService.registerApplication(APP_NAME);
-        factories.forEach(netCfgService::registerConfigFactory);
+        netCfgService.registerConfigFactory(factory);
         netCfgService.addListener(cfgLister);
         connectDevices();
-        addOrRemoveDevicesConfig();
         modified(context);
         log.info("Started");
     }
@@ -160,7 +146,7 @@
             log.error("Device builder did not terminate");
         }
         deviceBuilderExecutor.shutdownNow();
-        factories.forEach(netCfgService::unregisterConfigFactory);
+        netCfgService.unregisterConfigFactory(factory);
         netCfgService.removeListener(cfgLister);
         providerRegistry.unregister(this);
         providerService = null;
@@ -172,23 +158,6 @@
         log.info("Modified");
     }
 
-    //Old method to register devices provided via net-cfg under apps/snmp/ tree
-    private void addOrRemoveDevicesConfig() {
-        SnmpProviderConfig cfg = netCfgService.getConfig(appId, SnmpProviderConfig.class);
-        if (cfg != null) {
-            try {
-                cfg.getDevicesInfo().forEach(info -> {
-                    buildDevice(new DefaultSnmpDevice(info.ip().toString(),
-                                                      info.port(), info.username(),
-                                                      info.password()));
-
-                });
-            } catch (ConfigException e) {
-                log.error("Cannot read config error " + e);
-            }
-        }
-    }
-
     //Method to register devices provided via net-cfg under devices/ tree
     private void connectDevices() {
         Set<DeviceId> deviceSubjects =
@@ -344,14 +313,12 @@
             } else {
                 log.warn("Injecting device via this Json is deprecated, " +
                                  "please put configuration under devices/");
-                addOrRemoveDevicesConfig();
             }
         }
 
         @Override
         public boolean isRelevant(NetworkConfigEvent event) {
-            return (event.configClass().equals(SnmpDeviceConfig.class) ||
-                    event.configClass().equals(SnmpProviderConfig.class)) &&
+            return (event.configClass().equals(SnmpDeviceConfig.class)) &&
                     (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
                             event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED);
         }
diff --git a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpProviderConfig.java b/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpProviderConfig.java
deleted file mode 100644
index 43f4ad7..0000000
--- a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpProviderConfig.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.provider.snmp.device.impl;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.annotations.Beta;
-import com.google.common.collect.Sets;
-import org.onlab.packet.IpAddress;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.config.ConfigException;
-import org.onosproject.net.config.Config;
-
-import java.util.Set;
-
-/**
- * Configuration decoder for SNMP provider.
- * @deprecated 1.10.0 Kingfisher
- */
-@Deprecated
-@Beta
-public class SnmpProviderConfig extends Config<ApplicationId> {
-
-    public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
-    private static final String IP = "ip";
-    private static final int DEFAULT_TCP_PORT = 830;
-    private static final String PORT = "port";
-    private static final String NAME = "username";
-    private static final String PASSWORD = "password";
-
-    /**
-     * Retrieves a set of SnmpDeviceInfo containing all the device
-     * configuration pertaining to the SNMP device provider.
-     * @return set of device configurations.
-     *
-     * @throws ConfigException if configuration can't be read
-     */
-    public Set<SnmpDeviceInfo> getDevicesInfo() throws ConfigException {
-        Set<SnmpDeviceInfo> deviceInfos = Sets.newHashSet();
-
-        try {
-            for (JsonNode node : array) {
-                String ip = node.path(IP).asText();
-                IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
-                int port = node.path(PORT).asInt(DEFAULT_TCP_PORT);
-                String name = node.path(NAME).asText();
-                String password = node.path(PASSWORD).asText();
-                deviceInfos.add(new SnmpDeviceInfo(ipAddr, port, name, password));
-
-            }
-        } catch (IllegalArgumentException e) {
-            throw new ConfigException(CONFIG_VALUE_ERROR, e);
-        }
-
-        return deviceInfos;
-    }
-
-    /**
-     * Contains information about a SNMP device retrieved form the net-cfg subsystem.
-     */
-    public class SnmpDeviceInfo {
-        private final IpAddress ip;
-        private final int port;
-        private final String username;
-        private final String password;
-
-        /**
-         * Build an information object containing the given device specifics.
-         * @param ip ip
-         * @param port port
-         * @param username username
-         * @param password password (a.k.a community in SNMP)
-         */
-        public SnmpDeviceInfo(IpAddress ip, int port, String username, String password) {
-            this.ip = ip;
-            this.port = port;
-            this.username = username;
-            this.password = password;
-        }
-
-        /**
-         * Returns IpAddress of the device.
-         * @return ip
-         */
-        public IpAddress ip() {
-            return ip;
-        }
-
-        /**
-         * Returns port of the device.
-         * @return port
-         */
-        public int port() {
-            return port;
-        }
-
-        /**
-         * Returns username of the device.
-         * @return username
-         */
-        public String username() {
-            return username;
-        }
-
-        /**
-         * Returns password of the device.
-         * @return password
-         */
-        public String password() {
-            return password;
-        }
-    }
-
-}
-
diff --git a/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java b/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java
index c9e20b2..49374cc 100644
--- a/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java
+++ b/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java
@@ -21,12 +21,10 @@
 import com.google.common.collect.ImmutableSet;
 import org.junit.Before;
 import org.junit.Test;
-import org.onlab.packet.IpAddress;
 import org.onosproject.TestApplicationId;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.core.CoreServiceAdapter;
-import org.onosproject.net.config.ConfigException;
 import org.onosproject.net.AbstractProjectableModel;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultDevice;
@@ -60,7 +58,11 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.onlab.junit.TestTools.assertAfter;
 
 /**
@@ -79,14 +81,10 @@
     protected CoreService coreService = new MockCoreService();
     private final DeviceProviderService deviceProviderService = new MockDeviceProviderService();
     private final TestApplicationId applicationId = new TestApplicationId("TestAppId");
-    private final SnmpProviderConfig snmpProviderConfig = new MockSnmpProviderConfig();
     private final DeviceId deviceId = DeviceId.deviceId("snmp:1.1.1.1:1");
     private final DeviceId wrongDeviceId = DeviceId.deviceId("snmp:2.2.2.2:2");
     private final Set<ConfigFactory> cfgFactories = new HashSet<>();
     private final Set<NetworkConfigListener> netCfgListeners = new HashSet<>();
-    private final NetworkConfigEvent deviceAddedEvent =
-            new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED,
-                                   null, SnmpProviderConfig.class);
     private final NetworkConfigEvent deviceAddedIrrelevantEvent =
             new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED,
                                    null, BasicDeviceConfig.class);
@@ -119,7 +117,7 @@
     public void testActivate() {
         assertEquals("Incorrect provider service", deviceProviderService, provider.providerService);
         assertEquals("Incorrect application id", applicationId, provider.appId);
-        assertTrue("Incorrect config factories", cfgFactories.containsAll(provider.factories));
+        assertTrue("Incorrect config factories", cfgFactories.contains(provider.factory));
         assertTrue("Incorrect network config listener", netCfgListeners.contains(provider.cfgLister));
 
 
@@ -145,8 +143,6 @@
 
     @Test
     public void addDevice() {
-        assertTrue("Event should be relevant", provider.cfgLister.isRelevant(deviceAddedEvent));
-        provider.cfgLister.event(deviceAddedEvent);
         AbstractProjectableModel.setDriverService(null, new MockDriverService());
         //FIXME this needs sleep
         assertAfter(DELAY, TEST_DURATION, () ->
@@ -219,9 +215,7 @@
 
         @Override
         public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
-            if (configClass.equals(SnmpProviderConfig.class)) {
-                return (C) snmpProviderConfig;
-            } else if (configClass.equals(SnmpDeviceConfig.class)) {
+            if (configClass.equals(SnmpDeviceConfig.class)) {
                 return (C) config;
             } else {
                 return (C) new BasicDeviceConfig();
@@ -271,16 +265,6 @@
         }
     }
 
-    private class MockSnmpProviderConfig extends SnmpProviderConfig {
-        protected SnmpDeviceInfo deviceInfo = new SnmpDeviceInfo(IpAddress.valueOf("1.1.1.1"), 1, "test", "test");
-
-        @Override
-        public Set<SnmpProviderConfig.SnmpDeviceInfo> getDevicesInfo() throws ConfigException {
-            return ImmutableSet.of(deviceInfo);
-        }
-
-    }
-
     private class MockDriverService extends DriverServiceAdapter {
 
     }