summaryrefslogtreecommitdiffstats
path: root/v3po/vpp-cfg-init
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/vpp-cfg-init')
-rw-r--r--v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/AbstractDataTreeConverter.java99
-rw-r--r--v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/VppInitializer.java11
-rw-r--r--v3po/vpp-cfg-init/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/vpp/data/init/rev160407/VppConfigurationInitializerModule.java12
-rw-r--r--v3po/vpp-cfg-init/src/main/yang/vpp-cfg-init.yang25
-rw-r--r--v3po/vpp-cfg-init/src/test/java/io/fd/honeycomb/v3po/vpp/data/init/InitializerRegistryImplTest.java9
5 files changed, 46 insertions, 110 deletions
diff --git a/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/AbstractDataTreeConverter.java b/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/AbstractDataTreeConverter.java
index 3048dc18b..bf5a77d4b 100644
--- a/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/AbstractDataTreeConverter.java
+++ b/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/AbstractDataTreeConverter.java
@@ -20,20 +20,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
-import io.fd.honeycomb.v3po.data.ModifiableDataTree;
-import io.fd.honeycomb.v3po.translate.Context;
-import io.fd.honeycomb.v3po.translate.read.ReadContext;
-import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
-import io.fd.honeycomb.v3po.translate.read.ReaderRegistry;
-import java.util.Map;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+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.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,20 +42,14 @@ public abstract class AbstractDataTreeConverter<O extends DataObject, C extends
implements DataTreeInitializer {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDataTreeConverter.class);
- private final ReaderRegistry readerRegistry;
- private final ModifiableDataTree configDataTree;
- private final BindingNormalizedNodeSerializer serializer;
private final InstanceIdentifier<O> idOper;
private final InstanceIdentifier<C> idConfig;
+ private final DataBroker bindingDataBroker;
- public AbstractDataTreeConverter(@Nonnull final ReaderRegistry readerRegistry,
- @Nonnull final ModifiableDataTree configDataTree,
- @Nonnull final BindingNormalizedNodeSerializer serializer,
- @Nonnull final InstanceIdentifier<O> idOper,
- @Nonnull final InstanceIdentifier<C> idConfig) {
- this.readerRegistry = checkNotNull(readerRegistry, "readerRegistry should not be null");
- this.configDataTree = checkNotNull(configDataTree, "configDataTree should not be null");
- this.serializer = checkNotNull(serializer, "serializer should not be null");
+ public AbstractDataTreeConverter(final DataBroker bindingDataBroker,
+ final InstanceIdentifier<O> idOper,
+ final InstanceIdentifier<C> idConfig) {
+ this.bindingDataBroker = checkNotNull(bindingDataBroker, "bindingDataBroker should not be null");
this.idOper = checkNotNull(idOper, "idOper should not be null");
this.idConfig = checkNotNull(idConfig, "idConfig should not be null");
}
@@ -69,59 +57,42 @@ public abstract class AbstractDataTreeConverter<O extends DataObject, C extends
@Override
public final void initialize() throws InitializeException {
LOG.debug("AbstractDataTreeConverter.initialize()");
-
- final Optional<? extends DataObject> data;
- try (ReadContext ctx = new ReadContextImpl()) {
- data = readerRegistry.read(idOper, ctx);
- } catch (ReadFailedException e) {
- LOG.warn("Failed to read operational state", e);
- return;
- }
- LOG.debug("Config initialization data={}", data);
+ final Optional<O> data = readData();
if (data.isPresent()) {
- // conversion
- final O operationalData = idOper.getTargetType().cast(data.get());
- final C configData = convert(operationalData);
+ LOG.debug("Config initialization data={}", data);
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalizedData =
- serializer.toNormalizedNode(idConfig, configData);
-
- final DataTreeModification modification = configDataTree.takeSnapshot().newModification();
- final YangInstanceIdentifier biPath = normalizedData.getKey();
- final NormalizedNode<?, ?> biData = normalizedData.getValue();
- LOG.debug("Config initialization biPath={}, biData={}", biPath, biData);
- modification.write(biPath, biData);
- modification.ready();
+ final O operationalData = data.get();
+ final C configData = convert(operationalData);
- LOG.debug("Config writing modification ...");
try {
- configDataTree.initialize(modification);
- LOG.debug("Config writing modification written successfully.");
- } catch (DataValidationFailedException e) {
- throw new InitializeException("Failed to read operational state", e);
+ LOG.debug("Initializing config with data={}", configData);
+ writeData(configData);
+ LOG.debug("Config initialization successful");
+ } catch (TransactionCommitFailedException e) {
+ throw new InitializeException("Failed to perform config initialization", e);
}
} else {
LOG.warn("Data is not present");
}
}
- protected abstract C convert(final O operationalData);
-
- // 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;
+ private Optional<O> readData() {
+ try (ReadOnlyTransaction readTx = bindingDataBroker.newReadOnlyTransaction()) {
+ final CheckedFuture<Optional<O>, org.opendaylight.controller.md.sal.common.api.data.ReadFailedException>
+ readFuture = readTx.read(LogicalDatastoreType.OPERATIONAL, idOper);
+ return readFuture.checkedGet();
+ } catch (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException e) {
+ LOG.warn("Failed to read operational state", e);
}
+ return Optional.absent();
+ }
- @Override
- public void close() {
- // Make sure to clear the storage in case some customizer stored it to prevent memory leaks
- ctx.close();
- }
+ private void writeData(final C configData) throws TransactionCommitFailedException {
+ final WriteTransaction writeTx = bindingDataBroker.newWriteOnlyTransaction();
+ writeTx.merge(LogicalDatastoreType.CONFIGURATION, idConfig, configData);
+ writeTx.submit().checkedGet();
}
+
+ protected abstract C convert(final O operationalData);
}
diff --git a/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/VppInitializer.java b/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/VppInitializer.java
index c0316c0b8..3fad2a8d3 100644
--- a/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/VppInitializer.java
+++ b/v3po/vpp-cfg-init/src/main/java/io/fd/honeycomb/v3po/vpp/data/init/VppInitializer.java
@@ -16,18 +16,16 @@
package io.fd.honeycomb.v3po.vpp.data.init;
-import io.fd.honeycomb.v3po.data.ModifiableDataTree;
-import io.fd.honeycomb.v3po.translate.read.ReaderRegistry;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
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.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,10 +33,8 @@ import org.slf4j.LoggerFactory;
public class VppInitializer extends AbstractDataTreeConverter<VppState, Vpp> {
private static final Logger LOG = LoggerFactory.getLogger(VppInitializer.class);
- public VppInitializer(@Nonnull final ReaderRegistry readerRegistry,
- @Nonnull final ModifiableDataTree configDataTree,
- @Nonnull final BindingNormalizedNodeSerializer serializer) {
- super(readerRegistry, configDataTree, serializer, InstanceIdentifier.create(VppState.class), InstanceIdentifier.create(Vpp.class) );
+ public VppInitializer(@Nonnull final DataBroker bindingDataBroker) {
+ super(bindingDataBroker, InstanceIdentifier.create(VppState.class), InstanceIdentifier.create(Vpp.class));
}
@Override
@@ -61,7 +57,6 @@ public class VppInitializer extends AbstractDataTreeConverter<VppState, Vpp> {
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 =
diff --git a/v3po/vpp-cfg-init/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/vpp/data/init/rev160407/VppConfigurationInitializerModule.java b/v3po/vpp-cfg-init/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/vpp/data/init/rev160407/VppConfigurationInitializerModule.java
index 8b6f589c4..eddc74d27 100644
--- a/v3po/vpp-cfg-init/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/vpp/data/init/rev160407/VppConfigurationInitializerModule.java
+++ b/v3po/vpp-cfg-init/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/vpp/data/init/rev160407/VppConfigurationInitializerModule.java
@@ -1,13 +1,11 @@
package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.vpp.data.init.rev160407;
-import io.fd.honeycomb.v3po.data.ModifiableDataTree;
-import io.fd.honeycomb.v3po.translate.read.ReaderRegistry;
import io.fd.honeycomb.v3po.vpp.data.init.DataTreeInitializer;
import io.fd.honeycomb.v3po.vpp.data.init.InitializerRegistry;
import io.fd.honeycomb.v3po.vpp.data.init.InitializerRegistryImpl;
import io.fd.honeycomb.v3po.vpp.data.init.VppInitializer;
import java.util.Collections;
-import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,14 +33,12 @@ public class VppConfigurationInitializerModule extends
@Override
public java.lang.AutoCloseable createInstance() {
- LOG.info("VppConfigurationInitializerModule.createInstance()");
- final ReaderRegistry readerRegistry = getReaderRegistryDependency();
- final ModifiableDataTree configDataTree = getConfigDataTreeDependency();
- final BindingNormalizedNodeSerializer serializer = getSerializerDependency();
+ LOG.debug("VppConfigurationInitializerModule.createInstance()");
+ final DataBroker bindingDataBroker = getBindingDataBrokerDependency();
// TODO make configurable
final VppInitializer vppInitializer =
- new VppInitializer(readerRegistry, configDataTree, serializer);
+ new VppInitializer(bindingDataBroker);
final InitializerRegistry initializer =
new InitializerRegistryImpl(Collections.<DataTreeInitializer>singletonList(vppInitializer));
diff --git a/v3po/vpp-cfg-init/src/main/yang/vpp-cfg-init.yang b/v3po/vpp-cfg-init/src/main/yang/vpp-cfg-init.yang
index 15a842e0e..e4ce95aea 100644
--- a/v3po/vpp-cfg-init/src/main/yang/vpp-cfg-init.yang
+++ b/v3po/vpp-cfg-init/src/main/yang/vpp-cfg-init.yang
@@ -31,33 +31,14 @@ module vpp-cfg-init {
case vpp-cfg-initializer-impl {
when "/config:modules/config:module/config:type = 'vpp-cfg-initializer-impl'";
- container reader-registry {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity tapi:honeycomb-reader-registry;
- }
- }
- }
-
- // TODO swich to binding broker
- container config-data-tree {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity dapi:honeycomb-modifiable-data-tree;
- }
- }
- }
-
- container serializer {
+ container binding-data-broker {
uses config:service-ref {
refine type {
mandatory true;
- config:required-identity md-sal-binding:binding-normalized-node-serializer;
+ config:required-identity md-sal-binding:binding-async-data-broker;
}
}
- }
+ }
}
}
diff --git a/v3po/vpp-cfg-init/src/test/java/io/fd/honeycomb/v3po/vpp/data/init/InitializerRegistryImplTest.java b/v3po/vpp-cfg-init/src/test/java/io/fd/honeycomb/v3po/vpp/data/init/InitializerRegistryImplTest.java
index d77ac3fe5..d562fb60c 100644
--- a/v3po/vpp-cfg-init/src/test/java/io/fd/honeycomb/v3po/vpp/data/init/InitializerRegistryImplTest.java
+++ b/v3po/vpp-cfg-init/src/test/java/io/fd/honeycomb/v3po/vpp/data/init/InitializerRegistryImplTest.java
@@ -19,7 +19,6 @@ package io.fd.honeycomb.v3po.vpp.data.init;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
@@ -34,18 +33,12 @@ public class InitializerRegistryImplTest {
@Mock(name="dti3")
private DataTreeInitializer dti3;
- private ArrayList<DataTreeInitializer> initializers;
-
private InitializerRegistryImpl initializerRegistry;
@Before
public void setUp() throws Exception {
initMocks(this);
- initializers = new ArrayList<>();
- initializers.add(dti1);
- initializers.add(dti2);
- initializers.add(dti3);
- initializerRegistry = new InitializerRegistryImpl(initializers);
+ initializerRegistry = new InitializerRegistryImpl(Arrays.asList(dti1, dti2, dti3));
}
@Test(expected = IllegalArgumentException.class)