summaryrefslogtreecommitdiffstats
path: root/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write
diff options
context:
space:
mode:
Diffstat (limited to 'infra/translate-api/src/main/java/io/fd/honeycomb/translate/write')
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/DataObjectUpdate.java114
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/ListWriter.java33
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteContext.java50
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteFailedException.java166
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java48
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriterFactory.java38
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/ModifiableWriterRegistryBuilder.java31
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java213
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistryBuilder.java27
9 files changed, 720 insertions, 0 deletions
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/DataObjectUpdate.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/DataObjectUpdate.java
new file mode 100644
index 000000000..e76d76fcd
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/DataObjectUpdate.java
@@ -0,0 +1,114 @@
+/*
+ * 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.write;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Simple wrapper for BA id + data before and after state. Does not allow both before and after to be null.
+ */
+public class DataObjectUpdate {
+
+ @Nonnull
+ private final InstanceIdentifier<?> id;
+ @Nullable
+ private final DataObject dataBefore;
+ @Nullable
+ private final DataObject dataAfter;
+
+ private DataObjectUpdate(@Nonnull final InstanceIdentifier<?> id,
+ @Nullable final DataObject dataBefore,
+ @Nullable final DataObject dataAfter) {
+ this.id = checkNotNull(id);
+ this.dataAfter = dataAfter;
+ this.dataBefore = dataBefore;
+ }
+
+ public DataObject getDataBefore() {
+ return dataBefore;
+ }
+
+ public DataObject getDataAfter() {
+ return dataAfter;
+ }
+
+ public InstanceIdentifier<?> getId() {
+ return id;
+ }
+
+ public static DataObjectUpdate create(@Nonnull final InstanceIdentifier<?> id,
+ @Nullable final DataObject dataBefore,
+ @Nullable final DataObject dataAfter) {
+ checkArgument(!(dataBefore == null && dataAfter == null), "Both before and after data are null");
+ if (dataBefore != null) {
+ checkArgument(id.getTargetType().isAssignableFrom(dataBefore.getClass()));
+ }
+ if (dataAfter != null) {
+ checkArgument(id.getTargetType().isAssignableFrom(dataAfter.getClass()));
+ }
+
+ return dataAfter == null
+ ? new DataObjectDelete(id, dataBefore)
+ : new DataObjectUpdate(id, dataBefore, dataAfter);
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ final DataObjectUpdate that = (DataObjectUpdate) o;
+
+ return id.equals(that.id);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "DataObjectUpdate{" + "id=" + id
+ + ", dataBefore=" + dataBefore
+ + ", dataAfter=" + dataAfter
+ + '}';
+ }
+
+ public DataObjectUpdate reverse() {
+ return DataObjectUpdate.create(id, dataAfter, dataBefore);
+ }
+
+ public static class DataObjectDelete extends DataObjectUpdate {
+
+ private DataObjectDelete(@Nonnull final InstanceIdentifier<?> id,
+ @Nullable final DataObject dataBefore) {
+ super(id, dataBefore, null);
+ }
+ }
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/ListWriter.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/ListWriter.java
new file mode 100644
index 000000000..ea4ed9c93
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/ListWriter.java
@@ -0,0 +1,33 @@
+/*
+ * 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.write;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+
+/**
+ * List writer, responsible for translation between a list of DataObjects and any other side.
+ * Handling all update operations(create, update, delete)
+ *
+ * @param <D> Specific DataObject derived type, that is handled by this writer
+ * @param <K> Identifier/key for D
+ */
+@Beta
+public interface ListWriter<D extends DataObject & Identifiable<K>, K extends Identifier<D>> extends Writer<D> {
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteContext.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteContext.java
new file mode 100644
index 000000000..17aea8d8a
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteContext.java
@@ -0,0 +1,50 @@
+/*
+ * 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.write;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Optional;
+import io.fd.honeycomb.translate.ModificationContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Context providing information about current state of DataTree to writers
+ */
+@Beta
+public interface WriteContext extends ModificationContext {
+
+ /**
+ * Read any config data object before current modification was applied
+ *
+ * @param currentId Id of an object to read
+ *
+ * @return Data before the modification was applied
+ */
+ <T extends DataObject> Optional<T> readBefore(@Nonnull final InstanceIdentifier<T> currentId);
+
+ /**
+ * Read any config data object from current modification
+ *
+ * @param currentId Id of an object to read
+ *
+ * @return Data from the modification
+ */
+ <T extends DataObject> Optional<T> readAfter(@Nonnull final InstanceIdentifier<T> currentId);
+
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteFailedException.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteFailedException.java
new file mode 100644
index 000000000..8f89d3163
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriteFailedException.java
@@ -0,0 +1,166 @@
+/*
+ * 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.write;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.honeycomb.translate.TranslationException;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Thrown when a writer or customizer is not able to write/update/delete data .
+ */
+public class WriteFailedException extends TranslationException {
+
+ private final InstanceIdentifier<?> failedId;
+
+ /**
+ * Constructs an WriteFailedException given data id, exception detail message and exception cause.
+ *
+ * @param failedId instance identifier of the data object that could not be read
+ * @param cause the cause of read failure
+ * @param message the exception detail message
+ */
+ public WriteFailedException(@Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final String message,
+ @Nonnull final Throwable cause) {
+ super(message, cause);
+ this.failedId = checkNotNull(failedId, "failedId should not be null");
+ }
+
+ /**
+ * Constructs an WriteFailedException given data id.
+ *
+ * @param failedId instance identifier of the data object that could not be written
+ */
+ public WriteFailedException(@Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final String message) {
+ super(message);
+ this.failedId = checkNotNull(failedId, "failedId should not be null");
+ }
+
+ /**
+ * Constructs an WriteFailedException given data id and exception cause.
+ *
+ * @param failedId instance identifier of the data object that could not be read
+ * @param cause the cause of read failure
+ */
+ public WriteFailedException(@Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final Throwable cause) {
+ super(cause);
+ this.failedId = checkNotNull(failedId, "failedId should not be null");
+ }
+
+ /**
+ * Returns id of the data object that could not be written.
+ *
+ * @return data object instance identifier
+ */
+ @Nonnull
+ public InstanceIdentifier<?> getFailedId() {
+ return failedId;
+ }
+
+
+ /**
+ * Delete specific write failed exception
+ */
+ public static class DeleteFailedException extends WriteFailedException {
+
+ public DeleteFailedException(@Nonnull final InstanceIdentifier<?> failedId, @Nonnull final Throwable cause) {
+ super(failedId, getMsg(failedId), cause);
+ }
+
+ private static String getMsg(@Nonnull final InstanceIdentifier<?> failedId) {
+ return String.format("Failed to delete data at: %s", failedId);
+ }
+
+ public DeleteFailedException(@Nonnull final InstanceIdentifier<?> failedId) {
+ super(failedId, getMsg(failedId));
+ }
+ }
+
+ /**
+ * Create specific write failed exception
+ */
+ public static class CreateFailedException extends WriteFailedException {
+
+ private final DataObject data;
+
+ public CreateFailedException(@Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final DataObject data,
+ @Nonnull final Throwable cause) {
+ super(failedId, getMsg(failedId, data), cause);
+ this.data = checkNotNull(data, "data");
+ }
+
+ private static String getMsg(final @Nonnull InstanceIdentifier<?> failedId, final DataObject data) {
+ return String.format("Failed to create data: %s at: %s", data, failedId);
+ }
+
+ public CreateFailedException(@Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final DataObject data) {
+ super(failedId, getMsg(failedId, data));
+ this.data = checkNotNull(data, "data");
+ }
+
+ public DataObject getData() {
+ return data;
+ }
+ }
+
+ /**
+ * Update specific write failed exception
+ */
+ public static class UpdateFailedException extends WriteFailedException {
+
+ private final DataObject dataBefore;
+ private final DataObject dataAfter;
+
+ public UpdateFailedException(@Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final DataObject dataBefore,
+ @Nonnull final DataObject dataAfter,
+ @Nonnull final Throwable cause) {
+ super(failedId, getMsg(failedId, dataBefore, dataAfter), cause);
+ this.dataBefore = checkNotNull(dataBefore, "dataBefore");
+ this.dataAfter = checkNotNull(dataAfter, "dataAfter");
+ }
+
+ private static String getMsg(final @Nonnull InstanceIdentifier<?> failedId, final DataObject dataBefore,
+ final DataObject dataAfter) {
+ return String.format("Failed to update data from: %s to: %s, at: %s", dataBefore, dataAfter, failedId);
+ }
+
+ public UpdateFailedException(@Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final DataObject dataBefore,
+ @Nonnull final DataObject dataAfter) {
+ super(failedId, getMsg(failedId, dataBefore, dataAfter));
+ this.dataBefore = checkNotNull(dataBefore, "dataBefore");
+ this.dataAfter = checkNotNull(dataAfter, "dataAfter");
+ }
+
+ public DataObject getDataBefore() {
+ return dataBefore;
+ }
+
+ public DataObject getDataAfter() {
+ return dataAfter;
+ }
+ }
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java
new file mode 100644
index 000000000..e6538012b
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java
@@ -0,0 +1,48 @@
+/*
+ * 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.write;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.translate.SubtreeManager;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Base writer, responsible for translation between DataObjects and any other side. Handling all update operations(create,
+ * update, delete)
+ *
+ * @param <D> Specific DataObject derived type, that is handled by this writer
+ */
+@Beta
+public interface Writer<D extends DataObject> extends SubtreeManager<D> {
+
+ /**
+ * Handle update operation. U from CRUD.
+ *
+ * @param id Identifier of data being written
+ * @param dataBefore Old data
+ * @param dataAfter New, updated data
+ * @param ctx Write context enabling writer to get information about candidate data as well as current data
+ * @throws WriteFailedException if update failed
+ */
+ void update(@Nonnull final InstanceIdentifier<? extends DataObject> id,
+ @Nullable final DataObject dataBefore,
+ @Nullable final DataObject dataAfter,
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriterFactory.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriterFactory.java
new file mode 100644
index 000000000..70328c7f5
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/WriterFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.write;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
+import javax.annotation.Nonnull;
+
+/**
+ * Factory producing writers for {@link ModifiableWriterRegistryBuilder}.
+ */
+@Beta
+public interface WriterFactory extends AutoCloseable {
+
+ /**
+ * Initialize 1 or more writers and add them to provided registry.
+ */
+ void init(@Nonnull ModifiableWriterRegistryBuilder registry);
+
+ @Override
+ default void close() {
+ // NOOP TODO allow unregister
+ }
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/ModifiableWriterRegistryBuilder.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/ModifiableWriterRegistryBuilder.java
new file mode 100644
index 000000000..27761e5b4
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/ModifiableWriterRegistryBuilder.java
@@ -0,0 +1,31 @@
+/*
+ * 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.write.registry;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.translate.ModifiableSubtreeManagerRegistryBuilder;
+import io.fd.honeycomb.translate.write.Writer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+/**
+ * Mutable registry that allows adding new writers.
+ */
+@Beta
+public interface ModifiableWriterRegistryBuilder
+ extends ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> {
+
+}
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
new file mode 100644
index 000000000..2467972da
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java
@@ -0,0 +1,213 @@
+/*
+ * 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.write.registry;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+import io.fd.honeycomb.translate.TranslationException;
+import io.fd.honeycomb.translate.write.DataObjectUpdate;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.Writer;
+import java.util.Set;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Special {@link Writer} capable of performing bulk updates.
+ */
+@Beta
+public interface WriterRegistry {
+
+ /**
+ * Performs bulk update.
+ *
+ * @throws BulkUpdateException in case bulk update fails
+ * @throws TranslationException in case some other error occurs while processing update request
+ */
+ void update(@Nonnull DataObjectUpdates updates,
+ @Nonnull WriteContext ctx) throws TranslationException;
+
+ /**
+ * Simple DTO containing updates for {@link WriterRegistry}. Currently only deletes and updates (create + update)
+ * are distinguished.
+ */
+ @Beta
+ final class DataObjectUpdates {
+
+ private final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates;
+ private final Multimap<InstanceIdentifier<?>, DataObjectUpdate.DataObjectDelete> deletes;
+
+ /**
+ * Create new instance.
+ *
+ * @param updates All updates indexed by their unkeyed {@link InstanceIdentifier}
+ * @param deletes All deletes indexed by their unkeyed {@link InstanceIdentifier}
+ */
+ public DataObjectUpdates(@Nonnull final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates,
+ @Nonnull final Multimap<InstanceIdentifier<?>, DataObjectUpdate.DataObjectDelete> deletes) {
+ this.deletes = deletes;
+ this.updates = updates;
+ }
+
+ public Multimap<InstanceIdentifier<?>, DataObjectUpdate> getUpdates() {
+ return updates;
+ }
+
+ public Multimap<InstanceIdentifier<?>, DataObjectUpdate.DataObjectDelete> getDeletes() {
+ return deletes;
+ }
+
+ public boolean isEmpty() {
+ return updates.isEmpty() && deletes.isEmpty();
+ }
+
+ @Override
+ public String toString() {
+ return "DataObjectUpdates{" + "updates=" + updates + ", deletes=" + deletes + '}';
+ }
+
+ /**
+ * Get a {@link Set} containing all update types from both updates as well as deletes.
+ */
+ public Set<InstanceIdentifier<?>> getTypeIntersection() {
+ return Sets.union(deletes.keySet(), updates.keySet());
+ }
+
+ /**
+ * Check whether there is only a single type of data object to be updated.
+ *
+ * @return true if there is only a single type of updates (update + delete)
+ */
+ public boolean containsOnlySingleType() {
+ return getTypeIntersection().size() == 1;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other == null || getClass() != other.getClass()) {
+ return false;
+ }
+
+ final DataObjectUpdates that = (DataObjectUpdates) other;
+
+ if (!updates.equals(that.updates)) {
+ return false;
+ }
+ return deletes.equals(that.deletes);
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = updates.hashCode();
+ result = 31 * result + deletes.hashCode();
+ return result;
+ }
+
+ }
+
+ /**
+ * Thrown when bulk update failed.
+ */
+ @Beta
+ class BulkUpdateException extends TranslationException {
+
+ private final Reverter reverter;
+ private final Set<InstanceIdentifier<?>> failedIds;
+
+ /**
+ * Constructs an BulkUpdateException.
+ * @param failedIds instance identifiers of the data objects that were not processed during bulk update.
+ * @param cause the cause of bulk update failure
+ */
+ public BulkUpdateException(@Nonnull final Set<InstanceIdentifier<?>> failedIds,
+ @Nonnull final Reverter reverter,
+ @Nonnull final Throwable cause) {
+ super("Bulk update failed at: " + failedIds, cause);
+ this.failedIds = failedIds;
+ this.reverter = checkNotNull(reverter, "reverter should not be null");
+ }
+
+ /**
+ * Reverts changes that were successfully applied during bulk update before failure occurred.
+ *
+ * @throws Reverter.RevertFailedException if revert fails
+ */
+ public void revertChanges() throws Reverter.RevertFailedException {
+ reverter.revert();
+ }
+
+ public Set<InstanceIdentifier<?>> getFailedIds() {
+ return failedIds;
+ }
+ }
+
+ /**
+ * Abstraction over revert mechanism in case of a bulk update failure.
+ */
+ @Beta
+ interface Reverter {
+
+ /**
+ * Reverts changes that were successfully applied during bulk update before failure occurred. Changes are
+ * reverted in reverse order they were applied.
+ *
+ * @throws RevertFailedException if not all of applied changes were successfully reverted
+ */
+ void revert() throws RevertFailedException;
+
+ /**
+ * Thrown when some of the changes applied during bulk update were not reverted.
+ */
+ @Beta
+ class RevertFailedException extends TranslationException {
+
+ // TODO change to list of VppDataModifications to make debugging easier
+ private final Set<InstanceIdentifier<?>> notRevertedChanges;
+
+ /**
+ * Constructs a RevertFailedException with the list of changes that were not reverted.
+ *
+ * @param notRevertedChanges list of changes that were not reverted
+ * @param cause the cause of revert failure
+ */
+ public RevertFailedException(@Nonnull final Set<InstanceIdentifier<?>> notRevertedChanges,
+ final Throwable cause) {
+ super(cause);
+ checkNotNull(notRevertedChanges, "notRevertedChanges should not be null");
+ this.notRevertedChanges = ImmutableSet.copyOf(notRevertedChanges);
+ }
+
+ /**
+ * Returns the list of changes that were not reverted.
+ *
+ * @return list of changes that were not reverted
+ */
+ @Nonnull
+ public Set<InstanceIdentifier<?>> getNotRevertedChanges() {
+ return notRevertedChanges;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistryBuilder.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistryBuilder.java
new file mode 100644
index 000000000..5e3481966
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistryBuilder.java
@@ -0,0 +1,27 @@
+/*
+ * 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.write.registry;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.translate.SubtreeManagerRegistryBuilder;
+
+/**
+ * Builder for writer registries.
+ */
+@Beta
+public interface WriterRegistryBuilder extends SubtreeManagerRegistryBuilder<WriterRegistry> {
+}