ONOS-3941 Adding Executor pool and support for username but passwordless https login in Rest SB

Change-Id: Ia3da59dbffcabf233a27931aa756488629e8dd63
diff --git a/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java b/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
index 18c376b..55e2fb8 100644
--- a/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
+++ b/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
@@ -59,7 +59,10 @@
 import java.util.Base64;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
+import static org.onlab.util.Tools.groupedThreads;
 import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_ADDED;
 import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UPDATED;
 import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
@@ -102,6 +105,9 @@
     protected static final String ISNOTNULL = "Rest device is not null";
     private static final String UNKNOWN = "unknown";
 
+    private final ExecutorService executor =
+            Executors.newFixedThreadPool(5, groupedThreads("onos/restsbprovider", "device-installer-%d"));
+
     private final ConfigFactory factory =
             new ConfigFactory<ApplicationId, RestProviderConfig>(APP_SUBJECT_FACTORY,
                                                                  RestProviderConfig.class,
@@ -115,6 +121,8 @@
     private final NetworkConfigListener cfgLister = new InternalNetworkConfigListener();
     private ApplicationId appId;
 
+    private Set<DeviceId> addedDevices = new HashSet<>();
+
 
     @Activate
     public void activate() {
@@ -156,9 +164,9 @@
     public boolean isReachable(DeviceId deviceId) {
         RestSBDevice restDevice = controller.getDevice(deviceId);
         if (restDevice == null) {
-            log.warn("BAD REQUEST: the requested device id: " +
-                             deviceId.toString() +
-                             "  is not associated to any REST Device");
+            log.debug("the requested device id: " +
+                              deviceId.toString() +
+                              "  is not associated to any REST Device");
             return false;
         }
         return restDevice.isActive();
@@ -181,6 +189,7 @@
         providerService.deviceConnected(deviceId, deviceDescription);
         nodeId.setActive(true);
         controller.addDevice(nodeId);
+        addedDevices.add(deviceId);
     }
 
     //when do I call it ?
@@ -212,7 +221,7 @@
             log.error("Configuration error {}", e);
         }
         log.debug("REST Devices {}", controller.getDevices());
-        controller.getDevices().keySet().forEach(deviceId -> {
+        addedDevices.forEach(deviceId -> {
             DriverHandler h = driverService.createHandler(deviceId);
             PortDiscovery portConfig = h.behaviour(PortDiscovery.class);
             if (portConfig != null) {
@@ -221,6 +230,8 @@
                 log.warn("No portGetter behaviour for device {}", deviceId);
             }
         });
+        addedDevices.clear();
+
     }
 
     private boolean testDeviceConnection(RestSBDevice device) {
@@ -240,8 +251,9 @@
             } else {
                 urlConn = (HttpURLConnection) url.openConnection();
             }
-            if (device.password() != null) {
-                String userPassword = device.name() + ":" + device.password();
+            if (device.username() != null) {
+                String pwd = device.password() == null ? "" : ":" + device.password();
+                String userPassword = device.username() + pwd;
                 String basicAuth = Base64.getEncoder()
                         .encodeToString(userPassword.getBytes(StandardCharsets.UTF_8));
                 urlConn.setRequestProperty(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + basicAuth);
@@ -267,7 +279,7 @@
 
         @Override
         public void event(NetworkConfigEvent event) {
-            connectDevices();
+            executor.submit(RestDeviceProvider.this::connectDevices);
         }
 
         @Override