diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-03-22 17:57:16 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-03-31 14:27:54 +0000 |
commit | 4c4f1743dc29e87b0ab4b39087f79f7f01befa49 (patch) | |
tree | b339f6bed0337eb78fe9db81463fb66e2a42724c /v3po/impl/src/main/java/io | |
parent | 41efda74f2d306399208b2a5d1f9ea85c8fbda43 (diff) |
Dedicated NETCONF north interface for v3po
Change-Id: I3a001ef68f7ff43ec1b2a935dd474ec966cea878
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/impl/src/main/java/io')
-rw-r--r-- | v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java | 90 | ||||
-rw-r--r-- | v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProvider.java | 12 |
2 files changed, 100 insertions, 2 deletions
diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java index 8a0dead0e..4afd86099 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java @@ -23,20 +23,26 @@ import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.v3po.impl.data.VppDataBrokerInitializationProvider; import io.fd.honeycomb.v3po.impl.data.VppReaderRegistry; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import javax.annotation.Nonnull; +import javax.annotation.concurrent.NotThreadSafe; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Consumer; +import org.opendaylight.controller.sal.core.api.Provider; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.SoftwareLoopback; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType; @@ -54,10 +60,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.vppjapi.vppApi; import org.openvpp.vppjapi.vppInterfaceDetails; +import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class V3poProvider implements BindingAwareProvider, AutoCloseable { +public class V3poProvider implements BindingAwareProvider, AutoCloseable, Broker { private static final Logger LOG = LoggerFactory.getLogger(V3poProvider.class); private final Broker domBroker; @@ -209,4 +216,85 @@ public class V3poProvider implements BindingAwareProvider, AutoCloseable { vppDataBrokerInitializationProvider.close(); } } + + // DomBroker functionality below. Should go out of here. TODO do that when cleaning up this provider + + @Override + public ConsumerSession registerConsumer(final Consumer consumer) { + final SimpleConsumerSession session = new SimpleConsumerSession( + Collections.<Class<? extends BrokerService>, BrokerService>singletonMap(DOMDataBroker.class, + vppDataBrokerInitializationProvider.getBroker().get())); + consumer.onSessionInitiated(session); + return session; + } + + @Deprecated + @Override + public ConsumerSession registerConsumer(final Consumer consumer, final BundleContext bundleContext) { + throw new UnsupportedOperationException(); + } + + @Override + public ProviderSession registerProvider(final Provider provider) { + final SimpleProviderSession session = new SimpleProviderSession( + Collections.<Class<? extends BrokerService>, BrokerService>singletonMap(DOMDataBroker.class, + vppDataBrokerInitializationProvider.getBroker().get())); + provider.onSessionInitiated(session); + return session; + } + + @Override + public ProviderSession registerProvider(final Provider provider, final BundleContext bundleContext) { + throw new UnsupportedOperationException(); + } + + @NotThreadSafe + private static class SimpleConsumerSession implements ConsumerSession { + private boolean closed; + private final Map<Class<? extends BrokerService>, BrokerService> services; + + private SimpleConsumerSession(final Map<Class<? extends BrokerService>, BrokerService> services) { + this.services = services; + } + + @Override + public boolean isClosed() { + return closed; + } + + @Override + public <T extends BrokerService> T getService(final Class<T> aClass) { + return (T)services.get(aClass); + } + + @Override + public void close() { + closed = true; + } + } + + @NotThreadSafe + private static class SimpleProviderSession implements ProviderSession { + private boolean closed; + private final Map<Class<? extends BrokerService>, BrokerService> services; + + private SimpleProviderSession(final Map<Class<? extends BrokerService>, BrokerService> services) { + this.services = services; + } + + @Override + public boolean isClosed() { + return closed; + } + + @Override + public <T extends BrokerService> T getService(final Class<T> aClass) { + return (T)services.get(aClass); + } + + @Override + public void close() { + closed = true; + } + } } diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProvider.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProvider.java index b7a24ea90..129a1b84b 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProvider.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProvider.java @@ -85,6 +85,7 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto private final ReaderRegistry readerRegistry; private final InstanceIdentifier<Node> mountPointPath; private ObjectRegistration<DOMMountPoint> mountPointRegistration; + private DOMDataBroker broker; public VppDataBrokerInitializationProvider(@Nonnull final DataBroker bindingBroker, final ReaderRegistry readerRegistry) { this.bindingBroker = Preconditions.checkNotNull(bindingBroker, "bindingBroker should not be null"); @@ -116,7 +117,7 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto final DOMMountPointService.DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(path); mountPointBuilder.addInitialSchemaContext(globalContext); - final DOMDataBroker broker = initVppDataBroker(globalContext, serializer); + broker = initVppDataBroker(globalContext, serializer); mountPointBuilder.addService(DOMDataBroker.class, broker); mountPointRegistration = mountPointBuilder.register(); @@ -245,11 +246,20 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto new LoggingFuturesCallBack<Void>("Initializing VPP config DataTree failed", LOG)); } + public Optional<DOMDataBroker> getBroker() { + return Optional.fromNullable(broker); + } + @Override public void close() throws Exception { if (mountPointRegistration != null) { mountPointRegistration.close(); } + + if (broker != null) { + broker = null; + } + // remove MD-SAL placeholder data for VPP mount point: final WriteTransaction rwTx = bindingBroker.newWriteOnlyTransaction(); // does not fail if data is not present: |