Remove deprecated NETCONF error interfaces 53/97453/5
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 12 Sep 2021 14:43:52 +0000 (16:43 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 12 Sep 2021 15:48:49 +0000 (17:48 +0200)
RpcError.Error{Severity,Type} as well as YangError have their
replacements, hence remove them.

Change-Id: Ib90f3d63ee85524fd03e1f81fd5c4e0fd74a1d78
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
14 files changed:
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/ErrorSeverity.java
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/ErrorType.java
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/NetconfLayer.java
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/OperationFailedException.java
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/RpcError.java
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/RpcResultBuilder.java
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangError.java [deleted file]
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/OperationFailedExceptionTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RpcResultBuilderTest.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/codec/YangInvalidValueException.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/AbstractIntegerStringCodec.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/BinaryStringCodec.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/CompiledPatternContext.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/StringStringCodec.java

index 04983d2ac0a0258a81400a1d8ba16e925f76d48d..7bc15bd2d15a56905fb40dcb6399181b82e60108 100644 (file)
@@ -24,21 +24,19 @@ public enum ErrorSeverity {
     /**
      * An error preventing an operation from completing successfully.
      */
-    ERROR("error", RpcError.ErrorSeverity.ERROR),
+    ERROR("error"),
     /**
      * A warning not affecting an operation's ability to complete successfully.
      */
-    WARNING("warning", RpcError.ErrorSeverity.ERROR);
+    WARNING("warning");
 
     private static final Map<String, ErrorSeverity> BY_ELEMENT_BODY =
         Maps.uniqueIndex(Arrays.asList(values()), ErrorSeverity::elementBody);
 
-    private final RpcError.ErrorSeverity legacy;
     private final String elementBody;
 
-    ErrorSeverity(final String elementName, final RpcError.ErrorSeverity legacy) {
+    ErrorSeverity(final String elementName) {
         this.elementBody = requireNonNull(elementName);
-        this.legacy = requireNonNull(legacy);
     }
 
     /**
@@ -50,11 +48,6 @@ public enum ErrorSeverity {
         return elementBody;
     }
 
-    @Deprecated
-    public RpcError.ErrorSeverity toLegacy() {
-        return legacy;
-    }
-
     public static @Nullable ErrorSeverity forElementBody(final String elementBody) {
         return BY_ELEMENT_BODY.get(requireNonNull(elementBody));
     }
index 42b8d49638b470ad7d2055a930a6f22789103a19..d421232f3ebda81d70e86c01551a8774d6a1f455 100644 (file)
@@ -26,33 +26,31 @@ public enum ErrorType {
      * A {@link NetconfLayer#TRANSPORT} layer error. This typically happens on transport endpoints, where a protocol
      * plugin needs to report a NETCONF-equivalent condition.
      */
-    TRANSPORT("transport", NetconfLayer.TRANSPORT, RpcError.ErrorType.TRANSPORT),
+    TRANSPORT("transport", NetconfLayer.TRANSPORT),
     /**
      * A {@link NetconfLayer#RPC} layer error. This typically happens on request routers, where a request may end up
      * being resolved due to implementation-internal causes, such as timeouts and state loss.
      */
-    RPC("rpc", NetconfLayer.RPC, RpcError.ErrorType.RPC),
+    RPC("rpc", NetconfLayer.RPC),
     /**
      * A {@link NetconfLayer#OPERATIONS} layer error. These typically happen in a NETCONF protocol implementation.
      */
-    PROTOCOL("protocol", NetconfLayer.OPERATIONS, RpcError.ErrorType.PROTOCOL),
+    PROTOCOL("protocol", NetconfLayer.OPERATIONS),
     /**
      * A {@link NetconfLayer#CONTENT} layer error. These typically happen due to YANG data handling, such as
      * type checking and structural consistency.
      */
-    APPLICATION("application", NetconfLayer.CONTENT, RpcError.ErrorType.APPLICATION);
+    APPLICATION("application", NetconfLayer.CONTENT);
 
     private static final Map<String, ErrorType> BY_ELEMENT_BODY =
         Maps.uniqueIndex(Arrays.asList(values()), ErrorType::elementBody);
 
-    private final RpcError.ErrorType legacy;
     private final String elementBody;
     private final NetconfLayer layer;
 
-    ErrorType(final String elementName, final NetconfLayer layer, final RpcError.ErrorType legacy) {
+    ErrorType(final String elementName, final NetconfLayer layer) {
         this.elementBody = requireNonNull(elementName);
         this.layer = requireNonNull(layer);
-        this.legacy = requireNonNull(legacy);
     }
 
     /**
@@ -73,11 +71,6 @@ public enum ErrorType {
         return layer;
     }
 
-    @Deprecated
-    public final RpcError.ErrorType toLegacy() {
-        return legacy;
-    }
-
     public static @Nullable ErrorType forElementBody(final String elementBody) {
         return BY_ELEMENT_BODY.get(requireNonNull(elementBody));
     }
index ef346f371e9db3527b6d68ddcb282b23a801628a..a44e7fab8dd4335a6ebc336ab23ef6c4ea89c5d2 100644 (file)
@@ -44,8 +44,8 @@ package org.opendaylight.yangtools.yang.common;
  */
 public enum NetconfLayer {
     /**
-     * Content layer, for example configuration data. This layer is implied indirectly in constructs defined in
-     * {@link YangError} and corresponds to {@link ErrorType#APPLICATION}
+     * Content layer, for example configuration data. This layer is implied indirectly in all YANG-based validation and
+     * corresponds to {@link ErrorType#APPLICATION}
      */
     CONTENT,
     /**
index 289901397fff396ff0511f48ffd3adc771982747..616c3633e8ab549dcdb1bb7d11fe1f70dbdcd7cc 100644 (file)
@@ -15,7 +15,6 @@ import com.google.common.collect.ImmutableList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 
 /**
  * A general base exception for an operation failure.
index ac10b77947805edaf8ed22f58dd873e646042863..9a22d22732d3d7cc24cf596110b6b401092998c8 100644 (file)
@@ -7,78 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
 /**
  * Representation of an error.
  */
 public interface RpcError {
-    // FIXME: 8.0.0: remove this in favor of Netconf.ErrorSeverity
-    @NonNullByDefault
-    enum ErrorSeverity {
-        ERROR {
-            @Override
-            public org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf() {
-                return org.opendaylight.yangtools.yang.common.ErrorSeverity.ERROR;
-            }
-        },
-        WARNING {
-            @Override
-            public org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf() {
-                return org.opendaylight.yangtools.yang.common.ErrorSeverity.WARNING;
-            }
-        };
-
-        public abstract org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf();
-    }
-
-    /**
-     * Enumeration of {@code error-type} values. These provide glue between {@link NetconfLayer} and various sources of
-     * such errors.
-     */
-    // FIXME: 8.0.0: remove this in favor of common.ErrorType
-    @NonNullByDefault
-    enum ErrorType {
-        /**
-         * Indicates an error occurred during transport of data, eg over the network.
-         */
-        TRANSPORT {
-            @Override
-            public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
-                return org.opendaylight.yangtools.yang.common.ErrorType.TRANSPORT;
-            }
-        },
-        /**
-         * Indicates an error occurred during a remote procedure call.
-         */
-        RPC {
-            @Override
-            public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
-                return org.opendaylight.yangtools.yang.common.ErrorType.RPC;
-            }
-        },
-        /**
-         * Indicates an error at a protocol layer, eg if invalid data was passed by the caller.
-         */
-        PROTOCOL {
-            @Override
-            public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
-                return org.opendaylight.yangtools.yang.common.ErrorType.PROTOCOL;
-            }
-        },
-        /**
-         * Indicates an error occurred during internal processing.
-         */
-        APPLICATION {
-            @Override
-            public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
-                return org.opendaylight.yangtools.yang.common.ErrorType.APPLICATION;
-            }
-        };
-
-        public abstract org.opendaylight.yangtools.yang.common.ErrorType toNetconf();
-    }
-
     /**
      * Returns the error severity, as determined by the application reporting the error.
      *
index c47052dd81a74330dd8ff3f86bd3bdb19b4fffa4..3289d3d7ddc9ca8ff8b9e7c0a5d335466eaf32b2 100644 (file)
@@ -16,8 +16,6 @@ import java.io.Serializable;
 import java.util.Collection;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Builder;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 
 /**
  * A builder for creating RpcResult instances.
diff --git a/common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangError.java b/common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangError.java
deleted file mode 100644 (file)
index 589cfb0..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.common;
-
-import com.google.common.annotations.Beta;
-import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
-
-/**
- * An error condition raised as a consequence of a YANG-defined contract. This interface should not be directly
- * implemented, but rather should be attached to a well-defined Exception class.
- *
- * @deprecated This interface is not completely sufficient to describe errors, as it lacks the ability to carry instance
- *             path as well as more-info elements.
- */
-@Beta
-@Deprecated(forRemoval = true, since = "7.0.4")
-// FIXME: 8.0.0: remove this class
-public interface YangError {
-    /**
-     * Returns the conceptual layer at which the error occurred.
-     *
-     * @return an {@link ErrorType} enum.
-     */
-    @NonNull ErrorType getErrorType();
-
-    /**
-     * Returns the error severity, as determined by the application reporting the error.
-     *
-     * @return an {@link ErrorSeverity} enum.
-     */
-    @NonNull ErrorSeverity getSeverity();
-
-    /**
-     * Returns the error tag, as determined by the application reporting the error.
-     *
-     * @return an error tag.
-     */
-    @NonNull String getErrorTag();
-
-    /**
-     * Returns the value of the argument of YANG {@code error-app-tag} statement.
-     *
-     * @return string with the application error tag, or empty if it was not provided.
-     */
-    Optional<String> getErrorAppTag();
-
-    /**
-     * Returns the value of the argument of YANG {@code error-message} statement.
-     *
-     * @return string with the error message, or empty if it was not provided.
-     */
-    Optional<String> getErrorMessage();
-}
index 27e6c22fa40a78adaedec15aa5e882b4fa589bff..8bc171c122d5948dd88fbab3d1de1fde52c142cb 100644 (file)
@@ -7,22 +7,22 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 
 public class OperationFailedExceptionTest {
-
     @Test
     public void testOperationFailedException() {
         final Throwable cause = new Throwable("mock cause");
-        final RpcError rpcErrorShort = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg");
+        final RpcError rpcErrorShort = RpcResultBuilder.newError(ErrorType.RPC, "tag", "msg");
         final OperationFailedException operationFailedException1 = new OperationFailedException("error msg", cause,
                 rpcErrorShort);
         final OperationFailedException operationFailedException2 = new OperationFailedException("error msg",
                 rpcErrorShort);
         assertEquals(operationFailedException1.getErrorList(), operationFailedException2.getErrorList());
-        assertTrue(operationFailedException1.toString().contains("error msg"));
+        assertThat(operationFailedException1.toString(), containsString("error msg"));
     }
 }
index 74166dfede8792046f199e77a5a8b8711409c5e2..eae1e797c2b30046c825711b0592dcefbca99f7b 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.common;
 
 import static org.junit.Assert.assertEquals;
@@ -19,8 +18,6 @@ import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.List;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 
 /**
  * Unit tests for RpcResultBuilder.
@@ -115,12 +112,11 @@ public class RpcResultBuilderTest {
     @Test
     public void testErrors() {
         final RpcResultBuilder<Object> rpcResultBuilder = RpcResultBuilder.status(true);
-        final RpcError rpcErrorShort = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg");
-        final RpcError rpcErrorLong = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg", "applicationTag",
+        final RpcError rpcErrorShort = RpcResultBuilder.newError(ErrorType.RPC, "tag", "msg");
+        final RpcError rpcErrorLong = RpcResultBuilder.newError(ErrorType.RPC, "tag", "msg", "applicationTag",
                 "info", null);
-        final RpcError rpcErrorShortWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg");
-        final RpcError rpcErrorLongWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg",
-                "applicationTag",
+        final RpcError rpcErrorShortWarn = RpcResultBuilder.newWarning(ErrorType.RPC, "tag", "msg");
+        final RpcError rpcErrorLongWarn = RpcResultBuilder.newWarning(ErrorType.RPC, "tag", "msg", "applicationTag",
                 "info", null);
         rpcResultBuilder.withRpcError(rpcErrorShort);
         final RpcResult<Object> rpcResult = rpcResultBuilder.build();
index a75cfc2649395f18bae3614f9cb8a156020c0ed4..a0434e9e171e46fc42a1eb350fdcc7fb06d2f6f4 100644 (file)
@@ -11,13 +11,11 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import java.util.List;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
-import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.YangError;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.ImmutableYangNetconfError;
 import org.opendaylight.yangtools.yang.data.api.YangNetconfError;
 import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware;
@@ -40,14 +38,14 @@ import org.opendaylight.yangtools.yang.model.api.ConstraintMetaDefinition;
  * which defines the appropriate severity and adds more semantics.
  */
 @Beta
-public class YangInvalidValueException extends IllegalArgumentException implements YangError, YangNetconfErrorAware {
+public class YangInvalidValueException extends IllegalArgumentException implements YangNetconfErrorAware {
     private static final long serialVersionUID = 1L;
 
-    private final RpcError.@NonNull ErrorType errorType;
+    private final @NonNull ErrorType errorType;
     private final @Nullable String errorAppTag;
     private final @Nullable String errorMessage;
 
-    public YangInvalidValueException(final RpcError.ErrorType errorType, final ConstraintMetaDefinition constraint,
+    public YangInvalidValueException(final ErrorType errorType, final ConstraintMetaDefinition constraint,
             final String message) {
         super(requireNonNull(message));
         this.errorType = requireNonNull(errorType);
@@ -55,41 +53,11 @@ public class YangInvalidValueException extends IllegalArgumentException implemen
         this.errorMessage = constraint.getErrorMessage().orElse(null);
     }
 
-    @Deprecated
-    @Override
-    public final RpcError.ErrorType getErrorType() {
-        return errorType;
-    }
-
-    @Deprecated
-    @Override
-    public final RpcError.ErrorSeverity getSeverity() {
-        return RpcError.ErrorSeverity.ERROR;
-    }
-
-    @Deprecated
-    @Override
-    public final String getErrorTag() {
-        return "invalid-value";
-    }
-
-    @Deprecated
-    @Override
-    public final Optional<String> getErrorAppTag() {
-        return Optional.ofNullable(errorAppTag);
-    }
-
-    @Deprecated
-    @Override
-    public final Optional<String> getErrorMessage() {
-        return Optional.ofNullable(errorMessage);
-    }
-
     @Override
     public List<YangNetconfError> getNetconfErrors() {
         return List.of(ImmutableYangNetconfError.builder()
             .severity(ErrorSeverity.ERROR)
-            .type(errorType.toNetconf())
+            .type(errorType)
             .tag(ErrorTag.INVALID_VALUE)
             .message(errorMessage)
             .appTag(errorAppTag)
index ac69cab0cf8a15bcc09fc81418607eacce15af05..82f6b8971a994cdeaf243dddce6f2cc0e4483752 100644 (file)
@@ -16,7 +16,7 @@ import com.google.common.collect.RangeSet;
 import java.util.Optional;
 import java.util.regex.Pattern;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.common.Uint64;
@@ -127,7 +127,7 @@ public abstract class AbstractIntegerStringCodec<N extends Number & Comparable<N
     }
 
     private static int provideBase(final String integer) {
-        if ((integer.length() == 1 && integer.charAt(0) == '0') || INT_PATTERN.matcher(integer).matches()) {
+        if (integer.length() == 1 && integer.charAt(0) == '0' || INT_PATTERN.matcher(integer).matches()) {
             return 10;
         } else if (HEX_PATTERN.matcher(integer).matches()) {
             return 16;
index 920a19897e752f28575b76dfac756a4070fe868e..bdc318347841502796efa56971bc7aa6fb56d7bc 100644 (file)
@@ -12,7 +12,7 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.Beta;
 import com.google.common.collect.RangeSet;
 import java.util.Base64;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
 import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
index c6fd32c15d6bcaf6f3d5ee8f4f4ebbf00e7777aa..20e9fac00ca5509f6ece5ffe8a6a2954c4d0de54 100644 (file)
@@ -11,7 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import java.util.Optional;
 import java.util.regex.Pattern;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
 import org.opendaylight.yangtools.yang.model.api.type.ModifierKind;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
index 4d1bcedc3c145cdfc4486efb9f4e23ba77c7ed6d..9f379abf5f9fdabe1f8e63fb9dd77452f0db9b6c 100644 (file)
@@ -11,7 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.RangeSet;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
 import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;