Committed by
Gerrit Code Review
Refactoring ID creation for netconf and REST
Change-Id: I4165ad53e19c86d9d9b304d09e24dcfeec2b9ddf
Showing
4 changed files
with
20 additions
and
11 deletions
| ... | @@ -40,6 +40,7 @@ public class NetconfDeviceInfo { | ... | @@ -40,6 +40,7 @@ public class NetconfDeviceInfo { |
| 40 | private IpAddress ipAddress; | 40 | private IpAddress ipAddress; |
| 41 | private int port; | 41 | private int port; |
| 42 | private File keyFile; | 42 | private File keyFile; |
| 43 | + private DeviceId deviceId; | ||
| 43 | 44 | ||
| 44 | 45 | ||
| 45 | /** | 46 | /** |
| ... | @@ -143,13 +144,14 @@ public class NetconfDeviceInfo { | ... | @@ -143,13 +144,14 @@ public class NetconfDeviceInfo { |
| 143 | * @return DeviceId | 144 | * @return DeviceId |
| 144 | */ | 145 | */ |
| 145 | public DeviceId getDeviceId() { | 146 | public DeviceId getDeviceId() { |
| 146 | - | 147 | + if (deviceId == null) { |
| 147 | - try { | 148 | + try { |
| 148 | - return DeviceId.deviceId(new URI(this.toString())); | 149 | + deviceId = DeviceId.deviceId(new URI("netconf", ipAddress.toString() + ":" + port, null)); |
| 149 | - } catch (URISyntaxException e) { | 150 | + } catch (URISyntaxException e) { |
| 150 | - log.debug("Unable to build deviceID for device {} ", this, e); | 151 | + throw new IllegalArgumentException("Unable to build deviceID for device " + toString(), e); |
| 152 | + } | ||
| 151 | } | 153 | } |
| 152 | - return null; | 154 | + return deviceId; |
| 153 | } | 155 | } |
| 154 | 156 | ||
| 155 | @Override | 157 | @Override | ... | ... |
| ... | @@ -81,8 +81,7 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -81,8 +81,7 @@ public class NetconfControllerImpl implements NetconfController { |
| 81 | @Override | 81 | @Override |
| 82 | public NetconfDevice getNetconfDevice(IpAddress ip, int port) { | 82 | public NetconfDevice getNetconfDevice(IpAddress ip, int port) { |
| 83 | for (DeviceId info : netconfDeviceMap.keySet()) { | 83 | for (DeviceId info : netconfDeviceMap.keySet()) { |
| 84 | - if (IpAddress.valueOf(info.uri().getHost()).equals(ip) && | 84 | + if (info.uri().getSchemeSpecificPart().equals(ip.toString() + ":" + port)) { |
| 85 | - info.uri().getPort() == port) { | ||
| 86 | return netconfDeviceMap.get(info); | 85 | return netconfDeviceMap.get(info); |
| 87 | } | 86 | } |
| 88 | } | 87 | } |
| ... | @@ -102,7 +101,7 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -102,7 +101,7 @@ public class NetconfControllerImpl implements NetconfController { |
| 102 | 101 | ||
| 103 | @Override | 102 | @Override |
| 104 | public void removeDevice(NetconfDeviceInfo deviceInfo) { | 103 | public void removeDevice(NetconfDeviceInfo deviceInfo) { |
| 105 | - if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) { | 104 | + if (!netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) { |
| 106 | log.warn("Device {} is not present", deviceInfo); | 105 | log.warn("Device {} is not present", deviceInfo); |
| 107 | } else { | 106 | } else { |
| 108 | stopDevice(deviceInfo); | 107 | stopDevice(deviceInfo); | ... | ... |
| ... | @@ -22,6 +22,8 @@ import org.apache.commons.lang3.StringUtils; | ... | @@ -22,6 +22,8 @@ import org.apache.commons.lang3.StringUtils; |
| 22 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
| 24 | 24 | ||
| 25 | +import java.net.URI; | ||
| 26 | +import java.net.URISyntaxException; | ||
| 25 | import java.util.Objects; | 27 | import java.util.Objects; |
| 26 | 28 | ||
| 27 | /** | 29 | /** |
| ... | @@ -74,7 +76,13 @@ public class DefaultRestSBDevice implements RestSBDevice { | ... | @@ -74,7 +76,13 @@ public class DefaultRestSBDevice implements RestSBDevice { |
| 74 | 76 | ||
| 75 | @Override | 77 | @Override |
| 76 | public DeviceId deviceId() { | 78 | public DeviceId deviceId() { |
| 77 | - return DeviceId.deviceId(REST + COLON + ip + COLON + port); | 79 | + try { |
| 80 | + return DeviceId.deviceId(new URI(REST, ip + COLON + port, null)); | ||
| 81 | + } catch (URISyntaxException e) { | ||
| 82 | + throw new IllegalArgumentException("Cannot create deviceID " + | ||
| 83 | + REST + COLON + ip + | ||
| 84 | + COLON + port, e); | ||
| 85 | + } | ||
| 78 | } | 86 | } |
| 79 | 87 | ||
| 80 | @Override | 88 | @Override | ... | ... |
-
Please register or login to post a comment