@Override public int hashCode() { return Objects.hashCode(driver.name()); } }
@Override public void event(DriverEvent event) { executor.execute(() -> attemptMergeAll(event.subject().name())); }
private String getDeviceString(Device dev) { StringBuilder buf = new StringBuilder(); if (dev != null) { buf.append(String.format("Device: %s, ", dev.id())); buf.append(String.format("%s, ", dev.type())); buf.append(String.format("%s, ", dev.manufacturer())); buf.append(String.format("%s, ", dev.hwVersion())); buf.append(String.format("%s, ", dev.swVersion())); if (dev instanceof DefaultDevice) { DefaultDevice dfltDev = (DefaultDevice) dev; if (dfltDev.driver() != null) { buf.append(String.format("%s, ", dfltDev.driver().name())); } String channelId = dfltDev.annotations().value("channelId"); if (channelId != null) { buf.append(String.format("%s, ", channelId)); } } } return buf.toString(); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); SortedSet<String> strings = delegate.getStrings(); // Fetch our service and feed it's offerings to the string completer DriverService service = AbstractShellCommand.get(DriverService.class); service.getDrivers().forEach(d -> strings.add(d.name())); // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
private void printDriver(Driver driver, boolean first) { if (outputJson()) { json(driver); } else if (nameOnly) { print("%s", driver.name()); } else { List<Driver> parents = Optional.ofNullable(driver.parents()) .orElse(ImmutableList.of()); List<String> parentsNames = parents.stream() .map(Driver::name).collect(Collectors.toList()); if (first) { print(FMT, driver.name(), parentsNames, driver.manufacturer(), driver.hwVersion(), driver.swVersion()); } else { print(" Inherited from %s", driver.name()); } driver.behaviours().forEach(b -> printBehaviour(b, driver)); driver.properties().forEach((k, v) -> print(FMT_P, k, v)); //recursion call to print each parent parents.stream().forEach(parent -> printDriver(parent, false)); } }
private DomainIntentConfigurable initDomainIntentDriver(DeviceId deviceId) { // Attempt to lookup the handler in the cache DriverHandler handler = driverHandlers.get(deviceId); if (handler == null) { try { // Otherwise create it and if it has DomainIntentConfig behaviour, cache it handler = driverService.createHandler(deviceId); if (!handler.driver().hasBehaviour(DomainIntentConfigurable.class)) { log.warn("DomainIntentConfig behaviour not supported for device {}", deviceId); return null; } } catch (ItemNotFoundException e) { log.warn("No applicable driver for device {}", deviceId); return null; } driverHandlers.put(deviceId, handler); } // Always (re)initialize the pipeline behaviour log.info("Driver {} bound to device {} ... initializing driver", handler.driver().name(), deviceId); return handler.behaviour(DomainIntentConfigurable.class); } }
private void invalidatePipelinerIfNecessary(Device device) { DriverHandler handler = driverHandlers.get(device.id()); if (handler != null && !Objects.equals(handler.driver().name(), device.annotations().value(DRIVER))) { invalidatePipeliner(device.id()); } }
private void setupPipelineHandler(DeviceId deviceId) { // Attempt to lookup the handler in the cache DriverHandler handler = driverHandlers.get(deviceId); if (handler == null) { try { // Otherwise create it and if it has pipeline behaviour, cache it handler = driverService.createHandler(deviceId); if (!handler.driver().hasBehaviour(Pipeliner.class)) { log.warn("Pipeline behaviour not supported for device {}", deviceId); return; } } catch (ItemNotFoundException e) { log.warn("No applicable driver for device {}", deviceId); return; } driverHandlers.put(deviceId, handler); } // Always (re)initialize the pipeline behaviour log.info("Driver {} bound to device {} ... initializing driver", handler.driver().name(), deviceId); Pipeliner pipeliner = handler.behaviour(Pipeliner.class); pipeliner.init(deviceId, context); pipeliners.putIfAbsent(deviceId, pipeliner); }
@Override public ObjectNode encode(Device device, CodecContext context) { checkNotNull(device, "Device cannot be null"); DeviceService service = context.getService(DeviceService.class); DriverService driveService = context.getService(DriverService.class); ObjectNode result = context.mapper().createObjectNode() .put(ID, device.id().toString()) .put(TYPE, device.type().name()) .put(AVAILABLE, service.isAvailable(device.id())) .put(ROLE, service.getRole(device.id()).toString()) .put(MFR, device.manufacturer()) .put(HW, device.hwVersion()) .put(SW, device.swVersion()) .put(SERIAL, device.serialNumber()) .put(DRIVER, driveService.getDriver(device.id()).name()) .put(CHASSIS_ID, device.chassisId().toString()) .put(LAST_UPDATE, Long.toString(service.getLastUpdatedInstant(device.id()))) .put(HUMAN_READABLE_LAST_UPDATE, service.localStatus(device.id())); return annotate(result, device, context); }
handler.driver().name(), deviceId); hTime = now(); Pipeliner pipeliner = handler.behaviour(Pipeliner.class);
@Override public void write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) { kryo.writeClassAndObject(output, object.extensionInstruction().type()); kryo.writeClassAndObject(output, object.deviceId()); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); // It raises ItemNotFoundException if it failed to find driver Driver driver = driverService.getDriver(object.deviceId()); kryo.writeClassAndObject(output, driver.name()); kryo.writeClassAndObject(output, object.extensionInstruction().serialize()); }
/** * Prints information about the specified device. * * @param deviceService device service * @param device infrastructure device */ protected void printDevice(DeviceService deviceService, Device device) { if (device != null) { String driver = get(DriverService.class).getDriver(device.id()).name(); if (shortOnly) { print(FMT_SHORT, device.id(), deviceService.isAvailable(device.id()), deviceService.getRole(device.id()), device.type(), driver); } else { print(FMT, device.id(), deviceService.isAvailable(device.id()), deviceService.localStatus(device.id()), deviceService.getRole(device.id()), device.type(), device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId(), driver, annotations(device.annotations(), ImmutableSet.of(AnnotationKeys.DRIVER))); } } } }