Committed by
Gerrit Code Review
ONOS-3929 Netconf Device Factory
Change-Id: I03f63dd5344f3bde8786acd0fc5de367e8e39c6e
Showing
5 changed files
with
64 additions
and
7 deletions
... | @@ -39,7 +39,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -39,7 +39,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
39 | public class NetconfConfigGetter extends AbstractHandlerBehaviour | 39 | public class NetconfConfigGetter extends AbstractHandlerBehaviour |
40 | implements ConfigGetter { | 40 | implements ConfigGetter { |
41 | 41 | ||
42 | - private final Logger log = getLogger(NetconfControllerConfig.class); | 42 | + private final Logger log = getLogger(getClass()); |
43 | 43 | ||
44 | //FIXME the error string should be universal for all implementations of | 44 | //FIXME the error string should be universal for all implementations of |
45 | // ConfigGetter | 45 | // ConfigGetter |
... | @@ -58,7 +58,7 @@ public class NetconfConfigGetter extends AbstractHandlerBehaviour | ... | @@ -58,7 +58,7 @@ public class NetconfConfigGetter extends AbstractHandlerBehaviour |
58 | getConfig(type); | 58 | getConfig(type); |
59 | } catch (IOException e) { | 59 | } catch (IOException e) { |
60 | log.error("Configuration could not be retrieved {}", | 60 | log.error("Configuration could not be retrieved {}", |
61 | - e.getStackTrace().toString()); | 61 | + e.getMessage()); |
62 | } | 62 | } |
63 | return UNABLE_TO_READ_CONFIG; | 63 | return UNABLE_TO_READ_CONFIG; |
64 | } | 64 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.netconf; | ||
18 | + | ||
19 | +/** | ||
20 | + * Abstract interface for the creation of a NETCONF device. | ||
21 | + */ | ||
22 | +public interface NetconfDeviceFactory { | ||
23 | + | ||
24 | + /** | ||
25 | + * Creates a new NETCONF device based on the supplied information. | ||
26 | + * @param netconfDeviceInfo information of the device to create. | ||
27 | + * @return Instance of NetconfDevice. | ||
28 | + * @throws NetconfException when problems arise creating the device and establishing | ||
29 | + * the connection. | ||
30 | + */ | ||
31 | + NetconfDevice createNetconfDevice(NetconfDeviceInfo netconfDeviceInfo) | ||
32 | + throws NetconfException; | ||
33 | +} |
... | @@ -21,6 +21,12 @@ package org.onosproject.netconf; | ... | @@ -21,6 +21,12 @@ package org.onosproject.netconf; |
21 | */ | 21 | */ |
22 | public interface NetconfSessionFactory { | 22 | public interface NetconfSessionFactory { |
23 | 23 | ||
24 | + /** | ||
25 | + * Creates a new NETCONF session for the specified device. | ||
26 | + * @param netconfDeviceInfo information of the device to create the session for. | ||
27 | + * @return Instance of NetconfSession. | ||
28 | + * @throws NetconfException when problems arise establishing the connection. | ||
29 | + */ | ||
24 | NetconfSession createNetconfSession(NetconfDeviceInfo netconfDeviceInfo) | 30 | NetconfSession createNetconfSession(NetconfDeviceInfo netconfDeviceInfo) |
25 | throws NetconfException; | 31 | throws NetconfException; |
26 | } | 32 | } | ... | ... |
... | @@ -27,9 +27,9 @@ import org.slf4j.LoggerFactory; | ... | @@ -27,9 +27,9 @@ import org.slf4j.LoggerFactory; |
27 | import java.io.IOException; | 27 | import java.io.IOException; |
28 | 28 | ||
29 | /** | 29 | /** |
30 | - * Implementation of a NETCONF device. | 30 | + * Defautl implementation of a NETCONF device. |
31 | */ | 31 | */ |
32 | -public class NetconfDeviceImpl implements NetconfDevice { | 32 | +public class DefaultNetconfDevice implements NetconfDevice { |
33 | 33 | ||
34 | public static final Logger log = LoggerFactory | 34 | public static final Logger log = LoggerFactory |
35 | .getLogger(NetconfSessionImpl.class); | 35 | .getLogger(NetconfSessionImpl.class); |
... | @@ -39,8 +39,15 @@ public class NetconfDeviceImpl implements NetconfDevice { | ... | @@ -39,8 +39,15 @@ public class NetconfDeviceImpl implements NetconfDevice { |
39 | protected NetconfSessionFactory sessionFactory = new SshNetconfSessionFactory(); | 39 | protected NetconfSessionFactory sessionFactory = new SshNetconfSessionFactory(); |
40 | private NetconfSession netconfSession; | 40 | private NetconfSession netconfSession; |
41 | 41 | ||
42 | - | 42 | + /** |
43 | - public NetconfDeviceImpl(NetconfDeviceInfo deviceInfo) | 43 | + * Creates a new default NETCONF device with the information provided. |
44 | + * The device gets created only if no exception is thrwn while connecting to | ||
45 | + * it and establishing the NETCONF session. | ||
46 | + * @param deviceInfo information about the device to be created. | ||
47 | + * @throws NetconfException if there are problems in creating or establishing | ||
48 | + * the underlying NETCONF connection and session. | ||
49 | + */ | ||
50 | + public DefaultNetconfDevice(NetconfDeviceInfo deviceInfo) | ||
44 | throws NetconfException { | 51 | throws NetconfException { |
45 | netconfDeviceInfo = deviceInfo; | 52 | netconfDeviceInfo = deviceInfo; |
46 | try { | 53 | try { | ... | ... |
... | @@ -24,6 +24,7 @@ import org.onlab.packet.IpAddress; | ... | @@ -24,6 +24,7 @@ import org.onlab.packet.IpAddress; |
24 | import org.onosproject.net.DeviceId; | 24 | import org.onosproject.net.DeviceId; |
25 | import org.onosproject.netconf.NetconfController; | 25 | import org.onosproject.netconf.NetconfController; |
26 | import org.onosproject.netconf.NetconfDevice; | 26 | import org.onosproject.netconf.NetconfDevice; |
27 | +import org.onosproject.netconf.NetconfDeviceFactory; | ||
27 | import org.onosproject.netconf.NetconfDeviceInfo; | 28 | import org.onosproject.netconf.NetconfDeviceInfo; |
28 | import org.onosproject.netconf.NetconfDeviceListener; | 29 | import org.onosproject.netconf.NetconfDeviceListener; |
29 | import org.onosproject.netconf.NetconfException; | 30 | import org.onosproject.netconf.NetconfException; |
... | @@ -49,6 +50,7 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -49,6 +50,7 @@ public class NetconfControllerImpl implements NetconfController { |
49 | private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<>(); | 50 | private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<>(); |
50 | 51 | ||
51 | protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>(); | 52 | protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>(); |
53 | + protected NetconfDeviceFactory deviceFactory = new DefaultNetconfDeviceFactory(); | ||
52 | 54 | ||
53 | @Activate | 55 | @Activate |
54 | public void activate(ComponentContext context) { | 56 | public void activate(ComponentContext context) { |
... | @@ -109,7 +111,7 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -109,7 +111,7 @@ public class NetconfControllerImpl implements NetconfController { |
109 | } | 111 | } |
110 | 112 | ||
111 | private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) throws NetconfException { | 113 | private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) throws NetconfException { |
112 | - NetconfDevice netconfDevice = new NetconfDeviceImpl(deviceInfo); | 114 | + NetconfDevice netconfDevice = deviceFactory.createNetconfDevice(deviceInfo); |
113 | for (NetconfDeviceListener l : netconfDeviceListeners) { | 115 | for (NetconfDeviceListener l : netconfDeviceListeners) { |
114 | l.deviceAdded(deviceInfo); | 116 | l.deviceAdded(deviceInfo); |
115 | } | 117 | } |
... | @@ -129,4 +131,13 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -129,4 +131,13 @@ public class NetconfControllerImpl implements NetconfController { |
129 | public Map<DeviceId, NetconfDevice> getDevicesMap() { | 131 | public Map<DeviceId, NetconfDevice> getDevicesMap() { |
130 | return netconfDeviceMap; | 132 | return netconfDeviceMap; |
131 | } | 133 | } |
134 | + | ||
135 | + //Device factory for the specific NetconfDeviceImpl | ||
136 | + private class DefaultNetconfDeviceFactory implements NetconfDeviceFactory { | ||
137 | + | ||
138 | + @Override | ||
139 | + public NetconfDevice createNetconfDevice(NetconfDeviceInfo netconfDeviceInfo) throws NetconfException { | ||
140 | + return new DefaultNetconfDevice(netconfDeviceInfo); | ||
141 | + } | ||
142 | + } | ||
132 | } | 143 | } | ... | ... |
-
Please register or login to post a comment