Committed by
Gerrit Code Review
ONOS-3791 NETCONF session factory and exception on device connection
Change-Id: I7c6651a4f76537056a2dc8f94d54818b5b238b9a
Showing
5 changed files
with
48 additions
and
11 deletions
| 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 session. | ||
| 21 | + */ | ||
| 22 | +public interface NetconfSessionFactory { | ||
| 23 | + | ||
| 24 | + NetconfSession createNetconfSession(NetconfDeviceInfo netconfDeviceInfo) | ||
| 25 | + throws NetconfException; | ||
| 26 | +} |
| ... | @@ -46,7 +46,7 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -46,7 +46,7 @@ public class NetconfControllerImpl implements NetconfController { |
| 46 | public static final Logger log = LoggerFactory | 46 | public static final Logger log = LoggerFactory |
| 47 | .getLogger(NetconfControllerImpl.class); | 47 | .getLogger(NetconfControllerImpl.class); |
| 48 | 48 | ||
| 49 | - public Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<>(); | 49 | + private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<>(); |
| 50 | 50 | ||
| 51 | protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>(); | 51 | protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>(); |
| 52 | 52 | ||
| ... | @@ -130,6 +130,4 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -130,6 +130,4 @@ public class NetconfControllerImpl implements NetconfController { |
| 130 | public Map<DeviceId, NetconfDevice> getDevicesMap() { | 130 | public Map<DeviceId, NetconfDevice> getDevicesMap() { |
| 131 | return netconfDeviceMap; | 131 | return netconfDeviceMap; |
| 132 | } | 132 | } |
| 133 | - | ||
| 134 | - | ||
| 135 | } | 133 | } | ... | ... |
| ... | @@ -20,6 +20,7 @@ import org.onosproject.netconf.NetconfDevice; | ... | @@ -20,6 +20,7 @@ import org.onosproject.netconf.NetconfDevice; |
| 20 | import org.onosproject.netconf.NetconfDeviceInfo; | 20 | import org.onosproject.netconf.NetconfDeviceInfo; |
| 21 | import org.onosproject.netconf.NetconfException; | 21 | import org.onosproject.netconf.NetconfException; |
| 22 | import org.onosproject.netconf.NetconfSession; | 22 | import org.onosproject.netconf.NetconfSession; |
| 23 | +import org.onosproject.netconf.NetconfSessionFactory; | ||
| 23 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
| 24 | import org.slf4j.LoggerFactory; | 25 | import org.slf4j.LoggerFactory; |
| 25 | 26 | ||
| ... | @@ -35,12 +36,15 @@ public class NetconfDeviceImpl implements NetconfDevice { | ... | @@ -35,12 +36,15 @@ public class NetconfDeviceImpl implements NetconfDevice { |
| 35 | 36 | ||
| 36 | private NetconfDeviceInfo netconfDeviceInfo; | 37 | private NetconfDeviceInfo netconfDeviceInfo; |
| 37 | private boolean deviceState = false; | 38 | private boolean deviceState = false; |
| 39 | + protected NetconfSessionFactory sessionFactory = new SshNetconfSessionFactory(); | ||
| 38 | private NetconfSession netconfSession; | 40 | private NetconfSession netconfSession; |
| 39 | 41 | ||
| 40 | - public NetconfDeviceImpl(NetconfDeviceInfo deviceInfo) throws NetconfException { | 42 | + |
| 43 | + public NetconfDeviceImpl(NetconfDeviceInfo deviceInfo) | ||
| 44 | + throws NetconfException { | ||
| 41 | netconfDeviceInfo = deviceInfo; | 45 | netconfDeviceInfo = deviceInfo; |
| 42 | try { | 46 | try { |
| 43 | - netconfSession = new NetconfSessionImpl(netconfDeviceInfo); | 47 | + netconfSession = sessionFactory.createNetconfSession(deviceInfo); |
| 44 | } catch (IOException e) { | 48 | } catch (IOException e) { |
| 45 | throw new NetconfException("Cannot create connection and session for device " + | 49 | throw new NetconfException("Cannot create connection and session for device " + |
| 46 | deviceInfo, e); | 50 | deviceInfo, e); |
| ... | @@ -72,4 +76,13 @@ public class NetconfDeviceImpl implements NetconfDevice { | ... | @@ -72,4 +76,13 @@ public class NetconfDeviceImpl implements NetconfDevice { |
| 72 | public NetconfDeviceInfo getDeviceInfo() { | 76 | public NetconfDeviceInfo getDeviceInfo() { |
| 73 | return netconfDeviceInfo; | 77 | return netconfDeviceInfo; |
| 74 | } | 78 | } |
| 79 | + | ||
| 80 | + public class SshNetconfSessionFactory implements NetconfSessionFactory { | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public NetconfSession createNetconfSession(NetconfDeviceInfo netconfDeviceInfo) throws NetconfException { | ||
| 84 | + return new NetconfSessionImpl(netconfDeviceInfo); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 75 | } | 88 | } | ... | ... |
| ... | @@ -401,6 +401,4 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -401,6 +401,4 @@ public class NetconfSessionImpl implements NetconfSession { |
| 401 | completedReply.complete(event.getMessagePayload()); | 401 | completedReply.complete(event.getMessagePayload()); |
| 402 | } | 402 | } |
| 403 | } | 403 | } |
| 404 | - | ||
| 405 | - | ||
| 406 | } | 404 | } | ... | ... |
| ... | @@ -46,6 +46,7 @@ import org.onosproject.netconf.NetconfController; | ... | @@ -46,6 +46,7 @@ import org.onosproject.netconf.NetconfController; |
| 46 | import org.onosproject.netconf.NetconfDevice; | 46 | import org.onosproject.netconf.NetconfDevice; |
| 47 | import org.onosproject.netconf.NetconfDeviceInfo; | 47 | import org.onosproject.netconf.NetconfDeviceInfo; |
| 48 | import org.onosproject.netconf.NetconfDeviceListener; | 48 | import org.onosproject.netconf.NetconfDeviceListener; |
| 49 | +import org.onosproject.netconf.NetconfException; | ||
| 49 | import org.slf4j.Logger; | 50 | import org.slf4j.Logger; |
| 50 | 51 | ||
| 51 | import java.io.IOException; | 52 | import java.io.IOException; |
| ... | @@ -190,10 +191,11 @@ public class NetconfDeviceProvider extends AbstractProvider | ... | @@ -190,10 +191,11 @@ public class NetconfDeviceProvider extends AbstractProvider |
| 190 | addr.ip(), | 191 | addr.ip(), |
| 191 | addr.port())); | 192 | addr.port())); |
| 192 | } catch (IOException e) { | 193 | } catch (IOException e) { |
| 193 | - log.info("Can't connect to NETCONF " + | 194 | + throw new RuntimeException( |
| 194 | - "device on {}:{}", | 195 | + new NetconfException( |
| 195 | - addr.ip(), | 196 | + "Can't connect to NETCONF " + |
| 196 | - addr.port()); | 197 | + "device on " + addr.ip() + |
| 198 | + ":" + addr.port(), e)); | ||
| 197 | } | 199 | } |
| 198 | } | 200 | } |
| 199 | ); | 201 | ); | ... | ... |
-
Please register or login to post a comment