private Link composeLink(Map<ProviderId, LinkDescription> descs) { ProviderId primary = getBaseProviderId(descs); LinkDescription base = descs.get(verifyNotNull(primary)); ConnectPoint src = base.src(); ConnectPoint dst = base.dst(); Type type = base.type(); DefaultAnnotations annotations = DefaultAnnotations.builder().build(); annotations = merge(annotations, base.annotations()); for (Entry<ProviderId, LinkDescription> e : descs.entrySet()) { if (primary.equals(e.getKey())) { continue; } // TODO: should keep track of Description timestamp // and only merge conflicting keys when timestamp is newer // Currently assuming there will never be a key conflict between // providers // annotation merging. not so efficient, should revisit later annotations = merge(annotations, e.getValue().annotations()); } boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true"); return new DefaultLink(primary, src, dst, type, ACTIVE, isDurable, annotations); }
@Override public LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst) { Link link = getLink(src, dst); if (link == null) { return null; } if (link.isDurable()) { return link.state() == INACTIVE ? null : updateLink(linkKey(link.src(), link.dst()), link, new DefaultLink(link.providerId(), link.src(), link.dst(), link.type(), INACTIVE, link.isDurable(), link.annotations())); } return removeLink(src, dst); }