From e1743c8eccee7d5ea8ad2c247d2575e8fd219fe4 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Tue, 12 Apr 2016 10:13:18 +0200 Subject: HONEYCOMB-9: Remove references to VPP from translation layer Change-Id: I281db366a112edc08203e8cb392a212708d4552a Signed-off-by: Maros Marsalek --- v3po/impl/pom.xml | 2 +- .../io/fd/honeycomb/v3po/impl/V3poProvider.java | 8 +- .../honeycomb/v3po/impl/data/ReaderRegistry.java | 116 ++++++++++++++++++++ .../v3po/impl/data/VppConfigDataTree.java | 19 ++-- .../data/VppDataBrokerInitializationProvider.java | 6 +- .../fd/honeycomb/v3po/impl/data/VppDataTree.java | 6 +- .../v3po/impl/data/VppOperationalDataTree.java | 8 +- .../v3po/impl/data/VppReaderRegistry.java | 117 --------------------- .../v3po/impl/data/VppWriteTransaction.java | 4 +- .../v3po/impl/data/VppWriterRegistry.java | 105 ------------------ .../honeycomb/v3po/impl/data/WriterRegistry.java | 104 ++++++++++++++++++ .../v3po/impl/data/VPPConfigDataTreeTest.java | 31 +++--- .../VppDataBrokerInitializationProviderTest.java | 4 +- .../v3po/impl/data/VppOperationalDataTreeTest.java | 8 +- 14 files changed, 268 insertions(+), 270 deletions(-) create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReaderRegistry.java delete mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppReaderRegistry.java delete mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriterRegistry.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/WriterRegistry.java (limited to 'v3po/impl') diff --git a/v3po/impl/pom.xml b/v3po/impl/pom.xml index a8109a888..56dcf8555 100644 --- a/v3po/impl/pom.xml +++ b/v3po/impl/pom.xml @@ -36,7 +36,7 @@ ${project.groupId} - vpp-facade-impl + translate-impl ${project.version} 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 931ecefd6..0ea4525f0 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 @@ -21,8 +21,8 @@ import com.google.common.collect.Lists; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.v3po.impl.data.VppDataBrokerInitializationProvider; -import io.fd.honeycomb.v3po.impl.data.VppReaderRegistry; -import io.fd.honeycomb.v3po.impl.data.VppWriterRegistry; +import io.fd.honeycomb.v3po.impl.data.ReaderRegistry; +import io.fd.honeycomb.v3po.impl.data.WriterRegistry; import java.io.IOException; import java.util.Collections; import java.util.HashMap; @@ -196,8 +196,8 @@ public class V3poProvider implements BindingAwareProvider, AutoCloseable, Broker vppPollOperData); startOperationalUpdateTimer(); - final VppReaderRegistry readerRegistry = VppReaderRegistry.getInstance(api); - final VppWriterRegistry writerRegistry = VppWriterRegistry.getInstance(api); + final ReaderRegistry readerRegistry = ReaderRegistry.getInstance(api); + final WriterRegistry writerRegistry = WriterRegistry.getInstance(api); // TODO make configurable: vppDataBrokerInitializationProvider = new VppDataBrokerInitializationProvider(db, readerRegistry, writerRegistry); diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReaderRegistry.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReaderRegistry.java new file mode 100644 index 000000000..5e547094f --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReaderRegistry.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.data; + +import com.google.common.base.Optional; +import com.google.common.collect.Multimap; +import io.fd.honeycomb.v3po.translate.impl.read.CompositeChildReader; +import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader; +import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader; +import io.fd.honeycomb.v3po.translate.util.read.DelegatingReaderRegistry; +import io.fd.honeycomb.v3po.translate.util.read.ReflexiveChildReaderCustomizer; +import io.fd.honeycomb.v3po.translate.util.read.ReflexiveRootReaderCustomizer; +import io.fd.honeycomb.v3po.translate.util.RWUtils; +import io.fd.honeycomb.v3po.translate.read.ChildReader; +import io.fd.honeycomb.v3po.translate.read.ReadContext; +import io.fd.honeycomb.v3po.translate.read.ReadFailedException; +import io.fd.honeycomb.v3po.translate.read.Reader; +import io.fd.honeycomb.v3po.translate.v3po.vppstate.BridgeDomainCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.vppstate.VersionCustomizer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nonnull; +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.VppStateBuilder; +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.BridgeDomainsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; +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.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.vppjapi.vppApi; + +// TODO use some DI framework instead of singleton +public class ReaderRegistry implements io.fd.honeycomb.v3po.translate.read.ReaderRegistry { + + private static ReaderRegistry instance; + + private final DelegatingReaderRegistry reader; + + private ReaderRegistry(@Nonnull final vppApi vppApi) { + final CompositeRootReader vppStateReader = initVppStateReader(vppApi); + // TODO add more root readers + reader = new DelegatingReaderRegistry(Collections.>singletonList(vppStateReader)); + } + + private static CompositeRootReader initVppStateReader(@Nonnull final vppApi vppApi) { + + final ChildReader versionReader = new CompositeChildReader<>( + Version.class, new VersionCustomizer(vppApi)); + + final CompositeListReader + bridgeDomainReader = new CompositeListReader<>( + BridgeDomain.class, + new BridgeDomainCustomizer(vppApi)); + + final ChildReader bridgeDomainsReader = new CompositeChildReader<>( + BridgeDomains.class, + RWUtils.singletonChildReaderList(bridgeDomainReader), + new ReflexiveChildReaderCustomizer<>(BridgeDomainsBuilder.class)); + + final List>> childVppReaders = new ArrayList<>(); + childVppReaders.add(versionReader); + childVppReaders.add(bridgeDomainsReader); + + return new CompositeRootReader<>( + VppState.class, + childVppReaders, + RWUtils.emptyAugReaderList(), + new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class)); + } + + public static synchronized ReaderRegistry getInstance(@Nonnull final vppApi vppApi) { + if (instance == null) { + instance = new ReaderRegistry(vppApi); + } + return instance; + } + + @Nonnull + @Override + public Multimap, ? extends DataObject> readAll( + @Nonnull final ReadContext ctx) throws ReadFailedException { + return reader.readAll(ctx); + } + + @Nonnull + @Override + public Optional read(@Nonnull final InstanceIdentifier id, + @Nonnull final ReadContext ctx) throws ReadFailedException { + return reader.read(id, ctx); + } + + @Nonnull + @Override + public InstanceIdentifier getManagedDataObjectType() { + return reader.getManagedDataObjectType(); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppConfigDataTree.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppConfigDataTree.java index 72848ad0f..1a631fc2e 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppConfigDataTree.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppConfigDataTree.java @@ -21,10 +21,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; -import io.fd.honeycomb.v3po.vpp.facade.VppException; -import io.fd.honeycomb.v3po.vpp.facade.impl.write.util.TransactionWriteContext; -import io.fd.honeycomb.v3po.vpp.facade.write.WriteContext; -import io.fd.honeycomb.v3po.vpp.facade.write.WriterRegistry; +import io.fd.honeycomb.v3po.translate.TranslationException; +import io.fd.honeycomb.v3po.translate.util.write.TransactionWriteContext; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import java.util.Collections; import java.util.Map; import javax.annotation.Nonnull; @@ -54,7 +53,7 @@ public final class VppConfigDataTree implements VppDataTree { private final BindingNormalizedNodeSerializer serializer; private final DataTree dataTree; - private final VppWriterRegistry writer; + private final WriterRegistry writer; public static final ReadableVppDataTree EMPTY_OPERATIONAL = new ReadableVppDataTree() { @Override public CheckedFuture>, ReadFailedException> read( @@ -72,7 +71,7 @@ public final class VppConfigDataTree implements VppDataTree { * @param vppWriter service for translation between Java Binding Data and Vpp. */ public VppConfigDataTree(@Nonnull final BindingNormalizedNodeSerializer serializer, - @Nonnull final DataTree dataTree, @Nonnull final VppWriterRegistry vppWriter) { + @Nonnull final DataTree dataTree, @Nonnull final WriterRegistry vppWriter) { this.serializer = checkNotNull(serializer, "serializer should not be null"); this.dataTree = checkNotNull(dataTree, "dataTree should not be null"); this.writer = checkNotNull(vppWriter, "vppWriter should not be null"); @@ -85,7 +84,7 @@ public final class VppConfigDataTree implements VppDataTree { @Override public void commit(final DataTreeModification modification) - throws DataValidationFailedException, VppException { + throws DataValidationFailedException, TranslationException { dataTree.validate(modification); final DataTreeCandidate candidate = dataTree.prepare(modification); @@ -109,21 +108,21 @@ public final class VppConfigDataTree implements VppDataTree { final DOMDataReadOnlyTransaction afterTx = new VppReadOnlyTransaction(EMPTY_OPERATIONAL, modificationSnapshot); try(final WriteContext ctx = new TransactionWriteContext(serializer, beforeTx, afterTx)) { writer.update(nodesBefore, nodesAfter, ctx); - } catch (WriterRegistry.BulkUpdateException e) { + } catch (io.fd.honeycomb.v3po.translate.write.WriterRegistry.BulkUpdateException e) { LOG.warn("Failed to apply all changes", e); LOG.info("Trying to revert successful changes for current transaction"); try { e.revertChanges(); LOG.info("Changes successfully reverted"); - } catch (WriterRegistry.Reverter.RevertFailedException revertFailedException) { + } catch (io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter.RevertFailedException revertFailedException) { // fail with failed revert LOG.error("Failed to revert successful changes", revertFailedException); throw revertFailedException; } throw e; // fail with success revert - } catch (VppException e) { + } catch (TranslationException e) { LOG.error("Error while processing data change (before={}, after={})", nodesBefore, nodesAfter, e); throw e; } 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 d84f0b7b7..bdfc89079 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 @@ -24,7 +24,7 @@ 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.impl.LoggingFuturesCallBack; -import io.fd.honeycomb.v3po.vpp.facade.read.ReaderRegistry; +import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; import java.util.Collection; import java.util.Collections; import javassist.ClassPool; @@ -85,13 +85,13 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto private final DataBroker bindingBroker; private final ReaderRegistry readerRegistry; private final InstanceIdentifier mountPointPath; - private final VppWriterRegistry writerRegistry; + private final WriterRegistry writerRegistry; private ObjectRegistration mountPointRegistration; private DOMDataBroker broker; public VppDataBrokerInitializationProvider(@Nonnull final DataBroker bindingBroker, final ReaderRegistry readerRegistry, - final VppWriterRegistry writerRegistry) { + final WriterRegistry writerRegistry) { this.bindingBroker = checkNotNull(bindingBroker, "bindingBroker should not be null"); this.readerRegistry = checkNotNull(readerRegistry, "readerRegistry should not be null"); this.writerRegistry = checkNotNull(writerRegistry, "writerRegistry should not be null"); diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java index 7e62b57b0..aba8ab133 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java @@ -17,7 +17,7 @@ package io.fd.honeycomb.v3po.impl.data; import com.google.common.annotations.Beta; -import io.fd.honeycomb.v3po.vpp.facade.VppException; +import io.fd.honeycomb.v3po.translate.TranslationException; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; @@ -31,9 +31,9 @@ public interface VppDataTree { * * @param modification VPP data tree modification * @throws DataValidationFailedException if modification data is not valid - * @throws VppException if commit failed while updating VPP state + * @throws TranslationException if commit failed while updating VPP state */ - void commit(final DataTreeModification modification) throws DataValidationFailedException, VppException; + void commit(final DataTreeModification modification) throws DataValidationFailedException, TranslationException; /** * Creates read-only snapshot of a VppDataTree. diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTree.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTree.java index 12d281611..8f606fdbf 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTree.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTree.java @@ -26,10 +26,10 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Multimap; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; -import io.fd.honeycomb.v3po.vpp.facade.Context; -import io.fd.honeycomb.v3po.vpp.facade.read.ReadContext; -import io.fd.honeycomb.v3po.vpp.facade.read.ReadFailedException; -import io.fd.honeycomb.v3po.vpp.facade.read.ReaderRegistry; +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.Collection; import java.util.Map; import javax.annotation.Nonnull; diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppReaderRegistry.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppReaderRegistry.java deleted file mode 100644 index ba1865494..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppReaderRegistry.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.v3po.impl.data; - -import com.google.common.base.Optional; -import com.google.common.collect.Multimap; -import io.fd.honeycomb.v3po.vpp.facade.impl.read.CompositeChildVppReader; -import io.fd.honeycomb.v3po.vpp.facade.impl.read.CompositeListVppReader; -import io.fd.honeycomb.v3po.vpp.facade.impl.read.CompositeRootVppReader; -import io.fd.honeycomb.v3po.vpp.facade.impl.read.util.DelegatingReaderRegistry; -import io.fd.honeycomb.v3po.vpp.facade.impl.read.util.ReflexiveChildReaderCustomizer; -import io.fd.honeycomb.v3po.vpp.facade.impl.read.util.ReflexiveRootReaderCustomizer; -import io.fd.honeycomb.v3po.vpp.facade.impl.util.VppRWUtils; -import io.fd.honeycomb.v3po.vpp.facade.read.ChildVppReader; -import io.fd.honeycomb.v3po.vpp.facade.read.ReadContext; -import io.fd.honeycomb.v3po.vpp.facade.read.ReadFailedException; -import io.fd.honeycomb.v3po.vpp.facade.read.ReaderRegistry; -import io.fd.honeycomb.v3po.vpp.facade.read.VppReader; -import io.fd.honeycomb.v3po.vpp.facade.v3po.vppstate.BridgeDomainCustomizer; -import io.fd.honeycomb.v3po.vpp.facade.v3po.vppstate.VersionCustomizer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.annotation.Nonnull; -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.VppStateBuilder; -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.BridgeDomainsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; -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.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.vppjapi.vppApi; - -// TODO use some DI framework instead of singleton -public class VppReaderRegistry implements ReaderRegistry { - - private static VppReaderRegistry instance; - - private final DelegatingReaderRegistry reader; - - private VppReaderRegistry(@Nonnull final vppApi vppApi) { - final CompositeRootVppReader vppStateReader = initVppStateReader(vppApi); - // TODO add more root readers - reader = new DelegatingReaderRegistry(Collections.>singletonList(vppStateReader)); - } - - private static CompositeRootVppReader initVppStateReader(@Nonnull final vppApi vppApi) { - - final ChildVppReader versionReader = new CompositeChildVppReader<>( - Version.class, new VersionCustomizer(vppApi)); - - final CompositeListVppReader - bridgeDomainReader = new CompositeListVppReader<>( - BridgeDomain.class, - new BridgeDomainCustomizer(vppApi)); - - final ChildVppReader bridgeDomainsReader = new CompositeChildVppReader<>( - BridgeDomains.class, - VppRWUtils.singletonChildReaderList(bridgeDomainReader), - new ReflexiveChildReaderCustomizer<>(BridgeDomainsBuilder.class)); - - final List>> childVppReaders = new ArrayList<>(); - childVppReaders.add(versionReader); - childVppReaders.add(bridgeDomainsReader); - - return new CompositeRootVppReader<>( - VppState.class, - childVppReaders, - VppRWUtils.emptyAugReaderList(), - new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class)); - } - - public static synchronized VppReaderRegistry getInstance(@Nonnull final vppApi vppApi) { - if (instance == null) { - instance = new VppReaderRegistry(vppApi); - } - return instance; - } - - @Nonnull - @Override - public Multimap, ? extends DataObject> readAll( - @Nonnull final ReadContext ctx) throws ReadFailedException { - return reader.readAll(ctx); - } - - @Nonnull - @Override - public Optional read(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - return reader.read(id, ctx); - } - - @Nonnull - @Override - public InstanceIdentifier getManagedDataObjectType() { - return reader.getManagedDataObjectType(); - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriteTransaction.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriteTransaction.java index 1baa586b1..b33fffa68 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriteTransaction.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriteTransaction.java @@ -26,7 +26,7 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import io.fd.honeycomb.v3po.vpp.facade.VppException; +import io.fd.honeycomb.v3po.translate.TranslationException; import javax.annotation.Nonnull; import javax.annotation.concurrent.NotThreadSafe; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; @@ -121,7 +121,7 @@ final class VppWriteTransaction implements DOMDataWriteTransaction { try { configDataTree.commit(modification); status = COMMITED; - } catch (DataValidationFailedException | VppException e) { + } catch (DataValidationFailedException | TranslationException e) { status = FAILED; LOG.error("Failed to commit VPP state modification", e); return Futures.immediateFailedCheckedFuture( diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriterRegistry.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriterRegistry.java deleted file mode 100644 index 04b4bd631..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppWriterRegistry.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.v3po.impl.data; - -import io.fd.honeycomb.v3po.vpp.facade.VppException; -import io.fd.honeycomb.v3po.vpp.facade.impl.util.VppRWUtils; -import io.fd.honeycomb.v3po.vpp.facade.impl.write.CompositeChildVppWriter; -import io.fd.honeycomb.v3po.vpp.facade.impl.write.CompositeListVppWriter; -import io.fd.honeycomb.v3po.vpp.facade.impl.write.CompositeRootVppWriter; -import io.fd.honeycomb.v3po.vpp.facade.impl.write.util.DelegatingWriterRegistry; -import io.fd.honeycomb.v3po.vpp.facade.impl.write.util.NoopWriterCustomizer; -import io.fd.honeycomb.v3po.vpp.facade.impl.write.util.ReflexiveChildWriterCustomizer; -import io.fd.honeycomb.v3po.vpp.facade.v3po.vpp.BridgeDomainCustomizer; -import io.fd.honeycomb.v3po.vpp.facade.write.ChildVppWriter; -import io.fd.honeycomb.v3po.vpp.facade.write.VppWriter; -import io.fd.honeycomb.v3po.vpp.facade.write.WriteContext; -import io.fd.honeycomb.v3po.vpp.facade.write.WriterRegistry; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -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.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.vppjapi.vppApi; - -// TODO use some DI framework instead of singleton -public class VppWriterRegistry implements WriterRegistry { - - private static VppWriterRegistry instance; - - private final DelegatingWriterRegistry writer; - - private VppWriterRegistry(@Nonnull final vppApi vppApi) { - final CompositeRootVppWriter vppWriter = initVppStateWriter(vppApi); - writer = new DelegatingWriterRegistry(Collections.>singletonList(vppWriter)); - } - - private static CompositeRootVppWriter initVppStateWriter(@Nonnull final vppApi vppApi) { - final CompositeListVppWriter bridgeDomainWriter = new CompositeListVppWriter<>( - BridgeDomain.class, - new BridgeDomainCustomizer(vppApi)); - - final ChildVppWriter bridgeDomainsWriter = new CompositeChildVppWriter<>( - BridgeDomains.class, - VppRWUtils.singletonChildWriterList(bridgeDomainWriter), - new ReflexiveChildWriterCustomizer()); - - final List>> childWriters = new ArrayList<>(); - childWriters.add(bridgeDomainsWriter); - - return new CompositeRootVppWriter<>( - Vpp.class, - childWriters, - new NoopWriterCustomizer()); - } - - public static synchronized VppWriterRegistry getInstance(@Nonnull final vppApi vppApi) { - if (instance == null) { - instance = new VppWriterRegistry(vppApi); - } - return instance; - } - - @Nonnull - @Override - public InstanceIdentifier getManagedDataObjectType() { - return writer.getManagedDataObjectType(); - } - - @Override - public void update(@Nonnull final InstanceIdentifier id, - @Nullable final DataObject dataBefore, - @Nullable final DataObject data, @Nonnull final WriteContext ctx) throws VppException { - writer.update(id, dataBefore, data, ctx); - } - - @Override - public void update(@Nonnull final Map, DataObject> dataBefore, - @Nonnull final Map, DataObject> dataAfter, - @Nonnull final WriteContext ctx) - throws VppException { - writer.update(dataBefore, dataAfter, ctx); - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/WriterRegistry.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/WriterRegistry.java new file mode 100644 index 000000000..00dc22520 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/WriterRegistry.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.data; + +import io.fd.honeycomb.v3po.translate.TranslationException; +import io.fd.honeycomb.v3po.translate.util.RWUtils; +import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter; +import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter; +import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter; +import io.fd.honeycomb.v3po.translate.util.write.DelegatingWriterRegistry; +import io.fd.honeycomb.v3po.translate.util.write.NoopWriterCustomizer; +import io.fd.honeycomb.v3po.translate.util.write.ReflexiveChildWriterCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.vpp.BridgeDomainCustomizer; +import io.fd.honeycomb.v3po.translate.write.ChildWriter; +import io.fd.honeycomb.v3po.translate.write.Writer; +import io.fd.honeycomb.v3po.translate.write.WriteContext; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +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.vpp.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.vppjapi.vppApi; + +// TODO use some DI framework instead of singleton +public class WriterRegistry implements io.fd.honeycomb.v3po.translate.write.WriterRegistry { + + private static WriterRegistry instance; + + private final DelegatingWriterRegistry writer; + + private WriterRegistry(@Nonnull final vppApi vppApi) { + final CompositeRootWriter vppWriter = initVppStateWriter(vppApi); + writer = new DelegatingWriterRegistry(Collections.>singletonList(vppWriter)); + } + + private static CompositeRootWriter initVppStateWriter(@Nonnull final vppApi vppApi) { + final CompositeListWriter bridgeDomainWriter = new CompositeListWriter<>( + BridgeDomain.class, + new BridgeDomainCustomizer(vppApi)); + + final ChildWriter bridgeDomainsWriter = new CompositeChildWriter<>( + BridgeDomains.class, + RWUtils.singletonChildWriterList(bridgeDomainWriter), + new ReflexiveChildWriterCustomizer()); + + final List>> childWriters = new ArrayList<>(); + childWriters.add(bridgeDomainsWriter); + + return new CompositeRootWriter<>( + Vpp.class, + childWriters, + new NoopWriterCustomizer()); + } + + public static synchronized WriterRegistry getInstance(@Nonnull final vppApi vppApi) { + if (instance == null) { + instance = new WriterRegistry(vppApi); + } + return instance; + } + + @Nonnull + @Override + public InstanceIdentifier getManagedDataObjectType() { + return writer.getManagedDataObjectType(); + } + + @Override + public void update(@Nonnull final InstanceIdentifier id, + @Nullable final DataObject dataBefore, + @Nullable final DataObject data, @Nonnull final WriteContext ctx) throws TranslationException { + writer.update(id, dataBefore, data, ctx); + } + + @Override + public void update(@Nonnull final Map, DataObject> dataBefore, + @Nonnull final Map, DataObject> dataAfter, + @Nonnull final WriteContext ctx) + throws TranslationException { + writer.update(dataBefore, dataAfter, ctx); + } +} diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java index 207a64a99..c4315cd38 100644 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java @@ -31,9 +31,8 @@ import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; -import io.fd.honeycomb.v3po.vpp.facade.VppException; -import io.fd.honeycomb.v3po.vpp.facade.write.WriteContext; -import io.fd.honeycomb.v3po.vpp.facade.write.WriterRegistry; +import io.fd.honeycomb.v3po.translate.TranslationException; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -60,7 +59,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; public class VPPConfigDataTreeTest { @Mock - private VppWriterRegistry vppWriter; + private WriterRegistry vppWriter; @Mock private BindingNormalizedNodeSerializer serializer; @Mock @@ -156,11 +155,12 @@ public class VPPConfigDataTreeTest { final DataObject dataBefore = mockDataObject("before", Ethernet.class); final DataObject dataAfter = mockDataObject("after", Ethernet.class); - final WriterRegistry.Reverter reverter = mock(WriterRegistry.Reverter.class); + final io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter reverter = mock( + io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter.class); // Fail on update: - final VppException failedOnUpdateException = new VppException("update failed"); - doThrow(new WriterRegistry.BulkUpdateException(InstanceIdentifier.create(Ethernet.class), reverter, + final TranslationException failedOnUpdateException = new TranslationException("update failed"); + doThrow(new io.fd.honeycomb.v3po.translate.write.WriterRegistry.BulkUpdateException(InstanceIdentifier.create(Ethernet.class), reverter, failedOnUpdateException)).when(vppWriter).update(anyMap(), anyMap(), any(WriteContext.class)); // Prepare modification: @@ -175,7 +175,7 @@ public class VPPConfigDataTreeTest { // Run the test try { proxy.commit(modification); - } catch (WriterRegistry.BulkUpdateException e) { + } catch (io.fd.honeycomb.v3po.translate.write.WriterRegistry.BulkUpdateException e) { verify(vppWriter).update(anyMap(), anyMap(), any(WriteContext.class)); verify(reverter).revert(); assertEquals(failedOnUpdateException, e.getCause()); @@ -191,16 +191,17 @@ public class VPPConfigDataTreeTest { final DataObject dataBefore = mockDataObject("before", Ethernet.class); final DataObject dataAfter = mockDataObject("after", Ethernet.class); - final WriterRegistry.Reverter reverter = mock(WriterRegistry.Reverter.class); + final io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter reverter = mock( + io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter.class); // Fail on update: - doThrow(new WriterRegistry.BulkUpdateException(InstanceIdentifier.create(Ethernet.class), reverter, - new VppException("update failed"))).when(vppWriter).update(anyMap(), anyMap(), any(WriteContext.class)); + doThrow(new io.fd.honeycomb.v3po.translate.write.WriterRegistry.BulkUpdateException(InstanceIdentifier.create(Ethernet.class), reverter, + new TranslationException("update failed"))).when(vppWriter).update(anyMap(), anyMap(), any(WriteContext.class)); // Fail on revert: - final VppException failedOnRevertException = new VppException("update failed"); - final WriterRegistry.Reverter.RevertFailedException revertFailedException = - new WriterRegistry.Reverter.RevertFailedException(Collections.>emptyList(), + final TranslationException failedOnRevertException = new TranslationException("update failed"); + final io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter.RevertFailedException revertFailedException = + new io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter.RevertFailedException(Collections.>emptyList(), failedOnRevertException); doThrow(revertFailedException).when(reverter).revert(); @@ -216,7 +217,7 @@ public class VPPConfigDataTreeTest { // Run the test try { proxy.commit(modification); - } catch (WriterRegistry.Reverter.RevertFailedException e) { + } catch (io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter.RevertFailedException e) { verify(vppWriter).update(anyMap(), anyMap(), any(WriteContext.class)); verify(reverter).revert(); assertEquals(failedOnRevertException, e.getCause()); diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java index 2c50ec92d..51f57a252 100644 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java @@ -26,7 +26,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.util.concurrent.CheckedFuture; -import io.fd.honeycomb.v3po.vpp.facade.read.ReaderRegistry; +import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -45,7 +45,7 @@ public class VppDataBrokerInitializationProviderTest { @Mock private ReaderRegistry readerRegistry; @Mock - private VppWriterRegistry writerRegistry; + private WriterRegistry writerRegistry; private VppDataBrokerInitializationProvider provider; diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java index 09e70941b..049c2a0c8 100644 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java @@ -34,8 +34,8 @@ import com.google.common.collect.Iterables; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; import com.google.common.util.concurrent.CheckedFuture; -import io.fd.honeycomb.v3po.vpp.facade.read.ReadContext; -import io.fd.honeycomb.v3po.vpp.facade.read.ReaderRegistry; +import io.fd.honeycomb.v3po.translate.read.ReadContext; +import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -121,7 +121,7 @@ public class VppOperationalDataTreeTest { @Test public void testReadFailed() throws Exception{ - doThrow(io.fd.honeycomb.v3po.vpp.facade.read.ReadFailedException.class).when(reader).readAll(any(ReadContext.class)); + doThrow(io.fd.honeycomb.v3po.translate.read.ReadFailedException.class).when(reader).readAll(any(ReadContext.class)); final CheckedFuture>, ReadFailedException> future = operationalData.read( YangInstanceIdentifier.EMPTY); @@ -129,7 +129,7 @@ public class VppOperationalDataTreeTest { try { future.checkedGet(); } catch (ReadFailedException e) { - assertTrue(e.getCause() instanceof io.fd.honeycomb.v3po.vpp.facade.read.ReadFailedException); + assertTrue(e.getCause() instanceof io.fd.honeycomb.v3po.translate.read.ReadFailedException); return; } fail("ReadFailedException was expected"); -- cgit 1.2.3-korg