Committed by
Gerrit Code Review
ONOS-3941 Adding Executor pool and support for username but passwordless https login in Rest SB
Change-Id: Ia3da59dbffcabf233a27931aa756488629e8dd63
Showing
6 changed files
with
45 additions
and
29 deletions
... | @@ -26,7 +26,6 @@ import org.onosproject.net.CltSignalType; | ... | @@ -26,7 +26,6 @@ import org.onosproject.net.CltSignalType; |
26 | import org.onosproject.net.DefaultAnnotations; | 26 | import org.onosproject.net.DefaultAnnotations; |
27 | import org.onosproject.net.DeviceId; | 27 | import org.onosproject.net.DeviceId; |
28 | import org.onosproject.net.PortNumber; | 28 | import org.onosproject.net.PortNumber; |
29 | -import org.onosproject.net.SparseAnnotations; | ||
30 | import org.onosproject.net.behaviour.PortDiscovery; | 29 | import org.onosproject.net.behaviour.PortDiscovery; |
31 | import org.onosproject.net.device.OduCltPortDescription; | 30 | import org.onosproject.net.device.OduCltPortDescription; |
32 | import org.onosproject.net.device.PortDescription; | 31 | import org.onosproject.net.device.PortDescription; |
... | @@ -53,6 +52,8 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour | ... | @@ -53,6 +52,8 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour |
53 | private static final String EMPTY_STRING = ""; | 52 | private static final String EMPTY_STRING = ""; |
54 | private static final String NAME = "name"; | 53 | private static final String NAME = "name"; |
55 | private static final String ADMIN_STATE = "admin-state"; | 54 | private static final String ADMIN_STATE = "admin-state"; |
55 | + private static final String LINESIDE_NAME = "lineside"; | ||
56 | + private static final String CLIENTSIDE_NAME = "clientside"; | ||
56 | 57 | ||
57 | private static final ArrayList<String> LINESIDE_PORT_ID = Lists.newArrayList( | 58 | private static final ArrayList<String> LINESIDE_PORT_ID = Lists.newArrayList( |
58 | "4", "48"); | 59 | "4", "48"); |
... | @@ -85,9 +86,10 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour | ... | @@ -85,9 +86,10 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour |
85 | portsConfig.stream().forEach(sub -> { | 86 | portsConfig.stream().forEach(sub -> { |
86 | String portId = sub.getString(PORT_ID); | 87 | String portId = sub.getString(PORT_ID); |
87 | String name = sub.getString(NAME); | 88 | String name = sub.getString(NAME); |
88 | - SparseAnnotations annotations = DefaultAnnotations.builder() | 89 | + DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() |
89 | - .set(AnnotationKeys.NAME, name).build(); | 90 | + .set(AnnotationKeys.NAME, name); |
90 | if (LINESIDE_PORT_ID.contains(portId)) { | 91 | if (LINESIDE_PORT_ID.contains(portId)) { |
92 | + annotations.set(AnnotationKeys.PORT_NAME, LINESIDE_NAME); | ||
91 | String wsportInfoRequest = SPECIFIC_PORT_PATH + portId + | 93 | String wsportInfoRequest = SPECIFIC_PORT_PATH + portId + |
92 | SPECIFIC_PORT_CONFIG; | 94 | SPECIFIC_PORT_CONFIG; |
93 | ports.add(XmlConfigParser.parseWaveServerCienaOchPorts( | 95 | ports.add(XmlConfigParser.parseWaveServerCienaOchPorts( |
... | @@ -95,17 +97,17 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour | ... | @@ -95,17 +97,17 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour |
95 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) | 97 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
96 | .replace(" ", EMPTY_STRING))), | 98 | .replace(" ", EMPTY_STRING))), |
97 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), | 99 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), |
98 | - annotations)); | 100 | + annotations.build())); |
99 | //adding corresponding opposite side port | 101 | //adding corresponding opposite side port |
100 | ports.add(XmlConfigParser.parseWaveServerCienaOchPorts( | 102 | ports.add(XmlConfigParser.parseWaveServerCienaOchPorts( |
101 | sub.getLong(PORT_ID) + 1, | 103 | sub.getLong(PORT_ID) + 1, |
102 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) | 104 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
103 | .replace(" ", EMPTY_STRING))), | 105 | .replace(" ", EMPTY_STRING))), |
104 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), | 106 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), |
105 | - DefaultAnnotations.builder() | 107 | + annotations.set(AnnotationKeys.NAME, name.replace(".1", ".2")) |
106 | - .set(AnnotationKeys.NAME, name.replace(".1", ".2")) | ||
107 | .build())); | 108 | .build())); |
108 | } else if (!portId.equals("5") && !portId.equals("49")) { | 109 | } else if (!portId.equals("5") && !portId.equals("49")) { |
110 | + annotations.set(AnnotationKeys.PORT_NAME, CLIENTSIDE_NAME); | ||
109 | //FIXME change when all optical types have two way information methods, see jira tickets | 111 | //FIXME change when all optical types have two way information methods, see jira tickets |
110 | final int speed100GbpsinMbps = 100000; | 112 | final int speed100GbpsinMbps = 100000; |
111 | CltSignalType cltType = toGbps(Long.parseLong( | 113 | CltSignalType cltType = toGbps(Long.parseLong( |
... | @@ -114,7 +116,7 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour | ... | @@ -114,7 +116,7 @@ public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour |
114 | CltSignalType.CLT_100GBE : null; | 116 | CltSignalType.CLT_100GBE : null; |
115 | ports.add(new OduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), | 117 | ports.add(new OduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), |
116 | sub.getString(ADMIN_STATE).equals(ENABLED), | 118 | sub.getString(ADMIN_STATE).equals(ENABLED), |
117 | - cltType, annotations)); | 119 | + cltType, annotations.build())); |
118 | } | 120 | } |
119 | }); | 121 | }); |
120 | return ports; | 122 | return ports; | ... | ... |
... | @@ -34,7 +34,7 @@ public class DefaultRestSBDevice implements RestSBDevice { | ... | @@ -34,7 +34,7 @@ public class DefaultRestSBDevice implements RestSBDevice { |
34 | private static final String COLON = ":"; | 34 | private static final String COLON = ":"; |
35 | private final IpAddress ip; | 35 | private final IpAddress ip; |
36 | private final int port; | 36 | private final int port; |
37 | - private final String name; | 37 | + private final String username; |
38 | private final String password; | 38 | private final String password; |
39 | private boolean isActive; | 39 | private boolean isActive; |
40 | private String protocol; | 40 | private String protocol; |
... | @@ -47,7 +47,7 @@ public class DefaultRestSBDevice implements RestSBDevice { | ... | @@ -47,7 +47,7 @@ public class DefaultRestSBDevice implements RestSBDevice { |
47 | Preconditions.checkNotNull(protocol, "protocol address cannot be null"); | 47 | Preconditions.checkNotNull(protocol, "protocol address cannot be null"); |
48 | this.ip = ip; | 48 | this.ip = ip; |
49 | this.port = port; | 49 | this.port = port; |
50 | - this.name = name; | 50 | + this.username = name; |
51 | this.password = StringUtils.isEmpty(password) ? null : password; | 51 | this.password = StringUtils.isEmpty(password) ? null : password; |
52 | this.isActive = isActive; | 52 | this.isActive = isActive; |
53 | this.protocol = protocol; | 53 | this.protocol = protocol; |
... | @@ -65,8 +65,8 @@ public class DefaultRestSBDevice implements RestSBDevice { | ... | @@ -65,8 +65,8 @@ public class DefaultRestSBDevice implements RestSBDevice { |
65 | } | 65 | } |
66 | 66 | ||
67 | @Override | 67 | @Override |
68 | - public String name() { | 68 | + public String username() { |
69 | - return name; | 69 | + return username; |
70 | } | 70 | } |
71 | 71 | ||
72 | @Override | 72 | @Override |
... | @@ -110,7 +110,7 @@ public class DefaultRestSBDevice implements RestSBDevice { | ... | @@ -110,7 +110,7 @@ public class DefaultRestSBDevice implements RestSBDevice { |
110 | return MoreObjects.toStringHelper(this) | 110 | return MoreObjects.toStringHelper(this) |
111 | .add("url", url) | 111 | .add("url", url) |
112 | .add("protocol", protocol) | 112 | .add("protocol", protocol) |
113 | - .add("name", name) | 113 | + .add("username", username) |
114 | .add("port", port) | 114 | .add("port", port) |
115 | .add("ip", ip) | 115 | .add("ip", ip) |
116 | .toString(); | 116 | .toString(); |
... | @@ -125,7 +125,7 @@ public class DefaultRestSBDevice implements RestSBDevice { | ... | @@ -125,7 +125,7 @@ public class DefaultRestSBDevice implements RestSBDevice { |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | RestSBDevice device = (RestSBDevice) obj; | 127 | RestSBDevice device = (RestSBDevice) obj; |
128 | - return this.name.equals(device.name()) && this.ip.equals(device.ip()) && | 128 | + return this.username.equals(device.username()) && this.ip.equals(device.ip()) && |
129 | this.port == device.port(); | 129 | this.port == device.port(); |
130 | 130 | ||
131 | } | 131 | } | ... | ... |
... | @@ -38,11 +38,11 @@ public interface RestSBDevice { | ... | @@ -38,11 +38,11 @@ public interface RestSBDevice { |
38 | int port(); | 38 | int port(); |
39 | 39 | ||
40 | /** | 40 | /** |
41 | - * Returns the name of this device. | 41 | + * Returns the username of this device. |
42 | * | 42 | * |
43 | - * @return name | 43 | + * @return username |
44 | */ | 44 | */ |
45 | - String name(); | 45 | + String username(); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Returns the password of this device. | 48 | * Returns the password of this device. | ... | ... |
... | @@ -182,8 +182,9 @@ public class RestSBControllerImpl implements RestSBController { | ... | @@ -182,8 +182,9 @@ public class RestSBControllerImpl implements RestSBController { |
182 | try { | 182 | try { |
183 | log.debug("Url request {} ", getUrlString(device, request)); | 183 | log.debug("Url request {} ", getUrlString(device, request)); |
184 | HttpPatch httprequest = new HttpPatch(getUrlString(device, request)); | 184 | HttpPatch httprequest = new HttpPatch(getUrlString(device, request)); |
185 | - if (deviceMap.get(device).password() != null) { | 185 | + if (deviceMap.get(device).username() != null) { |
186 | - String userPassword = deviceMap.get(device).name() + COLON + deviceMap.get(device).password(); | 186 | + String pwd = deviceMap.get(device).password() == null ? "" : COLON + deviceMap.get(device).password(); |
187 | + String userPassword = deviceMap.get(device).username() + pwd; | ||
187 | String base64string = Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8)); | 188 | String base64string = Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8)); |
188 | httprequest.addHeader(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + base64string); | 189 | httprequest.addHeader(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + base64string); |
189 | } | 190 | } |
... | @@ -232,9 +233,10 @@ public class RestSBControllerImpl implements RestSBController { | ... | @@ -232,9 +233,10 @@ public class RestSBControllerImpl implements RestSBController { |
232 | private WebResource getWebResource(DeviceId device, String request) { | 233 | private WebResource getWebResource(DeviceId device, String request) { |
233 | log.debug("Sending request to URL {} ", getUrlString(device, request)); | 234 | log.debug("Sending request to URL {} ", getUrlString(device, request)); |
234 | WebResource webResource = client.resource(getUrlString(device, request)); | 235 | WebResource webResource = client.resource(getUrlString(device, request)); |
235 | - if (deviceMap.containsKey(device) && deviceMap.get(device).password() != null) { | 236 | + if (deviceMap.containsKey(device) && deviceMap.get(device).username() != null) { |
236 | - client.addFilter(new HTTPBasicAuthFilter(deviceMap.get(device).name(), | 237 | + client.addFilter(new HTTPBasicAuthFilter(deviceMap.get(device).username(), |
237 | - deviceMap.get(device).password())); | 238 | + deviceMap.get(device).password() == null ? |
239 | + "" : deviceMap.get(device).password())); | ||
238 | } | 240 | } |
239 | return webResource; | 241 | return webResource; |
240 | } | 242 | } | ... | ... |
... | @@ -59,7 +59,10 @@ import java.security.NoSuchAlgorithmException; | ... | @@ -59,7 +59,10 @@ import java.security.NoSuchAlgorithmException; |
59 | import java.util.Base64; | 59 | import java.util.Base64; |
60 | import java.util.HashSet; | 60 | import java.util.HashSet; |
61 | import java.util.Set; | 61 | import java.util.Set; |
62 | +import java.util.concurrent.ExecutorService; | ||
63 | +import java.util.concurrent.Executors; | ||
62 | 64 | ||
65 | +import static org.onlab.util.Tools.groupedThreads; | ||
63 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_ADDED; | 66 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_ADDED; |
64 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UPDATED; | 67 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UPDATED; |
65 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; | 68 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
... | @@ -102,6 +105,9 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -102,6 +105,9 @@ public class RestDeviceProvider extends AbstractProvider |
102 | protected static final String ISNOTNULL = "Rest device is not null"; | 105 | protected static final String ISNOTNULL = "Rest device is not null"; |
103 | private static final String UNKNOWN = "unknown"; | 106 | private static final String UNKNOWN = "unknown"; |
104 | 107 | ||
108 | + private final ExecutorService executor = | ||
109 | + Executors.newFixedThreadPool(5, groupedThreads("onos/restsbprovider", "device-installer-%d")); | ||
110 | + | ||
105 | private final ConfigFactory factory = | 111 | private final ConfigFactory factory = |
106 | new ConfigFactory<ApplicationId, RestProviderConfig>(APP_SUBJECT_FACTORY, | 112 | new ConfigFactory<ApplicationId, RestProviderConfig>(APP_SUBJECT_FACTORY, |
107 | RestProviderConfig.class, | 113 | RestProviderConfig.class, |
... | @@ -115,6 +121,8 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -115,6 +121,8 @@ public class RestDeviceProvider extends AbstractProvider |
115 | private final NetworkConfigListener cfgLister = new InternalNetworkConfigListener(); | 121 | private final NetworkConfigListener cfgLister = new InternalNetworkConfigListener(); |
116 | private ApplicationId appId; | 122 | private ApplicationId appId; |
117 | 123 | ||
124 | + private Set<DeviceId> addedDevices = new HashSet<>(); | ||
125 | + | ||
118 | 126 | ||
119 | @Activate | 127 | @Activate |
120 | public void activate() { | 128 | public void activate() { |
... | @@ -156,7 +164,7 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -156,7 +164,7 @@ public class RestDeviceProvider extends AbstractProvider |
156 | public boolean isReachable(DeviceId deviceId) { | 164 | public boolean isReachable(DeviceId deviceId) { |
157 | RestSBDevice restDevice = controller.getDevice(deviceId); | 165 | RestSBDevice restDevice = controller.getDevice(deviceId); |
158 | if (restDevice == null) { | 166 | if (restDevice == null) { |
159 | - log.warn("BAD REQUEST: the requested device id: " + | 167 | + log.debug("the requested device id: " + |
160 | deviceId.toString() + | 168 | deviceId.toString() + |
161 | " is not associated to any REST Device"); | 169 | " is not associated to any REST Device"); |
162 | return false; | 170 | return false; |
... | @@ -181,6 +189,7 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -181,6 +189,7 @@ public class RestDeviceProvider extends AbstractProvider |
181 | providerService.deviceConnected(deviceId, deviceDescription); | 189 | providerService.deviceConnected(deviceId, deviceDescription); |
182 | nodeId.setActive(true); | 190 | nodeId.setActive(true); |
183 | controller.addDevice(nodeId); | 191 | controller.addDevice(nodeId); |
192 | + addedDevices.add(deviceId); | ||
184 | } | 193 | } |
185 | 194 | ||
186 | //when do I call it ? | 195 | //when do I call it ? |
... | @@ -212,7 +221,7 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -212,7 +221,7 @@ public class RestDeviceProvider extends AbstractProvider |
212 | log.error("Configuration error {}", e); | 221 | log.error("Configuration error {}", e); |
213 | } | 222 | } |
214 | log.debug("REST Devices {}", controller.getDevices()); | 223 | log.debug("REST Devices {}", controller.getDevices()); |
215 | - controller.getDevices().keySet().forEach(deviceId -> { | 224 | + addedDevices.forEach(deviceId -> { |
216 | DriverHandler h = driverService.createHandler(deviceId); | 225 | DriverHandler h = driverService.createHandler(deviceId); |
217 | PortDiscovery portConfig = h.behaviour(PortDiscovery.class); | 226 | PortDiscovery portConfig = h.behaviour(PortDiscovery.class); |
218 | if (portConfig != null) { | 227 | if (portConfig != null) { |
... | @@ -221,6 +230,8 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -221,6 +230,8 @@ public class RestDeviceProvider extends AbstractProvider |
221 | log.warn("No portGetter behaviour for device {}", deviceId); | 230 | log.warn("No portGetter behaviour for device {}", deviceId); |
222 | } | 231 | } |
223 | }); | 232 | }); |
233 | + addedDevices.clear(); | ||
234 | + | ||
224 | } | 235 | } |
225 | 236 | ||
226 | private boolean testDeviceConnection(RestSBDevice device) { | 237 | private boolean testDeviceConnection(RestSBDevice device) { |
... | @@ -240,8 +251,9 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -240,8 +251,9 @@ public class RestDeviceProvider extends AbstractProvider |
240 | } else { | 251 | } else { |
241 | urlConn = (HttpURLConnection) url.openConnection(); | 252 | urlConn = (HttpURLConnection) url.openConnection(); |
242 | } | 253 | } |
243 | - if (device.password() != null) { | 254 | + if (device.username() != null) { |
244 | - String userPassword = device.name() + ":" + device.password(); | 255 | + String pwd = device.password() == null ? "" : ":" + device.password(); |
256 | + String userPassword = device.username() + pwd; | ||
245 | String basicAuth = Base64.getEncoder() | 257 | String basicAuth = Base64.getEncoder() |
246 | .encodeToString(userPassword.getBytes(StandardCharsets.UTF_8)); | 258 | .encodeToString(userPassword.getBytes(StandardCharsets.UTF_8)); |
247 | urlConn.setRequestProperty(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + basicAuth); | 259 | urlConn.setRequestProperty(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + basicAuth); |
... | @@ -267,7 +279,7 @@ public class RestDeviceProvider extends AbstractProvider | ... | @@ -267,7 +279,7 @@ public class RestDeviceProvider extends AbstractProvider |
267 | 279 | ||
268 | @Override | 280 | @Override |
269 | public void event(NetworkConfigEvent event) { | 281 | public void event(NetworkConfigEvent event) { |
270 | - connectDevices(); | 282 | + executor.submit(RestDeviceProvider.this::connectDevices); |
271 | } | 283 | } |
272 | 284 | ||
273 | @Override | 285 | @Override | ... | ... |
... | @@ -39,7 +39,7 @@ public class RestProviderConfig extends Config<ApplicationId> { | ... | @@ -39,7 +39,7 @@ public class RestProviderConfig extends Config<ApplicationId> { |
39 | private static final String IP = "ip"; | 39 | private static final String IP = "ip"; |
40 | private static final int DEFAULT_HTTP_PORT = 80; | 40 | private static final int DEFAULT_HTTP_PORT = 80; |
41 | private static final String PORT = "port"; | 41 | private static final String PORT = "port"; |
42 | - private static final String NAME = "name"; | 42 | + private static final String USERNAME = "username"; |
43 | private static final String PASSWORD = "password"; | 43 | private static final String PASSWORD = "password"; |
44 | private static final String PROTOCOL = "protocol"; | 44 | private static final String PROTOCOL = "protocol"; |
45 | private static final String URL = "url"; | 45 | private static final String URL = "url"; |
... | @@ -52,11 +52,11 @@ public class RestProviderConfig extends Config<ApplicationId> { | ... | @@ -52,11 +52,11 @@ public class RestProviderConfig extends Config<ApplicationId> { |
52 | String ip = node.path(IP).asText(); | 52 | String ip = node.path(IP).asText(); |
53 | IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip); | 53 | IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip); |
54 | int port = node.path(PORT).asInt(DEFAULT_HTTP_PORT); | 54 | int port = node.path(PORT).asInt(DEFAULT_HTTP_PORT); |
55 | - String name = node.path(NAME).asText(); | 55 | + String username = node.path(USERNAME).asText(); |
56 | String password = node.path(PASSWORD).asText(); | 56 | String password = node.path(PASSWORD).asText(); |
57 | String protocol = node.path(PROTOCOL).asText(); | 57 | String protocol = node.path(PROTOCOL).asText(); |
58 | String url = node.path(URL).asText(); | 58 | String url = node.path(URL).asText(); |
59 | - devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, name, | 59 | + devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, username, |
60 | password, protocol, | 60 | password, protocol, |
61 | url, false)); | 61 | url, false)); |
62 | 62 | ... | ... |
-
Please register or login to post a comment