From 757222979bc02d0aaba1870eea36413383d15bde Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Tue, 8 Nov 2016 10:13:36 +0100 Subject: HONEYCOMB-270 Add isPresent() to Readers/Customizers So that they can influence whether empty data is to be considered as present + Move registries implementations from util to impl + Introduce DelegatingReader trait + Extend GenericReader where possible to reduce duplication Change-Id: I5a416acd0c4eab1fbc30fcbe585719991dbe9215 Signed-off-by: Maros Marsalek --- .../translate/util/read/AbstractGenericReader.java | 9 +- .../translate/util/read/BindingBrokerReader.java | 5 + .../translate/util/read/DelegatingReader.java | 103 +++++++++ .../util/read/KeepaliveReaderWrapper.java | 40 +--- .../translate/util/read/ReflexiveReader.java | 57 ----- .../util/read/ReflexiveReaderCustomizer.java | 2 +- .../util/read/registry/CompositeReader.java | 241 --------------------- .../read/registry/CompositeReaderRegistry.java | 131 ----------- .../registry/CompositeReaderRegistryBuilder.java | 114 ---------- .../util/read/registry/InitSubtreeReader.java | 72 ------ .../util/read/registry/SubtreeReader.java | 241 --------------------- .../util/read/registry/TypeHierarchy.java | 101 --------- 12 files changed, 120 insertions(+), 996 deletions(-) create mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/DelegatingReader.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReader.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReader.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistry.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistryBuilder.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/InitSubtreeReader.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java delete mode 100644 infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/TypeHierarchy.java (limited to 'infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read') diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java index 40c78b3c9..b19b72ecf 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java @@ -56,18 +56,15 @@ public abstract class AbstractGenericReader read = built.equals(emptyValue) - ? Optional.absent() - : Optional.of(built); + final Optional read = isPresent(id, built, ctx) + ? Optional.of(built) + : Optional.absent(); LOG.debug("{}: Current node read successfully. Result: {}", this, read); return read; diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/BindingBrokerReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/BindingBrokerReader.java index b7a38e97f..e59e642c4 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/BindingBrokerReader.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/BindingBrokerReader.java @@ -50,6 +50,11 @@ public final class BindingBrokerReader id, final D built, final ReadContext ctx) { + throw new UnsupportedOperationException("Not supported"); + } + @Nonnull @Override public Optional read(@Nonnull final InstanceIdentifier id, diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/DelegatingReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/DelegatingReader.java new file mode 100644 index 000000000..513639610 --- /dev/null +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/DelegatingReader.java @@ -0,0 +1,103 @@ +/* + * 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.translate.util.read; + +import com.google.common.base.Optional; +import io.fd.honeycomb.translate.read.ListReader; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.read.Reader; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * A trait of a delegating reader. Delegates all the calls to its delegate. + */ +public interface DelegatingReader> extends Reader { + + Reader getDelegate(); + + @Nonnull + default Optional read(@Nonnull final InstanceIdentifier id, + @Nonnull final ReadContext ctx) throws ReadFailedException { + return getDelegate().read(id, ctx); + } + + default void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final B builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + getDelegate().readCurrentAttributes(id, builder, ctx); + } + + @Nonnull + default B getBuilder(final InstanceIdentifier id) { + return getDelegate().getBuilder(id); + } + + default void merge(@Nonnull final Builder parentBuilder, + @Nonnull final D readValue) { + getDelegate().merge(parentBuilder, readValue); + } + + @Override + default boolean isPresent(InstanceIdentifier id, D built, final ReadContext ctx) throws ReadFailedException { + return getDelegate().isPresent(id, built, ctx); + } + + @Nonnull + default InstanceIdentifier getManagedDataObjectType() { + return getDelegate().getManagedDataObjectType(); + } + + /** + * ListReader specific delegating trait. + */ + interface DelegatingListReader, K extends Identifier, B extends Builder> + extends DelegatingReader, ListReader { + + ListReader getDelegate(); + + @Override + default List getAllIds(@Nonnull InstanceIdentifier id, @Nonnull ReadContext ctx) + throws ReadFailedException { + return getDelegate().getAllIds(id, ctx); + } + + @Nonnull + @Override + default List readList(@Nonnull final InstanceIdentifier id, @Nonnull final ReadContext ctx) + throws ReadFailedException { + return getDelegate().readList(id, ctx); + } + + @Override + default void merge(@Nonnull final Builder builder, + @Nonnull final List readData) { + getDelegate().merge(builder, readData); + } + + @Override + default void merge(@Nonnull final Builder parentBuilder, @Nonnull final D readValue) { + getDelegate().merge(parentBuilder, readValue); + } + } +} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapper.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapper.java index 5ab9bc59e..9a695a53c 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapper.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapper.java @@ -18,11 +18,10 @@ package io.fd.honeycomb.translate.util.read; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.Reader; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.Reader; import java.io.Closeable; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -40,7 +39,7 @@ import org.slf4j.LoggerFactory; * In case a specific error occurs, Keep-alive failure listener gets notified. */ public final class KeepaliveReaderWrapper> - implements Reader, Runnable, Closeable { + implements DelegatingReader,Runnable, Closeable { private static final Logger LOG = LoggerFactory.getLogger(KeepaliveReaderWrapper.class); @@ -73,34 +72,6 @@ public final class KeepaliveReaderWrapper read(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - return delegate.read(id, ctx); - } - - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final B builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - delegate.readCurrentAttributes(id, builder, ctx); - } - - @Nonnull - public B getBuilder(final InstanceIdentifier id) { - return delegate.getBuilder(id); - } - - public void merge(@Nonnull final Builder parentBuilder, - @Nonnull final D readValue) { - delegate.merge(parentBuilder, readValue); - } - - @Nonnull - @Override - public InstanceIdentifier getManagedDataObjectType() { - return delegate.getManagedDataObjectType(); - } - @Override public void run() { LOG.trace("Invoking keepalive"); @@ -123,6 +94,11 @@ public final class KeepaliveReaderWrapper getDelegate() { + return delegate; + } + /** * Listener that gets called whenever keepalive fails as expected. */ diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReader.java deleted file mode 100644 index 2aa35514e..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReader.java +++ /dev/null @@ -1,57 +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.translate.util.read; - -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Reader that performs no read operation on its own, just fills in the hierarchy. - *

- * Might be slow due to reflection ! - */ -public class ReflexiveReader> extends AbstractGenericReader { - - private final ReflexiveReaderCustomizer customizer; - - public ReflexiveReader(final InstanceIdentifier identifier, final Class builderClass) { - super(identifier); - this.customizer = new ReflexiveReaderCustomizer<>(identifier.getTargetType(), builderClass); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final B builder, - @Nonnull final ReadContext ctx) - throws ReadFailedException { - customizer.readCurrentAttributes(id, builder, ctx); - } - - @Nonnull - @Override - public B getBuilder(final InstanceIdentifier id) { - return customizer.getBuilder(id); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final C readValue) { - customizer.merge(parentBuilder, readValue); - } -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReaderCustomizer.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReaderCustomizer.java index 18e6285f3..087873306 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReaderCustomizer.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveReaderCustomizer.java @@ -33,7 +33,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Might be slow. */ -class ReflexiveReaderCustomizer> extends NoopReaderCustomizer { +public class ReflexiveReaderCustomizer> extends NoopReaderCustomizer { private final Class typeClass; private final Class builderClass; diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReader.java deleted file mode 100644 index b52fd09ec..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReader.java +++ /dev/null @@ -1,241 +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.translate.util.read.registry; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import io.fd.honeycomb.translate.read.InitFailedException; -import io.fd.honeycomb.translate.read.InitListReader; -import io.fd.honeycomb.translate.read.Initializer; -import io.fd.honeycomb.translate.read.ListReader; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.read.Reader; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.AbstractGenericReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.Identifiable; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class CompositeReader> - extends AbstractGenericReader - implements Initializer { - - private static final Logger LOG = LoggerFactory.getLogger(CompositeReader.class); - - private final Reader delegate; - private final ImmutableMap, Reader>> childReaders; - - private CompositeReader(final Reader reader, - final ImmutableMap, Reader>> childReaders) { - super(reader.getManagedDataObjectType()); - this.delegate = reader; - this.childReaders = childReaders; - } - - @VisibleForTesting - ImmutableMap, Reader>> getChildReaders() { - return childReaders; - } - - @SuppressWarnings("unchecked") - public static InstanceIdentifier appendTypeToId( - final InstanceIdentifier parentId, final InstanceIdentifier type) { - final InstanceIdentifier.PathArgument t = new InstanceIdentifier.Item<>(type.getTargetType()); - return (InstanceIdentifier) InstanceIdentifier.create(Iterables.concat( - parentId.getPathArguments(), Collections.singleton(t))); - } - - @Nonnull - @Override - public Optional read(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - if (shouldReadCurrent(id)) { - LOG.trace("{}: Reading current: {}", this, id); - return readCurrent((InstanceIdentifier) id, ctx); - } else if (shouldDelegateToChild(id)) { - LOG.trace("{}: Reading child: {}", this, id); - return readSubtree(id, ctx); - } else { - // Fallback - LOG.trace("{}: Delegating read: {}", this, id); - return delegate.read(id, ctx); - } - } - - private boolean shouldReadCurrent(@Nonnull final InstanceIdentifier id) { - return id.getTargetType().equals(getManagedDataObjectType().getTargetType()); - } - - private boolean shouldDelegateToChild(@Nonnull final InstanceIdentifier id) { - return childReaders.containsKey(RWUtils.getNextId(id, getManagedDataObjectType()).getType()); - } - - private Optional readSubtree(final InstanceIdentifier id, - final ReadContext ctx) throws ReadFailedException { - final InstanceIdentifier.PathArgument nextId = RWUtils.getNextId(id, getManagedDataObjectType()); - final Reader> nextReader = childReaders.get(nextId.getType()); - checkArgument(nextReader != null, "Unable to read: %s. No delegate present, available readers at next level: %s", - id, childReaders.keySet()); - return nextReader.read(id, ctx); - } - - @SuppressWarnings("unchecked") - private void readChildren(final InstanceIdentifier id, @Nonnull final ReadContext ctx, final B builder) - throws ReadFailedException { - LOG.debug("{}: Reading children: {}", this, childReaders.keySet()); - for (Reader child : childReaders.values()) { - final InstanceIdentifier childId = appendTypeToId(id, child.getManagedDataObjectType()); - - LOG.debug("{}: Reading child from: {}", this, child); - if (child instanceof ListReader) { - final List list = ((ListReader) child).readList(childId, ctx); - // Dont set empty lists - if (!list.isEmpty()) { - ((ListReader) child).merge(builder, list); - } - } else { - final Optional read = child.read(childId, ctx); - if (read.isPresent()) { - child.merge(builder, read.get()); - } - } - } - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final B builder, - @Nonnull final ReadContext ctx) - throws ReadFailedException { - delegate.readCurrentAttributes(id, builder, ctx); - readChildren(id, ctx, builder); - } - - @Nonnull - @Override - public B getBuilder(final InstanceIdentifier id) { - return delegate.getBuilder(id); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final D readValue) { - delegate.merge(parentBuilder, readValue); - } - - /** - * Wrap a Reader as a Composite Reader. - */ - static > Reader createForReader( - @Nonnull final Reader reader, - @Nonnull final ImmutableMap, Reader>> childReaders) { - - return (reader instanceof ListReader) - ? new CompositeListReader<>((ListReader) reader, childReaders) - : new CompositeReader<>(reader, childReaders); - } - - @SuppressWarnings("unchecked") - @Override - public void init(final DataBroker broker, final InstanceIdentifier id, final ReadContext ctx) throws InitFailedException { - if (delegate instanceof Initializer) { - LOG.trace("{}: Initializing current: {}", this, id); - ((Initializer) delegate).init(broker, id, ctx); - } - - for (Reader child : childReaders.values()) { - final InstanceIdentifier childId = appendTypeToId(id, child.getManagedDataObjectType()); - - if (child instanceof Initializer) { - LOG.trace("{}: Initializing child: {}", this, childId); - ((Initializer) child).init(broker, childId, ctx); - } - } - } - - private static class CompositeListReader, B extends Builder, K extends Identifier> - extends CompositeReader - implements InitListReader { - - private final ListReader delegate; - - private CompositeListReader(final ListReader reader, - final ImmutableMap, Reader>> childReaders) { - super(reader, childReaders); - this.delegate = reader; - } - - @Nonnull - @Override - public List readList(@Nonnull final InstanceIdentifier id, @Nonnull final ReadContext ctx) - throws ReadFailedException { - LOG.trace("{}: Reading all list entries", this); - final List allIds = delegate.getAllIds(id, ctx); - LOG.debug("{}: Reading list entries for: {}", this, allIds); - - // Override read list in order to perform readCurrent + readChildren here - final ArrayList allEntries = new ArrayList<>(allIds.size()); - for (K key : allIds) { - final InstanceIdentifier.IdentifiableItem currentBdItem = RWUtils.getCurrentIdItem(id, key); - final InstanceIdentifier keyedId = RWUtils.replaceLastInId(id, currentBdItem); - final Optional read = readCurrent(keyedId, ctx); - if (read.isPresent()) { - final DataObject singleItem = read.get(); - checkArgument(getManagedDataObjectType().getTargetType().isAssignableFrom(singleItem.getClass())); - allEntries.add(getManagedDataObjectType().getTargetType().cast(singleItem)); - } - } - return allEntries; - } - - @Override - public void init(final DataBroker broker, final InstanceIdentifier id, final ReadContext ctx) - throws InitFailedException { - try { - final List allIds = delegate.getAllIds(id, ctx); - for (K key : allIds) { - super.init(broker, RWUtils.replaceLastInId(id, RWUtils.getCurrentIdItem(id, key)), ctx); - } - } catch (ReadFailedException e) { - throw new InitFailedException(id, e); - } - } - - @Override - public void merge(@Nonnull final Builder builder, @Nonnull final List readData) { - delegate.merge(builder, readData); - } - - @Override - public List getAllIds(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - return delegate.getAllIds(id, ctx); - } - } -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistry.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistry.java deleted file mode 100644 index 9505a7730..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistry.java +++ /dev/null @@ -1,131 +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.translate.util.read.registry; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import com.google.common.collect.LinkedListMultimap; -import com.google.common.collect.Multimap; -import io.fd.honeycomb.translate.read.InitFailedException; -import io.fd.honeycomb.translate.read.Initializer; -import io.fd.honeycomb.translate.read.ListReader; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.read.Reader; -import io.fd.honeycomb.translate.read.registry.ReaderRegistry; -import io.fd.honeycomb.translate.util.RWUtils; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Simple reader registry able to perform and aggregated read (ROOT read) on top of all provided readers. Also able to - * delegate a specific read to one of the delegate readers. - *

- * This could serve as a utility to hold & hide all available readers in upper layers. - */ -public final class CompositeReaderRegistry implements ReaderRegistry { - - private static final Logger LOG = LoggerFactory.getLogger(CompositeReaderRegistry.class); - - private final Map, Reader>> rootReaders; - - /** - * Create new {@link CompositeReaderRegistry}. - * - * @param rootReaders List of delegate readers - */ - public CompositeReaderRegistry(@Nonnull final List>> rootReaders) { - this.rootReaders = RWUtils.uniqueLinkedIndex(checkNotNull(rootReaders), RWUtils.MANAGER_CLASS_FUNCTION); - } - - @VisibleForTesting - Map, Reader>> getRootReaders() { - return rootReaders; - } - - @Override - @Nonnull - public Multimap, ? extends DataObject> readAll( - @Nonnull final ReadContext ctx) throws ReadFailedException { - - LOG.debug("Reading from all delegates: {}", this); - LOG.trace("Reading from all delegates: {}", rootReaders.values()); - - final Multimap, DataObject> objects = LinkedListMultimap.create(); - for (Reader> rootReader : rootReaders.values()) { - LOG.debug("Reading from delegate: {}", rootReader); - - if (rootReader instanceof ListReader) { - final List listEntries = - ((ListReader) rootReader).readList(rootReader.getManagedDataObjectType(), ctx); - if (!listEntries.isEmpty()) { - objects.putAll(rootReader.getManagedDataObjectType(), listEntries); - } - } else { - final Optional read = rootReader.read(rootReader.getManagedDataObjectType(), ctx); - if (read.isPresent()) { - objects.putAll(rootReader.getManagedDataObjectType(), Collections.singletonList(read.get())); - } - } - } - - return objects; - } - - - @Override - public void initAll(@Nonnull final DataBroker broker, @Nonnull final ReadContext ctx) throws InitFailedException { - for (Reader> rootReader : rootReaders.values()) { - if (rootReader instanceof Initializer) { - ((Initializer) rootReader).init(broker, rootReader.getManagedDataObjectType(), ctx); - } - } - } - - @Nonnull - @Override - public Optional read(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) - throws ReadFailedException { - final InstanceIdentifier.PathArgument first = checkNotNull( - Iterables.getFirst(id.getPathArguments(), null), "Empty id"); - final Reader> reader = rootReaders.get(first.getType()); - checkNotNull(reader, - "Unable to read %s. Missing reader. Current readers for: %s", id, rootReaders.keySet()); - LOG.debug("Reading from delegate: {}", reader); - return reader.read(id, ctx); - } - - @Override - public String toString() { - return getClass().getSimpleName() - + rootReaders.keySet().stream().map(Class::getSimpleName).collect(Collectors.toList()); - } - -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistryBuilder.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistryBuilder.java deleted file mode 100644 index da9bbe934..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/CompositeReaderRegistryBuilder.java +++ /dev/null @@ -1,114 +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.translate.util.read.registry; - -import com.google.common.collect.ImmutableMap; -import io.fd.honeycomb.translate.read.InitReader; -import io.fd.honeycomb.translate.read.Reader; -import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; -import io.fd.honeycomb.translate.read.registry.ReaderRegistry; -import io.fd.honeycomb.translate.read.registry.ReaderRegistryBuilder; -import io.fd.honeycomb.translate.util.AbstractSubtreeManagerRegistryBuilderBuilder; -import io.fd.honeycomb.translate.util.read.ReflexiveReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.NotThreadSafe; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@NotThreadSafe -public final class CompositeReaderRegistryBuilder - extends AbstractSubtreeManagerRegistryBuilderBuilder>, ReaderRegistry> - implements ModifiableReaderRegistryBuilder, ReaderRegistryBuilder { - - private static final Logger LOG = LoggerFactory.getLogger(CompositeReaderRegistryBuilder.class); - - @Override - protected Reader> getSubtreeHandler(@Nonnull final Set> handledChildren, - @Nonnull final Reader> reader) { - return reader instanceof InitReader - ? InitSubtreeReader.createForReader(handledChildren, reader) - : SubtreeReader.createForReader(handledChildren, reader); - } - - @Override - public void addStructuralReader(@Nonnull InstanceIdentifier id, - @Nonnull Class> builderType) { - add(new ReflexiveReader<>(id, builderType)); - } - - - - /** - * Create {@link CompositeReaderRegistry} with Readers ordered according to submitted relationships. - *

- * Note: The ordering only applies between nodes on the same level, inter-level and inter-subtree relationships are - * ignored. - */ - @Override - public ReaderRegistry build() { - ImmutableMap, Reader>> mappedReaders = - getMappedHandlers(); - LOG.debug("Building Reader registry with Readers: {}", - mappedReaders.keySet().stream() - .map(InstanceIdentifier::getTargetType) - .map(Class::getSimpleName) - .collect(Collectors.joining(", "))); - - LOG.trace("Building Reader registry with Readers: {}", mappedReaders); - final List> readerOrder = new ArrayList<>(mappedReaders.keySet()); - - // Wrap readers into composite readers recursively, collect roots and create registry - final TypeHierarchy typeHierarchy = TypeHierarchy.create(mappedReaders.keySet()); - final List>> orderedRootReaders = - typeHierarchy.getRoots().stream() - .map(rootId -> toCompositeReader(rootId, mappedReaders, typeHierarchy)) - .collect(Collectors.toList()); - - // We are violating the ordering from mappedReaders, since we are forming a composite structure - // but at least order root writers - orderedRootReaders.sort((reader1, reader2) -> readerOrder.indexOf(reader1.getManagedDataObjectType()) - - readerOrder.indexOf(reader2.getManagedDataObjectType())); - - return new CompositeReaderRegistry(orderedRootReaders); - } - - private Reader> toCompositeReader( - final InstanceIdentifier instanceIdentifier, - final ImmutableMap, Reader>> mappedReaders, - final TypeHierarchy typeHierarchy) { - - // Order child readers according to the mappedReadersCollection - final ImmutableMap.Builder, Reader>> childReadersMapB = ImmutableMap.builder(); - for (InstanceIdentifier childId : mappedReaders.keySet()) { - if (typeHierarchy.getDirectChildren(instanceIdentifier).contains(childId)) { - childReadersMapB.put(childId.getTargetType(), toCompositeReader(childId, mappedReaders, typeHierarchy)); - } - } - - final ImmutableMap, Reader>> childReadersMap = childReadersMapB.build(); - return childReadersMap.isEmpty() - ? mappedReaders.get(instanceIdentifier) - : CompositeReader.createForReader(mappedReaders.get(instanceIdentifier), childReadersMap); - } -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/InitSubtreeReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/InitSubtreeReader.java deleted file mode 100644 index 4edc38f9d..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/InitSubtreeReader.java +++ /dev/null @@ -1,72 +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.translate.util.read.registry; - -import io.fd.honeycomb.translate.read.InitFailedException; -import io.fd.honeycomb.translate.read.InitListReader; -import io.fd.honeycomb.translate.read.InitReader; -import io.fd.honeycomb.translate.read.ListReader; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.Reader; -import java.util.Set; -import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.Identifiable; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -class InitSubtreeReader> - extends SubtreeReader - implements InitReader { - - private InitSubtreeReader(final InitReader delegate, - final Set> handledTypes) { - super(delegate, handledTypes); - } - - @Override - public void init(final DataBroker broker, final InstanceIdentifier id, final ReadContext ctx) throws InitFailedException { - ((InitReader) delegate).init(broker, id, ctx); - } - - /** - * Wrap a Reader as an initializing subtree Reader. - */ - static > Reader createForReader(@Nonnull final Set> handledChildren, - @Nonnull final Reader reader) { - return (reader instanceof ListReader) - ? new InitSubtreeListReader<>((InitListReader) reader, handledChildren) - : new InitSubtreeReader<>(((InitReader) reader), handledChildren); - } - - private static class InitSubtreeListReader, B extends Builder, K extends Identifier> - extends SubtreeListReader - implements InitListReader { - - InitSubtreeListReader(final InitListReader delegate, - final Set> handledTypes) { - super(delegate, handledTypes); - } - - @Override - public void init(final DataBroker broker, final InstanceIdentifier id, final ReadContext ctx) throws InitFailedException { - ((InitListReader) delegate).init(broker, id, ctx); - } - } -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java deleted file mode 100644 index 3bc76b19a..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java +++ /dev/null @@ -1,241 +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.translate.util.read.registry; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import io.fd.honeycomb.translate.read.ListReader; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.read.Reader; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.ReflectionUtils; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.Identifiable; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Simple Reader delegate for subtree Readers (Readers handling also children nodes) providing a list of all the - * children nodes being handled. - */ -class SubtreeReader> implements Reader { - - private static final Logger LOG = LoggerFactory.getLogger(SubtreeReader.class); - - protected final Reader delegate; - private final Set> handledChildTypes = new HashSet<>(); - - SubtreeReader(final Reader delegate, Set> handledTypes) { - this.delegate = delegate; - for (InstanceIdentifier handledType : handledTypes) { - // Iid has to start with Reader's handled root type - checkArgument(delegate.getManagedDataObjectType().getTargetType().equals( - handledType.getPathArguments().iterator().next().getType()), - "Handled node from subtree has to be identified by an instance identifier starting from: %s." - + "Instance identifier was: %s", getManagedDataObjectType().getTargetType(), handledType); - checkArgument(Iterables.size(handledType.getPathArguments()) > 1, - "Handled node from subtree identifier too short: %s", handledType); - handledChildTypes.add(InstanceIdentifier.create(Iterables.concat( - getManagedDataObjectType().getPathArguments(), Iterables.skip(handledType.getPathArguments(), 1)))); - } - } - - /** - * Return set of types also handled by this Reader. All of the types are children of the type managed by this Reader - * excluding the type of this Reader. - */ - Set> getHandledChildTypes() { - return handledChildTypes; - } - - @Override - @Nonnull - public Optional read( - @Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - final InstanceIdentifier wildcarded = RWUtils.makeIidWildcarded(id); - - // Reading entire subtree and filtering if is current reader responsible - if (getHandledChildTypes().contains(wildcarded)) { - LOG.debug("{}: Subtree node managed by this writer requested: {}. Reading current and filtering", this, id); - // If there's no dedicated reader, use read current - final InstanceIdentifier currentId = RWUtils.cutId(id, getManagedDataObjectType()); - final Optional current = delegate.read(currentId, ctx); - // then perform post-reading filtering (return only requested sub-node) - final Optional readSubtree = current.isPresent() - ? filterSubtree(current.get(), id, getManagedDataObjectType().getTargetType()) - : current; - - LOG.debug("{}: Subtree: {} read successfully. Result: {}", this, id, readSubtree); - return readSubtree; - - // If child that's handled here is not requested, then delegate should be able to handle the read - } else { - return delegate.read(id, ctx); - } - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final B builder, - @Nonnull final ReadContext ctx) - throws ReadFailedException { - delegate.readCurrentAttributes(id, builder, ctx); - } - - @Nonnull - @Override - public B getBuilder(final InstanceIdentifier id) { - return delegate.getBuilder(id); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final D readValue) { - delegate.merge(parentBuilder, readValue); - } - - @Nonnull - private static Optional filterSubtree(@Nonnull final DataObject parent, - @Nonnull final InstanceIdentifier absolutPath, - @Nonnull final Class managedType) { - final InstanceIdentifier.PathArgument nextId = - RWUtils.getNextId(absolutPath, InstanceIdentifier.create(parent.getClass())); - - final Optional nextParent = findNextParent(parent, nextId, managedType); - - if (Iterables.getLast(absolutPath.getPathArguments()).equals(nextId)) { - return nextParent; // we found the dataObject identified by absolutePath - } else if (nextParent.isPresent()) { - return filterSubtree(nextParent.get(), absolutPath, nextId.getType()); - } else { - return nextParent; // we can't go further, return Optional.absent() - } - } - - private static Optional findNextParent(@Nonnull final DataObject parent, - @Nonnull final InstanceIdentifier.PathArgument nextId, - @Nonnull final Class managedType) { - Optional method = ReflectionUtils.findMethodReflex(managedType, "get", - Collections.emptyList(), nextId.getType()); - - if (method.isPresent()) { - return Optional.fromNullable(filterSingle(parent, nextId, method.get())); - } else { - // List child nodes - method = ReflectionUtils.findMethodReflex(managedType, - "get" + nextId.getType().getSimpleName(), Collections.emptyList(), List.class); - - if (method.isPresent()) { - return filterList(parent, nextId, method.get()); - } else { - throw new IllegalStateException( - "Unable to filter " + nextId + " from " + parent + " getters not found using reflexion"); - } - } - } - - @SuppressWarnings("unchecked") - private static Optional filterList(final DataObject parent, - final InstanceIdentifier.PathArgument nextId, - final Method method) { - final List invoke = (List) invoke(method, nextId, parent); - - checkArgument(nextId instanceof InstanceIdentifier.IdentifiableItem, - "Unable to perform wildcarded read for %s", nextId); - final Identifier key = ((InstanceIdentifier.IdentifiableItem) nextId).getKey(); - - final Method keyGetter = ReflectionUtils.findMethodReflex(nextId.getType(), "get", - Collections.emptyList(), key.getClass()).get(); - - return Optional.fromNullable(invoke.stream() - .filter(item -> key.equals(invoke(keyGetter, nextId, item))) - .findFirst().orElse(null)); - } - - private static DataObject filterSingle(final DataObject parent, - final InstanceIdentifier.PathArgument nextId, final Method method) { - return nextId.getType().cast(invoke(method, nextId, parent)); - } - - private static Object invoke(final Method method, - final InstanceIdentifier.PathArgument nextId, final DataObject parent) { - try { - return method.invoke(parent); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new IllegalArgumentException("Unable to get " + nextId + " from " + parent, e); - } - } - - @Override - @Nonnull - public InstanceIdentifier getManagedDataObjectType() { - return delegate.getManagedDataObjectType(); - } - - /** - * Wrap a Reader as a subtree Reader. - */ - static > Reader createForReader(@Nonnull final Set> handledChildren, - @Nonnull final Reader reader) { - return (reader instanceof ListReader) - ? new SubtreeListReader<>((ListReader) reader, handledChildren) - : new SubtreeReader<>(reader, handledChildren); - } - - static class SubtreeListReader, B extends Builder, K extends Identifier> - extends SubtreeReader implements ListReader { - - final ListReader delegate; - - SubtreeListReader(final ListReader delegate, - final Set> handledTypes) { - super(delegate, handledTypes); - this.delegate = delegate; - } - - @Nonnull - @Override - public List readList(@Nonnull final InstanceIdentifier id, @Nonnull final ReadContext ctx) - throws ReadFailedException { - return delegate.readList(id, ctx); - } - - @Override - public void merge(@Nonnull final Builder builder, @Nonnull final List readData) { - delegate.merge(builder, readData); - } - - @Override - public List getAllIds(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - return delegate.getAllIds(id, ctx); - } - } - -} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/TypeHierarchy.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/TypeHierarchy.java deleted file mode 100644 index a30663221..000000000 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/TypeHierarchy.java +++ /dev/null @@ -1,101 +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.translate.util.read.registry; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.collect.Iterables; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.jgrapht.experimental.dag.DirectedAcyclicGraph; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -final class TypeHierarchy { - private final DirectedAcyclicGraph, Parent> hierarchy; - - private TypeHierarchy(@Nonnull final DirectedAcyclicGraph, Parent> hierarchy) { - this.hierarchy = hierarchy; - } - - Set> getAllChildren(InstanceIdentifier id) { - final HashSet> instanceIdentifiers = new HashSet<>(); - for (InstanceIdentifier childId : getDirectChildren(id)) { - instanceIdentifiers.add(childId); - instanceIdentifiers.addAll(getAllChildren(childId)); - } - return instanceIdentifiers; - } - - Set> getDirectChildren(InstanceIdentifier id) { - checkArgument(hierarchy.vertexSet().contains(id), - "Unknown reader: %s. Known readers: %s", id, hierarchy.vertexSet()); - - return hierarchy.outgoingEdgesOf(id).stream() - .map(hierarchy::getEdgeTarget) - .collect(Collectors.toSet()); - } - - Set> getRoots() { - return hierarchy.vertexSet().stream() - .filter(vertex -> hierarchy.incomingEdgesOf(vertex).size() == 0) - .collect(Collectors.toSet()); - } - - /** - * Create reader hierarchy from a flat set of instance identifiers. - * - * @param allIds Set of unkeyed instance identifiers - */ - static TypeHierarchy create(@Nonnull Set> allIds) { - final DirectedAcyclicGraph, Parent> - readersHierarchy = new DirectedAcyclicGraph<>((sourceVertex, targetVertex) -> new Parent()); - - for (InstanceIdentifier allId : allIds) { - checkArgument(!Iterables.isEmpty(allId.getPathArguments()), "Empty ID detected"); - - if (Iterables.size(allId.getPathArguments()) == 1) { - readersHierarchy.addVertex(allId); - } - - List pathArgs = new LinkedList<>(); - pathArgs.add(allId.getPathArguments().iterator().next()); - - for (InstanceIdentifier.PathArgument pathArgument : Iterables.skip(allId.getPathArguments(), 1)) { - final InstanceIdentifier previous = InstanceIdentifier.create(pathArgs); - pathArgs.add(pathArgument); - final InstanceIdentifier current = InstanceIdentifier.create(pathArgs); - - readersHierarchy.addVertex(previous); - readersHierarchy.addVertex(current); - - try { - readersHierarchy.addDagEdge(previous, current); - } catch (DirectedAcyclicGraph.CycleFoundException e) { - throw new IllegalArgumentException("Loop in hierarchy detected", e); - } - } - } - - return new TypeHierarchy(readersHierarchy); - } - - private static final class Parent{} -} -- cgit 1.2.3-korg