@Override public String value(String key) { if (filtered.contains(key)) { return null; } return delegate.value(key); }
/** * Produces a JSON object from the specified key/value annotations. * * @param mapper ObjectMapper to use while converting to JSON * @param annotations key/value annotations * @return JSON object */ public static ObjectNode annotations(ObjectMapper mapper, Annotations annotations) { ObjectNode result = mapper.createObjectNode(); for (String key : annotations.keys()) { result.put(key, annotations.value(key)); } return result; }
@Override public Set<String> keys() { return Sets.difference(delegate.keys(), filtered); }
/** * Adds JSON encoding of the given item annotations to the specified node. * * @param node node to add annotations to * @param entity annotated entity * @param context encode context * @return the given node */ protected ObjectNode annotate(ObjectNode node, T entity, CodecContext context) { if (!entity.annotations().keys().isEmpty()) { JsonCodec<Annotations> codec = context.codec(Annotations.class); node.set("annotations", codec.encode(entity.annotations(), context)); } return node; }
/** * Get the ControllerIp from the device . * * @param device Device * @return Controller Ip */ public static String getControllerIpOfSwitch(Device device) { String url = device.annotations().value(SWITCH_CHANNEL_ID); return url.substring(0, url.lastIndexOf(":")); }
@Override public String toString() { Map<String, String> mapView = new HashMap<>(); keys().forEach(key -> mapView.put(key, delegate.value(key))); return mapView.toString(); } }
private boolean containsSuppressionAnnotation(final Annotations annotations) { for (Entry<String, String> entry : suppressedAnnotation.entrySet()) { final String suppValue = entry.getValue(); final String suppKey = entry.getKey(); if (suppValue == ANY_VALUE) { if (annotations.keys().contains(suppKey)) { return true; } } else { if (suppValue.equals(annotations.value(suppKey))) { return true; } } } return false; }
/** * Get the ControllerIp from the device . * * @param device Device * @return Controller Ip */ public String getControllerIpOfSwitch(Device device) { String url = device.annotations().value(SWITCH_CHANNEL_ID); return url.substring(0, url.lastIndexOf(":")); }
/** * Produces a string image of the specified key/value annotations. * * @param annotations key/value annotations * @return string image with ", k1=v1, k2=v2, ..." pairs */ public static String annotations(Annotations annotations) { if (annotations == null) { annotations = DefaultAnnotations.EMPTY; } StringBuilder sb = new StringBuilder(); Set<String> keys = new TreeSet<>(annotations.keys()); for (String key : keys) { sb.append(", ").append(key).append('=').append(annotations.value(key)); } return sb.toString(); }
private boolean canMarkOnline(Device device) { final boolean providerMarkOnline = Boolean.parseBoolean( device.annotations().value(AnnotationKeys.PROVIDER_MARK_ONLINE)); return !providerMarkOnline; }
/** * Produces a string image of the specified key/value annotations. * Excludes the keys in the given Set. * * @param annotations key/value annotations * @param excludedKeys keys not to add in the resulting string * @return string image with ", k1=v1, k2=v2, ..." pairs */ public static String annotations(Annotations annotations, Set<String> excludedKeys) { StringBuilder sb = new StringBuilder(); Set<String> keys = new TreeSet<>(annotations.keys()); keys.removeAll(excludedKeys); for (String key : keys) { sb.append(", ").append(key).append('=').append(annotations.value(key)); } return sb.toString(); }
protected String getVni(Host host) { return host.annotations().value(VXLAN_ID); }
protected String getTenantId(Host host) { return host.annotations().value(TENANT_ID); }
/** * Returns OpenstackPort object for the Port reference given. * * @param port Port object * @return OpenstackPort reference, or null when not found */ public OpenstackPort openstackPort(Port port) { String uuid = port.annotations().value(PORT_NAME).substring(3); return openstackPortList.stream().filter(p -> p.id().startsWith(uuid)) .findAny().orElse(null); }
private PortNumber getTunnelPort(DeviceId deviceId) { Port port = deviceService.getPorts(deviceId).stream() .filter(p -> p.annotations().value(PORT_NAME).equals( OpenstackSwitchingManager.PORTNAME_PREFIX_TUNNEL)) .findAny().orElse(null); if (port == null) { log.error("No TunnelPort was created."); return null; } return port.number(); }
@Override public OpenstackPort port(Port port) { String uuid = port.annotations().value(PORT_NAME).substring(3); return getPorts().stream() .filter(p -> p.id().startsWith(uuid)) .findAny().orElse(null); }
public static Optional<OmsPort> asOmsPort(Port port) { if (port instanceof OmsPort) { return Optional.of((OmsPort) port); } try { Annotations an = port.annotations(); Frequency minFrequency = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.MIN_FREQ_HZ))); Frequency maxFrequency = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.MAX_FREQ_HZ))); Frequency grid = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.GRID_HZ))); return Optional.of(new DefaultOmsPort(port, minFrequency, maxFrequency, grid)); } catch (NumberFormatException e) { log.warn("{} was not well-formed OMS port.", port, e); return Optional.empty(); } }