You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "Alex Rudyy (JIRA)" <ji...@apache.org> on 2015/03/11 16:50:39 UTC

[jira] [Updated] (QPID-6438) [Java Broker] Extends REST interfaces to result in errors when object already exist on create and when object does not exist on update

     [ https://issues.apache.org/jira/browse/QPID-6438?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Rudyy updated QPID-6438:
-----------------------------
    Description: 
At the moment PUT method requests are used for both configured object creation and their updates. Our REST layer looks for ID or name( coupled with object parent) in order to decide whether it is an update request or not. Update is made when object with the same id or the same name and parent is found. Otherwise a new object is created.

We need to extend existing REST API to return errors in the following cases
* when object with the same name/id already exists on create 
* when  object does not  exists on update

The existing REST interfaces should not be affected by the change and should continue working as expected keeping backward compatibility.

The REST interfaces will be changed as depicted below

h2. CO creation

Methods PUT or POST can be used to create CO.

CO can be created by submitting PUT request to CO URI with body containing object json or by submitting PUT/POST request to parent URI.
The request encoding should be json (application/json) and request body should contain a CO json object.
On successful completion of operation a response code 201 should be returned  and response header "Location" should be set to CO URI. 
If object with a such name/id already exist and parent URI is used to create object, an error response with response code 409 (conflict) and body containing json with the reason of operation failure should be returned. On any other error, response with response code 400 (bad request) or  422 (validation error) and body containing json with the reason of operation failure should be returned.
If object with a such name/id already exist and object URI is used, then CO update should be performed.

For example, if Queue with name "my-queue" needs to be created on a virtual host with name "vh" (which is contained within virtual host node with name "vhn") either of the following requests should be made
{noformat}
PUT /api/latest/queue/vhn/vh HTTP/1.1
{noformat}
{noformat}
POST /api/latest/queue/vhn/vh HTTP/1.1
{noformat}
{noformat}
PUT /api/latest/queue/vhn/vh/my-queue HTTP/1.1
{noformat}
Response code 201 should be returned on successful queue creation. Response header "Location" should be set to "/api/latest/queue/test/my-queue".  If queue with a such name already exist with either of 2 first requests above, an error response with response code 409 (conflict) and body containing json message that queue exists should be returned. If queue with a such name already and last request is used, then CO update should occur.

h2. CO update

Methods PUT or POST can be used to update CO. Update request should be made against CO URI.
If CO does not exists and PUT method is used, such object should be created
If CO does not exists and POST method is used, an error should occur and response with error code 404 and json with error message should be returned.
The request encoding should be json (application/json) and request body should contain a CO json object (with all or changed only attributes)
On successful completion of operation a response code 200 should be returned. If any error occur on update, a response with response code 400 or 422 or 404 should be sent back to the client containing json body with error details.

 For example, if Queue with name "my-queue" is required to be updated on a virtual host with name "vh" (contained in virtual host node with name "vhn") either of the following requests should be made:
{noformat}
POST /api/latest/queue/vhn/vh/my-queue HTTP/1.1
{noformat}
{noformat}
POST /api/latest/queue/vhn/vh/my-queue HTTP/1.1
{noformat}


  was:
PUT method requests are used for both configured object creation and their updates. Our REST layer looks for ID or name( coupled with object parent) in order to decide whether it is an update request or not.
Update is made when object with the same id or the same name and parent is found. Otherwise a new object is created.

On creation of new configured objects(for example, virtual host nodes) the same name as existing object can be specified by mistake. As result, an update request is performed causing updating attributes in existing object and saving those attributes in the database. In practice, it might cause configuration issues, for instance,
if user tries to create a new BDB HA VHN and specifies an existing VHN name, the existing VHN attributes are updated and on next broker restart a new VHN with a new store can be created.

In many REST best practices it is recommended to use POST requests to create REST resources and PUT requests to update/create resources.

We can use the same approach in the Qpid REST layer, i.e. send POST requests if we definitely want to create new objects via web management console or REST

        Summary: [Java Broker] Extends REST interfaces to result in errors when object already exist on create and when object does not exist on update   (was: [Java Broker] Add support for POST method into REST interfaces in order to create configured objects via POST)

> [Java Broker] Extends REST interfaces to result in errors when object already exist on create and when object does not exist on update 
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: QPID-6438
>                 URL: https://issues.apache.org/jira/browse/QPID-6438
>             Project: Qpid
>          Issue Type: Improvement
>          Components: Java Broker
>    Affects Versions: 0.18, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30, 0.32
>            Reporter: Alex Rudyy
>            Assignee: Alex Rudyy
>             Fix For: 6.0 [Java]
>
>
> At the moment PUT method requests are used for both configured object creation and their updates. Our REST layer looks for ID or name( coupled with object parent) in order to decide whether it is an update request or not. Update is made when object with the same id or the same name and parent is found. Otherwise a new object is created.
> We need to extend existing REST API to return errors in the following cases
> * when object with the same name/id already exists on create 
> * when  object does not  exists on update
> The existing REST interfaces should not be affected by the change and should continue working as expected keeping backward compatibility.
> The REST interfaces will be changed as depicted below
> h2. CO creation
> Methods PUT or POST can be used to create CO.
> CO can be created by submitting PUT request to CO URI with body containing object json or by submitting PUT/POST request to parent URI.
> The request encoding should be json (application/json) and request body should contain a CO json object.
> On successful completion of operation a response code 201 should be returned  and response header "Location" should be set to CO URI. 
> If object with a such name/id already exist and parent URI is used to create object, an error response with response code 409 (conflict) and body containing json with the reason of operation failure should be returned. On any other error, response with response code 400 (bad request) or  422 (validation error) and body containing json with the reason of operation failure should be returned.
> If object with a such name/id already exist and object URI is used, then CO update should be performed.
> For example, if Queue with name "my-queue" needs to be created on a virtual host with name "vh" (which is contained within virtual host node with name "vhn") either of the following requests should be made
> {noformat}
> PUT /api/latest/queue/vhn/vh HTTP/1.1
> {noformat}
> {noformat}
> POST /api/latest/queue/vhn/vh HTTP/1.1
> {noformat}
> {noformat}
> PUT /api/latest/queue/vhn/vh/my-queue HTTP/1.1
> {noformat}
> Response code 201 should be returned on successful queue creation. Response header "Location" should be set to "/api/latest/queue/test/my-queue".  If queue with a such name already exist with either of 2 first requests above, an error response with response code 409 (conflict) and body containing json message that queue exists should be returned. If queue with a such name already and last request is used, then CO update should occur.
> h2. CO update
> Methods PUT or POST can be used to update CO. Update request should be made against CO URI.
> If CO does not exists and PUT method is used, such object should be created
> If CO does not exists and POST method is used, an error should occur and response with error code 404 and json with error message should be returned.
> The request encoding should be json (application/json) and request body should contain a CO json object (with all or changed only attributes)
> On successful completion of operation a response code 200 should be returned. If any error occur on update, a response with response code 400 or 422 or 404 should be sent back to the client containing json body with error details.
>  For example, if Queue with name "my-queue" is required to be updated on a virtual host with name "vh" (contained in virtual host node with name "vhn") either of the following requests should be made:
> {noformat}
> POST /api/latest/queue/vhn/vh/my-queue HTTP/1.1
> {noformat}
> {noformat}
> POST /api/latest/queue/vhn/vh/my-queue HTTP/1.1
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org