-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74059/
-----------------------------------------------------------
Review request for ranger, bhavik patel, Dhaval Shah, Abhay Kulkarni, Madhan
Neethiraj, Mehul Parikh, Ramesh Mani, Sailaja Polavarapu, and Velmurugan
Periasamy.
Bugs: RANGER-3824
https://issues.apache.org/jira/browse/RANGER-3824
Repository: ranger
Description
-------
**Problem Statement:**
Post request for /service/tags/resources error message is not proper for
duplicate resource.
Steps to reproduce :
1. Make post request to /service/tags/resources API
eg :
curl --location --request POST 'https://host:6182/service/tags/resources' \
--header 'Authorization: Basic auth==' \
--header 'Content-Type: application/json' \
--data-raw '{"serviceName": "cm_hdfs", "resourceElements": {"path": {"values":
["/dummy/ddddddd"]}}}
'
Response : 400 Bad Request
Exception [EclipseLink-4002
] (Eclipse Persistence Services - 2.7.7.v20200504-69f2c2b80d):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: duplicate key
value violates unique constraint
"x_service_resource_idx_svc_id_resource_signature"
Detail: Key (service_id, resource_signature)=(1,
e7bc212b933a480d3dbb6ae3b6168f0482d5d7a1646693c8ba1801ed818ca837) already
exists.
Error Code: 0
Call: INSERT INTO x_service_resource (id, ADDED_BY_ID, CREATE_TIME, guid,
is_enabled, resource_signature, service_id, service_resource_elements_text,
tags_text, UPDATE_TIME, UPD_BY_ID, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?)
bind => [
12 parameters bound
]
Expected : Error message to be proper
Condition 1 : updateIfexists = true , should update existing resource
Condition 2: updateIfexists = False , should give proper error message
**Analysis:**
If this is as per design then we don't need to fix this. However i am proposing
a solution here to fix the current behaviour.
Current behaviour:
if guid is not sent then call to TagValidator.preCreateServiceResource() could
not fetch existing matching resource based on guid and returns the null object,
however it populate the resourcesignature so that resource Signature also can
be persisted. Since there is unique constraint on serviceName and
resourceSignature field then second attempt to the API throws the error
irrespective of 'updateIfexists' value.
**Proposed solution:**
if resource is not found based on guid value or if provided guid is null then
resource can be searched again using the resourceSignature value and if records
is found then return object will be updated when updateIfexists is set to
true(default is true) else it will skip the operation and throw the error.
Diffs
-----
agents-common/src/main/java/org/apache/ranger/plugin/store/TagValidator.java
08b1e45fd
Diff: https://reviews.apache.org/r/74059/diff/1/
Testing
-------
Installed ranger admin with the patch and curl request to API is able to update
the resource object when updateIfexists is set to true. It throws an error when
object exists and updateIfexists is set to false.
Thanks,
Pradeep Agrawal