Mark netconf related factory as functional interface

- deprecate/remove redundant factory implementations

Change-Id: I29ba9f3397c37c02b37d07dff16a4203186c5fcd
This commit is contained in:
Yuta HIGUCHI 2018-06-12 16:21:06 -07:00 committed by Yuta HIGUCHI
parent b6d64d55bf
commit 2ee4fba094
8 changed files with 27 additions and 26 deletions

View File

@ -33,7 +33,7 @@ public class MockNetconfController implements NetconfController {
private Map<DeviceId, NetconfDevice> devicesMap;
public MockNetconfController() {
devicesMap = new HashMap<DeviceId, NetconfDevice>();
devicesMap = new HashMap<>();
}
@Override
@ -56,13 +56,9 @@ public class MockNetconfController implements NetconfController {
IpAddress ipAddress = Ip4Address.valueOf(nameParts[1]);
int port = Integer.parseInt(nameParts[2]);
NetconfDeviceInfo ncdi = new NetconfDeviceInfo("mock", "mock", ipAddress, port);
try {
mockNetconfDevice = (new MockNetconfDeviceFactory()).createNetconfDevice(ncdi);
devicesMap.put(deviceId, mockNetconfDevice);
} catch (NetconfException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mockNetconfDevice = new MockNetconfDevice(ncdi);
devicesMap.put(deviceId, mockNetconfDevice);
return mockNetconfDevice;
}

View File

@ -20,6 +20,10 @@ import org.onosproject.netconf.NetconfDeviceFactory;
import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfException;
/**
* @deprecated in 1.14.0
*/
@Deprecated
public class MockNetconfDeviceFactory implements NetconfDeviceFactory {
@Override

View File

@ -19,6 +19,7 @@ package org.onosproject.netconf;
/**
* Abstract interface for the creation of a NETCONF device.
*/
@FunctionalInterface
public interface NetconfDeviceFactory {
/**

View File

@ -19,6 +19,7 @@ package org.onosproject.netconf;
/**
* Abstract interface for the creation of a NETCONF session.
*/
@FunctionalInterface
public interface NetconfSessionFactory {
/**

View File

@ -49,7 +49,7 @@ public class DefaultNetconfDevice implements NetconfDevice {
public DefaultNetconfDevice(NetconfDeviceInfo deviceInfo)
throws NetconfException {
netconfDeviceInfo = deviceInfo;
sessionFactory = new NetconfSessionMinaImpl.MinaSshNetconfSessionFactory();
sessionFactory = (ncDevInfo) -> new NetconfSessionMinaImpl(ncDevInfo);
try {
netconfSession = sessionFactory.createNetconfSession(deviceInfo);
} catch (NetconfException e) {

View File

@ -118,7 +118,7 @@ public class NetconfControllerImpl implements NetconfController {
private final NetconfDeviceOutputEventListener downListener = new DeviceDownEventListener();
protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>();
protected NetconfDeviceFactory deviceFactory = new DefaultNetconfDeviceFactory();
protected NetconfDeviceFactory deviceFactory = (deviceInfo) -> new DefaultNetconfDevice(deviceInfo);
protected final ExecutorService executor =
Executors.newCachedThreadPool(groupedThreads("onos/netconfdevicecontroller",
@ -343,14 +343,17 @@ public class NetconfControllerImpl implements NetconfController {
}
//Device factory for the specific NetconfDeviceImpl
/**
* Device factory for the specific NetconfDeviceImpl.
*
* @deprecated in 1.14.0
*/
@Deprecated
private class DefaultNetconfDeviceFactory implements NetconfDeviceFactory {
@Override
public NetconfDevice createNetconfDevice(NetconfDeviceInfo netconfDeviceInfo)
throws NetconfException {
log.info("Creating NETCONF session to {} with {}",
netconfDeviceInfo.getDeviceId(), NetconfSshClientLib.APACHE_MINA);
return new DefaultNetconfDevice(netconfDeviceInfo);
}
}

View File

@ -199,6 +199,9 @@ public class NetconfSessionMinaImpl implements NetconfSession {
}
private void startClient() throws IOException {
log.info("Creating NETCONF session to {}",
deviceInfo.getDeviceId());
client = SshClient.setUpDefaultClient();
client.getProperties().putIfAbsent(FactoryManager.IDLE_TIMEOUT,
TimeUnit.SECONDS.toMillis(idleTimeout));
@ -1019,6 +1022,10 @@ public class NetconfSessionMinaImpl implements NetconfSession {
}
}
/**
* @deprecated in 1.14.0
*/
@Deprecated
public static class MinaSshNetconfSessionFactory implements NetconfSessionFactory {
@Override

View File

@ -17,6 +17,7 @@ package org.onosproject.netconf.ctl.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
@ -35,7 +36,6 @@ import org.onosproject.net.config.NetworkConfigRegistryAdapter;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.key.DeviceKeyService;
import org.onosproject.netconf.NetconfDevice;
import org.onosproject.netconf.NetconfDeviceFactory;
import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfDeviceListener;
import org.onosproject.netconf.NetconfDeviceOutputEvent;
@ -120,7 +120,7 @@ public class NetconfControllerImplTest {
@Before
public void setUp() throws Exception {
ctrl = new NetconfControllerImpl();
ctrl.deviceFactory = new TestNetconfDeviceFactory();
ctrl.deviceFactory = (ncDevInfo) -> new TestNetconfDevice(ncDevInfo);
ctrl.cfgService = cfgService;
ctrl.deviceService = deviceService;
ctrl.deviceKeyService = deviceKeyService;
@ -397,17 +397,6 @@ public class NetconfControllerImplTest {
assertEquals("Incorrect device map size", 1, ctrl.getDevicesMap().size());
}
/**
* Mock NetconfDeviceFactory class.
*/
private class TestNetconfDeviceFactory implements NetconfDeviceFactory {
@Override
public NetconfDevice createNetconfDevice(NetconfDeviceInfo netconfDeviceInfo) throws NetconfException {
return new TestNetconfDevice(netconfDeviceInfo);
}
}
/**
* Mock NetconfDeviceImpl class, used for creating test devices.
*/