summaryrefslogtreecommitdiffstats
path: root/v3po/translate-api
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-04-12 10:13:37 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-04-12 10:13:37 +0200
commit28208ac2b1b9e068c51eee79cf1bfedc6a818195 (patch)
tree4bb01d13f3a070ddb7b6b4bd22393a61a527dad8 /v3po/translate-api
parent1c690387dcfe8730ca9c0d4fc5ea732b172ae249 (diff)
HONEYCOMB-9: Migrate Interface listener
Change-Id: Iffde1ee21b749a8c8efa96c243f7f8bb0811b4c7 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/translate-api')
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/VppApiInvocationException.java76
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/ChildWriter.java6
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteFailedException.java154
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/Writer.java7
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriterRegistry.java17
-rw-r--r--v3po/translate-api/src/test/java/io/fd/honeycomb/v3po/translate/VppApiInvocationExceptionTest.java44
6 files changed, 163 insertions, 141 deletions
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/VppApiInvocationException.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/VppApiInvocationException.java
deleted file mode 100644
index 298c698f7..000000000
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/VppApiInvocationException.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.translate;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
-import javax.annotation.Nonnull;
-
-/**
- * Thrown when Vpp jAPI method invocation failed.
- */
-@Beta
-public class VppApiInvocationException extends TranslationException {
- private final String methodName;
- private final int ctxId;
- private final int errorCode;
-
- /**
- * Constructs an VppApiInvocationFailedException with the specified api method name and error code.
- *
- * @param methodName method name that failed to invoke
- * @param ctxId api request context identifier
- * @param errorCode negative error code value associated with this failure
- * @throws NullPointerException if apiMethodName is null
- * @throws IllegalArgumentException if errorCode is nonnegative
- */
- public VppApiInvocationException(@Nonnull final String methodName, final int ctxId, final int errorCode) {
- super(String.format("vppApi.%s failed with error code: %d (ctxId=%d) ", methodName, errorCode, ctxId));
- this.methodName = Preconditions.checkNotNull(methodName, "apiMethodName is null!");
- this.ctxId = ctxId;
- Preconditions.checkArgument(errorCode < 0);
- this.errorCode = errorCode;
- }
-
- /**
- * Returns method name that failed to invoke.
- *
- * @return method name
- */
- public String getMethodName() {
- return methodName;
- }
-
- /**
- * Returns api request context identifier.
- *
- * @return value of context identifier
- */
- public int getCtxId() {
- return ctxId;
- }
-
- /**
- * Returns the error code associated with this failure.
- *
- * @return a negative integer error code
- */
- public int getErrorCode() {
- return errorCode;
- }
-}
-
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/ChildWriter.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/ChildWriter.java
index f933cfd4a..b38f26983 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/ChildWriter.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/ChildWriter.java
@@ -38,7 +38,7 @@ public interface ChildWriter<D extends DataObject> extends Writer<D> {
*/
void writeChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentDataAfter,
- @Nonnull final WriteContext ctx);
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
/**
* Extract data object managed by this writer(if necessary) from parent data and perform delete.
@@ -49,7 +49,7 @@ public interface ChildWriter<D extends DataObject> extends Writer<D> {
*/
void deleteChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentDataBefore,
- @Nonnull final WriteContext ctx);
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
/**
* Extract data object managed by this writer(if necessary) from parent data and perform delete.
@@ -62,5 +62,5 @@ public interface ChildWriter<D extends DataObject> extends Writer<D> {
void updateChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentDataBefore,
@Nonnull final DataObject parentDataAfter,
- @Nonnull final WriteContext ctx);
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteFailedException.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteFailedException.java
new file mode 100644
index 000000000..a924c7646
--- /dev/null
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteFailedException.java
@@ -0,0 +1,154 @@
+/*
+ * 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.v3po.translate.write;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.honeycomb.v3po.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 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
+ */
+ 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");
+ }
+
+ /**
+ * 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/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/Writer.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/Writer.java
index 08465fdd7..77abe341c 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/Writer.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/Writer.java
@@ -17,7 +17,6 @@
package io.fd.honeycomb.v3po.translate.write;
import com.google.common.annotations.Beta;
-import io.fd.honeycomb.v3po.translate.TranslationException;
import io.fd.honeycomb.v3po.translate.SubtreeManager;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -36,14 +35,14 @@ public interface Writer<D extends DataObject> extends SubtreeManager<D> {
/**
* Handle update operation. U from CRUD.
*
- * @param id Identifier(from root) of data being written
+ * @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 TranslationException if update failed
+ * @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 TranslationException;
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriterRegistry.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriterRegistry.java
index c5a8116c8..d30f06d13 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriterRegistry.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriterRegistry.java
@@ -47,10 +47,9 @@ public interface WriterRegistry extends Writer<DataObject> {
* Thrown when bulk update failed.
*/
@Beta
- class BulkUpdateException extends TranslationException {
+ class BulkUpdateException extends WriteFailedException {
private final Reverter reverter;
- private final InstanceIdentifier<?> failedId; // TODO change to VppDataModification
/**
* Constructs an BulkUpdateException.
@@ -60,8 +59,7 @@ public interface WriterRegistry extends Writer<DataObject> {
*/
public BulkUpdateException(@Nonnull final InstanceIdentifier<?> failedId, @Nonnull final Reverter reverter,
final Throwable cause) {
- super("Bulk update failed at " + failedId, cause);
- this.failedId = checkNotNull(failedId, "failedId should not be null");
+ super(failedId, "Bulk update failed at " + failedId, cause);
this.reverter = checkNotNull(reverter, "reverter should not be null");
}
@@ -74,19 +72,10 @@ public interface WriterRegistry extends Writer<DataObject> {
reverter.revert();
}
- /**
- * Returns instance identifier of the data object that caused bulk update to fail.
- *
- * @return data object's instance identifier
- */
- @Nonnull
- public InstanceIdentifier<?> getFailedId() {
- return failedId;
- }
}
/**
- * Abstraction over revert mechanism in cast of a bulk update failure
+ * Abstraction over revert mechanism in case of a bulk update failure
*/
@Beta
interface Reverter {
diff --git a/v3po/translate-api/src/test/java/io/fd/honeycomb/v3po/translate/VppApiInvocationExceptionTest.java b/v3po/translate-api/src/test/java/io/fd/honeycomb/v3po/translate/VppApiInvocationExceptionTest.java
deleted file mode 100644
index b2cfbd216..000000000
--- a/v3po/translate-api/src/test/java/io/fd/honeycomb/v3po/translate/VppApiInvocationExceptionTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.translate;
-
-import java.util.Random;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class VppApiInvocationExceptionTest {
-
- @Test
- public void testInstantiation() {
- final String apiMethodName = "methodName";
- final int ctxId = 1;
- final int code = -1;
- VppApiInvocationException e = new VppApiInvocationException(apiMethodName, ctxId, code);
- Assert.assertEquals(apiMethodName, e.getMethodName());
- Assert.assertEquals(ctxId, e.getCtxId());
- Assert.assertEquals(code, e.getErrorCode());
- Assert.assertTrue(e.getMessage().contains(apiMethodName));
- Assert.assertTrue(e.getMessage().contains(String.valueOf(code)));
- Assert.assertTrue(e.getMessage().contains(String.valueOf(ctxId)));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testInstantiationFailed() {
- final int code = new Random().nextInt(Integer.MAX_VALUE);
- VppApiInvocationException e = new VppApiInvocationException("apiMethodName", 1, code);
- }
-}