@Override public HostDescription combine(HostId hostId, HostDescription descr, Optional<Config> prevConfig) { HostAnnotationConfig cfg = lookupConfig(hostId); if (cfg == null) { return descr; } Map<String, String> annotations = cfg.annotations(); Builder builder = DefaultAnnotations.builder(); builder.putAll(descr.annotations()); if (prevConfig.isPresent()) { HostAnnotationConfig prevHostAnnotationConfig = (HostAnnotationConfig) prevConfig.get(); for (String key : prevHostAnnotationConfig.annotations().keySet()) { if (!annotations.containsKey(key)) { builder.remove(key); } } } builder.putAll(annotations); return DefaultHostDescription.copyReplacingAnnotation(descr, builder.build()); }
@Override public DeviceDescription combine(DeviceId deviceId, DeviceDescription descr, Optional<Config> prevConfig) { DeviceAnnotationConfig cfg = lookupConfig(deviceId); if (cfg == null) { return descr; } Map<String, String> annotations = cfg.annotations(); Builder builder = DefaultAnnotations.builder(); builder.putAll(descr.annotations()); if (prevConfig.isPresent()) { DeviceAnnotationConfig prevDeviceAnnotationConfig = (DeviceAnnotationConfig) prevConfig.get(); for (String key : prevDeviceAnnotationConfig.annotations().keySet()) { if (!annotations.containsKey(key)) { builder.remove(key); } } } builder.putAll(annotations); return DefaultDeviceDescription.copyReplacingAnnotation(descr, builder.build()); }
private LinkDescription description(Link link, String key, String value) { checkNotNull(key, "Key cannot be null"); DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); if (value != null) { builder.set(key, value); } else { builder.remove(key); } return new DefaultLinkDescription(link.src(), link.dst(), link.type(), link.isExpected(), builder.build()); }