diff options
Diffstat (limited to 'infra/translate-utils/src')
21 files changed, 221 insertions, 152 deletions
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java index 71bcd9def..2bd2de1ec 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java @@ -101,7 +101,7 @@ public final class RWUtils { @Nonnull public static <D extends DataObject & Identifiable<K>, K extends Identifier<D>> InstanceIdentifier.IdentifiableItem<D, K> getCurrentIdItem( @Nonnull final InstanceIdentifier<D> id, final K key) { - return new InstanceIdentifier.IdentifiableItem<>(id.getTargetType(), key); + return InstanceIdentifier.IdentifiableItem.of(id.getTargetType(), key); } /** @@ -160,7 +160,7 @@ public final class RWUtils { */ @SuppressWarnings("unchecked") public static <D extends DataObject> InstanceIdentifier<D> makeIidLastWildcarded(final InstanceIdentifier<D> id) { - final InstanceIdentifier.Item<D> wildcardedItem = new InstanceIdentifier.Item<>(id.getTargetType()); + final InstanceIdentifier.Item<D> wildcardedItem = InstanceIdentifier.Item.of(id.getTargetType()); final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); return (InstanceIdentifier<D>) InstanceIdentifier.create( Iterables.concat( @@ -170,7 +170,7 @@ public final class RWUtils { private static InstanceIdentifier.PathArgument cleanPathArgumentFromKeys(final InstanceIdentifier.PathArgument pathArgument) { return pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?> - ? new InstanceIdentifier.Item<>(pathArgument.getType()) + ? InstanceIdentifier.Item.of(pathArgument.getType()) : pathArgument; } } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RealtimeMappingContext.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RealtimeMappingContext.java index f10d312f1..09dba79da 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RealtimeMappingContext.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RealtimeMappingContext.java @@ -16,15 +16,14 @@ package io.fd.honeycomb.translate.util; -import com.google.common.base.Optional; import io.fd.honeycomb.translate.MappingContext; +import java.util.Optional; +import java.util.concurrent.ExecutionException; import javax.annotation.Nonnull; -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.ReadFailedException; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -38,10 +37,10 @@ public final class RealtimeMappingContext implements MappingContext { @Override public <T extends DataObject> Optional<T> read(@Nonnull final InstanceIdentifier<T> currentId) { - try (ReadOnlyTransaction tx = contextBindingBrokerDependency.newReadOnlyTransaction()) { + try (ReadTransaction tx = contextBindingBrokerDependency.newReadOnlyTransaction()) { try { - return tx.read(LogicalDatastoreType.OPERATIONAL, currentId).checkedGet(); - } catch (ReadFailedException e) { + return tx.read(LogicalDatastoreType.OPERATIONAL, currentId).get(); + } catch (InterruptedException | ExecutionException e) { throw new IllegalStateException("Unable to perform read of " + currentId, e); } } @@ -52,8 +51,8 @@ public final class RealtimeMappingContext implements MappingContext { final WriteTransaction writeTx = contextBindingBrokerDependency.newWriteOnlyTransaction(); writeTx.delete(LogicalDatastoreType.OPERATIONAL, path); try { - writeTx.submit().checkedGet(); - } catch (TransactionCommitFailedException e) { + writeTx.commit().get(); + } catch (InterruptedException | ExecutionException e) { throw new IllegalStateException("Unable to perform delete of " + path, e); } } @@ -61,10 +60,10 @@ public final class RealtimeMappingContext implements MappingContext { @Override public <T extends DataObject> void merge(final InstanceIdentifier<T> path, final T data) { final WriteTransaction writeTx = contextBindingBrokerDependency.newWriteOnlyTransaction(); - writeTx.merge(LogicalDatastoreType.OPERATIONAL, path, data, true); + writeTx.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path, data); try { - writeTx.submit().checkedGet(); - } catch (TransactionCommitFailedException e) { + writeTx.commit().get(); + } catch (InterruptedException | ExecutionException e) { throw new IllegalStateException("Unable to perform merge of " + path, e); } } @@ -72,10 +71,10 @@ public final class RealtimeMappingContext implements MappingContext { @Override public <T extends DataObject> void put(final InstanceIdentifier<T> path, final T data) { final WriteTransaction writeTx = contextBindingBrokerDependency.newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.OPERATIONAL, path, data, true); + writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, path, data); try { - writeTx.submit().checkedGet(); - } catch (TransactionCommitFailedException e) { + writeTx.commit().get(); + } catch (InterruptedException | ExecutionException e) { throw new IllegalStateException("Unable to perform put of " + path, e); } } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/ReflectionUtils.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/ReflectionUtils.java index 74c7be97c..7e1099ab7 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/ReflectionUtils.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/ReflectionUtils.java @@ -16,9 +16,9 @@ package io.fd.honeycomb.translate.util; -import com.google.common.base.Optional; import java.lang.reflect.Method; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; /** @@ -36,7 +36,7 @@ public final class ReflectionUtils { * @param paramTypes List of input argument types * @param retType Return type * - * @return Found method or Optional.absent() if there's no such method + * @return Found method or Optional.empty() if there's no such method */ @Nonnull public static Optional<Method> findMethodReflex(@Nonnull final Class<?> managedType, @@ -49,7 +49,7 @@ public final class ReflectionUtils { } } - return Optional.absent(); + return Optional.empty(); } private static boolean isMethodMatch(final @Nonnull String prefix, diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java index 4d4e9fddd..33753bbca 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java @@ -16,14 +16,14 @@ package io.fd.honeycomb.translate.util; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import io.fd.honeycomb.translate.MappingContext; +import java.util.Optional; +import java.util.concurrent.ExecutionException; import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.mdsal.binding.api.ReadWriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -43,9 +43,9 @@ public class TransactionMappingContext implements MappingContext { @Override public <T extends DataObject> Optional<T> read(@Nonnull final InstanceIdentifier<T> currentId) { try { - return readWriteTransaction.read(LogicalDatastoreType.OPERATIONAL, currentId).checkedGet(); - } catch (ReadFailedException e) { - throw new IllegalStateException("Unable to perform read", e); + return readWriteTransaction.read(LogicalDatastoreType.OPERATIONAL, currentId).get(); + } catch (InterruptedException | ExecutionException ex) { + throw new IllegalStateException("Unable to perform read", ex); } } @@ -64,8 +64,8 @@ public class TransactionMappingContext implements MappingContext { readWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, path, data, true); } - public CheckedFuture<Void, TransactionCommitFailedException> submit() { - return readWriteTransaction.submit(); + public FluentFuture<? extends CommitInfo> commit() { + return readWriteTransaction.commit(); } @Override 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 b19b72ecf..897174e1f 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 @@ -19,11 +19,11 @@ package io.fd.honeycomb.translate.util.read; import static com.google.common.base.Preconditions.checkArgument; import com.google.common.annotations.Beta; -import com.google.common.base.Optional; 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.read.ReadFailedException; +import java.util.Optional; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -64,7 +64,7 @@ public abstract class AbstractGenericReader<D extends DataObject, B extends Buil final D built = builder.build(); final Optional<D> read = isPresent(id, built, ctx) ? Optional.of(built) - : Optional.absent(); + : Optional.empty(); 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 e59e642c4..843175878 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 @@ -16,15 +16,16 @@ package io.fd.honeycomb.translate.util.read; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.Reader; import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.read.Reader; +import java.util.Optional; +import java.util.concurrent.ExecutionException; import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -59,13 +60,13 @@ public final class BindingBrokerReader<D extends DataObject, B extends Builder<D @Override public Optional<? extends DataObject> read(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final ReadContext ctx) throws ReadFailedException { - try (final ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction()) { - final CheckedFuture<? extends Optional<? extends DataObject>, org.opendaylight.controller.md.sal.common.api.data.ReadFailedException> + try (final ReadTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction()) { + final FluentFuture<? extends Optional<? extends DataObject>> read = readOnlyTransaction.read(datastoreType, id); try { - return read.checkedGet(); - } catch (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException e) { - throw new ReadFailedException(id, e); + return read.get(); + } catch (InterruptedException | ExecutionException ex) { + throw new ReadFailedException(id, ex); } } } 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 index 5e2e7062e..8d3eb4cbc 100644 --- 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 @@ -16,12 +16,12 @@ 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 java.util.Optional; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; 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 b4d8be495..249fca642 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 @@ -16,13 +16,13 @@ package io.fd.honeycomb.translate.util.read; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.Reader; import java.io.Closeable; +import java.util.Optional; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -110,7 +110,7 @@ public final class KeepaliveReaderWrapper<D extends DataObject, B extends Builde private static final class NoopMappingContext implements MappingContext { @Override public <T extends DataObject> Optional<T> read(@Nonnull final InstanceIdentifier<T> currentId) { - return Optional.absent(); + return Optional.empty(); } @Override diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java index daf6f3566..7ad04399f 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java @@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -import com.google.common.base.Optional; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; @@ -29,6 +28,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collections; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; 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 087873306..a70ccef53 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 @@ -18,12 +18,12 @@ package io.fd.honeycomb.translate.util.read; import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.base.Optional; import com.google.common.collect.Lists; import io.fd.honeycomb.translate.util.ReflectionUtils; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collections; +import java.util.Optional; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.Augmentation; diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java index a0856793d..a9e958240 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java @@ -20,10 +20,10 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.nonNull; -import com.google.common.base.Optional; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.util.read.cache.noop.NoopDumpPostProcessingFunction; +import java.util.Optional; import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; @@ -59,7 +59,7 @@ public final class DumpCacheManager<T, U> { * @param cache modification cache of current transaction * @throws ReadFailedException if execution of dumping request failed * @returns If present in cache ,returns cached instance, if not, tries to dump data using provided executor, - * otherwise Optional.absent() + * otherwise Optional.empty() */ public Optional<T> getDump(@Nonnull final InstanceIdentifier<?> identifier, @Nonnull final ModificationCache cache) @@ -75,7 +75,7 @@ public final class DumpCacheManager<T, U> { * @param dumpParams parameters to configure dump request * @throws ReadFailedException if execution of dumping request failed * @returns If present in cache ,returns cached instance, if not, tries to dump data using provided executor, - * otherwise Optional.absent() + * otherwise Optional.empty() */ public Optional<T> getDump(@Nonnull final InstanceIdentifier<?> identifier, @Nonnull final ModificationCache cache, final U dumpParams) diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java index 60a81a77a..22e30bd9e 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java @@ -16,20 +16,20 @@ package io.fd.honeycomb.translate.util.write; -import com.google.common.util.concurrent.CheckedFuture; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; + +import com.google.common.util.concurrent.FluentFuture; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.translate.write.Writer; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - +import java.util.concurrent.ExecutionException; import javax.annotation.Nonnull; import javax.annotation.Nullable; - -import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Simple DataBroker backed writer allowing to delegate writes to different brokers. @@ -55,11 +55,11 @@ public final class BindingBrokerWriter<D extends DataObject> implements Writer<D @Nonnull final WriteContext ctx) throws WriteFailedException { final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); writeTransaction.put(CONFIGURATION, (InstanceIdentifier<DataObject>) id, dataAfter); - final CheckedFuture<Void, TransactionCommitFailedException> result = writeTransaction.submit(); + final FluentFuture<? extends CommitInfo> result = writeTransaction.commit(); try { - result.checkedGet(); - } catch (TransactionCommitFailedException e) { - throw new WriteFailedException(id, e); + result.get(); + } catch (InterruptedException | ExecutionException ex) { + throw new WriteFailedException(id, ex); } } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/LegacyBindingBrokerWriter.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/LegacyBindingBrokerWriter.java new file mode 100644 index 000000000..f6c2f0ffa --- /dev/null +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/LegacyBindingBrokerWriter.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2019 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.write; + +import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; + +import com.google.common.util.concurrent.FluentFuture; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.translate.write.Writer; +import java.util.concurrent.ExecutionException; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Simple DataBroker backed writer allowing to delegate writes to different brokers. + */ +public final class LegacyBindingBrokerWriter<D extends DataObject> implements Writer<D> { + private final InstanceIdentifier<D> instanceIdentifier; + private final DataBroker dataBroker; + + public LegacyBindingBrokerWriter(final InstanceIdentifier<D> instanceIdentifier, final DataBroker dataBroker) { + this.instanceIdentifier = instanceIdentifier; + this.dataBroker = dataBroker; + } + + @Nonnull + @Override + public InstanceIdentifier<D> getManagedDataObjectType() { + return instanceIdentifier; + } + + @Override + public void processModification(@Nonnull final InstanceIdentifier<? extends DataObject> id, + @Nullable final DataObject dataBefore, @Nullable final DataObject dataAfter, + @Nonnull final WriteContext ctx) throws WriteFailedException { + final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + writeTransaction.put(CONFIGURATION, (InstanceIdentifier<DataObject>) id, dataAfter); + final FluentFuture<? extends CommitInfo> result = writeTransaction.commit(); + try { + result.get(); + } catch (InterruptedException | ExecutionException ex) { + throw new WriteFailedException(id, ex); + } + } + + @Override + public boolean supportsDirectUpdate() { + return false; + } +} diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java index e853d8632..d97b5b715 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java @@ -18,17 +18,17 @@ package io.fd.honeycomb.translate.util.write; import static com.google.common.base.Preconditions.checkState; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.write.WriteContext; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutionException; import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -39,15 +39,15 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; */ public final class TransactionWriteContext implements WriteContext { - private final DOMDataReadOnlyTransaction beforeTx; - private final DOMDataReadOnlyTransaction afterTx; + private final DOMDataTreeReadTransaction beforeTx; + private final DOMDataTreeReadTransaction afterTx; private final ModificationCache ctx; private final BindingNormalizedNodeSerializer serializer; private final MappingContext mappingContext; public TransactionWriteContext(final BindingNormalizedNodeSerializer serializer, - final DOMDataReadOnlyTransaction beforeTx, - final DOMDataReadOnlyTransaction afterTx, + final DOMDataTreeReadTransaction beforeTx, + final DOMDataTreeReadTransaction afterTx, final MappingContext mappingContext) { this.serializer = serializer; this.beforeTx = beforeTx; @@ -70,18 +70,17 @@ public final class TransactionWriteContext implements WriteContext { private <T extends DataObject> Optional<T> read(final InstanceIdentifier<T> currentId, - final DOMDataReadOnlyTransaction tx) { + final DOMDataTreeReadTransaction tx) { final YangInstanceIdentifier path = serializer.toYangInstanceIdentifier(currentId); - final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = - tx.read(LogicalDatastoreType.CONFIGURATION, path); + final FluentFuture<Optional<NormalizedNode<?, ?>>> read = tx.read(LogicalDatastoreType.CONFIGURATION, path); try { // TODO HONEYCOMB-169 once the APIs are asynchronous use just Futures.transform - final Optional<NormalizedNode<?, ?>> optional = read.checkedGet(); + final Optional<NormalizedNode<?, ?>> optional = read.get(); if (!optional.isPresent()) { - return Optional.absent(); + return Optional.empty(); } final NormalizedNode<?, ?> data = optional.get(); @@ -91,7 +90,7 @@ public final class TransactionWriteContext implements WriteContext { checkState(targetType.isAssignableFrom(entry.getValue().getClass()), "Unexpected data object type, should be: %s, but was: %s", targetType, entry.getValue().getClass()); return Optional.of(targetType.cast(entry.getValue())); - } catch (ReadFailedException e) { + } catch (InterruptedException | ExecutionException e) { throw new IllegalStateException("Unable to perform read", e); } } diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java index cbf509827..f74a0a41a 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java @@ -27,20 +27,20 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.util.DataObjects; import io.fd.honeycomb.translate.util.write.TransactionWriteContext; import java.util.Map; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.ReadFailedException; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction; +import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -51,9 +51,9 @@ public class TransactionWriteContextTest { @Mock private BindingNormalizedNodeSerializer serializer; @Mock - private DOMDataReadOnlyTransaction beforeTx; + private DOMDataTreeReadTransaction beforeTx; @Mock - private DOMDataReadOnlyTransaction afterTx; + private DOMDataTreeReadTransaction afterTx; @Mock private Map.Entry entry; @Mock @@ -73,7 +73,7 @@ public class TransactionWriteContextTest { @Test public void testReadBeforeNoData() throws Exception { when(beforeTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn( - Futures.immediateCheckedFuture(Optional.absent())); + FluentFutures.immediateFluentFuture(Optional.empty())); final InstanceIdentifier<DataObjects.DataObject1> instanceId = InstanceIdentifier.create(DataObjects.DataObject1.class); @@ -89,7 +89,7 @@ public class TransactionWriteContextTest { @Test public void testReadBefore() throws Exception { when(beforeTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn( - Futures.immediateCheckedFuture(Optional.of(mock(NormalizedNode.class)))); + FluentFutures.immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))); final InstanceIdentifier<DataObjects.DataObject1> instanceId = InstanceIdentifier.create(DataObjects.DataObject1.class); @@ -107,14 +107,14 @@ public class TransactionWriteContextTest { @Test(expected = IllegalStateException.class) public void testReadBeforeFailed() throws Exception { when(beforeTx.read(LogicalDatastoreType.CONFIGURATION, yangId)).thenReturn( - Futures.immediateFailedCheckedFuture(mock(ReadFailedException.class))); + FluentFutures.immediateFailedFluentFuture(mock(ReadFailedException.class))); transactionWriteContext.readBefore(mock(InstanceIdentifier.class)); } @Test(expected = IllegalStateException.class) public void testReadAfterFailed() throws Exception { when(afterTx.read(LogicalDatastoreType.CONFIGURATION, yangId)).thenReturn( - Futures.immediateFailedCheckedFuture(mock(ReadFailedException.class))); + FluentFutures.immediateFailedFluentFuture(mock(ReadFailedException.class))); transactionWriteContext.readAfter(mock(InstanceIdentifier.class)); } diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/RealtimeMappingContextTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/RealtimeMappingContextTest.java index d6da2f368..d922d1454 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/RealtimeMappingContextTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/RealtimeMappingContextTest.java @@ -21,19 +21,18 @@ import static org.junit.Assert.assertSame; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.FluentFuture; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -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.ReadFailedException; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; +import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -44,7 +43,7 @@ public class RealtimeMappingContextTest { private RealtimeMappingContext ctx; private InstanceIdentifier<DataObject> id = InstanceIdentifier.create(DataObject.class); @Mock - private ReadOnlyTransaction readTx; + private ReadTransaction readTx; @Mock private WriteTransaction writeTx; @Mock @@ -58,59 +57,60 @@ public class RealtimeMappingContextTest { when(broker.newReadOnlyTransaction()).thenReturn(readTx); when(broker.newWriteOnlyTransaction()).thenReturn(writeTx); - when(writeTx.submit()).thenReturn(Futures.immediateCheckedFuture(null)); + when(writeTx.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); } @Test - public void testRead() throws Exception { - final CheckedFuture<Optional<DataObject>, ReadFailedException> futureData = - Futures.immediateCheckedFuture(Optional.of((data))); + public void testRead() { + final FluentFuture<Optional<DataObject>> futureData = + FluentFutures.immediateFluentFuture(Optional.of((data))); when(readTx.read(LogicalDatastoreType.OPERATIONAL, id)).thenReturn(futureData); assertSame(ctx.read(id).get(), data); verify(broker).newReadOnlyTransaction(); verify(readTx).read(LogicalDatastoreType.OPERATIONAL, id); - when(readTx.read(LogicalDatastoreType.OPERATIONAL, id)).thenReturn(Futures.immediateCheckedFuture(Optional.absent())); + when(readTx.read(LogicalDatastoreType.OPERATIONAL, id)) + .thenReturn(FluentFutures.immediateFluentFuture(Optional.empty())); assertFalse(ctx.read(id).isPresent()); } @Test - public void testMerge() throws Exception { + public void testMerge() { ctx.merge(id, data); verify(broker).newWriteOnlyTransaction(); - verify(writeTx).merge(LogicalDatastoreType.OPERATIONAL, id, data, true); + verify(writeTx).mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, id, data); } @Test(expected = IllegalStateException.class) public void testMergeFailure() throws Exception { - when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(ex)); + when(writeTx.commit()).thenReturn(FluentFutures.immediateFailedFluentFuture(ex)); ctx.merge(id, data); } @Test - public void testPut() throws Exception { + public void testPut() { ctx.put(id, data); verify(broker).newWriteOnlyTransaction(); - verify(writeTx).put(LogicalDatastoreType.OPERATIONAL, id, data, true); + verify(writeTx).mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, id, data); } @Test(expected = IllegalStateException.class) - public void testPutFailure() throws Exception { - when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(ex)); + public void testPutFailure() { + when(writeTx.commit()).thenReturn(FluentFutures.immediateFailedFluentFuture(ex)); ctx.put(id, data); } @Test - public void testDelete() throws Exception { + public void testDelete() { ctx.delete(id); verify(broker).newWriteOnlyTransaction(); verify(writeTx).delete(LogicalDatastoreType.OPERATIONAL, id); } @Test(expected = IllegalStateException.class) - public void testDeleteFailure() throws Exception { - when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(ex)); + public void testDeleteFailure() { + when(writeTx.commit()).thenReturn(FluentFutures.immediateFailedFluentFuture(ex)); ctx.delete(id); } }
\ No newline at end of file diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/TransactionMappingContextTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/TransactionMappingContextTest.java index 2dcee889a..a9747d0af 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/TransactionMappingContextTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/TransactionMappingContextTest.java @@ -21,16 +21,16 @@ import static org.junit.Assert.assertSame; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.FluentFuture; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.mdsal.binding.api.ReadWriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.ReadFailedException; +import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -49,27 +49,27 @@ public class TransactionMappingContextTest { MockitoAnnotations.initMocks(this); ctx = new TransactionMappingContext(writeTx); - when(writeTx.submit()).thenReturn(Futures.immediateCheckedFuture(null)); + when(writeTx.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); } @Test public void testRead() throws Exception { - final CheckedFuture<Optional<DataObject>, ReadFailedException> futureData = - Futures.immediateCheckedFuture(Optional.of((data))); + final FluentFuture<Optional<DataObject>> futureData = FluentFutures.immediateFluentFuture(Optional.of((data))); when(writeTx.read(LogicalDatastoreType.OPERATIONAL, id)).thenReturn(futureData); assertSame(ctx.read(id).get(), data); verify(writeTx).read(LogicalDatastoreType.OPERATIONAL, id); - when(writeTx.read(LogicalDatastoreType.OPERATIONAL, id)).thenReturn(Futures.immediateCheckedFuture(Optional.absent())); + when(writeTx.read(LogicalDatastoreType.OPERATIONAL, id)) + .thenReturn(FluentFutures.immediateFluentFuture(Optional.empty())); assertFalse(ctx.read(id).isPresent()); } @Test(expected = IllegalStateException.class) public void testReadFailure() throws Exception { - final CheckedFuture<Optional<DataObject>, ReadFailedException> futureData = - Futures.immediateFailedCheckedFuture(ex); + final FluentFuture<Optional<DataObject>> futureData = + FluentFutures.immediateFailedFluentFuture(ex); when(writeTx.read(LogicalDatastoreType.OPERATIONAL, id)).thenReturn(futureData); assertSame(ctx.read(id).get(), data); } diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/BindingBrokerReaderTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/BindingBrokerReaderTest.java index b6af72125..18ba1bd6a 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/BindingBrokerReaderTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/BindingBrokerReaderTest.java @@ -23,18 +23,18 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.translate.read.ReadContext; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.ReadFailedException; import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -46,7 +46,7 @@ public class BindingBrokerReaderTest { @Mock private ReadContext ctx; @Mock - private ReadOnlyTransaction tx; + private ReadTransaction tx; @Mock private DataObject data; private BindingBrokerReader<DataObject, DataObjectBuilder> bbReader; @@ -55,7 +55,8 @@ public class BindingBrokerReaderTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(broker.newReadOnlyTransaction()).thenReturn(tx); - when(tx.read(LogicalDatastoreType.CONFIGURATION, id)).thenReturn(Futures.immediateCheckedFuture(Optional.of(data))); + when(tx.read(LogicalDatastoreType.CONFIGURATION, id)) + .thenReturn(FluentFutures.immediateFluentFuture(Optional.of(data))); bbReader = new BindingBrokerReader<>(id, broker, LogicalDatastoreType.CONFIGURATION, DataObjectBuilder.class); } @@ -72,7 +73,7 @@ public class BindingBrokerReaderTest { @Test(expected = io.fd.honeycomb.translate.read.ReadFailedException.class) public void testFailedRead() throws Exception { when(tx.read(LogicalDatastoreType.CONFIGURATION, id)) - .thenReturn(Futures.immediateFailedCheckedFuture(new ReadFailedException("failing"))); + .thenReturn(FluentFutures.immediateFailedFluentFuture(new ReadFailedException("failing"))); bbReader.read(id, ctx); } diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizerTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizerTest.java index aa1d0f925..d884176f6 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizerTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizerTest.java @@ -59,7 +59,7 @@ public class ReflexiveListReaderCustomizerTest { final TestingListObjectBuilder builder = new TestingListObjectBuilder(); final InstanceIdentifier<TestingListObject> id = (InstanceIdentifier<TestingListObject>) InstanceIdentifier.create( - Collections.singletonList(new InstanceIdentifier.IdentifiableItem<>(TestingListObject.class, keyOne))); + Collections.singletonList(InstanceIdentifier.IdentifiableItem.of(TestingListObject.class, keyOne))); customizer.readCurrentAttributes(id, builder, readContext); assertEquals(keyOne, builder.getKey()); diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java index 5f9362458..e52583d2b 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java @@ -21,12 +21,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -import com.google.common.base.Optional; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadFailedException; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriterTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriterTest.java index 9e09112c9..49b76ce95 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriterTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriterTest.java @@ -20,16 +20,15 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.translate.write.WriteContext; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -50,7 +49,7 @@ public class BindingBrokerWriterTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(broker.newWriteOnlyTransaction()).thenReturn(tx); - when(tx.submit()).thenReturn(Futures.immediateCheckedFuture(null)); + when(tx.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); bbWriter = new BindingBrokerWriter<>(id, broker); } @@ -61,12 +60,12 @@ public class BindingBrokerWriterTest { bbWriter.processModification(id, data, data, ctx); verify(broker).newWriteOnlyTransaction(); verify(tx).put(LogicalDatastoreType.CONFIGURATION, id, data); - verify(tx).submit(); + verify(tx).commit(); } @Test(expected = io.fd.honeycomb.translate.write.WriteFailedException.class) public void testFailedWrite() throws Exception { - when(tx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("failing"))); + when(tx.commit()).thenReturn(FluentFutures.immediateFailedFluentFuture(new InterruptedException("failing"))); bbWriter.processModification(id, data, data, ctx); } }
\ No newline at end of file |