From 9b40ba8642ab884e87f9d51d53d5aa745bb5e4af Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Mon, 25 Jun 2018 16:05:42 +0200 Subject: [PATCH] return HTTP_CONFLICT (409) from POST create() in case of AlreadyExists see https://lists.opendaylight.org/pipermail/neutron-dev/2018-June/001702.html Change-Id: Idd0d65e720d209afbf993db2c202b7710ef6c9db Signed-off-by: Michael Vorburger --- .../northbound/api/AbstractNeutronNorthbound.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java b/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java index c1c1dd794..9a922c12d 100644 --- a/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java +++ b/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java @@ -7,6 +7,7 @@ */ package org.opendaylight.neutron.northbound.api; +import static org.opendaylight.neutron.spi.INeutronCRUD.Result.AlreadyExists; import static org.opendaylight.neutron.spi.INeutronCRUD.Result.DependencyMissing; import static org.opendaylight.neutron.spi.INeutronCRUD.Result.DoesNotExist; @@ -112,8 +113,11 @@ public abstract class AbstractNeutronNorthbound, R e T singleton = input.getSingleton(); singleton.initDefaults(); - if (neutronCRUD.add(singleton).equals(DependencyMissing)) { + Result result = neutronCRUD.add(singleton); + if (result.equals(DependencyMissing)) { return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build(); + } else if (result.equals(AlreadyExists)) { + return Response.status(HttpURLConnection.HTTP_CONFLICT).entity(input).build(); } } else { if (input.getBulk() == null) { @@ -121,9 +125,12 @@ public abstract class AbstractNeutronNorthbound, R e } for (T test : input.getBulk()) { test.initDefaults(); - if (neutronCRUD.add(test).equals(DependencyMissing)) { + Result result = neutronCRUD.add(test); + if (result.equals(DependencyMissing)) { LOG.warn("create failed due to input missing dependencies: {}", input); return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build(); + } else if (result.equals(AlreadyExists)) { + return Response.status(HttpURLConnection.HTTP_CONFLICT).entity(input).build(); } } } -- 2.36.6