From bb090e1254eacc95d7bd1dd45f6311967f81af86 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Mon, 24 Oct 2016 13:02:59 +0200 Subject: HONEYCOMB-255 - Cutting identifiers to prevent failing of reverts Mapping allready processes changes for reverting by InstanceIdentifier instead of using KeyedInstanceIdentifier(to prevent failing to identify handleable nodes) Modified logging to prevent double/triple logging of detailed cause of failed bulk update Reusing WriteContext for revert(removed try with resource to prevent closing of write context before revert) Change-Id: Ie939ebe443629f9cdad5b5b449aa8c5dac40ea67 Signed-off-by: Jan Srnicek Signed-off-by: Maros Marsalek --- .../translate/write/registry/WriterRegistry.java | 35 ++++++++++++++++++++-- .../write/registry/BulkUpdateExceptionTest.java | 9 ++++-- 2 files changed, 39 insertions(+), 5 deletions(-) (limited to 'infra/translate-api') diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java index d281ee558..51e6415a2 100644 --- a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java +++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java @@ -152,10 +152,12 @@ public interface WriterRegistry { /** * Reverts changes that were successfully applied during bulk update before failure occurred. * + * @param writeContext Non-closed {@code WriteContext} to be used by reverting logic.
Do not use same + * write context as was used in previous write * @throws Reverter.RevertFailedException if revert fails */ - public void revertChanges() throws Reverter.RevertFailedException { - reverter.revert(); + public void revertChanges(@Nonnull final WriteContext writeContext) throws Reverter.RevertFailedException { + reverter.revert(writeContext); } public Set> getFailedIds() { @@ -172,10 +174,13 @@ public interface WriterRegistry { /** * Reverts changes that were successfully applied during bulk update before failure occurred. Changes are * reverted in reverse order they were applied. + * Used {@code WriteContext} needs to be in non-closed state, creating fresh one for revert + * is recommended, same way as for write, to allow {@code Reverter} use same logic as write. * + * @param writeContext Non-closed {@code WriteContext} to be used by reverting logic * @throws RevertFailedException if not all of applied changes were successfully reverted */ - void revert() throws RevertFailedException; + void revert(@Nonnull final WriteContext writeContext) throws RevertFailedException; /** * Thrown when some of the changes applied during bulk update were not reverted. @@ -209,5 +214,29 @@ public interface WriterRegistry { return notRevertedChanges; } } + + /** + * Thrown after bulk operation was successfully reverted, + * to maintain marking of transaction as failed,without double logging of + * cause of update fail(its logged before reverting in ModifiableDataTreeDelegator + */ + @Beta + class RevertSuccessException extends TranslationException { + private final Set> failedIds; + + /** + * Constructs an RevertSuccessException. + * + * @param failedIds instance identifiers of the data objects that were not processed during bulk update. + */ + public RevertSuccessException(@Nonnull final Set> failedIds) { + super("Bulk update failed for: " + failedIds); + this.failedIds = failedIds; + } + + public Set> getFailedIds() { + return failedIds; + } + } } } \ No newline at end of file diff --git a/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java b/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java index c1880ca26..ae0c36d5b 100644 --- a/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java +++ b/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.verify; import com.google.common.collect.Sets; +import io.fd.honeycomb.translate.write.WriteContext; import java.util.HashSet; import org.junit.Before; import org.junit.Test; @@ -31,6 +32,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class BulkUpdateExceptionTest { private InstanceIdentifier id = InstanceIdentifier.create(DataObject.class); + + @Mock + private WriteContext writeContext; + @Mock private WriterRegistry.Reverter reverter; @@ -47,7 +52,7 @@ public class BulkUpdateExceptionTest { assertEquals(failedIds, bulkUpdateException.getFailedIds()); - bulkUpdateException.revertChanges(); - verify(reverter).revert(); + bulkUpdateException.revertChanges(writeContext); + verify(reverter).revert(writeContext); } } \ No newline at end of file -- cgit 1.2.3-korg