Example #1
0
 @Override
 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");
     return false;
   }
   return restDevice.isActive();
 }
Example #2
0
 private void connectDevices() {
   RestProviderConfig cfg = cfgService.getConfig(appId, RestProviderConfig.class);
   try {
     if (cfg != null && cfg.getDevicesAddresses() != null) {
       // Precomputing the devices to be removed
       Set<RestSBDevice> toBeRemoved = new HashSet<>(controller.getDevices().values());
       toBeRemoved.removeAll(cfg.getDevicesAddresses());
       // Adding new devices
       cfg.getDevicesAddresses()
           .stream()
           .filter(device -> testDeviceConnection(device))
           .forEach(
               device -> {
                 deviceAdded(device);
               });
       // Removing devices not wanted anymore
       toBeRemoved.stream().forEach(device -> deviceRemoved(device));
     }
   } catch (ConfigException e) {
     log.error("Configuration error {}", e);
   }
   log.info("REST Devices {}", controller.getDevices());
   controller
       .getDevices()
       .keySet()
       .forEach(
           deviceId -> {
             DriverHandler h = driverService.createHandler(deviceId);
             PortDiscovery portConfig = h.behaviour(PortDiscovery.class);
             if (portConfig != null) {
               providerService.updatePorts(deviceId, portConfig.getPorts());
             } else {
               log.warn("No portGetter behaviour for device {}", deviceId);
             }
           });
 }
Example #3
0
 private void deviceAdded(RestSBDevice nodeId) {
   Preconditions.checkNotNull(nodeId, ISNOTNULL);
   DeviceId deviceId = nodeId.deviceId();
   ChassisId cid = new ChassisId();
   String ipAddress = nodeId.ip().toString();
   SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).build();
   DeviceDescription deviceDescription =
       new DefaultDeviceDescription(
           deviceId.uri(),
           Device.Type.SWITCH,
           UNKNOWN,
           UNKNOWN,
           UNKNOWN,
           UNKNOWN,
           cid,
           annotations);
   providerService.deviceConnected(deviceId, deviceDescription);
   nodeId.setActive(true);
   controller.addDevice(nodeId);
 }
Example #4
0
 // when do I call it ?
 public void deviceRemoved(RestSBDevice nodeId) {
   Preconditions.checkNotNull(nodeId, ISNOTNULL);
   DeviceId deviceId = nodeId.deviceId();
   providerService.deviceDisconnected(deviceId);
   controller.removeDevice(nodeId);
 }