import org.opendaylight.restconf.api.QueryParameters;
import org.opendaylight.restconf.api.query.PrettyPrintParam;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.errors.RestconfFuture;
import org.opendaylight.restconf.nb.rfc8040.ErrorTagMapping;
import org.opendaylight.restconf.nb.rfc8040.URLConstants;
import org.opendaylight.restconf.server.api.OperationInputBody;
import org.opendaylight.restconf.server.api.PatchStatusContext;
import org.opendaylight.restconf.server.api.RestconfServer;
+import org.opendaylight.restconf.server.api.ServerError;
import org.opendaylight.restconf.server.api.ServerRequest;
import org.opendaylight.restconf.server.api.XmlChildBody;
import org.opendaylight.restconf.server.api.XmlDataPostBody;
return HttpStatusCode.INTERNAL_SERVER_ERROR;
}
- private @NonNull HttpStatusCode statusOfFirst(final List<RestconfError> error) {
- return errorTagMapping.statusOf(error.get(0).getErrorTag());
+ private @NonNull HttpStatusCode statusOfFirst(final List<ServerError> error) {
+ return errorTagMapping.statusOf(error.get(0).tag());
}
});
}
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.api.ApiPath;
+import org.opendaylight.restconf.api.ErrorMessage;
import org.opendaylight.restconf.api.FormattableBody;
import org.opendaylight.restconf.api.query.ContentParam;
import org.opendaylight.restconf.api.query.WithDefaultsParam;
import org.opendaylight.restconf.server.api.PatchStatusContext;
import org.opendaylight.restconf.server.api.PatchStatusEntity;
import org.opendaylight.restconf.server.api.ResourceBody;
+import org.opendaylight.restconf.server.api.ServerError;
+import org.opendaylight.restconf.server.api.ServerErrorInfo;
+import org.opendaylight.restconf.server.api.ServerErrorPath;
import org.opendaylight.restconf.server.api.ServerRequest;
import org.opendaylight.restconf.server.spi.ApiPathCanonizer;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer;
tx.create(targetNode, patchEntity.getNode());
editCollection.add(new PatchStatusEntity(editId, true, null));
} catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ editCollection.add(new PatchStatusEntity(editId, false, convertErrors(e.getErrors())));
noError = false;
}
break;
tx.delete(targetNode);
editCollection.add(new PatchStatusEntity(editId, true, null));
} catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ editCollection.add(new PatchStatusEntity(editId, false, convertErrors(e.getErrors())));
noError = false;
}
break;
tx.merge(targetNode, patchEntity.getNode());
editCollection.add(new PatchStatusEntity(editId, true, null));
} catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ editCollection.add(new PatchStatusEntity(editId, false, convertErrors(e.getErrors())));
noError = false;
}
break;
tx.replace(targetNode, patchEntity.getNode());
editCollection.add(new PatchStatusEntity(editId, true, null));
} catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ editCollection.add(new PatchStatusEntity(editId, false, convertErrors(e.getErrors())));
noError = false;
}
break;
tx.remove(targetNode);
editCollection.add(new PatchStatusEntity(editId, true, null));
} catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ editCollection.add(new PatchStatusEntity(editId, false, convertErrors(e.getErrors())));
noError = false;
}
break;
default:
editCollection.add(new PatchStatusEntity(editId, false, List.of(
- new RestconfError(ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED,
+ new ServerError(ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED,
"Not supported Yang Patch operation"))));
noError = false;
break;
if (!noError) {
tx.cancel();
ret.set(new DataYangPatchResult(
- new PatchStatusContext(databind(), patch.patchId(), List.copyOf(editCollection), false, null)));
+ new PatchStatusContext(patch.patchId(), List.copyOf(editCollection), false, null)));
return ret;
}
@Override
public void onSuccess(final CommitInfo result) {
ret.set(new DataYangPatchResult(
- new PatchStatusContext(databind(), patch.patchId(), List.copyOf(editCollection), true, null)));
+ new PatchStatusContext(patch.patchId(), List.copyOf(editCollection), true, null)));
}
@Override
public void onFailure(final Throwable cause) {
// if errors occurred during transaction commit then patch failed and global errors are reported
ret.set(new DataYangPatchResult(
- new PatchStatusContext(databind(), patch.patchId(), List.copyOf(editCollection), false,
- TransactionUtil.decodeException(cause, "PATCH", null, modelContext()).getErrors())));
+ new PatchStatusContext(patch.patchId(), List.copyOf(editCollection), false, convertErrors(
+ TransactionUtil.decodeException(cause, "PATCH", null, modelContext()).getErrors()))));
}
}, MoreExecutors.directExecutor());
return ret;
}
+ @Deprecated
+ private ServerError convertError(final RestconfError error) {
+ final var message = error.getErrorMessage();
+ final var path = error.getErrorPath();
+ final var info = error.getErrorInfo();
+
+ return new ServerError(error.getErrorType(), error.getErrorTag(),
+ message != null ? new ErrorMessage(message) : null, error.getErrorAppTag(),
+ path != null ? new ServerErrorPath(databind, path) : null,
+ info != null ? new ServerErrorInfo(info) : null);
+ }
+
+ @Deprecated
+ private List<ServerError> convertErrors(final List<RestconfError> errors) {
+ return errors.stream().map(this::convertError).collect(Collectors.toUnmodifiableList());
+ }
+
private static void insertWithPointPost(final RestconfTransaction tx, final YangInstanceIdentifier path,
final NormalizedNode data, final PathArgument pointArg, final NormalizedNodeContainer<?> readList,
final boolean before) {
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.restconf.common.errors.RestconfError;
/**
* Holder of patch status context.
*/
public record PatchStatusContext(
- @NonNull DatabindContext databind,
@NonNull String patchId,
@NonNull List<PatchStatusEntity> editCollection,
boolean ok,
- @Nullable List<RestconfError> globalErrors) implements DatabindAware {
+ @Nullable List<ServerError> globalErrors) {
public PatchStatusContext {
- requireNonNull(databind);
requireNonNull(patchId);
requireNonNull(editCollection);
}
* 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.restconf.server.api;
+import static java.util.Objects.requireNonNull;
+
import java.util.List;
-import org.opendaylight.restconf.common.errors.RestconfError;
public class PatchStatusEntity {
-
private final String editId;
- private final List<RestconfError> editErrors;
+ private final List<ServerError> editErrors;
private final boolean ok;
- public PatchStatusEntity(final String editId, final boolean ok, final List<RestconfError> editErrors) {
- this.editId = editId;
+ public PatchStatusEntity(final String editId, final boolean ok, final List<ServerError> editErrors) {
+ this.editId = requireNonNull(editId);
this.ok = ok;
this.editErrors = editErrors;
}
return ok;
}
- public List<RestconfError> getEditErrors() {
+ public List<ServerError> getEditErrors() {
return editErrors;
}
}
import javax.xml.stream.XMLStreamWriter;
import org.opendaylight.restconf.api.FormattableBody;
import org.opendaylight.restconf.api.query.PrettyPrintParam;
-import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.server.api.PatchStatusContext;
+import org.opendaylight.restconf.server.api.ServerError;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.patch.rev170222.yang.patch.status.YangPatchStatus;
import org.opendaylight.yangtools.yang.data.codec.gson.DefaultJSONValueWriter;
writer.name("ok").beginArray().nullValue().endArray();
}
- private void writeErrors(final List<RestconfError> errors, final JsonWriter writer) throws IOException {
+ private static void writeErrors(final List<ServerError> errors, final JsonWriter writer) throws IOException {
writer.name("errors").beginObject().name("error").beginArray();
- for (var restconfError : errors) {
+ for (var error : errors) {
writer.beginObject()
- .name("error-type").value(restconfError.getErrorType().elementBody())
- .name("error-tag").value(restconfError.getErrorTag().elementBody());
+ .name("error-type").value(error.type().elementBody())
+ .name("error-tag").value(error.tag().elementBody());
- final var errorPath = restconfError.getErrorPath();
+ final var errorPath = error.path();
if (errorPath != null) {
writer.name("error-path");
- status.databind().jsonCodecs().instanceIdentifierCodec()
- .writeValue(new DefaultJSONValueWriter(writer), errorPath);
+ errorPath.databind().jsonCodecs().instanceIdentifierCodec()
+ .writeValue(new DefaultJSONValueWriter(writer), errorPath.path());
}
- final var errorMessage = restconfError.getErrorMessage();
+ final var errorMessage = error.message();
if (errorMessage != null) {
- writer.name("error-message").value(errorMessage);
+ writer.name("error-message").value(errorMessage.elementBody());
}
- final var errorInfo = restconfError.getErrorInfo();
+ final var errorInfo = error.info();
if (errorInfo != null) {
- writer.name("error-info").value(errorInfo);
+ writer.name("error-info").value(errorInfo.elementBody());
}
writer.endObject();
writer.endArray().endObject();
}
- private void reportErrors(final List<RestconfError> errors, final XMLStreamWriter writer)
+ private static void reportErrors(final List<ServerError> errors, final XMLStreamWriter writer)
throws XMLStreamException {
writer.writeStartElement("errors");
for (var restconfError : errors) {
writer.writeStartElement("error-type");
- writer.writeCharacters(restconfError.getErrorType().elementBody());
+ writer.writeCharacters(restconfError.type().elementBody());
writer.writeEndElement();
writer.writeStartElement("error-tag");
- writer.writeCharacters(restconfError.getErrorTag().elementBody());
+ writer.writeCharacters(restconfError.tag().elementBody());
writer.writeEndElement();
// optional node
- final var errorPath = restconfError.getErrorPath();
+ final var errorPath = restconfError.path();
if (errorPath != null) {
writer.writeStartElement("error-path");
- status.databind().xmlCodecs().instanceIdentifierCodec().writeValue(writer, errorPath);
+ errorPath.databind().xmlCodecs().instanceIdentifierCodec().writeValue(writer, errorPath.path());
writer.writeEndElement();
}
// optional node
- final var errorMessage = restconfError.getErrorMessage();
+ final var errorMessage = restconfError.message();
if (errorMessage != null) {
writer.writeStartElement("error-message");
- writer.writeCharacters(errorMessage);
+ writer.writeCharacters(errorMessage.elementBody());
writer.writeEndElement();
}
// optional node
- final var errorInfo = restconfError.getErrorInfo();
+ final var errorInfo = restconfError.info();
if (errorInfo != null) {
writer.writeStartElement("error-info");
- writer.writeCharacters(errorInfo);
+ writer.writeCharacters(errorInfo.elementBody());
writer.writeEndElement();
}
}
import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.api.ApiPath;
+import org.opendaylight.restconf.api.ErrorMessage;
import org.opendaylight.restconf.api.query.ContentParam;
import org.opendaylight.restconf.api.query.WithDefaultsParam;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
final var editErrors = edit.getEditErrors();
assertEquals(1, editErrors.size());
final var editError = editErrors.get(0);
- assertEquals("Data does not exist", editError.getErrorMessage());
- assertEquals(ErrorType.PROTOCOL, editError.getErrorType());
- assertEquals(ErrorTag.DATA_MISSING, editError.getErrorTag());
+ assertEquals(new ErrorMessage("Data does not exist"), editError.message());
+ assertEquals(ErrorType.PROTOCOL, editError.type());
+ assertEquals(ErrorTag.DATA_MISSING, editError.tag());
}
@Override
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.api.ApiPath;
+import org.opendaylight.restconf.api.ErrorMessage;
import org.opendaylight.restconf.api.QueryParameters;
import org.opendaylight.restconf.api.query.InsertParam;
import org.opendaylight.restconf.api.query.PointParam;
assertNotNull(globalErrors);
assertEquals(1, globalErrors.size());
final var globalError = globalErrors.get(0);
- assertEquals("Data does not exist", globalError.getErrorMessage());
- assertEquals(ErrorType.PROTOCOL, globalError.getErrorType());
- assertEquals(ErrorTag.DATA_MISSING, globalError.getErrorTag());
+ assertEquals(new ErrorMessage("Data does not exist"), globalError.message());
+ assertEquals(ErrorType.PROTOCOL, globalError.type());
+ assertEquals(ErrorTag.DATA_MISSING, globalError.tag());
}
@Override
*/
package org.opendaylight.restconf.server.spi;
-import static org.mockito.Mockito.mock;
-
import java.io.IOException;
import java.util.List;
import org.junit.Test;
-import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
-import org.opendaylight.restconf.server.api.DatabindContext;
import org.opendaylight.restconf.server.api.PatchStatusContext;
import org.opendaylight.restconf.server.api.PatchStatusEntity;
+import org.opendaylight.restconf.server.api.ServerError;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
public class YangPatchStatusBodyTest extends AbstractJukeboxTest {
- private final RestconfError error = new RestconfError(ErrorType.PROTOCOL, new ErrorTag("data-exists"),
+ private final ServerError error = new ServerError(ErrorType.PROTOCOL, new ErrorTag("data-exists"),
"Data already exists");
private final PatchStatusEntity statusEntity = new PatchStatusEntity("patch1", true, null);
private final PatchStatusEntity statusEntityError = new PatchStatusEntity("patch1", false, List.of(error));
- private final DatabindContext databind = DatabindContext.ofModel(mock(EffectiveModelContext.class));
/**
* Test if per-operation status is omitted if global error is present.
*/
@Test
public void testOutputWithGlobalError() throws IOException {
- final var body = new YangPatchStatusBody(new PatchStatusContext(databind, "patch", List.of(statusEntity), false,
+ final var body = new YangPatchStatusBody(new PatchStatusContext("patch", List.of(statusEntity), false,
List.of(error)));
assertFormat("""
*/
@Test
public void testOutputWithoutGlobalError() throws IOException {
- final var body = new YangPatchStatusBody(new PatchStatusContext(databind,"patch", List.of(statusEntityError),
- false, null));
+ final var body = new YangPatchStatusBody(new PatchStatusContext("patch", List.of(statusEntityError), false,
+ null));
assertFormat("""
{