diff options
author | 2016-04-11 08:56:06 +0200 | |
---|---|---|
committer | 2016-04-12 11:04:11 +0200 | |
commit | f93415dd8b3719b380b4295ab364420b9bf3d927 (patch) | |
tree | 057de7e397985b74cef738936983c7db6e741cd7 /v3po/impl/src/main/java | |
parent | d99066504f76a181c90832b939956f43b409c075 (diff) |
HONEYCOMB-34: Config tree initialization using ModifiableDataTree dependency
Change-Id: I9fa6119a92cc1979ed6f3364bb74e856a7a712c5
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/impl/src/main/java')
4 files changed, 119 insertions, 159 deletions
diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java index 84301b711..bbb004b73 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java @@ -20,22 +20,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.AsyncFunction; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import io.fd.honeycomb.v3po.data.ModifiableDataTree; import io.fd.honeycomb.v3po.data.ReadableDataTree; import io.fd.honeycomb.v3po.data.impl.DataBroker; -import io.fd.honeycomb.v3po.translate.Context; -import io.fd.honeycomb.v3po.translate.TranslationException; -import io.fd.honeycomb.v3po.translate.read.ReadContext; import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; import io.fd.honeycomb.v3po.translate.write.WriterRegistry; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.List; -import java.util.Map; import javax.annotation.Nonnull; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; @@ -43,19 +34,11 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.sal.core.api.Broker; import org.opendaylight.controller.sal.core.api.Provider; import org.opendaylight.controller.sal.core.api.model.SchemaService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; @@ -66,13 +49,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yangtools.concepts.ObjectRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -136,7 +115,7 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto final DOMMountPointService.DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(path); mountPointBuilder.addInitialSchemaContext(globalContext); - broker = initVppDataBroker(operationalDataTree, serializer, configDataTree); + broker = new DataBroker(operationalDataTree, configDataTree); mountPointBuilder.addService(DOMDataBroker.class, broker); mountPointRegistration = mountPointBuilder.register(); @@ -145,9 +124,6 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto mountPoint.getSchemaContext()); createMountPointPlaceholder(); - - // TODO initial sync has to go out of here -// initialVppConfigSynchronization(broker); } @Override @@ -168,98 +144,6 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto } } - private DOMDataBroker initVppDataBroker(final ReadableDataTree operationalDataTree, - final BindingNormalizedNodeSerializer serializer, - final ModifiableDataTree configDataTree) { - // init operational data tree before data broker is initialized - - try { - initConfig(serializer, configDataTree); - } catch (Exception e) { - LOG.warn("Failed to initialize config", e); - } - - return new DataBroker(operationalDataTree, configDataTree); - } - - // FIXME move to initializer after wiring is finished - private void initConfig(final BindingNormalizedNodeSerializer serializer, final ModifiableDataTree configDataTree) - throws TranslationException, DataValidationFailedException { - LOG.info("Config initialization"); - - final Optional<? extends DataObject> data = readerRegistry.read(InstanceIdentifier.create(VppState.class), new ReadContextImpl()); - LOG.info("Config initialization data={}", data); - - if (data.isPresent()) { - // conversion - VppState vppOperationalData = (VppState) data.get(); - final Vpp vppConfigData = convert(vppOperationalData); - - final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalizedData = - serializer.toNormalizedNode(InstanceIdentifier.create(Vpp.class), vppConfigData); - - final DataTreeModification modification = configDataTree.takeSnapshot().newModification(); - final YangInstanceIdentifier biPath = normalizedData.getKey(); - final NormalizedNode<?, ?> biData = normalizedData.getValue(); - LOG.info("Config initialization biPath={}, biData={}", biPath, biData); - modification.write(biPath, biData); - modification.ready(); - - LOG.info("Config writing modification ..."); - configDataTree.modify(modification); // TODO do not write to VPP - LOG.info("Config writing modification written successfully."); - } else { - LOG.info("Data is not present"); - } - } - - private Vpp convert(final VppState vppState) { - final BridgeDomains bridgeDomains = vppState.getBridgeDomains(); - final List<BridgeDomain> bridgeDomainList = bridgeDomains.getBridgeDomain(); - - VppBuilder vppBuilder = new VppBuilder(); - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomainsBuilder bdsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomainsBuilder(); - final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain> - listOfBDs = new ArrayList<>(); - - // TODO use reflexion - for (BridgeDomain bd : bridgeDomainList) { - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder bdBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder(); - bdBuilder.setLearn(bd.isLearn()); - bdBuilder.setUnknownUnicastFlood(bd.isUnknownUnicastFlood()); - bdBuilder.setArpTermination(bd.isArpTermination()); - bdBuilder.setFlood(bd.isFlood()); - bdBuilder.setForward(bd.isForward()); - bdBuilder.setKey(new BridgeDomainKey(bd.getKey().getName())); - // TODO bdBuilder.setL2Fib(bd.getL2Fib()); - bdBuilder.setName(bd.getName()); - listOfBDs.add(bdBuilder.build()); - } - - bdsBuilder.setBridgeDomain(listOfBDs); - vppBuilder.setBridgeDomains(bdsBuilder.build()); - return vppBuilder.build(); - } - - - // TODO move to utility module - private static final class ReadContextImpl implements ReadContext { - public final Context ctx = new Context(); - - @Nonnull - @Override - public Context getContext() { - return ctx; - } - - @Override - public void close() { - // Make sure to clear the storage in case some customizer stored it to prevent memory leaks - ctx.close(); - } - } - - /** * Writes placeholder data into MD-SAL's global datastore to indicate the presence of VPP mountpoint. */ @@ -279,47 +163,6 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto } } - // TODO operational and config models are not 1-1 - // decide what part of operational data should be written to config during initialization - private void initialVppConfigSynchronization(final DOMDataBroker broker) { - // read from operational - final DOMDataReadOnlyTransaction readTx = broker.newReadOnlyTransaction(); - - final YangInstanceIdentifier - id = YangInstanceIdentifier.builder().node(VppState.QNAME).node(BridgeDomains.QNAME).build(); - - LOG.trace("initialVppStateSynchronization id: {}", id); - - final ListenableFuture<Void> writeFuture = Futures.transform( - readTx.read(LogicalDatastoreType.OPERATIONAL, id), - new AsyncFunction<Optional<NormalizedNode<?, ?>>, Void>() { - @Override - public ListenableFuture<Void> apply(final Optional<NormalizedNode<?, ?>> readResult) - throws Exception { - if (readResult.isPresent()) { - final DOMDataWriteTransaction writeTx = broker.newWriteOnlyTransaction(); - final NormalizedNode<?, ?> node = readResult.get(); - LOG.trace("Read result: {}", node); - - // FIXME - // this will fail because we are reading OPERATIONAL data and writing to CONFIGURATION - // we need to provide extensible way to register initializer that would - // translate between models - - // writeTx.put(LogicalDatastoreType.CONFIGURATION, id, node); - return writeTx.submit(); - } else { - return Futures - .immediateFailedFuture( - new IllegalStateException("Failed to read data from VPP.")); - } - } - }); - - Futures.addCallback(writeFuture, - new LoggingFuturesCallBack<Void>("Initializing VPP config DataTree failed", LOG)); - } - public Optional<DOMDataBroker> getBroker() { return Optional.fromNullable(broker); } diff --git a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/DataBrokerModule.java b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/DataBrokerModule.java new file mode 100644 index 000000000..76f014456 --- /dev/null +++ b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/DataBrokerModule.java @@ -0,0 +1,104 @@ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210; + +import io.fd.honeycomb.v3po.data.impl.DataBroker; +import java.util.Map; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension; +import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener; +import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DataBrokerModule extends + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210.AbstractDataBrokerModule { + + private static final Logger LOG = LoggerFactory.getLogger(DataBrokerModule.class); + + public DataBrokerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public DataBrokerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210.DataBrokerModule oldModule, + java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + LOG.info("DataBrokerModule.createInstance()"); + return new CloseableDataBroker( + new DataBroker(getOperationalDataTreeDependency(), getConfigDataTreeDependency())); + } + + private static final class CloseableDataBroker implements AutoCloseable, DOMDataBroker { + + private final DataBroker delegate; + + CloseableDataBroker(final DataBroker delegate) { + this.delegate = delegate; + } + + @Override + public void close() throws Exception { + LOG.info("CloseableDataBroker.close()"); + // NOP + } + + @Override + public DOMDataReadOnlyTransaction newReadOnlyTransaction() { + LOG.trace("CloseableDataBroker.newReadOnlyTransaction()"); + return delegate.newReadOnlyTransaction(); + } + + @Override + public DOMDataReadWriteTransaction newReadWriteTransaction() { + LOG.trace("CloseableDataBroker.newReadWriteTransaction()"); + return delegate.newReadWriteTransaction(); + } + + @Override + public DOMDataWriteTransaction newWriteOnlyTransaction() { + LOG.trace("CloseableDataBroker.newWriteOnlyTransaction()"); + return delegate.newWriteOnlyTransaction(); + } + + @Override + public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, + final YangInstanceIdentifier path, + final DOMDataChangeListener listener, + final DataChangeScope triggeringScope) { + LOG.trace("CloseableDataBroker.createTransactionChain store={}, path={}, listener={}, triggeringScope={}", + store, path, listener, triggeringScope); + return delegate.registerDataChangeListener(store, path, listener, triggeringScope); + } + + @Override + public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) { + LOG.trace("CloseableDataBroker.createTransactionChain listener={}", listener); + return delegate.createTransactionChain(listener); + } + + @Nonnull + @Override + public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() { + LOG.trace("CloseableDataBroker.getSupportedExtensions()"); + return delegate.getSupportedExtensions(); + } + } +} diff --git a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/DataBrokerModuleFactory.java b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/DataBrokerModuleFactory.java new file mode 100644 index 000000000..cc30beacf --- /dev/null +++ b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/DataBrokerModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: v3po-impl yang module local name: honeycomb-dom-data-broker +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Mon Apr 11 07:53:38 CEST 2016 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210; +public class DataBrokerModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210.AbstractDataBrokerModuleFactory { + +} diff --git a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java index bae4a29d3..959780496 100644 --- a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java +++ b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java @@ -58,7 +58,7 @@ public class V3poModule extends domBroker.registerProvider(new InitializationProvider()); final V3poProvider provider = new V3poProvider(domBroker, getVppJapiDependency(), getReaderRegistryDependency(), - getWriterRegistryDependency(), getBindingNormalizedNodeSerializerDependency(), + getWriterRegistryDependency(), getSerializerDependency(), getConfigDataTreeDependency(), getOperationalDataTreeDependency()); getBrokerDependency().registerProvider(provider); return provider; |