summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils
diff options
context:
space:
mode:
Diffstat (limited to 'infra/translate-utils')
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java19
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java11
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistry.java11
-rw-r--r--infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriterTest.java10
-rw-r--r--infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriterTest.java4
-rw-r--r--infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistryTest.java2
6 files changed, 38 insertions, 19 deletions
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java
index ff2174ed2..e2ea11535 100644
--- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java
+++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java
@@ -18,8 +18,8 @@ package io.fd.honeycomb.translate.util.write;
import static com.google.common.base.Preconditions.checkArgument;
-import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.translate.write.Writer;
import javax.annotation.Nonnull;
@@ -34,9 +34,11 @@ public abstract class AbstractGenericWriter<D extends DataObject> implements Wri
private static final Logger LOG = LoggerFactory.getLogger(AbstractGenericWriter.class);
private final InstanceIdentifier<D> instanceIdentifier;
+ private final boolean supportsUpdate;
- protected AbstractGenericWriter(final InstanceIdentifier<D> type) {
+ protected AbstractGenericWriter(final InstanceIdentifier<D> type, final boolean supportsUpdate) {
this.instanceIdentifier = RWUtils.makeIidWildcarded(type);
+ this.supportsUpdate = supportsUpdate;
}
protected void writeCurrent(final InstanceIdentifier<D> id, final D data, final WriteContext ctx)
@@ -67,10 +69,10 @@ public abstract class AbstractGenericWriter<D extends DataObject> implements Wri
@SuppressWarnings("unchecked")
@Override
- public void update(@Nonnull final InstanceIdentifier<? extends DataObject> id,
- @Nullable final DataObject dataBefore,
- @Nullable final DataObject dataAfter,
- @Nonnull final WriteContext ctx) throws WriteFailedException {
+ public void processModification(@Nonnull final InstanceIdentifier<? extends DataObject> id,
+ @Nullable final DataObject dataBefore,
+ @Nullable final DataObject dataAfter,
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
LOG.debug("{}: Updating : {}", this, id);
LOG.trace("{}: Updating : {}, from: {} to: {}", this, id, dataBefore, dataAfter);
@@ -134,4 +136,9 @@ public abstract class AbstractGenericWriter<D extends DataObject> implements Wri
public String toString() {
return String.format("Writer[%s]", getManagedDataObjectType().getTargetType().getSimpleName());
}
+
+ @Override
+ public boolean supportsDirectUpdate() {
+ return supportsUpdate;
+ }
}
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 f06e6ae2f..7b68376ba 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
@@ -49,9 +49,9 @@ public final class BindingBrokerWriter<D extends DataObject> implements Writer<D
}
@Override
- public void update(@Nonnull final InstanceIdentifier<? extends DataObject> id,
- @Nullable final DataObject dataBefore, @Nullable final DataObject dataAfter,
- @Nonnull final WriteContext ctx) throws WriteFailedException {
+ 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 CheckedFuture<Void, TransactionCommitFailedException> result = writeTransaction.submit();
@@ -61,4 +61,9 @@ public final class BindingBrokerWriter<D extends DataObject> implements Writer<D
throw new WriteFailedException(id, e);
}
}
+
+ @Override
+ public boolean supportsDirectUpdate() {
+ return false;
+ }
}
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistry.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistry.java
index 8f15c6f8d..13ae12fad 100644
--- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistry.java
+++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistry.java
@@ -20,6 +20,7 @@ import io.fd.honeycomb.translate.TranslationException;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.registry.WriterRegistry;
import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* Empty registry that does not perform any changes. Can be used in data layer, if we want to disable passing data to
@@ -28,12 +29,18 @@ import javax.annotation.Nonnull;
public class NoopWriterRegistry implements WriterRegistry, AutoCloseable {
@Override
- public void update(@Nonnull final DataObjectUpdates updates,
- @Nonnull final WriteContext ctx) throws TranslationException {
+ public void processModifications(@Nonnull final DataObjectUpdates updates,
+ @Nonnull final WriteContext ctx) throws TranslationException {
// NOOP
}
@Override
+ public boolean writerSupportsUpdate(@Nonnull final InstanceIdentifier<?> type) {
+ // returns true to make higher level performance better(does not have to break updates to delete+create pairs)
+ return true;
+ }
+
+ @Override
public void close() throws Exception {
// NOOP
}
diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriterTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriterTest.java
index 14c9c6044..9b95f7662 100644
--- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriterTest.java
+++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriterTest.java
@@ -51,7 +51,7 @@ public class AbstractGenericWriterTest {
@Test
public void testDelete() throws Exception {
before = mock(DataObject.class);
- t.update(id, before, null, ctx);
+ t.processModification(id, before, null, ctx);
verify(t).deleteCurrentAttributes(id, before, ctx);
}
@@ -59,7 +59,7 @@ public class AbstractGenericWriterTest {
@Test
public void testUpdate() throws Exception {
before = mock(DataObject.class);
- t.update(id, before, after, ctx);
+ t.processModification(id, before, after, ctx);
verify(t).updateCurrentAttributes(id, before, after, ctx);
}
@@ -67,7 +67,7 @@ public class AbstractGenericWriterTest {
@Test
public void testNoUpdate() throws Exception {
before = mock(DataObject.class);
- t.update(id, before, before, ctx);
+ t.processModification(id, before, before, ctx);
verify(t, times(0)).updateCurrentAttributes(id, before, after, ctx);
}
@@ -75,7 +75,7 @@ public class AbstractGenericWriterTest {
@Test
public void testCreate() throws Exception {
before = mock(DataObject.class);
- t.update(id, null, after, ctx);
+ t.processModification(id, null, after, ctx);
verify(t).writeCurrentAttributes(id, after, ctx);
}
@@ -83,7 +83,7 @@ public class AbstractGenericWriterTest {
private static class TestingWriter extends AbstractGenericWriter<DataObject> {
TestingWriter() {
- super(InstanceIdentifier.create(DataObject.class));
+ super(InstanceIdentifier.create(DataObject.class), false);
}
@Override
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 84dbb7b4e..9e09112c9 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
@@ -58,7 +58,7 @@ public class BindingBrokerWriterTest {
public void testWrite() throws Exception {
assertEquals(id, bbWriter.getManagedDataObjectType());
- bbWriter.update(id, data, data, ctx);
+ bbWriter.processModification(id, data, data, ctx);
verify(broker).newWriteOnlyTransaction();
verify(tx).put(LogicalDatastoreType.CONFIGURATION, id, data);
verify(tx).submit();
@@ -67,6 +67,6 @@ public class BindingBrokerWriterTest {
@Test(expected = io.fd.honeycomb.translate.write.WriteFailedException.class)
public void testFailedWrite() throws Exception {
when(tx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("failing")));
- bbWriter.update(id, data, data, ctx);
+ bbWriter.processModification(id, data, data, ctx);
}
} \ No newline at end of file
diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistryTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistryTest.java
index 411f24bc3..642e9f807 100644
--- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistryTest.java
+++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/NoopWriterRegistryTest.java
@@ -23,7 +23,7 @@ public class NoopWriterRegistryTest {
@Test
public void testNoop() throws Exception {
final NoopWriterRegistry noopWriterRegistry = new NoopWriterRegistry();
- noopWriterRegistry.update(null, null);
+ noopWriterRegistry.processModifications(null, null);
noopWriterRegistry.close();
}
} \ No newline at end of file