mneethiraj commented on code in PR #1229:
URL: https://github.com/apache/ranger/pull/1229#discussion_r3993953786
##########
security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java:
##########
Review Comment:
It is unnecessary to retrieve entire `XXService` and `XXServiceDef` objects
just to verify if the service-type is KMS. I suggest optimizing by using a DB
query:
jpa_named_queries.xml:
```
<named-query name="XXService.getServiceType">
<query>select svcDef.name from XXService obj, XXServiceDef
svcDef where obj.name = :svcName and obj.type = svcDef.id</query>
</named-query>
```
XXServiceDao.java:
```
public String getServiceType(String svcName) {
try {
return getEntityManager().createNamedQuery("XXService.getServiceType",
String.class)
.setParameter("svcName", svcName)
.getSingleResult()
} catch (NoResultException ignored) {
// ignore
}
return null;
}
```
SecurityZoneREST.java:
```
XXServiceDao svcDao = daoManager.getXXService();
for (String serviceName : serviceMap.keySet()) {
String serviceType = svcDao.getServiceType(serviceName);
if
(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME.equals(serviceType)) {
throw restErrorUtil.createRESTException("Not allowed to update security
zone containing KMS service", MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]