Remove deprecated netconf provider config class

Change-Id: I057634851dc4f5e348b7acf9e4aa4efe801fd453
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
index 86b27f6..9cf81d0 100644
--- a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
@@ -16,11 +16,8 @@
 
 package org.onosproject.provider.netconf.device.impl;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
-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;
@@ -33,17 +30,16 @@
 import org.onosproject.cfg.ComponentConfigService;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
-import org.onosproject.net.Port;
-import org.onosproject.net.behaviour.PortAdmin;
-import org.onosproject.net.config.ConfigException;
 import org.onosproject.mastership.MastershipService;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.MastershipRole;
+import org.onosproject.net.Port;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.behaviour.PortAdmin;
 import org.onosproject.net.config.ConfigFactory;
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.config.NetworkConfigListener;
@@ -81,7 +77,6 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Dictionary;
-import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
@@ -96,7 +91,6 @@
 
 import static java.util.concurrent.Executors.newScheduledThreadPool;
 import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
@@ -169,7 +163,7 @@
     private final Map<DeviceId, AtomicInteger> retriedPortDiscoveryMap = new ConcurrentHashMap<>();
     protected ScheduledFuture<?> scheduledTask;
 
-    protected final List<ConfigFactory> factories = ImmutableList.of(
+    protected final ConfigFactory factory =
             // TODO consider moving Config registration to NETCONF ctl bundle
             new ConfigFactory<DeviceId, NetconfDeviceConfig>(
                     SubjectFactories.DEVICE_SUBJECT_FACTORY,
@@ -178,16 +172,7 @@
                 public NetconfDeviceConfig createConfig() {
                     return new NetconfDeviceConfig();
                 }
-            },
-            new ConfigFactory<ApplicationId, NetconfProviderConfig>(APP_SUBJECT_FACTORY,
-                                                                    NetconfProviderConfig.class,
-                                                                    "netconf_devices",
-                                                                    true) {
-                @Override
-                public NetconfProviderConfig createConfig() {
-                    return new NetconfProviderConfig();
-                }
-            });
+            };
 
     protected final NetworkConfigListener cfgListener = new InternalNetworkConfigListener();
     private ApplicationId appId;
@@ -200,11 +185,10 @@
         componentConfigService.registerProperties(getClass());
         providerService = providerRegistry.register(this);
         appId = coreService.registerApplication(APP_NAME);
-        factories.forEach(cfgService::registerConfigFactory);
+        cfgService.registerConfigFactory(factory);
         cfgService.addListener(cfgListener);
         controller.addDeviceListener(innerNodeListener);
         deviceService.addListener(deviceListener);
-        translateConfig();
         executor.execute(NetconfDeviceProvider.this::connectDevices);
         modified(context);
         log.info("Started");
@@ -225,7 +209,7 @@
         providerRegistry.unregister(this);
         providerService = null;
         retriedPortDiscoveryMap.clear();
-        factories.forEach(cfgService::unregisterConfigFactory);
+        cfgService.unregisterConfigFactory(factory);
         scheduledTask.cancel(true);
         executor.shutdown();
         log.info("Stopped");
@@ -619,38 +603,6 @@
         }
     }
 
-
-    protected void translateConfig() {
-        NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class);
-        if (cfg != null) {
-            try {
-                cfg.getDevicesAddresses().forEach(addr -> {
-                    DeviceId deviceId = getDeviceId(addr.ip().toString(), addr.port());
-                    log.info("Translating config for device {}", deviceId);
-                    if (cfgService.getConfig(deviceId, NetconfDeviceConfig.class) == null) {
-                        ObjectMapper mapper = new ObjectMapper();
-                        ObjectNode device = mapper.createObjectNode();
-                        device.put("ip", addr.ip().toString());
-                        device.put("port", addr.port());
-                        device.put("username", addr.name());
-                        device.put("password", addr.password());
-                        device.put("sshkey", addr.sshkey());
-                        cfgService.applyConfig(deviceId, NetconfDeviceConfig.class, device);
-                    } else {
-                        // This is a corner case where new updated config is
-                        // pushed with old /app tree after an initial with the
-                        // new device/ tree. Since old method will be deprecated
-                        // it's ok to ignore
-                        log.warn("Config for device {} already exists, ignoring", deviceId);
-                    }
-
-                });
-            } catch (ConfigException e) {
-                log.error("Cannot read config error " + e);
-            }
-        }
-    }
-
     /**
      * Listener for configuration events.
      */
@@ -664,15 +616,13 @@
             } else {
                 log.warn("Injecting device via this Json is deprecated, " +
                                  "please put configuration under devices/ as shown in the wiki");
-                translateConfig();
             }
 
         }
 
         @Override
         public boolean isRelevant(NetworkConfigEvent event) {
-            return (event.configClass().equals(NetconfDeviceConfig.class) ||
-                    event.configClass().equals(NetconfProviderConfig.class)) &&
+            return (event.configClass().equals(NetconfDeviceConfig.class)) &&
                     (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
                             event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED);
         }
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfProviderConfig.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfProviderConfig.java
deleted file mode 100644
index 94190fa..0000000
--- a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfProviderConfig.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2015-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.netconf.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 for Netconf provider.
- * @deprecated 1.10.0 Kingfisher
- */
-@Beta
-@Deprecated
-public class NetconfProviderConfig 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";
-    private static final String SSHKEY = "sshkey";
-
-    public Set<NetconfDeviceAddress> getDevicesAddresses() throws ConfigException {
-        Set<NetconfDeviceAddress> devicesAddresses = 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();
-                String sshkey = node.path(SSHKEY).asText();
-                devicesAddresses.add(new NetconfDeviceAddress(ipAddr, port, name, password, sshkey));
-
-            }
-        } catch (IllegalArgumentException e) {
-            throw new ConfigException(CONFIG_VALUE_ERROR, e);
-        }
-
-        return devicesAddresses;
-    }
-
-    public class
-    NetconfDeviceAddress {
-        private final IpAddress ip;
-        private final int port;
-        private final String name;
-        private final String password;
-        private final String sshkey;
-
-        public NetconfDeviceAddress(IpAddress ip, int port, String name, String password) {
-            this.ip = ip;
-            this.port = port;
-            this.name = name;
-            this.password = password;
-            this.sshkey = "";
-        }
-
-        public NetconfDeviceAddress(IpAddress ip, int port, String name, String password, String sshkey) {
-            this.ip = ip;
-            this.port = port;
-            this.name = name;
-            this.password = password;
-            this.sshkey = sshkey;
-        }
-
-        public IpAddress ip() {
-            return ip;
-        }
-
-        public int port() {
-            return port;
-        }
-
-        public String name() {
-            return name;
-        }
-
-        public String password() {
-            return password;
-        }
-
-        public String sshkey() {
-            return sshkey;
-        }
-    }
-
-}
diff --git a/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java b/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java
index 802c002..c16de45 100644
--- a/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java
+++ b/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java
@@ -19,19 +19,16 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Multimap;
 import com.google.common.util.concurrent.MoreExecutors;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.onlab.packet.IpAddress;
 import org.onosproject.cfg.ComponentConfigAdapter;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.core.DefaultApplicationId;
-import org.onosproject.net.config.ConfigException;
 import org.onosproject.mastership.MastershipService;
 import org.onosproject.mastership.MastershipServiceAdapter;
 import org.onosproject.net.AbstractProjectableModel;
@@ -84,6 +81,7 @@
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.concurrent.CountDownLatch;
+
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
@@ -126,15 +124,10 @@
                                    DeviceId.deviceId(NETCONF_DEVICE_ID_STRING),
                                    netconfDeviceConfig, null,
                                    NetconfDeviceConfig.class);
-
-    private final NetworkConfigEvent deviceAddedEventOld =
-            new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED,
-                                   null, NetconfProviderConfig.class);
     private final NetworkConfigEvent deviceAddedEventTranslated =
             new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED,
                                    DeviceId.deviceId(NETCONF_DEVICE_ID_STRING_OLD),
                                    NetconfDeviceConfig.class);
-    private final NetconfProviderConfig netconfProviderConfig = new MockNetconfProviderConfig();
     private static final String NETCONF_DEVICE_ID_STRING = "netconf:1.1.1.1:830";
     private static final String NETCONF_DEVICE_ID_STRING_OLD = "netconf:1.1.1.2:1";
     private static final String NETCONF_DEVICE_ID_STRING_IPV6 = "netconf:2001:0db8:0000:0000:0000:ff00:0042:8329:830";
@@ -214,7 +207,7 @@
         assertTrue("Provider should be registered", deviceRegistry.getProviders().contains(provider.id()));
         assertEquals("Incorrect device service", deviceService, provider.deviceService);
         assertEquals("Incorrect provider service", providerService, provider.providerService);
-        assertTrue("Incorrect config factories", cfgFactories.containsAll(provider.factories));
+        assertTrue("Incorrect config factories", cfgFactories.contains(provider.factory));
         assertNotNull("Device listener should be added", deviceService.listener);
         assertFalse("Thread to connect device should be running",
                     provider.executor.isShutdown() || provider.executor.isTerminated());
@@ -264,30 +257,11 @@
     }
 
     @Test
-    @Ignore("Test is brittle")
-    public void addDeviceOld() throws InterruptedException {
-        // expecting 1 device add
-        deviceAdded = new CountDownLatch(1);
-        assertNotNull(providerService);
-        assertTrue("Event should be relevant", provider.cfgListener.isRelevant(deviceAddedEvent));
-        assertTrue("Event should be relevant", provider.cfgListener.isRelevant(deviceAddedEventOld));
-        available = true;
-        provider.cfgListener.event(deviceAddedEventOld);
-
-        deviceAdded.await();
-        assertEquals("Device should be added", 1, deviceStore.getDeviceCount());
-        assertTrue("Device incorrectly added" + NETCONF_DEVICE_ID_STRING_OLD,
-                   devices.containsKey(DeviceId.deviceId(NETCONF_DEVICE_ID_STRING_OLD)));
-        devices.clear();
-    }
-
-    @Test
     public void addDeviceNew() throws InterruptedException {
         // expecting 1 device add
         deviceAdded = new CountDownLatch(1);
         assertNotNull(providerService);
         assertTrue("Event should be relevant", provider.cfgListener.isRelevant(deviceAddedEvent));
-        assertTrue("Event should be relevant", provider.cfgListener.isRelevant(deviceAddedEventOld));
         available = true;
         provider.cfgListener.event(deviceAddedEvent);
 
@@ -475,9 +449,6 @@
         @Override
         public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
             if (available) {
-                if (configClass.equals(NetconfProviderConfig.class)) {
-                    return (C) netconfProviderConfig;
-                }
                 DeviceId did = (DeviceId) subject;
                 if (configClass.equals(NetconfDeviceConfig.class)
                         && did.equals(DeviceId.deviceId(NETCONF_DEVICE_ID_STRING))) {
@@ -526,15 +497,6 @@
 
     }
 
-    private class MockNetconfProviderConfig extends NetconfProviderConfig {
-        final NetconfDeviceAddress deviceInfo = new NetconfDeviceAddress(IP_OLD, 1, TEST, TEST);
-
-        @Override
-        public Set<NetconfProviderConfig.NetconfDeviceAddress> getDevicesAddresses() throws ConfigException {
-            return ImmutableSet.of(deviceInfo);
-        }
-    }
-
     private class MockDevice extends DefaultDevice {
 
         MockDevice(DeviceId id) {